Forum > Graphics
Strange implementation of CreateBitmapFromRawImage ?
LBAWinOwns:
--- Code: ---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;
--- End code ---
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: --- 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;
--- End code ---
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: ---
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.data[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 ;
--- End code ---
It worked, but was somewhat slow, so I thought I could make it like this instead, so it will be faster:
--- Code: ---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.Width,self.Height));
--- End code ---
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:
--- Quote from: "LBAWinOwns" ---
--- Code: ---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;
--- End code ---
In my eyes this looks insane, but I'm a noob :oops:.
--- End quote ---
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:
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:
If you want to use qt's createbitmapfromrawimage, set the widgetset to qt and call CreateBitMapFromRawImage in the LCLIntf unit.
LBAWinOwns:
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.
Navigation
[0] Message Index
[#] Next page