Browse Source

+ Added .assign method

michael 22 years ago
parent
commit
f9c0c12ac2
3 changed files with 40 additions and 2 deletions
  1. 35 0
      fcl/image/fpimage.inc
  2. 2 1
      fcl/image/fpimage.pp
  3. 3 1
      fcl/image/fpwritexpm.pp

+ 35 - 0
fcl/image/fpimage.inc

@@ -294,3 +294,38 @@ begin
 end;
 end;
 
 
 
 
+Procedure TFPCustomImage.Assign(Source: TPersistent);
+
+Var
+  Src : TFPCustomImage;
+  X,Y : Integer;
+
+begin
+  If Source is TFPCustomImage then
+    begin
+    Src:=TFPCustomImage(Source);
+    // Copy extra info
+    FExtra.Assign(Src.Fextra);
+    // Copy palette if needed.
+    UsePalette:=Src.UsePalette;
+    If UsePalette then
+      begin
+      Palette.Count:=0;
+      Palette.Build(Src);
+      end;
+    // Copy image.  
+    SetSize(Src.Width,Src.height);
+    If UsePalette then
+      For x:=0 to Src.Width-1 do
+        For y:=0 to src.Height-1 do
+          pixels[X,Y]:=src.pixels[X,Y]
+    else  
+      For x:=0 to Src.Width-1 do
+        For y:=0 to src.Height-1 do
+          self[X,Y]:=src[X,Y];
+    end
+  else  
+    Inherited Assign(Source);
+end;
+
+    

+ 2 - 1
fcl/image/fpimage.pp

@@ -72,7 +72,7 @@ type
       property Count : integer read GetCount write SetCount;
       property Count : integer read GetCount write SetCount;
   end;
   end;
 
 
-  TFPCustomImage = class
+  TFPCustomImage = class(TPersistent)
     private
     private
       FOnProgress : TFPImgProgressEvent;
       FOnProgress : TFPImgProgressEvent;
       FExtra : TStringlist;
       FExtra : TStringlist;
@@ -106,6 +106,7 @@ type
     public
     public
       constructor create (AWidth,AHeight:integer); virtual;
       constructor create (AWidth,AHeight:integer); virtual;
       destructor destroy; override;
       destructor destroy; override;
+      procedure Assign(Source: TPersistent); override;
       // Saving and loading
       // Saving and loading
       procedure LoadFromStream (Str:TStream; Handler:TFPCustomImageReader);
       procedure LoadFromStream (Str:TStream; Handler:TFPCustomImageReader);
       procedure LoadFromFile (const filename:String; Handler:TFPCustomImageReader);
       procedure LoadFromFile (const filename:String; Handler:TFPCustomImageReader);

+ 3 - 1
fcl/image/fpwritexpm.pp

@@ -32,8 +32,10 @@ function ColorToHex (c:TFPColor; size:integer) : string;
 var fmt : string;
 var fmt : string;
     l : integer;
     l : integer;
 begin
 begin
+{
   with c do
   with c do
     write ('color=',red,',',green,',',blue,',',alpha);
     write ('color=',red,',',green,',',blue,',',alpha);
+}
   l := size div 3;
   l := size div 3;
   fmt := inttostr(l);
   fmt := inttostr(l);
   fmt := '%'+fmt+'.'+fmt+'x';
   fmt := '%'+fmt+'.'+fmt+'x';
@@ -88,7 +90,7 @@ begin
     for r := 0 to c-1 do
     for r := 0 to c-1 do
       begin
       begin
       if img.palette[r] <> colTransparent then
       if img.palette[r] <> colTransparent then
-        l.Add (format('"%s c #%s",',[p[r],ColorToHex(img.palette.color[r],12)]))
+        l.Add (format('"%s c #%s",',[p[r],ColorToHex(img.palette.color[r],6)]))
       else
       else
         l.Add (format('"%s c None",',[p[r]]));
         l.Add (format('"%s c None",',[p[r]]));
       end;
       end;