unit convImages;

interface

uses windows,light,types,classes,graphics,TextImages,iniFiles,jpeg,
SysUtils,ComCtrls,ClipBrd,ExtCtrls,convinf;

var
 JPYFORMAT:Cardinal;

type
  TBlendImageMode = 0..16;
  TCellCreateEvent = procedure(name:string;flag:boolean) of object;
  TNotifyNameEvent = procedure (name:string) of object;  

  TPosInf =record
   x,y,h,w,alpha:Integer;
   mode:ShortInt;
   trans,selected:boolean;  //  ,visible
  end;

  TPathCtrl = class(TPersistent)
  public
   pathName,middlePath,scenarioName,openFileName,baseName:string;
   nowFileName:string;
   hasSummary:boolean;
   procedure Assign(Source: TPersistent);override;
  end;

 TImageParts = class(TObject)
  public
   bitmap:TBitmap;
   x,y,h,w,alpha:Integer;
   mode:ShortInt;
   selected,visible:boolean;
   constructor create();
   function getPosInf():TPosInf;
  end;

 PImageParts = ^TImageParts;
 ifMode = (ifNormal,ifmove,ifResizeAll,ifResizeV,ifResizeH,IfInit);

 TImageInfo=class(TPersistent)
 public
  noisetype,dirtype,Filter,ColorExchange,Mask,ColorMap,cash,turn:Shortint;
  Lights,loadtype:Smallint;
  flip,mirror,mmx,needClip:boolean;
  delCount,depth:Integer;
  color:TColor;
  posInf:TPosInf;
  clip:TRect;
  fileName,sectionName,flagName:string;
  procedure Assign(Source: TPersistent);override;
  procedure FreeEx();
  constructor create();
 end;

 TEDDirector=class(TImageDirector)
  procedure DrawHDC(var bitmap:TBitmap;const inf:TAnimeInf);override;
  function loadJPV(fileName:string;var bitmap:TBitmap;lcount:Integer=0):boolean;override;
 public
  Image:TImage;
  constructor create();
  function getBaseName(fileName:string):string;
  function getIniComment(fileName:string):string;  
  procedure replaceIni(items:TStrings;sections:TStrings);
  function loadJpeg(fileName:string;var bitmap:TBitmap):boolean;override;
  procedure writeSection(var iniFile:TCustomIniFile;inf:TImageInfo);
  procedure writeInitSection(var iniFile:TCustomIniFile;const inf:TImageInfo);
  function readInitSection(var iniFile:TCustomIniFile):TImageInfo;
  function readSection(var iniFile:TCustomIniFile;const section:string):TImageInfo;
 end;


procedure customizeBitmap(const inf:TImageInfo;var bitmap:TBitmap);

implementation

uses StrUtils;

procedure TPathCtrl.Assign(Source: TPersistent);
var
 newObj:TPathCtrl;
begin
 if(Source is TPathCtrl)then
 begin
  newObj:=TPathCtrl(Source);
  self.pathName:=newObj.pathName;
  self.middlePath:=newObj.middlePath;
  self.scenarioName:=newObj.scenarioName;
  self.openFileName:=newObj.openFileName;
  self.baseName:=newObj.baseName;
  self.nowFileName:=newObj.nowFileName;
  self.hasSummary:=newObj.hasSummary;
 end
 else
  inherited;
end;


constructor TImageInfo.create();
begin
 inherited;
 delCount:=0;
 clip:=Rect(-1,-1,-1,-1);
end;

procedure TImageInfo.FreeEx();
begin
 if(delCount<1)then self.Free()
 else dec(delCount);
end;

procedure TImageInfo.Assign(Source: TPersistent);
begin
 if(Source is TImageInfo)then
 begin
  with Source as TImageInfo do
  begin
   self.noisetype:=noisetype;
   self.Lights:=Lights;
   self.Filter:=Filter;
   self.ColorExchange:=ColorExchange;
   self.Mask:=Mask;
   self.ColorMap:=ColorMap;
   self.turn:=turn;
   self.flip:=flip;
   self.mirror:=mirror;
   self.dirtype:=dirtype;
   self.sectionName:=sectionName;
   self.fileName:=fileName;
   self.flagName:=flagName;
   self.needClip:=needClip;
   self.color:=color;
   self.posInf:=posInf;
   self.clip:=clip;
   self.mmx:=mmx;
  end;
 end
 else
  inherited;
end;

(*ImageParts*)
constructor TImageParts.create();
begin
 inherited;
 bitmap:=TBitmap.Create();
 bitmap.PixelFormat:=pf32bit;
 self.mode:=0;
 self.visible:=true;
 X:=0;
 Y:=0;
end;

(*オブジェクトから位置情報を作成*)
function TImageParts.getPosInf():TPosInf;
begin
 result.x:=self.x;
 result.y:=self.y;
 result.h:=self.h;
 result.w:=self.w;
 result.alpha:=self.alpha;

 if(bitmap<>nil)then
  result.trans:=self.bitmap.Transparent;

 result.mode:=self.mode;
end;


(*JPEGファイルを読み込んでビットマップ形式にする*)

constructor TEDDirector.create();
begin
 inherited;
 animation:=false;
 searched:=false;
 isSound:=false;
end;

(*どのフォルダをシナリオフォルダとするか*)
function TEDDirector.getBaseName(fileName:string):string;
var
 ini:TIniFile;
 v,i:Integer;
begin

 result:=ExtractFileDir(fileName);

 if(FileExists(fileName))then
 begin
  ini:=TIniFile.Create(fileName);
  v:=ini.ReadInteger('init','dirdepth',0);

   for i:=1 to v do
   begin
    result:=ExtractFileDir(result);
   end;

  ini.Free();
 end;

end;

function TEDDirector.getIniComment(fileName:string):string;
var
 ini:TIniFile;
begin


 if(FileExists(fileName))then
 begin
  ini:=TIniFile.Create(fileName);
  result:=ini.ReadString('init','comment','');
  ini.Free();
 end;

end;


function TEDDirector.loadJpeg(fileName:string;var bitmap:TBitmap):boolean;
var
 jImage:TJpegImage;
begin

  jImage:=TJpegImage.Create();
  jImage.Performance:=JPEG.jpBestSpeed;

  if(bitmap=nil)then
   bitmap:=TBitmap.create();

  try
   JImage.PixelFormat:=jf24Bit;
   JImage.LoadFromFile(fileName);
   bitmap.HandleType:=bmDIB;
   bitmap.PixelFormat:=pf24bit;
   bitmap.Width:=jImage.Width;
   bitmap.Height:=jImage.Height;
   bitmap.Canvas.Draw(0,0,jImage);
   result:=true;
  except
   result:=false;
  end;

  jImage.Free;

end;

(*ＪＰＹの冒頭部分を読み込み*)
function TEDDirector.readInitSection(var iniFile:TCustomIniFile):TImageInfo;
const
 section='init';
var
 vString:string;
 vArray:TIntegerDynArray;
begin
 result:=TImageInfo.Create();
 result.fileName:=iniFile.ReadString(section,'fileName','');
 result.dirtype:=iniFile.ReadInteger(section,'dirtype',-1);

 result.noisetype:=iniFile.ReadInteger(section,'noise',0);
 result.Lights:=iniFile.ReadInteger(section,'noisepoint',0);

 {if(result.fileName='')then
 begin
  result.posInf.w:=iniFile.ReadInteger(section,'backwidth',632);
  result.posInf.h:=iniFile.ReadInteger(section,'backheight',420);
 end
 else
 begin }
  result.posInf.w:=iniFile.ReadInteger(section,'backwidth',-1);
  result.posInf.h:=iniFile.ReadInteger(section,'backheight',-1);
// end;

 result.turn:=iniFile.ReadInteger(section,'turn',0);
 result.ColorExchange:=iniFile.ReadInteger(section,'colorExchange',0);
 result.Filter:=iniFile.ReadInteger(section,'filter',0);
 result.Mask:=iniFile.ReadInteger(section,'mask',0);
 result.ColorMap:=iniFile.ReadInteger(section,'colormap',0);
 result.flip:=iniFile.ReadBool(section,'flip',false);
 result.mirror:=iniFile.ReadBool(section,'mirror',false);
 result.posInf.alpha:=iniFile.ReadInteger(section,'alpha',0);

 vString:=iniFile.ReadString(section,'clip','');
 vArray:=TTagText.getIntArray(vstring,4,-1);
 result.clip:=Bounds(vArray[0],vArray[1],vArray[2],vArray[3]);
 result.needClip:=(vArray[0]>-1)and(vArray[1]>-1)
                   and(vArray[2]>0)and(VArray[3]>0);

 result.color:=
 TTagText.getColor(iniFile.ReadString(section,'backColor','0'));

end;

function TEDDirector.readSection(var iniFile:TCustomIniFile;const section:string):TImageInfo;
var
 vString:string;
 vArray:TIntegerDynArray;
begin
 result:=TImageInfo.Create();
 result.sectionName:=section;
 result.flagName:=iniFile.ReadString(section,'flagName','');
 result.fileName:=iniFile.ReadString(section,'fileName','?');
 result.dirtype:=iniFile.ReadInteger(section,'dirtype',4);
 result.posInf.w:=iniFile.ReadInteger(section,'width',-1);
 result.posInf.h:=iniFile.ReadInteger(section,'height',-1);

 vString:=iniFile.ReadString(section,'position','');
 vArray:=TTagText.getIntArray(vstring,2,0);
 result.posInf.x:=vArray[0];
 result.posInf.y:=vArray[1];

 result.posInf.mode:=iniFile.ReadInteger(section,'paintmode',0);
 result.posInf.trans:=iniFile.ReadBool(section,'transparent',true);

 result.color:=TTagText.getColor(iniFile.ReadString(section,'color','0'));

 result.noisetype:=iniFile.ReadInteger(section,'noise',0);
 result.Lights:=iniFile.ReadInteger(section,'noisepoint',0);
 result.turn:=iniFile.ReadInteger(section,'turn',0);
 result.ColorExchange:=iniFile.ReadInteger(section,'colorExchange',0);
 result.Filter:=iniFile.ReadInteger(section,'filter',0);
 result.Mask:=iniFile.ReadInteger(section,'mask',0);
 result.ColorMap:=iniFile.ReadInteger(section,'colormap',0);
 result.flip:=iniFile.ReadBool(section,'flip',false);
 result.mirror:=iniFile.ReadBool(section,'mirror',false);
 result.posInf.alpha:=iniFile.ReadInteger(section,'alpha',0);

 vString:=iniFile.ReadString(section,'clip','');
 vArray:=TTagText.getIntArray(vstring,4,-1);
 result.clip:=Bounds(vArray[0],vArray[1],vArray[2],vArray[3]);

 result.needClip:=(vArray[0]>-1)and(vArray[1]>-1)
                   and(vArray[2]>0)and(VArray[3]>0);



end;

procedure TEDDirector.writeInitSection(var iniFile:TCustomIniFile;const inf:TImageInfo);
var
 v:Cardinal;
const
 section='init';
begin

 if(inf.depth>0)then
  iniFile.WriteInteger(section,'dirdepth',inf.depth)
 else
  iniFile.DeleteKey(section,'dirdepth');

 if(inf.fileName<>'')then
  iniFile.WriteString(section,'fileName',inf.fileName)
 else
  iniFile.DeleteKey(section,'fileName');

 if(inf.dirtype>-1)then
  iniFile.WriteInteger(section,'dirtype',inf.dirtype)
 else
  iniFile.DeleteKey(section,'dirtype');

 if(inf.posInf.w>0)then
  iniFile.WriteInteger(section,'backwidth',inf.posInf.w)
 else
  iniFile.WriteInteger(section,'backwidth',632);

 if(inf.posInf.h>0)then
  iniFile.WriteInteger(section,'backheight',inf.posInf.h)
 else
  iniFile.WriteInteger(section,'backheight',420);

 if(inf.Filter<>0)then
  iniFile.WriteInteger(section,'filter',inf.Filter)
 else
  iniFile.DeleteKey(section,'filter');

 if(inf.ColorExchange<>0)then
  iniFile.WriteInteger(section,'colorExchange',inf.ColorExchange)
 else
  iniFile.DeleteKey(section,'colorExchange');

 if(inf.ColorMap<>0)then
  iniFile.WriteInteger(section,'colorMap',inf.ColorMap)
 else
  iniFile.DeleteKey(section,'colorMap');

 if(inf.Mask<>0)then
  iniFile.WriteInteger(section,'mask',inf.Mask)
 else
  iniFile.DeleteKey(section,'mask');

 v:=TTagText.covertColor(inf.color);
 iniFile.WriteString(section,'backcolor','$'+IntToHex(v,6));

 if(inf.noisetype<>0)or(inf.Lights<>0)then
 begin
  iniFile.WriteInteger(section,'noisepoint',inf.Lights);
  iniFile.WriteInteger(section,'noise',inf.noisetype);
 end
 else
 begin
  iniFile.DeleteKey(section,'noise');
  iniFile.DeleteKey(section,'noisepoint');
 end;

 if(inf.posInf.alpha<>0)then
  iniFile.WriteInteger(section,'alpha',inf.posInf.alpha)
 else
  iniFile.DeleteKey(section,'alpha');

 if(inf.mirror)then
  iniFile.WriteBool(section,'mirror',inf.mirror)
 else
  iniFile.DeleteKey(section,'mirror');

 if(inf.flip)then
  iniFile.WriteBool(section,'flip',inf.flip)
 else
  iniFile.DeleteKey(section,'flip');

 if(inf.turn<>0)then
  iniFile.WriteInteger(section,'turn',inf.turn)
 else
  iniFile.DeleteKey(section,'turn');

 inf.FreeEx();
end;

procedure TEDDirector.writeSection(var iniFile:TCustomIniFile;inf:TImageInfo);
var
 section:string;
 v:Cardinal;
begin
 section:=inf.sectionName;

 if(inf.flagName<>'')then
  iniFile.WriteString(section,'flagName',inf.flagName)
 else
  iniFile.DeleteKey(section,'flagName');

 if(inf.dirtype>-1)then
  iniFile.WriteInteger(section,'dirtype',inf.dirtype)
 else
  iniFile.DeleteKey(section,'dirtype');
  
 iniFile.WriteString(section,'fileName',inf.fileName);
 if(inf.fileName='')then
 begin
  v:=TTagText.covertColor(inf.color);
  iniFile.WriteString(section,'color','$'+IntToHex(v,6));
 end;
 

 if(inf.posInf.w>-1)then
  iniFile.WriteInteger(section,'width',inf.posInf.w)
 else
  iniFile.DeleteKey(section,'width');

 if(inf.posInf.h>-1)then
  iniFile.WriteInteger(section,'height',inf.posInf.h)
 else
  iniFile.DeleteKey(section,'height');


 
 iniFile.WriteString(section,'position',
  IntToStr(inf.posInf.x)+','+IntToStr(inf.posInf.y));

 iniFile.WriteInteger(section,'paintmode',inf.posInf.mode);
 iniFile.WriteBool(section,'transparent',inf.posInf.trans);

 if(inf.Filter<>0)then
  iniFile.WriteInteger(section,'filter',inf.Filter)
 else
  iniFile.DeleteKey(section,'filter');

 if(inf.ColorExchange<>0)then
  iniFile.WriteInteger(section,'colorExchange',inf.ColorExchange)
 else
  iniFile.DeleteKey(section,'colorExchange');

 if(inf.ColorMap<>0)then
  iniFile.WriteInteger(section,'colorMap',inf.ColorMap)
 else
  iniFile.DeleteKey(section,'colorMap');

 if(inf.Mask<>0)then
  iniFile.WriteInteger(section,'mask',inf.Mask)
 else
  iniFile.DeleteKey(section,'mask');

 if(inf.noisetype<>0)or(inf.Lights<>0)then
 begin
  iniFile.WriteInteger(section,'noisepoint',inf.Lights);
  iniFile.WriteInteger(section,'noise',inf.noisetype);
 end
 else
 begin
  iniFile.DeleteKey(section,'noise');
  iniFile.DeleteKey(section,'noisepoint');
 end;

 if(inf.posInf.alpha<>0)then
  iniFile.WriteInteger(section,'alpha',inf.posInf.alpha)
 else
  iniFile.DeleteKey(section,'alpha');

 if(inf.mirror)then
  iniFile.WriteBool(section,'mirror',inf.mirror)
 else
  iniFile.DeleteKey(section,'mirror');

 if(inf.flip)then
  iniFile.WriteBool(section,'flip',inf.flip)
 else
  iniFile.DeleteKey(section,'flip');

 if(inf.turn<>0)then
  iniFile.WriteInteger(section,'turn',inf.turn)
 else
  iniFile.DeleteKey(section,'turn');

 inf.FreeEx(); 
end;

procedure TEDDirector.replaceIni(items:TStrings;sections:TStrings);
var
 dest:TStringList;
 i,row:Integer;
 s:string;
begin
 dest:=TStringList.Create();
 try

  for i:=0 to sections.Count-1 do
  begin
   row:=items.IndexOf('['+sections[i]+']');

   if(row>-1)then
    repeat
     s:=items.Strings[row];
     dest.Add(s);
     inc(row);
    until (row>items.Count-1)or
    (AnsiStartsText('[',items.Strings[row]));

  end;

  items.Assign(dest);
 finally
  
  dest.Free();
 end;

end;

procedure TEDDirector.DrawHDC(var bitmap:TBitmap;const inf:TAnimeInf);
var
 copybitmap:TBitmap;
 union:TRect;
 paintInf:TPaintInf;
begin

   try
     if(needErase=3)then  //滑らか画像
     begin
      copyBitmap:=TBitmap.Create();
      copyBitmap.PixelFormat:=pf32bit;
      try
       unionRect(union,Bounds(resumePoint.X,resumePoint.Y,resumeBitmap.Width,resumeBitmap.Height),
        Bounds(inf.x,inf.y,bitmap.Width,bitmap.Height));
       copyBitmap.Width:=union.Right - union.Left;
       copyBitmap.Height:=union.Bottom - union.Top;
       bitblt(copyBitmap.Canvas.Handle,0,0,copyBitmap.Width,copyBitmap.Height,
        Image.Canvas.Handle,//cwdc,
        union.Left,union.Top,SrcCopy);
       bitblt(copyBitmap.Canvas.Handle,resumePoint.X-union.Left,
        resumePoint.Y-union.Top,resumeBitmap.Width,resumeBitmap.Height,
        resumeBitmap.Canvas.Handle,0,0,SrcCopy);

       if(inf.animemode>1)then
       begin
        resumeBitmap.Width:=bitmap.Width;
        resumeBitmap.Height:=bitmap.Height;
        bitBlt(resumeBitmap.Canvas.Handle,0,0,bitmap.Width,bitmap.Height,
         copyBitmap.Canvas.Handle,inf.x-union.Left,inf.y-union.Top,SrcCopy);
       end;

       paintInf.isClip:=inf.isClip;
       paintInf.destX:=inf.cx-union.Left;
       paintInf.destY:=inf.cy-union.Top;
       paintInf.destW:=inf.cw;
       paintInf.destH:=inf.ch;
       paintInf.srcX:=inf.x-union.Left;
       paintInf.srcY:=inf.y-union.Top; 
       paintInf.srcH:=inf.h; //bitmap.Height;
       paintInf.srcW:=inf.w; //bitmap.Width;
       paintInf.alpha:=inf.alpha;
       paintInf.mode:=inf.paintMode;
       adCanvas.setBitmap(copyBitmap);
     //  Handle:=copyBitmap.Canvas.Handle;
       adCanvas.StretchDrawEx(bitmap,paintInf);
    //   releaseDC(0,adCanvas.Handle);
    //   adCanvas.Handle:=0;
      
       bitBlt(Image.Canvas.Handle,//cwdc,
       union.Left,union.Top,copyBitmap.Width,
        copyBitmap.Height,copyBitmap.Canvas.Handle,0,0,SrcCopy);

      finally
       copyBitmap.Free();
      end;

     end
     else
     begin



      if(needErase=2)then  //元に戻すだけなので高速描画
      begin

       BitBlt(Image.Canvas.Handle,//cwdc,
       resumePoint.X,resumePoint.Y,
              resumeBitmap.Width,resumeBitmap.Height,resumeBitmap.Canvas.Handle,
              0,0,srccopy);
      end;

      if(inf.animemode>1)then
      begin
      if(self.resumeBitmap=nil)then
       begin
        resumeBitmap:=TBitmap.Create();
        resumeBitmap.PixelFormat:=pf32bit;
        resumeBitmap.Transparent:=false;
       end;

      resumeBitmap.Width:=bitmap.Width;
      resumeBitmap.Height:=bitmap.Height;

      bitBlt(resumeBitmap.Canvas.Handle,0,0,resumeBitmap.Width,
       resumeBitmap.Height,Image.Canvas.Handle,//cwdc,
       inf.x,inf.y,SrcCopy);
      end;

     paintInf.isClip:=inf.isClip;
     paintInf.destX:=inf.cx;
     paintInf.destY:=inf.cy;
     paintInf.destW:=inf.cw;
     paintInf.destH:=inf.ch;
     paintInf.srcX:=inf.x;
     paintInf.srcY:=inf.y;
     paintInf.srcH:=inf.h; //bitmap.Height;
     paintInf.srcW:=inf.w;
      //bitmap.Width;
     paintInf.alpha:=inf.alpha;
     paintInf.mode:=inf.paintMode;

     adCanvas.setBitmap(Image.Picture.Bitmap);
   //  .Handle:=Image.Canvas.Handle;
     adCanvas.StretchDrawEx(bitmap,paintInf);
   //   bounds(inf.x,inf.y,bitmap.Width,bitmap.Height),bitmap,inf.paintmode,inf.alpha);
  //   releaseDC(whandle,adCanvas.Handle);
   //  adCanvas.Handle:=0;

     end;
      needErase:=inf.animemode;
      resumePoint:=Point(inf.x,inf.y);
  //  end;
   
  // if(animation)then self.animation:=waitTime(Inf.wait);
    if(Image<>nil)then Image.Repaint();
   finally
    
   end;
 // end;

 // end;

end;

procedure customizeBitmap(const inf:TImageInfo;var bitmap:TBitmap);
var
 v:Integer;
begin

 bitmap.PixelFormat:=pf32bit;

  if(inf.clip.Left>-1)and(inf.clip.Top>-1)
   and(inf.clip.Right>inf.clip.Left)and(inf.clip.Bottom>inf.clip.Top)then
  begin
   light.EffectClip(bitmap,inf.clip);
  end;

 if(inf.ColorExchange>0)then
  light.EffectShiftRGB(bitmap,inf.ColorExchange);

  case inf.Filter of
      8:light.EffectKakusan(bitmap);
     10:light.EffectEnbos(bitmap);
      9:light.EffectNOTMask(bitmap);
      7:bitmap.Mask(bitmap.Canvas.Pixels[0,0]);
   1..6:light.EffectCustom(bitmap,inf.Filter);
  end;

 if(inf.ColorMap>0)then
  light.EffectSepia(bitmap,inf.ColorMap);
                                      
 if(inf.flip)then light.EffectFlip(bitmap);

 if(inf.mirror)then light.EffectMirror(bitmap);

 case inf.noisetype of
  1:light.EffectLightMode(bitmap,inf.Lights);
  2:light.EffectMono(bitmap,inf.Lights);
  3:light.EffectNoize(bitmap,inf.Lights,1);
  4:light.EffectNoize(bitmap,inf.Lights,1);
  5:light.EffectsMosaic(bitmap,inf.Lights);  
 end;

 if(inf.Mask>0)then
  light.EffectThreadLine(bitmap,inf.Mask);

 case inf.turn of
  1:
  begin
   light.EffectsTurn90(bitmap);
   v:=inf.posInf.w;
   inf.posInf.w:=inf.posInf.h;
   inf.posInf.h:=v;
  end;
  2:
  begin
   light.EffectsTurn270(bitmap);
   v:=inf.posInf.w;
   inf.posInf.w:=inf.posInf.h;
   inf.posInf.h:=v;
  end;
 end;



 bitmap.TransparentColor:=bitmap.Canvas.Pixels[0,0];
 inf.FreeEx();
end;

(*現在のウィンドウを取得*)
function TEDDirector.loadJPV(fileName:string;var bitmap:TBitmap;lcount:Integer=0):boolean;
var
 ini:TMemIniFile;
 x,y,mode:Integer;
 s:string;
 vArray:TIntegerDynArray;
const
 DEFCOPY=0;
 PRECOPY=1;
 METACOPY=2;
 None=3;
begin

  if(bitmap=nil)then
   bitmap:=TBitmap.Create();

  bitmap.PixelFormat:=pf32bit;
  ini:=TMemIniFile.Create(fileName);
  try
   s:=ini.ReadString('jpdc:init','clip','');
   mode:=ini.ReadInteger('jpdc:init','copymode',DEFCOPY);

   vArray:=TTagText.getIntArray(s,4,-1);
   if(vArray[0]>-1)then x:=vArray[0]
   else x:=0;
   if(vArray[1]>-1)then y:=vArray[1]
   else y:=0;
   if(vArray[2]>0)then bitmap.Width:=vArray[2]
   else bitmap.Width:=632-x;
   if(vArray[3]>0)then bitmap.Height:=vArray[3]
   else bitmap.Height:=420-y;
  finally
   ini.Free();
  end;

  if(Image<>nil)then
  begin
   if(mode=none)then
   begin
    bitmap.Canvas.Brush.Color:=clwhite;
    bitmap.Canvas.FillRect(bitmap.Canvas.ClipRect);
   end
   else
    bitblt(bitmap.Canvas.Handle,0,0,bitmap.Width,bitmap.Height,
     Image.Canvas.Handle,x,y,srccopy);
   result:=true;
  end
  else
  begin
   result:=false;
  end;


end;



end.
