Jump to content
IGNORED

Anyone want to write a bitmap conversion utility?


SeaGtGruff

Recommended Posts

I've written a "bitmap kernel" for batari Basic, which displays a 2-color "hi-res" 96x192 bitmap using flicker blinds. Trouble is, it's a real pain in the ass to pull up a bitmap in Paint (or other graphics program) and manually type out all the bytes for it. I've never done any programming to open and read a bitmap file-- although I've printed out a tutorial about it from two old Dr. Dobbs issues that I found online. I'm hoping that somebody here might be able to bang out a utility program a lot quicker than I could (and would be nice enough to do so :)).

 

What I'm looking for is a routine that would take a 2-color bitmap and convert it to a text file with 8-bit binary values, like the following:

 

column_0
  byte %00000000
  byte %00000000
  byte %00110000
  byte %00001110
  byte %01000000
  byte %00111000
  byte %00000000
  byte %00000000
  etc.

column_1
  byte %00000000
  byte %00000000
  byte %00110000
  byte %00001110
  byte %01000000
  byte %00111000
  byte %00000000
  byte %00000000
  etc.

column_2
  byte %00000000
  byte %00000000
  byte %00110000
  byte %00001110
  byte %01000000
  byte %00111000
  byte %00000000
  byte %00000000
  etc.

Ideally, the bitmap would be 96x192, although the utility could work with any size bitmap-- the only real restriction being that the bitmap should be a 2-color bitmap, so that each pixel is either on or off. The bytes will be used for 2600 player data, so the first 8 columns of pixels would be written out as one column of 8-bit values, then the next 8 columns of pixels would be another column, etc., as shown in the example above. So for a 96x192 bitmap, there would be 192 values for the first column, 192 values for the next column, and so on, with 12 columns in all.

 

I can take a two-color picture and resize it to 96x192, so that's not a problem. And I can reformat the text output to suit my needs, so the output format of the utility could be different than I've described. For example, even converting a two-color bitmap to a text file with 0s and 1s would be okay-- one line of text for each row of pixels, without putting them as byte values:

 

000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000
000000000000000000001000000000000000000000000000000000000000
000000000000000000010100000000000000000000000000000000000000
000000000000000000100010000000000000000000000000000000000000
000000000000000001000001000000011111111111000000000000000000
000000000000000011111111100000010000000001000000000000000000
000000000000000000000000000000010000000001000000000000000000
000000000000000000000000000000010000000001000000000000000000
000000000000000000000000000000010000000001000000000000000000
000000000000000000000000000000011111111111000000000000000000
000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000

I'll probably write my own utility regardless, just so I learn how to do it, but it would be cool if someone could bang something out quickly, or if somebody knows of an existing utility that already does something like this.

 

Michael

Link to comment
Share on other sites

Nevermind, I found a utility that converts a bitmap to ASCII art, and I can make it do what I need. :) But I'll still probably (eventually) write a utility of my own to generate output in the exact format I'm looking for-- not just for me, but for other people who want to use my bB "bitmap kernel." :)

 

Michael

Link to comment
Share on other sites

I have a few converters on my website, on my Atari page, listed below SpiceWare Utility. One of them is a 48 pixel converter, which I could clone off and turn into a 96 pixel converter. Only limitation is your image must be accessable via URL (I had problems trying to make upload work).

 

Other thing is it outputs the images using my "graphics.h" file, instead of this:

.byte %00000000 ; 0

.byte %00000000 ; 1

.byte %00001100 ; 2

.byte %00001100 ; 3

.byte %00011100 ; 4

.byte %00011000 ; 5

.byte %00111100 ; 6

.byte %00111100 ; 7

.byte %01101000 ; 8

.byte %01110110 ; 9

.byte %01111110 ; 10

.byte %01000110 ; 11

.byte %00111100 ; 12

.byte %00111100 ; 13

.byte %00111100 ; 14

.byte %01110110 ; 15

.byte %11111111 ; 16

.byte %11111111 ; 17

.byte %11111011 ; 18

.byte %11111111 ; 19

.byte %11111111 ; 20

.byte %11111011 ; 21

.byte %11111111 ; 22

.byte %01111110 ; 23

.byte %00111100 ; 24

 

 

it outputs this, which I find much easier to read:

.byte zz________ ; 0

.byte zz________ ; 1

.byte zz____XX__ ; 2

.byte zz____XX__ ; 3

.byte zz___XXX__ ; 4

.byte zz___XX___ ; 5

.byte zz__XXXX__ ; 6

.byte zz__XXXX__ ; 7

.byte zz_XX_X___ ; 8

.byte zz_XXX_XX_ ; 9

.byte zz_XXXXXX_ ; 10

.byte zz_X___XX_ ; 11

.byte zz__XXXX__ ; 12

.byte zz__XXXX__ ; 13

.byte zz__XXXX__ ; 14

.byte zz_XXX_XX_ ; 15

.byte zzXXXXXXXX ; 16

.byte zzXXXXXXXX ; 17

.byte zzXXXXX_XX ; 18

.byte zzXXXXXXXX ; 19

.byte zzXXXXXXXX ; 20

.byte zzXXXXX_XX ; 21

.byte zzXXXXXXXX ; 22

.byte zz_XXXXXX_ ; 23

.byte zz__XXXX__ ; 24

graphics.h.zip

Link to comment
Share on other sites

Here's the Sprite Converter in action:

 

Screen 1 - select the image

post-3056-1250117952_thumb.png

 

Screen 2 - select the sprite's background color (optionally add/remove extra rows[use negative values to remove]). If the color numbers are hard to see you can hit Change Colors to select from different background colors(each click will advance to the new color).WARNING - the field values might change when using Change Colors - notice that Background Color reverted to 1

post-3056-1250117957_thumb.png post-3056-1250117962_thumb.png

 

Screen 3 - copy your results and paste into your code. Hit Next Sprite if you have more to convert.

post-3056-1250117966_thumb.png

Edited by SpiceWare
Link to comment
Share on other sites

No problem, it took less than 10 minutes. The hard work was done when I wrote Medieval Mayhem(figured out how to have PHP convert a gif to data for the dragon) and Stay Frosty(added the 1 sprite converter and 48 pixel converter).

 

To make this I just copied the four convert-48 php files, did a mass change from 48 to 96, and finally tweaked the output routine to do 12 sprites of data instead of 6.

Link to comment
Share on other sites

Note that the output is generated twice, right-side-up followed by upside-down (though the 2-sprite convert only outputs right-side-up as that's what MM needed)

 

Also if you have trouble getting bB to work with the graphic.h file, a few find/replace-all will convert the format:

 

from zz to %

 

from _ to 0

 

from X to 1

 

from .byte to byte (based on your example, I'm assuming that bB uses byte instead of DASM's .byte)

Link to comment
Share on other sites

I'm assuming that bB uses byte instead of DASM's .byte)

Actually, bB doesn't have a byte command-- I used inline assembly, so it's DASM's byte command. From what I've read in the DASM user's manual, byte, BYTE, .byte, and .BYTE are all the same. I just prefer to leave off the period, and to put it in uppercase:

 

BYTE

HEX

WORD

etc.

 

But I change my mind every so often about things like that-- one year I'm using ORG $F000, the next year I'm using ORG $1000, etc.-- so maybe someday I'll suddenly decide that I like .byte better! :)

 

Michael

Link to comment
Share on other sites

Wasn't aware that DASM support variations on byte - I suspect the initial DASM code I saw used .byte and I didn't pursue it any further.

 

Since you're inlining you shouldn't have any trouble getting graphic.h to work.

Edited by SpiceWare
Link to comment
Share on other sites

The output form BMP to Atari 2600 comes very close to what you want, but is limited to a width of 40 pixels which seems like a limitation that could easily be changed. The author didn't post source, but he could probably be reached to make the change.

 

I just gave it a shot and this is the output

 

PF0TitleLeft
.byte #%11110000
.byte #%11110000
.byte #%11110000
.byte #%11110000
.byte #%11110000
.byte #%11110000
.byte #%11110000
.byte #%11110000
.byte #%11110000
.byte #%11110000
.byte #%11110000
.byte #%11110000
.byte #%11110000
.byte #%11110000
.byte #%11110000
.byte #%11110000
.byte #%11110000
PF0TitleRight
.byte #%11000000
.byte #%11110000
.byte #%11110000
.byte #%11110000
.byte #%11110000
.byte #%11110000
.byte #%11110000
.byte #%01110000
.byte #%01110000
.byte #%10010000
.byte #%11110000
.byte #%11110000
.byte #%11110000
.byte #%11110000
.byte #%11110000
.byte #%11110000
.byte #%11110000
PF1TitleLeft
.byte #%11111111
.byte #%11111110
.byte #%11100000
.byte #%11111110
.byte #%11111111
.byte #%11111111
.byte #%11111111
.byte #%11111111
.byte #%11111111
.byte #%11111111
.byte #%11111111
.byte #%11111111
.byte #%11111111
.byte #%11111111
.byte #%11111111
.byte #%11111111
.byte #%11111111
PF1TitleRight
.byte #%11111111
.byte #%11010111
.byte #%11000000
.byte #%11111111
.byte #%11111111
.byte #%11111111
.byte #%11111111
.byte #%01111111
.byte #%01111111
.byte #%11110111
.byte #%11111111
.byte #%11111111
.byte #%11111111
.byte #%11111111
.byte #%11111111
.byte #%11111111
.byte #%11111111
PF2TitleLeft
.byte #%00000111
.byte #%00000000
.byte #%11110000
.byte #%11111110
.byte #%11111111
.byte #%11111111
.byte #%11111111
.byte #%11111111
.byte #%11111111
.byte #%01111111
.byte #%11111111
.byte #%11111111
.byte #%11111111
.byte #%11111111
.byte #%11111111
.byte #%11111111
.byte #%11111111
PF2TitleRight
.byte #%11111111
.byte #%11111111
.byte #%11111111
.byte #%11111111
.byte #%01111111
.byte #%11111111
.byte #%11111111
.byte #%11111111
.byte #%11111111
.byte #%11111111
.byte #%11111111
.byte #%11111111
.byte #%11111111
.byte #%11111111
.byte #%11111111
.byte #%11111111
.byte #%11111111

 

-Jeff

Link to comment
Share on other sites

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.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...