bmp wont display properly lazarus / 39-Graphics ---------------------------------------------------------------------- frozendonuts420 · 2023-08-24 08:46 Hello folks  I was trying this code from swag its years old but still useable, not sure why its not working it all compiles but the bmp will not display correctly its color is dark and only 3/4 of it is in order its also displaying backwards, heres the unit and a example of loading bmp.   This is old code so maybe there is a bug Im missing just spend 4 hours going over the code and Im not getting any where.  Im creating an audio visualizer id like to load the images in but they display incorrectly, it works for testing but Id like the image to show completely.  Im running in 8 bit 256 color mode on the bmps Any help would be appreciated, Id rather use this method so I dont have to add massive libraries to this program.  This is just in free pascal only. ---------------------------------------------------------------------- frozendonuts420 · 2023-08-24 08:51 I checked the code again and ran the bmp again its not backwards now, but it was before while i was debugging the code, but it still doesnt display correctly on the 8 bit 256 bmp ---------------------------------------------------------------------- marcov · 2023-08-24 09:30 Did you compile both the main program and the unit with -Mtp for maximal tp compatibility? Sorry, I have no knowledge of PTC. ---------------------------------------------------------------------- wp · 2023-08-24 10:16 You should also upload the test image - 8bpp paletted images are quite rare nowadays. Took one from the WinNT folder of my VM with Win2000. I loaded the testbmp1.pas into Lazarus and wrapped it into a "Simple Program" application. Like marcov already noted, I activated the mode TP in the project options. The project now compiled, but reported error "Project testbmp1 raised exception class 'TPTCError' with message: cannot recycle because it is not already open". Continuing even made Lazarus unusable because the screen switched into the specific 640x400x256 mode... Then I replaced ptcGraph by the standard graph unit which comes with fpc. This made the "not already open" error go away, but now I have a "RunError(100):disk read error" in the BlockRead instruction at around line 230. What does the "840" in "Until I > 840-1" mean? Could be image width - in this case my test case does not fit. Replace it by the width found in the bitmap header. ---------------------------------------------------------------------- frozendonuts420 · 2023-08-24 10:23 I tried but -Mtp but no change, not sure really, it displays 3/4 of image in a row then the other part of the image.  LIke if i just pushed it over it would line up....its not aligned properly is all i can tell, the code works just doesnt display correctly. ---------------------------------------------------------------------- frozendonuts420 · 2023-08-24 10:27 I fixed that its supposed to read 'until I>biwidth-1' the I may have been changed to I_ in my new test of the program ---------------------------------------------------------------------- frozendonuts420 · 2023-08-24 10:29 heres the latest bmp.pas file ---------------------------------------------------------------------- wp · 2023-08-24 11:04 Can run the test app with my bmp. I confirm that I do not see what other programs display... Tried for comparison a 24bpp bitmap, the LazarusForm.bmp from the Lazarus\images folder. It crashes when trying to write the first pixel, and it will store its color to RGBColor[col] at index 3558722 - but RGBColor is an array[0..255]. At least in the 24bpp mode your code has a severe issue here. ---------------------------------------------------------------------- frozendonuts420 · 2023-08-24 11:52 I see the 24 bit code is even buggier, well I guess I should get a library that works well in free pascal  I'll do some searches, I cant figure out why the 8 bit wont display correctly I give up.  The current version of the audio visualizer is using 8 bit but I plan to use 24 bit in the future, maybe it will be easier with official libraries. ---------------------------------------------------------------------- wp · 2023-08-24 23:10 Find in the attachment a simple image viewer using the ancient Graph unit. Image loading is done by means of the fcl-image library which is part of FPC (folder packages/fcl-images/src). The project is ready for loading bmp and jpg images, but can be expanded to other formats by adding the appropriate reader unit to the uses clause, e.g. fpreadpng or fpreadtiff for png or tiff images, respectively. ---------------------------------------------------------------------- frozendonuts420 · 2023-08-26 19:20 WP, thanks for showing me how to use the fcl-image library, just what I needed thank you. Im doing the finishing touches of my audio music visualizer, Im calling it Glitchee, I'll be posting it at github soon or somewhere.  Now I can load bmps   I will post a link here to it when I have it uploaded. ---------------------------------------------------------------------- wp · 2023-08-26 20:17 Quote from: frozendonuts420 on August 26, 2023, 09:20:32 pmthanks for showing me how to use the fcl-image library, just what I needed You're welcome. Just noticed yesterday that Michael Van Canneyt once wrote a nice, extended article on fcl-image. It is available for download at https://www.freepascal.org/~michael/articles/canvas/canvas.pdf. And, of course, I should also mention the wiki article: https://wiki.freepascal.org/fcl-image ---------------------------------------------------------------------- frozendonuts420 · 2023-09-01 02:48 Here's the link to Glitchee the music visualizer I was talking about.  I finally finished it the first release of the program. https://github.com/alien-android/GlitchEE/tree/main/GlitchEE1 ---------------------------------------------------------------------- Boleeman · 2023-09-02 03:44 I came across some Delphi code which I converted to Lazarus to interpolate a bmp and save to 8Bit bmp. Not sure if it is any use to you but I thought I would upload it anyway.