Pārlūkot izejas kodu

+ setting image attributes when loading images
* fixing copyright section in the file header

mazen 22 gadi atpakaļ
vecāks
revīzija
d76b345184
1 mainītis faili ar 40 papildinājumiem un 33 dzēšanām
  1. 40 33
      fcl/image/fpreadbmp.pp

+ 40 - 33
fcl/image/fpreadbmp.pp

@@ -1,7 +1,8 @@
+{*****************************************************************************}
 {
     $Id$
-    This file is part of the Free Pascal run time library.
-    Copyright (c) 2003 by the Free Pascal development team
+    This file is part of the Free Pascal's "Free Components Library".
+    Copyright (c) 2003 by Mazen NEIFER of the Free Pascal development team
 
     BMP writer implementation.
     
@@ -11,8 +12,8 @@
     This program is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-
- **********************************************************************}
+}
+{*****************************************************************************}
 {$mode objfpc}{$h+}
 unit FPReadBMP;
 
@@ -58,9 +59,6 @@ implementation
 
 uses BMPcomn;
 
-const
-  WhiteSpace = ' '#8#10#13;
-
 constructor TFPReaderBMP.create;
 begin
   inherited create;
@@ -85,37 +83,42 @@ procedure TFPReaderBMP.InternalRead(Stream:TStream; Img:TFPCustomImage);
   begin
     Stream.Read(BFI,SizeOf(BFI));
     with BFI do
-      if(bitCount = 8)
-      then
-        begin
-//          stream.read(Palet, bfh.bfOffset - 54);
-        end
+      begin
+        Img.Width:=Width;
+        Img.Height:=Height;
+        BytesPerPixel:=BitCount SHR 3;
+      end;
+    if BytesPerPixel=1
+    then
+      begin
+//        stream.read(Palet, bfh.bfOffset - 54);
+      end
 {Treating the 24bit BMP files}
-      else
-        begin
-          nBpLine:=Img.Width*SizeOf(TColorRGB);
-          ReadSize:=(nBpLine+3)AND $FFFFFFFC;//BMP needs evry line 4Bytes aligned
+    else
+      begin
+        nBpLine:=Img.Width*SizeOf(TColorRGB);
+        ReadSize:=(nBpLine+3)AND $FFFFFFFC;//BMP needs evry line 4Bytes aligned
 {$IFDEF UseDynArray}
-          SetLength(aLine,Img.Width+1);//3 extra byte for BMP 4Bytes alignement.
+        SetLength(aLine,Img.Width+1);//3 extra byte for BMP 4Bytes alignement.
 {$ELSE UseDynArray}
-          GetMem(aLine,(Img.Width+1)*SizeOf(TColorRGB));//3 extra byte for BMP 4Bytes alignement.
+        GetMem(aLine,(Img.Width+1)*SizeOf(TColorRGB));//3 extra byte for BMP 4Bytes alignement.
 {$ENDIF UseDynArray}
-          for Row:=img.Height-1 downto 0 do
-            begin
-              for Coulumn:=0 to img.Width-1 do
-                with aLine[Coulumn],aColor do
-                  begin
+        for Row:=img.Height-1 downto 0 do
+          begin
+            for Coulumn:=0 to img.Width-1 do
+              with aLine[Coulumn],aColor do
+                begin
 {Use only the high byte to convert the color}
-                    Red:=R shl 8;
-                    Green:=G shl 8;
-                    Blue:=B shl 8;
-                    img.colors[Coulumn,Row]:=aColor;
-                  end;
-              Stream.Write(aLine{$IFNDEF UseDynArray}^{$ENDIF UseDynArray},ReadSize);
-            end;
-        end;
+                  Red:=R shl 8;
+                  Green:=G shl 8;
+                  Blue:=B shl 8;
+                  img.colors[Coulumn,Row]:=aColor;
+                end;
+            Stream.Write(aLine{$IFNDEF UseDynArray}^{$ENDIF UseDynArray},ReadSize);
+          end;
+      end;
 {$IFNDEF UseDynArray}
-          FreeMem(aLine,(Img.Width+1)*SizeOf(TColorRGB));
+        FreeMem(aLine,(Img.Width+1)*SizeOf(TColorRGB));
 {$ENDIF UseDynArray}
   end;
 
@@ -140,7 +143,11 @@ initialization
 end.
 {
 $Log$
-Revision 1.1  2003-09-08 14:10:10  mazen
+Revision 1.2  2003-09-09 11:26:59  mazen
++ setting image attributes when loading images
+* fixing copyright section in the file header
+
+Revision 1.1  2003/09/08 14:10:10  mazen
 + adding support for loading bmp images
 
 }