DevLife: Converting BMP to PCL
You do it every time you buy something with your card at the supermarket. You might even do it when you go to the dentist. You sign your name, maybe even press a few buttons, and the signature gets saved and converted into a bitmap or some similar kind of format. Where I live, I need to take it further and convert the bitmap into a PCL file so that our IBM i (formerly known as the AS/400, or iSeries, or Series i, or whatever the IBM marketing folks have planned in the future as the name of the year to call this midrange beast) can duly attach this digital copy of our John Hancock to an invoice, perhaps, or even an inner-enterprise document. Whatever, like, whatever!! Guuyeeee!
So doing this kind of coding is tedious, dry, and beastly geeky. I feel like an assembly coder for gawdsake! Ouch, my inner geek can only take so much.
So here’s how you do it. As you can tell, this is procrastination at its finest. I’d rather type about it than actually DO IT.
I need a one-layer 8-bit bitmap. Not compressed.
Then I call ImageMagick to convert that sucker to a PCL format.
Easy, right? WRONG, reader, WRONG!!!!
The PCL that comes up is all messed up. It needs cleaning. Like a toilet needs cleaning. If you don’t clean it, well, you know.
So I take this ugly PCL and try to turn it into a beauty queen, one fracking BYTE at a time.
ImageMagick places 0x20’s all over the place, when I need nulls (0x00).
ImageMagick has row blocks of 250 bytes. I need them to be 32.
I also need to somewhat compress this file so it is smaller – that means getting rid of the extra rows in there I do not need — but this also means I cannot get rid of the good bytes — we need to make sure we create a file that is legible – it is a signature capture application, dummy, not a picture of some horse manure.
There is a whole bunch of other stuff in there that pisses me off that we will need to basically ignore.
I am not going to show you the code yet. Mostly, because I haven’t done it yet. I will be doing it, however, in C# this time. Why? Because I have to, that’s why, and that’s the way it is. Maybe I’ll post source code for you in upcoming posts on the FIST if anything just to keep you readers on top of your geek edge. For example, you’ll be able to say, proudly, at the next Comic Con that you were able to figure out how to convert an uncompressed one-layer bitmap to a Printer Control Language file using file streams, binary reader and writers, byte arrays, block copy methods and bitwise comparisons using the C# language. Fuck. Yes.
Here is a pic of the BMP, its PCL conversion from ImageMagick, and the resulting file I need in the end. Show THAT to your BFF!