Shop OBEX P1 Docs P2 Docs Learn Events
3rd party tool for graphics — Parallax Forums

3rd party tool for graphics

Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
edited 2007-04-26 07:28 in Propeller 1
I've been playing with the "graphics.spin" and the gr.pix command today and went looking for a way to convert .BMP into something that can be put easily into the "word" entries for defining a vector sprite.

I came across this 3rd party tool that gets very close to what is needed...

www.rupertmillard.net/mirror/peterbone/bmptoascii.zip

This is a BMP to ASCII converter that lets you limit the number of output characters,
(0123) change the output size of the ascii, as well as edit it in the editor before you
move it to your .spin code. very nice.. But of course keep your source small!

Wonder what Chip is using? [noparse]:)[/noparse]

Oldbitcollector

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"Two things are infinite: the universe and human stupidity; and I'm not sure about the universe." -Albert Einstein

Comments

  • Beau SchwabeBeau Schwabe Posts: 6,559
    edited 2007-04-14 05:21
    Oldbitcollector,

    BMP files are one of the easier graphics files to decode and manipulate. Perhaps if you define the exact output format you are looking for, I can put together a conversion program that would benefit others as well.
    I have a BMP parser that I put together a few years ago to convert BMP to SKILL (<- SKILL is a language code used by Virtuoso Layout Editor) to create BMP images in silicon. It would be relatively easy to alter the output to a specific format.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2007-04-14 06:27
    Well here's the code I'm playing with right now, it's a modified copy of Chip's graphics demo which moves animated monkeys across the screen. Note the entires for @pixdef and @monkey at the end of the file.

    I could be wrong, but it appears that the sprite has to be divided into bytes, but can be adjusted for height by adjusting the second number in the first "byte" entry.
    (byte 2, 11, 3, 3) --- (Change the 11 to add additional word entries (height)
    I'm note sure what the limitation is in width.

    So the conversion would divide the pixels by groups of 8, adding the correct syntax,
    and limit the colors to 0,1,2, or 3. (four colors)

    I'd say leave an option to put in the "word %%" syntax or just output as 8bit
    output that could be read in easily by an SD routine.


    Here's both the .spin code. (Don't mind the mess (also works with my joy code))
    and the original bmp of the monkey.


    Am I the first amateur to play with this? or has everyone else already
    been here and found better methods for doing this?

    Oldbitcollector

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe." -Albert Einstein

    Post Edited (Oldbitcollector) : 4/14/2007 6:51:49 AM GMT
  • Beau SchwabeBeau Schwabe Posts: 6,559
    edited 2007-04-14 21:15
    Oldbitcollector,
    Give me a little bit (probably next week).... I have a possible solution that would allow you to read several other graphics formats ..· JPG,BMP,TIFF, etc..
    ·
    Here, is just a brief glimpse of a Visual Basic test program.· The Idea would be to select an image, and then move a confined square matching the dimensions
    of your choice via the Pixel Sprite definition below, and then print, or create the proper sprite pattern under the confined square.· I need to see what a realistic
    size would be for a sprite image first.... memory, screen resolution etc.
    ·

    '' Pixel sprite definition:
    ''
    ''    word                            'word align, express dimensions and center, define pixels
    ''    byte    xwords, ywords, xorigin, yorigin
    ''    word    %%xxxxxxxx,%%xxxxxxxx
    ''    word    %%xxxxxxxx,%%xxxxxxxx
    ''    word    %%xxxxxxxx,%%xxxxxxxx
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
    1191 x 915 - 247K
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2007-04-15 01:28
    It looks like a typical scroller would use sprites around 24x24 pix, so something that looked like this would be typical.
    The "graphic" demo has a limitation of 4 colors, but I can't imagine this being a limitation, just something I haven't
    stumbled unto the fix for.

    word   'block                            
    byte   4,24,3,3                           
    word   %%11111111, %%11111111, %%11111111
    word   %%11111111, %%11111111, %%11111111
    word   %%11111111, %%11111111, %%11111111
    word   %%11111111, %%11111111, %%11111111
    word   %%11111111, %%11111111, %%11111111
    word   %%11111111, %%11111111, %%11111111
    word   %%11111111, %%11111111, %%11111111
    word   %%11111111, %%11111111, %%11111111
    word   %%11111111, %%11111111, %%11111111
    word   %%11111111, %%11111111, %%11111111
    word   %%11111111, %%11111111, %%11111111
    word   %%11111111, %%11111111, %%11111111
    word   %%11111111, %%11111111, %%11111111
    word   %%11111111, %%11111111, %%11111111
    word   %%11111111, %%11111111, %%11111111
    word   %%11111111, %%11111111, %%11111111
    word   %%11111111, %%11111111, %%11111111
    word   %%11111111, %%11111111, %%11111111
    word   %%11111111, %%11111111, %%11111111
    word   %%11111111, %%11111111, %%11111111
    word   %%11111111, %%11111111, %%11111111
    word   %%11111111, %%11111111, %%11111111
    word   %%11111111, %%11111111, %%11111111
    word   %%11111111, %%11111111, %%11111111
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe." -Albert Einstein
  • Beau SchwabeBeau Schwabe Posts: 6,559
    edited 2007-04-24 17:58
    Here is a Sprite Creator, it should be self explanatory. The output file is saved in the same directory as the source file with a '.sprite' filename extension

    To move the Sprite box to another position, left click and drag while holding down the mouse button.

    To resize the Sprite box, use the controls across the top information bar.


    Note:

    There are two files located in this Zip



    
    1) Sprite Creator v1-0.exe     Visual Basic Program File 
    2) VB40032.DLL                 Visual Basic Runtime Library support file 
     
    
    



    As long as you unzip them both in the same directory, the 'Sprite Creator' should work out fine.

    Enjoy
    EDIT - Updated Version below

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.

    Post Edited (Beau Schwabe (Parallax)) : 4/26/2007 7:32:49 AM GMT
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2007-04-25 01:46
    Beau,

    Thought I'd create a quick little .spin-card to say thanks.

    Thanks for the great tool!

    Oldbitcollector

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The comments and code above are proof that a million monkeys with a million propeller chips *could* write Shakespeare!
  • Beau SchwabeBeau Schwabe Posts: 6,559
    edited 2007-04-25 03:11
    Oldbitcollector,

    haha... thanks!

    Sorry it took so long to get this to you. When you had asked for the code or something that would do what you wanted, I already had about 90% of it completed.
    What I got stumped on was a way to convert the colors down to only 4 and still convey some sort of meaning. If I stripped all of the RGB (Red Green Blue) LSB (Least Significant Bits)
    down so that only the upper 2 bits remained, this still produced 64 possible colors Stripping it to only the upper bit produced 8 possible colors but the end result was terrible and I still
    needed to cut that value in half.

    I settled on a simple algorithm... convert the image to grey scale first...

    GreyScale = (Red + Green + Blue ) \ 3

    Next set RGB values so that they are all equal. (This is part of converting the image to grey scale)..

    Red = Green = Blue = GreyScale

    Now if you strip the LSB bits of the Grey Scale value down leaving only the upper 2 bits, you are left with 4 color combinations which is exactly what is needed...

    4Color = (GreyScale AND &HC0) \ &H40

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2007-04-25 03:50
    I noticed that it isn't seeing anything except JPG. (Not the best format for reducing colors.) Am I doing something wrong?

    Thanks
    Oldbitcollector

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The comments and code above are proof that a million monkeys with a million propeller chips *could* write Shakespeare!
  • Beau SchwabeBeau Schwabe Posts: 6,559
    edited 2007-04-25 04:06
    Oops, your right ... I fixed it so that it will load BMP's , JPG's, and GIF's.... I will look for some other formats that I can add.


    EDIT - Updated version below

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.

    Post Edited (Beau Schwabe (Parallax)) : 4/26/2007 7:31:34 AM GMT
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2007-04-25 04:27
    Ah! That helps! Now I can quickly reduce the graphics to 16 color bmp using Windoze paint, and then crank it into a 4 color sprite. Here's a tank sprite from Andre's collection. Very little fine tuning was required. Nice.

    Any chance of a visual magnification feature for when we are trying to get that square around an 8x8 block? My son was laughing at his dad with a nose to the screen until he saw the tank on the prop. [noparse]:)[/noparse]

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The comments and code above are proof that a million monkeys with a million propeller chips *could* write Shakespeare!
  • Beau SchwabeBeau Schwabe Posts: 6,559
    edited 2007-04-25 04:35
    Oldbitcollector,

    "Any chance of a visual magnification feature for when we are trying to get that square around an 8x8 block"

    I thought about that, but didn't want to paste the magnified view over the scanning area on the screen.
    Would keyboard arrow positioning be helpful rather than or in addition to a mouse?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2007-04-25 04:52
    Keyboard fine tune (ie: slow movement with cursor keys) would help considerably.

    I predict some cool games in these forums very soon... [noparse]:)[/noparse]


    Oldbitcollector

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The comments and code above are proof that a million monkeys with a million propeller chips *could* write Shakespeare!
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2007-04-25 04:55
    I'm going to ask a dumb question here... (Forgive me) But how do I go from this...

    ' Sprite Dimensions ; X= 16 Y= 16 Colors= 4
    ' Color #0 ; R,G,B - %00000000,%00000000,%00000000
    ' Color #1 ; R,G,B - %01000000,%01000000,%01000000
    ' Color #2 ; R,G,B - %10000000,%10000000,%10000000
    ' Color #3 ; R,G,B - %11000000,%11000000,%11000000

    to this....

    COLOR_0 = (COL_Black <<0)
    COLOR_1 = (COL_Cyan3 <<16)
    COLOR_2 = (COL_Blue << 8)
    COLOR_3 = (COL_Blue2 << 24)

    The above is a snippit of Andrea's code in which he defines RGB colors into one binary entry.
    I can't say I'm following the math on this one... If you look at my "sprite.spin" you'll see the entire CON code.

    Oldbitcollector

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The comments and code above are proof that a million monkeys with a million propeller chips *could* write Shakespeare!
  • Beau SchwabeBeau Schwabe Posts: 6,559
    edited 2007-04-25 05:43
    Oldbitcollector,

    ' Sprite Dimensions ; X= 16 Y= 16 Colors= 4
    ' Color #0 ; R,G,B - %00000000,%00000000,%00000000
    ' Color #1 ; R,G,B - %01000000,%01000000,%01000000
    ' Color #2 ; R,G,B - %10000000,%10000000,%10000000
    ' Color #3 ; R,G,B - %11000000,%11000000,%11000000
    
    


    This is just to show you how the Greyscale data is organized.· You can change it to anything you want with something like this...

    Pub SetColorPalette(ColorIndex,Color1,Color2,Color3,Color4)
      colors[noparse][[/noparse]ColorIndex] := (Color1) + (Color2 << 8) +  (Color3 << 16) + (Color4 << 24)
    


    ...borrowed from this link...

    http://forums.parallax.com/showthread.php?p=605448


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.

    Post Edited (Beau Schwabe (Parallax)) : 4/25/2007 5:47:45 AM GMT
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2007-04-26 02:43
    Thanks for that link.. I was do for some review, most of that thread went over my head the first time.. [noparse];)[/noparse]

    BTW, Here's some additional colors if anyone needs them..
      COL_Black      = $02
      COL_White      = $07 
      COL_Red        = $48
      COL_BloodRed   = $38
      COL_LightBrown = $18
      COL_Orange     = $28
      COL_Brown      = $AB
      COL_DarkBrown  = $9B
      COL_Yellow     = %1000_1_101
      COL_YelGrn     = $08
      COL_DarkGreen  = $4B
      COL_Green      = $4C
      COL_Grass      = $CF
      COL_SickGreen  = $EF
      COL_LightGreen = $4D
      COL_Lime       = $4E
      COL_Pink       = $EC
      COL_HotPink    = $4F
      COL_Grey       = $64
      COL_Shadow     = $00
      COL_DarkGrey   = $63
      COL_LightGrey  = $65
      COL_Magenta    = $58
      COL_HotPurple  = $7F
      COL_Purple     = $68
      COL_DarkPurple = $EB
      COL_Blue       = $9F
      COL_DarkBlue   = $1A
      COL_PaleBlue   = $1B
      COL_LightBlue  = $1C
      COL_Cyan       = $1D
      COL_Cyan2      = $1E
      COL_Fire       = $1F
    
    



    Oldbit

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The comments and code above are proof that a million monkeys with a million propeller chips *could* write Shakespeare!
  • Beau SchwabeBeau Schwabe Posts: 6,559
    edited 2007-04-26 07:28
    Sprite Creator Update .... version 1.0.3

    Note:

    There are two files located in this Zip

    1) Sprite Creator v1.0.3.exe    Visual Basic Program File 
    2) VB40032.DLL                  Visual Basic Runtime Library support file 
    
    



    As long as you unzip them both in the same directory, the 'Sprite Creator' should work out fine.

    Enjoy

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.

    Post Edited (Beau Schwabe (Parallax)) : 4/26/2007 7:33:22 AM GMT
Sign In or Register to comment.