Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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.


In reply to Re^4: Convert BMP to HTML by harangzsolt33
in thread Convert BMP to HTML by harangzsolt33

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2024-04-25 17:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found