in reply to Re^3: Convert BMP to HTML
in thread Convert BMP to HTML

Yes! It seems that does exactly the same things. Except I noticed that he uses "</TD>" and "</TR>" closing elements also. Mine doesn't do that, because it's unnecessary. All web browsers know that a "</TD>" block ends when another one begins or when TABLE object ends. Every byte counts. In my code, I also compress colors. For example, FC0102 becomes "RED" because it looks like red. Then black becomes a single zero, because web browsers accept it. Of course, it might not be standard or official, but if I can get away with it, then that's fine. So instead of saying BGCOLOR=BLACK, I just do BGCOLOR=0. Green would be BGCOLOR=00FF00 but I just write it as BGCOLOR=00F# because web browsers correctly interpret it as green.

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
    Making assumptions about error correcting heuristics of some current browsers just to save some bytes is not a good strategy.

    For instance: The markup of the monastery is basic enough to be interpreted by a new reader, like a Tk or mobile app. Those will not show the same intelligence.

    Furthermore, we do parse and filter the markup here. Unbalanced tags might lead to unwanted effects.

    Cheers Rolf
    (addicted to the 𐍀𐌴𐍂𐌻 Programming Language :)
    Wikisyntax for the Monastery

Re^5: Convert BMP to HTML
by Bod (Parson) on Oct 31, 2022 at 22:14 UTC
    Mine doesn't do that, because it's unnecessary. All web browsers know that a "</TD>" block ends when another one begins or when TABLE object ends

    Just because all most browsers will deal with erroneous HTML code is hardly an excuse to deliberately produce it.

      The closing tags for TD and TR are optional by the spec, it's not "erroneous HTML".

      map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

        With HTML5, you can omit A LOT of markup. This is perfectly valid HTML5, even without <head> and <body> elements (they are implicit), and without the closing </html>:

        <!DOCTYPE html> <html> <title>Valid HTML</title> <h1>Valid HTML</h1>

        Alexander

        --
        Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

        Interesting...thank you :)

      please put your "</TD>" into code tags.