Recent

Author Topic: BGRABitmap LineOrder.  (Read 2765 times)

RWC

  • Jr. Member
  • **
  • Posts: 92
BGRABitmap LineOrder.
« on: September 26, 2016, 07:00:57 pm »
I need to write to each consecutive pixel of a BGRABitmap starting from the bottom left corner to the top right. (using p^.red, p^.green, p^.blue, p^.alpha). This seemed straightforward, so before setting my PBGRAPixel pointer to image.data, I set image.LineOrder := riloBottomToTop; but got the Error: No member is provided to access property.

The link http://wiki.freepascal.org/BGRABitmap shows a Direct access to pixels example followed by the comment: Notice that the line order can be reverse, depending on the LineOrder property.

The example code shows ‘for n := bmp.NbPixels-1 downto 0 do’ but it does not change the ‘lineorder’ property, it only reverses the order of the pixel counter. i.e. if I change the code to: ‘for n := 0 to bmp.NbPixels-1 do’, I get an identical result. (which is not surprising since the pointer ‘p’ knows nothing about the counter ‘n’).

I didn’t want to use a separate scanline loop because my data is read consecutively from a MemoryStream (i.e. the input file is an XY matrix of 16bit big endian height values starting from bottom left to top right which I convert to pixel bytes).

At the moment my resulting image with the default LineOrder is upside down which I can easily flip in LazPaint but I was hoping there was a more direct way. (and without using the TrawImage method I remember from some time back). Any help is much appreciated – RWC.
LAZARUS  : Lazarus-1.4.2-fpc-2.6.4-win32. OS   : Windows Vista 32bit Home Premium SP2.
CPU  : Intel Core2 Quad CPU Q6600 2.4GHz. RAM : 3GB. PCIE : NVIDIA GeForce GT610. Audo : NVIDIA HD Audio.

lainz

  • Hero Member
  • *****
  • Posts: 3709
  • Leandro Diaz
Re: BGRABitmap LineOrder.
« Reply #1 on: September 26, 2016, 08:28:05 pm »
You can also flip it with BGRABitmap and no need of LazPaint.

Code: Pascal  [Select][+][-]
  1. Bitmap.VerticalFlip;

The LineOrder is read only. So this means that the order of the file in memory can be reversed, and you can see that accessing that property, but nothing more.

RWC

  • Jr. Member
  • **
  • Posts: 92
Re: [Solved] BGRABitmap LineOrder.
« Reply #2 on: September 27, 2016, 12:56:00 pm »
@Lainz: Yourself & circular are superstars in my books & Lazarus is the best blockbuster movie – many thanks – RWC.
LAZARUS  : Lazarus-1.4.2-fpc-2.6.4-win32. OS   : Windows Vista 32bit Home Premium SP2.
CPU  : Intel Core2 Quad CPU Q6600 2.4GHz. RAM : 3GB. PCIE : NVIDIA GeForce GT610. Audo : NVIDIA HD Audio.

circular

  • Hero Member
  • *****
  • Posts: 3446
    • Personal webpage
Re: BGRABitmap LineOrder.
« Reply #3 on: September 27, 2016, 06:17:31 pm »
Indeed, the line order depend on the platform.

So if you write data from bottom to top, you can do as Lainz suggested depending on the value of LineOrder:
Code: [Select]
if Bitmap.LineOrder = riloTopToBottom then Bitmap.VerticalFlip;
Regards
Conscience is the debugger of the mind

RWC

  • Jr. Member
  • **
  • Posts: 92
Re: BGRABitmap LineOrder.
« Reply #4 on: September 28, 2016, 07:06:52 am »
Quote
if Bitmap.LineOrder = riloTopToBottom then Bitmap.VerticalFlip;
@circular: That’s a neat solution – now I understand why it’s read only. VerticalFlip worked well but I’ll add this to remind me its platform dependent – thank you & best regards.
LAZARUS  : Lazarus-1.4.2-fpc-2.6.4-win32. OS   : Windows Vista 32bit Home Premium SP2.
CPU  : Intel Core2 Quad CPU Q6600 2.4GHz. RAM : 3GB. PCIE : NVIDIA GeForce GT610. Audo : NVIDIA HD Audio.

 

TinyPortal © 2005-2018