Strange implementation of CreateBitmapFromRawImage ? lazarus / 39-Graphics ---------------------------------------------------------------------- LBAWinOwns · 2007-07-12 22:31 Code: [Select]function CreateBitmapFromRawImage(const RawImage: TRawImage; var Bitmap, MaskBitmap: HBitmap; AlwaysCreateMask: boolean): boolean; {$IFDEF IF_BASE_MEMBER}virtual;{$ENDIF} function TWidgetSet.CreateBitmapFromRawImage(const RawImage: TRawImage;   var Bitmap, MaskBitmap: HBitmap; AlwaysCreateMask: boolean): boolean; begin   Bitmap:=0;   MaskBitmap:=0;   Result := false; end;           In my eyes this looks insane, but I'm a noob  :oops:. Anyway, my point is, instead of "CreateBitmapFromRawImage" doing a lot of complex tasks and then return some values for use. It just always fail the function without doing anything. I guess I have missed something, or I missuse this function. Anyway, what I want to do is this: I have my own kind of Raw Image type I have constructed. It looks like this: Code: [Select]  TGeneralRaw = class   Public     Height  : integer;     Width   : integer;     Data    : Ansistring;                 function palettetostring: ansistring; //RGB+RGB+RGB+RGB etc.     procedure Sparabitmap(bmp: TBitmap);     Palette : TPalette;     procedure palettetoimage(bmp: TBitmap;imgheight:word =50);   end;   I've made a procedure for the Sparabitmap procedure which is converting the bmp to what the Generalraw contains. my first slow procedure was basically like this: Code: [Select]       for Forer1 := 0 to self.Height-1 do         for Forer2 := 0 to self.Width-1 do           bmp.Canvas.Pixels[forer2,forer1]:=self.palette[byte(self.dat a[forer1*self.width+(forer2+1)])].Red or self.palette[byte(self.data[forer1*self.width+(forer2+1)])].Green shl 8 or self.palette[byte(self.data[forer1*self.width+(forer2+1)])].Blue shl 16 ; It worked, but was somewhat slow, so I thought I could make it like this instead, so it will be faster: Code: [Select]var RawImage:TRawImage; LazIntfImage:TLazIntfImage; BMPHandle,BMPMaskHandle:LongWord; begin RawImage.Description.Height:=self.Height; RawImage.Description.Width:=Self.Width; RawImage.Description.HasPalette:=true; RawImage.Description.PaletteColorCount:=$100; RawImage.Palette:=@Self.Palette; RawImage.Data:=@Self.Data[1];   if not CreateBitmapFromRawImage(RawImage,BMPHandle,BMPMaskHandle,false)   then     raise FPImageException.Create('Failed to create bitmaps'); bmp.CreateFromBitmapHandles(BMPHandle,BMPMaskHandle,rect(0,0,self.Widt h,self.Height)); By making this, I had manually insert the interface and implementation for the CreateBitmapFromRawImage function. When I did this, I suddenly noticed that the CreateBitmapFromRawImage implementation looks  so empty and weird and seem to give same output no matter what input(RawImage) you have. Thank you, Arash PS. Of course, I would definitely appreciate any other solution to show the image faster. (Yea, I edit the bitmap for a TImage to display it) ---------------------------------------------------------------------- Vincent Snijders · 2007-07-13 05:26 Quote from: "LBAWinOwns"Code: [Select]function CreateBitmapFromRawImage(const RawImage: TRawImage; var Bitmap, MaskBitmap: HBitmap; AlwaysCreateMask: boolean): boolean; {$IFDEF IF_BASE_MEMBER}virtual;{$ENDIF} function TWidgetSet.CreateBitmapFromRawImage(const RawImage: TRawImage;   var Bitmap, MaskBitmap: HBitmap; AlwaysCreateMask: boolean): boolean; begin   Bitmap:=0;   MaskBitmap:=0;   Result := false; end;           In my eyes this looks insane, but I'm a noob  :oops:. This is the default implementation, i.e. if not yet implemented by a widget interface. It merely does nothing and tells the caller, by setting Result to false. For an actual implementation see for example TWin32WidgetSet.CreateBitmapFromRawImage. ---------------------------------------------------------------------- LBAWinOwns · 2007-07-13 21:01 Thanks a lot Vincent! I did add the implementation for TQtWidgetSet.CreateBitmapFromRawImage in my code, I got it from the source qtwinapi.inc. The result was that the compiler said i need to declare "TQtImage". Well, going further and add it's references to my code would be to boil my code to spaghetti... So, how do I add units that are using .inc as extension? why are they .inc anyway. Once again, my goal is to get the CreateBitmapFromRawImage to work properly for me. thanks ---------------------------------------------------------------------- Vincent Snijders · 2007-07-13 21:04 If you want to use qt's createbitmapfromrawimage, set the widgetset to qt and call CreateBitMapFromRawImage in the LCLIntf unit. ---------------------------------------------------------------------- LBAWinOwns · 2007-07-14 19:55 Thanks, what is this whole widgetset and qt thing. Is it necessary to deal with it? Or can I get away with just adding LCLIntf unit and call LCLIntf.CreateBitMapFromRawImage. Since I did and it doesn't seem to go through the TWidgetSet.CreateBitmapFromRawImage . Hmm, I think I got it working fine now. But Now I got to another issue. I don't know if it's Lazarus's "fault", but is it me or is the TRawImage incomplete?, since I played a lot around with it, and never got the palette to ever really take effect upon the image. Then after getting a bit pissed, doing other stuff, then returning to my code, I suddenly noticed a the last line in the TRawImage interface was "// ToDo: add attributes for palette" So, is TRawImage incomplete? If that is the case, can I help completing it? edit: Correction: it is for the TRawImageDescription, used by TRawImage, that contains the "ToDo" commentary. ---------------------------------------------------------------------- Marc · 2007-07-16 09:24 First, TRawimage & co is beeing reworked at the moment. Second, indeed, there is no palette support. It will be added the moment it is needed by the lcl. ---------------------------------------------------------------------- LBAWinOwns · 2007-07-16 11:14 Is there any date planned on it being finished? Can I help finish it? If not, or it being released in a distant future, Do you have any idea how I can make a TImage rapidly show an Image I have saved in a raw format with a 24-bit palette and 8-bit indexing? ---------------------------------------------------------------------- Marc · 2007-07-16 11:40 Quote from: "LBAWinOwns"Is there any date planned on it being finished? Can I help finish it? Expect it this or next week Quote If not, or it being released in a distant future, Do you have any idea how I can make a TImage rapidly show an Image I have saved in a raw format with a 24-bit palette and 8-bit indexing? The fastest way is I think to add the missing implementation in TLazIntfImage (getPixel and putPixel are empty) ---------------------------------------------------------------------- theo · 2007-07-16 22:19 I don't understand exactly what you need, but maybe OpBitmap is something for you? http://www.theo.ch/lazarus/opbitmap1_5.zip It supports many Pixelformats and has Palettes. ---------------------------------------------------------------------- Marc · 2007-07-17 16:16 We need some missing code in TlazIntfImage, no other packages. TFPImage already supports all formats