[SOLVED] again troublemaker bitmap.PixelFormat problem lazarus / 39-Graphics ---------------------------------------------------------------------- ADMGNS · 2026-03-22 13:44 hello i'd found this sample from internet for along time ago. it was in Delphi. i've just converted it to FP/Laz and faced some problems.. i couldnt understand bitmap.PixelFormat problem when working with .bmp files. it works fine with 32bit .png files (embedde in TPicture) but not others. thank you ---------------------------------------------------------------------- Thaddy · 2026-03-22 14:11 For the water effect to work, don't you need to convert to pf32bit first? ---------------------------------------------------------------------- ADMGNS · 2026-03-22 14:19 hello no. it was pf24bit originally.. in delphi, no problem with 32bits or 24bits.. tenx ---------------------------------------------------------------------- wp · 2026-03-22 19:14 The problem seems to be that the PixelFormat does not necessarily report the memory usage of a pixel, it is my feeling that it only tells you how many pixels are USED to define a pixel. More specific data are obtained by querying the "Description" of the "RawImage" associated with the bitmap (bitmap.RawImage.Description) Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type   // excerpts from the sources TRawImageDescription = object    [...]    Depth: Byte; // used bits per pixel    [...]    BitsPerPixel: Byte; // bits per pixel. can be greater than Depth.    [...]  end;The field "Depth" describes the "used bits per pixel" and seems to correspond to the "PixelFormat". But there is also a file "BitsPerPixel" which "can be greater than 'Depth'", and thus seems to indicate the amount of memory occupied by a pixel - and this is relevant for the ScanLine access. When I add the following code at the end of your "TfrmMain.init" procedure, I get the result that bmpInput occupies 32 bits per pixel, but uses only 24 of them, while bmpOutput occupies and uses 24 ! Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   WriteStr(s, bmpInput.Pixelformat);  DebugLn('bmpInput.Pixelformat = ' + s);                     // --> pf24bit  DebugLn('bmpInput.RawImage.Description.BitsPerPixel = ' + IntToStr(bmpInput.RawImage.Description.BitsPerPixel));// 32  WriteStr(s, imgOriginal.Picture.Bitmap.Pixelformat);      DebugLn('imgOriginal.Picture.Bitmap.Pixelformat = ', s);     // --> pf24bit  WriteStr(s, imgOriginal.Picture.Bitmap.RawImage.Description.BitsPerPixel);   DebugLn('                          .RawImage.Description.BitsPerPixel = ' + s);  // --> 32  WriteStr(s, imgOriginal.Picture.Bitmap.RawImage.Description.Depth);  DebugLn('                        .RawImage.Description.Depth = ' + s);         // --> 24  DebugLn;   WriteStr(s, bmpOutput.PixelFormat);  DebugLn('bmpOutput.PixelFormat = ' + s);   // --> pf24bit  WriteStr(s, imgDisplay.Picture.Bitmap.Pixelformat);  DebugLn('imgDisplayPicture.Bitmap.Pixelformat = ', s);  // --> pf24bit  WriteStr(s, imgDisplay.Picture.Bitmap.RawImage.Description.BitsPerPixel);  DebugLn('                        .RawImage.Description.BitsPerPixel = ' + s);   // --> 24 Don't ask me why this happens, but it's a fact... The problem is that your ScanLine operations in TfrmMain.render proceed with the same step size (bpp) for both input and output bitmaps, but this is not correct: for the input image the bpp step size should be 4 (32bits per pixel) while for the output image is should be 3 (24 bpp). By defining two separate variables for them you can fix the issue: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TfrmMain.render();var  x, y, xx, yy: integer;  dx, dy: double;  brightness: integer;  bppInn, bppOut, i: integer;begin  bppInn := imgOriginal.Picture.Bitmap.RawImage.Description.BitsPerPixel div 8;  bppOut := imgDisplay.Picture.Bitmap.RawImage.Description.BitsPerPixel div 8;   imgDisplay.Picture.Bitmap.BeginUpdate();   for y:=0 to H0-1 do  begin    for x:=0 to W0-1 do    begin      [...]      rowOut[y][x*bppOut + 0] := min(255, max(0, rowInn[yy][xx*bppInn + 0] + brightness));      rowOut[y][x*bppOut + 1] := min(255, max(0, rowInn[yy][xx*bppInn + 1] + brightness));      rowOut[y][x*bppOut + 2] := min(255, max(0, rowInn[yy][xx*bppInn + 2] + brightness));    end;  end;  [...]end; ---------------------------------------------------------------------- ADMGNS · 2026-03-23 00:19 thank you for your detaily replies.. this problem is just about .bmp files.. .png and .jpg files are ok.. i'll check again and try this recipe.. thanks ---------------------------------------------------------------------- ADMGNS · 2026-03-23 17:42 hello wp i've applied the modifications you suggested and then tested lots types of images, so it seems that the problem has been solved.. and, the last code is at attachment.. thanks ---------------------------------------------------------------------- wp · 2026-03-23 22:02 Quote from: wp on March 22, 2026, 08:14:46 pmDon't ask me why this happens, but it's a fact... I wrote a small tool which extracts the image data of a TImage from the lfm file and stores them to disk (https://github.com/wp- xyz/LazSamples/tree/master/graphics/img_from_lfm). This tool tells me that the image which is embedded in your WaterEffect TImage is not a bmp but a png file. It has png color type 2 (true color) which is rgb without alpha, but occupies 32 bits per pixel. Do you still have the original image which you loaded into the TImage? How did you get it into the TImage? In Delphi? ---------------------------------------------------------------------- ADMGNS · 2026-05-01 11:16 hello sorry for late reply. really i dont remember, because i,d tried lots of images and/or formats. but, in Delphi, it was bitmap format, not other formats. regards PS: Photoshop bitmaps are a bit weird and problematic..