in reply to Re^3: Convert BMP to HTML
in thread Convert BMP to HTML
I have thought about using ROWSPAN as well, but I would have to significantly rewrite the code to detect not just long repeating lines of same color but box shaped areas which are all made up of the same color.
I use the word "CANVAS" in my code simply because ReadBMP converts the BMP file to an intermediary format that my script can work with. This image format is a single string that always starts with the word "CANVAS." That's how the program recognizes that the string is an image. The next 2 bytes hold the image format, which is then followed by 4-byte width and 4-byte height of the image. Then 3 bytes for the red, green, blue values for the first pixel starting in the upper left hand corner. This format is pretty straightforward (to me), because I designed it. And I also wrote ReadRAS() ReadRGB() and ReadPXR() subs, which are obsolete formats that are not supported by Imager. I don't understand why, because, for example, SUN Raster image format is a very clean and easy to understand format, and many times RAS files are smaller than BMP files. Writing a script to read and write RAS images is a whole lot simpler than writing a script that reads and writes BMP files. BMP files contain so much unnecessary complexity! Anyway, once the image is read and decoded, it is stored as a string whose first few bytes start with the word "CANVAS" and then the functions that I write simply act on that string. I can read a pixel using either substr() and vec() or unpack(). Those are my tools. I found that calling a SetPixel() or GetPixel() function slows down the code, because if you have to call a function millions of times, it adds significant delay. And when you're writing it in pure perl, it's better not to put that into separate subs. So, my getpixel and putpixel methods look like single substr() calls.
my ($R, $G, $B) = unpack('CCC', substr($$CANVAS, $PTR, 3)); # Reads a single pixel.
substr($$CANVAS, $PTR, 3) = "\0\0\xFF"; # Writes a single blue pixel somewhere.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^5: Convert BMP to HTML
by LanX (Saint) on Nov 01, 2022 at 06:41 UTC | |
by choroba (Cardinal) on Nov 02, 2022 at 10:48 UTC | |
Re^5: Convert BMP to HTML
by Bod (Parson) on Oct 31, 2022 at 22:14 UTC | |
by choroba (Cardinal) on Nov 02, 2022 at 10:48 UTC | |
by afoken (Chancellor) on Nov 02, 2022 at 15:38 UTC | |
by LanX (Saint) on Nov 03, 2022 at 10:05 UTC | |
by choroba (Cardinal) on Nov 03, 2022 at 13:25 UTC | |
| |
by LanX (Saint) on Nov 02, 2022 at 11:27 UTC | |
by Bod (Parson) on Nov 02, 2022 at 22:32 UTC | |
by Anonymous Monk on Oct 31, 2022 at 23:45 UTC |