[Solved] Rawimage help lazarus / 39-Graphics ---------------------------------------------------------------------- User137 · 2010-12-25 16:27 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. ---------------------------------------------------------------------- Marc · 2010-12-27 09:01 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: Quote from: User137 on December 25, 2010, 05:27:42 pmCode: [Select]...   for y:=0 to tex^.Height-1 do begin       ...       inc(n,3); //<---     end;     inc(n,3*tex^.Width);//<---   end; ---------------------------------------------------------------------- User137 · 2010-12-27 16:30 Quote from: Marc on December 27, 2010, 10:01:45 amInstead 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. QuoteIn 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. ---------------------------------------------------------------------- User137 · 2010-12-29 19:31 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.