Re: [lazarus] Scanlines again
On Sat, 05 Jan 2008 19:14:51 + Dominique Louis <[EMAIL PROTECTED]> wrote: > Firstly, I'd like to propose a slight change to the scanlines example > so that it is easier for developers to follow the code and to > possibly incorporate bits of it into their own code. > > type >TBGRA = packed record > b, g, r, a : byte; >end; >PBGRA = ^TBGRA; >TBGRAArray = array[ WORD ] of TBGRA; >PBGRAArray = ^TBGRAArray; > > > procedure TForm1.PaintToRGB32bitScanLine(Row, ImgWidth: integer; >LineStart: Pointer); > // LineStart is pointer to the start of a scanline with the following > format: > // 4 bytes per pixel. First byte is blue, second green, third is red. > // the fourth byte is the Alpha value, which is not specified in this > // example > // Black is 0,0,0, white is 255,255,255 > var >i: Integer; >lrow : PBGRAArray > begin >lrow := PBGRAArray( LineStart ) > >// fill line with gray >for i := 0 to ImgWidth - 1 do >begin > lrow^[ i ].r := 128; // set red to 128 > lrow^[ i ].g := 128; // set green to 128 > lrow^[ i ].b := 128; // set blue to 128 >end; >// set one diagonal pixel to red ( this creates a diagonal red > line ) lrow^[ ( Row mod ImgWidth ) ].r := 255; // set red to 255 - > full intensity >lrow^[ ( Row mod ImgWidth ) ].g := 0; // set green to 0 >lrow^[ ( Row mod ImgWidth ) ].b := 0; // set blue to 0 > end; > > > I think this is a lot easier to understand than the previous version. Ok. Can you create a patch? > Secondly, I have a scanline issue that I hope someone on here can > help with. I have 2 TImages on a Form ( I'm using Mac OS X if that > makes any difference ) one contains an image of a yellow light bulb. > I want to copy, pixel by pixel, the image from one TImage over to the > second TImage. Yes I know I could just assign the bitmap from one to > the other, but this is an exercise in Scanline manipulation. The > problem I have is that once copied the second TImage contains a blue > light bulb instead of a yellow one. > > The code I'm using is.. >MyBitmap := TBitmap.Create; >ScanLineImage := Image1.Picture.Bitmap.CreateIntfImage; >MyBitmap.Width := ScanLineImage.Width; >MyBitmap.Height:= ScanLineImage.Height; >IntfImage := MyBitmap.CreateIntfImage; >ImgFormatDescription.Init_BPP32_B8G8R8_BIO_TTB( ScanLineImage.Width, > ScanLineImage.Height ); >IntfImage.DataDescrption := ImgFormatDescription; > >for y := 0 to ScanLineImage.Height do Height-1 >begin > lrow := ScanLineImage.GetDataLineStart( y ); > brow := IntfImage.GetDataLineStart( y ); What's brow? > for x := 0 to ScanLineImage.Width do Width-1 > begin >brow^[ x ].r := lrow^[ x ].r; // set red >brow^[ x ].g := lrow^[ x ].g; // set green >brow^[ x ].b := lrow^[ x ].b; // set blue >brow^[ x ].a := lrow^[ x ].a; // set alpha value > end; >end; > >MyBitmap.LoadFromIntfImage( IntfImage ); >Image2.Picture.Bitmap := MyBitmap; > > > Can anyone see a flaw in my logic of using scanlines for this/this > way? Yes. MyBitmap.LoadFromIntfImage( IntfImage ) does no conversion. You created an image with the format ImgFormatDescription.Init_BPP32_B8G8R8_BIO_TTB which is probably not the format of your platform. Solution: Don't use ScanLine, but use the Colors property of IntfImage. See the examples/lazintfimage/fadein1.lpi. Mattias _ To unsubscribe: mail [EMAIL PROTECTED] with "unsubscribe" as the Subject archives at http://www.lazarus.freepascal.org/mailarchives
Re: [lazarus] Scanlines again
Hi Mattias, Using Mac OS X how do I create a patch? If you can tell me what I need to download/install then I'm happy to do that. Dominique. Mattias Gaertner wrote: On Sat, 05 Jan 2008 19:14:51 + Dominique Louis <[EMAIL PROTECTED]> wrote: Firstly, I'd like to propose a slight change to the scanlines example so that it is easier for developers to follow the code and to possibly incorporate bits of it into their own code. type TBGRA = packed record b, g, r, a : byte; end; PBGRA = ^TBGRA; TBGRAArray = array[ WORD ] of TBGRA; PBGRAArray = ^TBGRAArray; procedure TForm1.PaintToRGB32bitScanLine(Row, ImgWidth: integer; LineStart: Pointer); // LineStart is pointer to the start of a scanline with the following format: // 4 bytes per pixel. First byte is blue, second green, third is red. // the fourth byte is the Alpha value, which is not specified in this // example // Black is 0,0,0, white is 255,255,255 var i: Integer; lrow : PBGRAArray begin lrow := PBGRAArray( LineStart ) // fill line with gray for i := 0 to ImgWidth - 1 do begin lrow^[ i ].r := 128; // set red to 128 lrow^[ i ].g := 128; // set green to 128 lrow^[ i ].b := 128; // set blue to 128 end; // set one diagonal pixel to red ( this creates a diagonal red line ) lrow^[ ( Row mod ImgWidth ) ].r := 255; // set red to 255 - full intensity lrow^[ ( Row mod ImgWidth ) ].g := 0; // set green to 0 lrow^[ ( Row mod ImgWidth ) ].b := 0; // set blue to 0 end; I think this is a lot easier to understand than the previous version. Ok. Can you create a patch? Secondly, I have a scanline issue that I hope someone on here can help with. I have 2 TImages on a Form ( I'm using Mac OS X if that makes any difference ) one contains an image of a yellow light bulb. I want to copy, pixel by pixel, the image from one TImage over to the second TImage. Yes I know I could just assign the bitmap from one to the other, but this is an exercise in Scanline manipulation. The problem I have is that once copied the second TImage contains a blue light bulb instead of a yellow one. The code I'm using is.. MyBitmap := TBitmap.Create; ScanLineImage := Image1.Picture.Bitmap.CreateIntfImage; MyBitmap.Width := ScanLineImage.Width; MyBitmap.Height:= ScanLineImage.Height; IntfImage := MyBitmap.CreateIntfImage; ImgFormatDescription.Init_BPP32_B8G8R8_BIO_TTB( ScanLineImage.Width, ScanLineImage.Height ); IntfImage.DataDescrption := ImgFormatDescription; for y := 0 to ScanLineImage.Height do Height-1 begin lrow := ScanLineImage.GetDataLineStart( y ); brow := IntfImage.GetDataLineStart( y ); What's brow? for x := 0 to ScanLineImage.Width do Width-1 begin brow^[ x ].r := lrow^[ x ].r; // set red brow^[ x ].g := lrow^[ x ].g; // set green brow^[ x ].b := lrow^[ x ].b; // set blue brow^[ x ].a := lrow^[ x ].a; // set alpha value end; end; MyBitmap.LoadFromIntfImage( IntfImage ); Image2.Picture.Bitmap := MyBitmap; Can anyone see a flaw in my logic of using scanlines for this/this way? Yes. MyBitmap.LoadFromIntfImage( IntfImage ) does no conversion. You created an image with the format ImgFormatDescription.Init_BPP32_B8G8R8_BIO_TTB which is probably not the format of your platform. Solution: Don't use ScanLine, but use the Colors property of IntfImage. See the examples/lazintfimage/fadein1.lpi. Mattias _ To unsubscribe: mail [EMAIL PROTECTED] with "unsubscribe" as the Subject archives at http://www.lazarus.freepascal.org/mailarchives