Recent

Author Topic: Strange implementation of CreateBitmapFromRawImage ?  (Read 13370 times)

LBAWinOwns

  • New Member
  • *
  • Posts: 13
Strange implementation of CreateBitmapFromRawImage ?
« on: July 13, 2007, 12:31:21 am »
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.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 ;


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.Width,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

  • Administrator
  • Hero Member
  • *
  • Posts: 2661
    • My Lazarus wiki user page
Re: Strange implementation of CreateBitmapFromRawImage ?
« Reply #1 on: July 13, 2007, 07:26:45 am »
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

  • New Member
  • *
  • Posts: 13
RE: Re: Strange implementation of CreateBitmapFromRawImage ?
« Reply #2 on: July 13, 2007, 11:01:42 pm »
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

  • Administrator
  • Hero Member
  • *
  • Posts: 2661
    • My Lazarus wiki user page
RE: Re: Strange implementation of CreateBitmapFromRawImage ?
« Reply #3 on: July 13, 2007, 11:04:27 pm »
If you want to use qt's createbitmapfromrawimage, set the widgetset to qt and call CreateBitMapFromRawImage in the LCLIntf unit.

LBAWinOwns

  • New Member
  • *
  • Posts: 13
RE: Re: Strange implementation of CreateBitmapFromRawImage ?
« Reply #4 on: July 14, 2007, 09:55:11 pm »
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

  • Administrator
  • Hero Member
  • *
  • Posts: 2584
RE: Re: Strange implementation of CreateBitmapFromRawImage ?
« Reply #5 on: July 16, 2007, 11:24:37 am »
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.
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

LBAWinOwns

  • New Member
  • *
  • Posts: 13
RE: Re: Strange implementation of CreateBitmapFromRawImage ?
« Reply #6 on: July 16, 2007, 01:14:09 pm »
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

  • Administrator
  • Hero Member
  • *
  • Posts: 2584
Re: RE: Re: Strange implementation of CreateBitmapFromRawIma
« Reply #7 on: July 16, 2007, 01:40:38 pm »
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)
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1927
RE: Re: RE: Re: Strange implementation of CreateBitmapFromRa
« Reply #8 on: July 17, 2007, 12:19:28 am »
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

  • Administrator
  • Hero Member
  • *
  • Posts: 2584
RE: Re: RE: Re: Strange implementation of CreateBitmapFromRa
« Reply #9 on: July 17, 2007, 06:16:24 pm »
We need some missing code in TlazIntfImage, no other packages. TFPImage already supports all formats
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

 

TinyPortal © 2005-2018