Jump to content

Txt and bmp conversion


rockbloodystar

Recommended Posts

I have been looking into .bmp standards a while back, but got bogged down in versions and varieties fairly quickly. It is not as straightforward as you would think.

Then again, I tried to do it all myself, maybe that there are some nifty libraries to help you with this.

Link to comment
Share on other sites

This could be done, though it'd take some work unless this grid is a standard format and there's already software designed to handle it, in that case google it up :)

If not then you'll have to write something yourself, if you're a programmer great!, if not then you'll need to pick something easy to learn.

You'd first want to open the file, read each line into cells of an array until the end of the file and create an image buffer big enough to hold the pic, height will be the same as the number of lines in your grid, width would equal the number of values in a line.

You'll then need to parse each line, if the values are separated by spaces you'd check each character until you found a space, convert the characters before the space to an integer and draw a pixel with that value to x=0 and y=0, add 1 to x, make the current position in the line the new start position, read forwards to the next space, convert it and then draw another pixel.

Once you're done with a line, add 1 to y and then parse the next line/cell in your array, "for" loops are good for this.

And after all the lines are done, save the image buffer as image.bmp or whatever, and save the code for another day.

It'd be a fun learning experience :D

Link to comment
Share on other sites

The size of the image should be the same as the array.

The 0 to 255 is because those are the shades of grey in bmp.

Ah, well, download Gimp, its a free image editor. Create new image 255x255 and use the gradient fill tool. Set from pure white to pure black and it'll fill in all the in between shades for you.

Link to comment
Share on other sites

Well, you could take that array and load it up into a Basic program (QB64 for example {documentation}, or any other language you have access to/proficiency in for that matter), and create an image array (SCREEN and/or _NEWIMAGE command) and PSET the gray-scale decimal values into that image array ... then just have Basic write the array out as a BMP file (SAVEIMAGE command).

For reference.

- - - Updated - - -

By the way, what is this 'grid' stored/created with?

Link to comment
Share on other sites

Well, you could take that array and load it up into a Basic program (QB64 for example {documentation}, or any other language you have access to/proficiency in for that matter), and create an image array (SCREEN and/or _NEWIMAGE command) and PSET the gray-scale decimal values into that image array ... then just have Basic write the array out as a BMP file (SAVEIMAGE command).

For reference.

- - - Updated - - -

By the way, what is this 'grid' stored/created with?

Basic can do that now? Neat-o. I really need to get my paws dirty again.

Link to comment
Share on other sites

Yes. Actually, Basic has been able to read/write BMP files pretty much right from the beginning... the BLOAD and BSAVE commands.

I wish I had known that when I was 14. My horrible interpretation of Pong would have looked so much better :D

Link to comment
Share on other sites

I wish I had known that when I was 14. My horrible interpretation of Pong would have looked so much better :D

There were plenty of nifty things one could do with a BLOAD command, like define an array in memory and load the contents of a file into it... the file contents were an assembly subroutine, in binary, where you'd then define the location of the start of that variable in memory (VARPTR), use a DEF SEG statement to initialize a pointer to that segment of memory, and then jump (CALL) that subroutine. That's how we used to make Basic 'fast'. ;)

Edited by LordFerret
Link to comment
Share on other sites

There were plenty of nifty things one could do with a BLOAD command, like define an array in memory and load the contents of a file into it... the file contents were an assembly subroutine, in binary, where you'd then define the location of the start of that variable in memory (VARPTR), use a DEF SEG statement to initialize a pointer to that segment of memory, and then jump (CALL) that subroutine. That's how we used to make Basic 'fast'. ;)

Yeah, I was more of the young and ambitious but without any actual knowledge or skills type :D

Link to comment
Share on other sites

learn the tga header. its only 18 bytes and can be used to generate tga files from scratch with a hex editor. you will of course need to convert your numbers to hex.


0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, //no modification
0x00, 0x00, 0x00, 0x00, 0x40, 0x01, 0xf0, 0x00, //last four bytes here are width and height, 2 bytes each (little endian i think)
0x18, 0x00 //these two are bit depth (codes, not actual values), 16 bit = 0x10 0x01, 24 bit = 0x18 0x00, 32 bit = 0x20 0x08
//follow up with width*height*(bpp/8) bytes of data, not sure color order but i think its something weird like BRG (for grey pick 24 bit and just repeat each value 3x)

i was using this technique to dump the framebuffer on a software rendering engine i was working on. i just manually created the header for the type of file i was writing and stuck it in a byte array, then when i wrote the file i would just output the header followed by the raw data and close the file, you could then open it in photoshop or whatever. lots of graphics software that is not ms paint can open tga.

Edited by Nuke
Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...