Recent

Author Topic: [Solved] Rawimage help  (Read 5115 times)

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
[Solved] Rawimage help
« on: December 25, 2010, 05:27:42 pm »
Just recently i realized that left column of pixels in a PNG i load are same as that of right edge colums. I have a picture which has among other things yellow line on left side and red line at right. Using Rawimage to load and render it it comes up as red line on both sides starting from 3rd row of pixels (pixel at 0,1 has same color as pixel at Width-1,0, but pixel at 10,10 etc has same color as in original image). First line is correct and image itself apart that 1 column is correct. Am i using the format information wrong? Handling the data in actual bits.

Also the wiki link from other thread: http://lazarus-ccr.sourceforge.net/docs/lcl/graphtype/trawimagedescription.html

Trying to simplify my code a bit to see the essential:
Code: [Select]
var n: integer;
    ny,n2: cardinal;
    x,y,r,g,b,a: word;
    rp: TRawImagePosition;
...
  n:=0;
  for y:=0 to tex^.Height-1 do begin
    ny:=RawImage.Description.BitsPerLine*y;
    for x:=0 to tex^.Width-1 do begin      
      n2:=ny+x*RawImage.Description.BitsPerPixel;
      rp.Byte:=n2 div 8;
      rp.Bit:=n2 mod 8;
      RawImage.ReadChannels(rp,r,g,b,a);
      r:=r div 256; g:=g div 256; b:=b div 256;
      tex^.Data[n]:=r;
      tex^.Data[n+1]:=g;
      tex^.Data[n+2]:=b;
      inc(n,3);
    end;
    // (edit: fixed)
  end;

If i use TBitmap to load a BMP image it renders correctly but i can't use alpha-channel with BMP and its large file to use. Also canvas pixels isn't exactly fastest way to read the data.

I think i tested this to work long time ago with no errors but i keep updating lazarus svn and now unable to tell when or if this problem has just started.

edit: Aswell as PNG this acts the same way with Rawimage of JPG.

TImage is pixel perfect in whatever image or format i use.
« Last Edit: December 29, 2010, 09:01:06 pm by User137 »

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2512
Re: Rawimage help
« Reply #1 on: December 27, 2010, 10:01:45 am »
Instead of calculating the pixel indices yourself, you could us a TLazIntfImage to access the pixels, or a TRawImageLineStarts. The latter generates the right TRawImagePosition.

In your code you increase the value of n twice:

Code: [Select]
...
  for y:=0 to tex^.Height-1 do begin
      ...
      inc(n,3); //<---
    end;
    inc(n,3*tex^.Width);//<---
  end;
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Rawimage help
« Reply #2 on: December 27, 2010, 05:30:19 pm »
Instead of calculating the pixel indices yourself, you could us a TLazIntfImage to access the pixels, or a TRawImageLineStarts. The latter generates the right TRawImagePosition.
Thanks i'll look into them.

Quote
In your code you increase the value of n twice:
Actual code didn't look exactly that, made a little error in the simplified version to forum... Original code looked like:
Code: [Select]
     inc(n,tex^.values);
    end;
    if not UseScale then
      inc(n,tex^.values*(tex^.sizeX-tex^.Width));
But then i didn't remember what it meant right away. It actually lets me load the image into texture unscaled leaving the remaining part black/undefined. This was for drawing for example pixel perfect 50x40 picture while texture itself needs to reserve 64x64 for the 3D-card.
« Last Edit: December 27, 2010, 05:38:45 pm by User137 »

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Rawimage help
« Reply #3 on: December 29, 2010, 08:31:43 pm »
Sorry, the above code wasn't actually the issue this time - it should work. I had some other code at end of procedure that messed the data a little wrong. Its fixed now.

 

TinyPortal © 2005-2018