BMP to MD file converter

Talk about development tools here

Moderator: BigEvilCorporation

Post Reply
matteus
Very interested
Posts: 336
Joined: Mon Feb 04, 2008 1:41 pm

BMP to MD file converter

Post by matteus » Sun Jun 06, 2010 11:16 pm

It's been a while since I've posted here! Does anyone know of a tool that can convert BMP's to 60 colours and convert to MD format with four palettes?

Chilly pointed me at SixPack but its lacking the facilty to do a picture with anymore than 1 palette :) Now while I could go all out and try to make this image look ok at 16 colours, I'd prefer to make it perfect at its present 41! hehe any suggestions?

I've written a VB app (yes microsoft yuck yuck) that gets the image working with only MD palette colours but I just need this last little push to have something I can roll images out faster with :)

koilazka
Interested
Posts: 30
Joined: Mon Nov 30, 2009 1:51 am

Post by koilazka » Mon Jun 07, 2010 2:19 pm

It can be done as long as the bmp image uses 1 pallet for each 8x8 pattern.

1 pattern or sprite can only use 1 pallet at a time, unless you do some magic with 2 backgrounds or something.

As long as all the 8x8 patterns on the image use 1 of the 4 pallets (or 2 with 2 backgrounds) it should be ok.

It depends alot on the image, if its a really complex image, using 2 pallets on every pattern, the convertor may take a while to design and write.

Can you post the image you want to convert?

....

If you split the images manually in a paint program, you should be able to run them through a convertor.
Image

mic_
Very interested
Posts: 265
Joined: Tue Aug 12, 2008 12:26 pm
Location: Sweden
Contact:

Re: BMP to MD file converter

Post by mic_ » Tue Jun 08, 2010 6:17 pm

matteus wrote:It's been a while since I've posted here! Does anyone know of a tool that can convert BMP's to 60 colours and convert to MD format with four palettes?

Chilly pointed me at SixPack but its lacking the facilty to do a picture with anymore than 1 palette :) Now while I could go all out and try to make this image look ok at 16 colours, I'd prefer to make it perfect at its present 41! hehe any suggestions?

I've written a VB app (yes microsoft yuck yuck) that gets the image working with only MD palette colours but I just need this last little push to have something I can roll images out faster with :)
This is a feature I've been planning to add to Sixpack ever since I started writing it. It's a fairly complex problem to solve though - at least if you want good results (which I do).

Huge
Very interested
Posts: 197
Joined: Sat Dec 13, 2008 11:50 pm

Post by Huge » Wed Jun 09, 2010 4:16 pm

koilazka wrote:Image
Oh man, this reminds me of the hi-res sprite multiplex trick on C64. Good times.

matteus
Very interested
Posts: 336
Joined: Mon Feb 04, 2008 1:41 pm

Re: BMP to MD file converter

Post by matteus » Wed Jun 09, 2010 11:12 pm

mic_ wrote:This is a feature I've been planning to add to Sixpack ever since I started writing it. It's a fairly complex problem to solve though - at least if you want good results (which I do).
Well I'm kinda half way house at the moment, obviously first off you have to make sure every 8x8 tile has no more than 15 colours.

I'd then guess its a case of taking the top 60 colours within the picture and using that to form palettes....

Is the algorithm used to apply a single palette to a picture complicated? I need to write one shortly...

mic_
Very interested
Posts: 265
Joined: Tue Aug 12, 2008 12:26 pm
Location: Sweden
Contact:

Post by mic_ » Thu Jun 10, 2010 7:54 am

Applying a palette to a picture isn't complicated: take one pixel P and find the palette color C with the smallest distance between P and C in 3D-space ({R,G,B}).

The tricky part is actually generating the palette. Just keeping the most frequently used colors is generally a bad idea, because it gives preference to colors that happens to appear in large chunks.
Imagine an image that has a background consisting of a vertical gradient with 32 shades of blue, and a few objects in the foreground that mainly use non-blue colors. A "top color" quantizer would obviously have problems with an image like that.

To get good results you should probably use a minimum variance quantizer or a neural network-based quantizer. I use the latter in Sixpack.

matteus
Very interested
Posts: 336
Joined: Mon Feb 04, 2008 1:41 pm

Post by matteus » Thu Jun 10, 2010 11:27 am

mic_ wrote:The tricky part is actually generating the palette. Just keeping the most frequently used colors is generally a bad idea, because it gives preference to colors that happens to appear in large chunks.
Imagine an image that has a background consisting of a vertical gradient with 32 shades of blue, and a few objects in the foreground that mainly use non-blue colors. A "top color" quantizer would obviously have problems with an image like that.

To get good results you should probably use a minimum variance quantizer or a neural network-based quantizer. I use the latter in Sixpack.
My present method is to:

Loop each pixel
Get the Pixels R,G,B
Divide each R, G, B value by 36 and round down the values
For each of the R, G, B values that are above 252, default to 252
For each of the R, G, B values that are below 252 times by 36

tomaitheous
Very interested
Posts: 256
Joined: Tue Sep 11, 2007 9:10 pm

Post by tomaitheous » Thu Jun 10, 2010 6:35 pm

Something somewhat relative to this topic; range compression. Perception of a color brightness is partially relative (like anything else). If you avoid using pure black and use 1,1,1/1,0,1/1,0,0/0,0,1 - you get an interesting effect (as long as the person/viewer doesn't see true black anywhere on screen). It changes the perception of all the other colors through out the range. I did this for a video encoding, for 9bit master palette and a single 16color bitmap. Worked out fairly well. I'm pretty sure I've seen some stills that do this as well, in some games.

Graz
Very interested
Posts: 81
Joined: Thu Aug 23, 2007 12:36 am
Location: Orlando, FL

Post by Graz » Fri Jun 11, 2010 12:52 am

I wrote my own command line tool to do this (and a bunch of other tile munging stuff). It works OK, but I need to find better palette selection algorithms. I might try the NeuQuant algorithm that mic_ linked to. Here's what I get right now...

Layer A:
Image
Layer B:
Image
Composite:
Image

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Fri Jun 11, 2010 1:09 am

Using two layers is the "easy" way out. What I really want is one layer using more than one palette. Like matteus says - 16 colors in an 8x8 cell that might be chosen from 2 or more palettes.

koilazka
Interested
Posts: 30
Joined: Mon Nov 30, 2009 1:51 am

Post by koilazka » Fri Jun 11, 2010 1:44 am

I wrote some notes down how to write one layer convertor, but im too busy at the moment, it would be complicated to write.
This would be straight forward conversion, no compression unless needed.

Find the tile that uses the most colours in one, if > 15 colours do a tile compression.
Complete as many tiles as possible with that pallet, add new colours if original pallet had < 15.
Repeat above 4 times for each pallet.

Hopefully, if the image has 50 or less colours, and aint that complex (same colours used in the other pallets to much), the program shoud be able to complete most images with no compression.

This is only one basic way though, getting a computer to pick the right pallets to put a puzzels together, would be the messy part to write.

Graz
Very interested
Posts: 81
Joined: Thu Aug 23, 2007 12:36 am
Location: Orlando, FL

Post by Graz » Fri Jun 11, 2010 2:14 am

Chilly Willy wrote:Using two layers is the "easy" way out.
Yup, you're right, it was pretty easy to implement. I kind of had a different goal in mind though. I'd like to be able to put arbitrary colors next to each other rather than be constrained to using a fixed set of 15 colors within a single block. My idea is to try to find an organization of colors within the 2 or more palettes such that most of the tiles only use colors from a single palette. By doing this, I can leave most of plane B blank, only putting a non-transparent tile where colors outside the first palette are necessary, and hopefully, most of these would only require a single palette. I could even use strategically placed sprites to fill in the missing colors rather than a whole plane. This could be as simple as putting the most common colors in palette 0 and the next most common in palette 1 and so on.

What might be harder than getting the colors organized such that each tile only needs a single palette is an algorithm to effectively use shadow and highlight.

I have to admit, I didn't put too much thought into this and just stopped at 'good enough'.

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Fri Jun 11, 2010 3:16 am

:D

I put "easy" in quotes because everything is relative. Doing 31 colors in two layers is "easy" relative to other schemes, but still a neat trick.

The issue with two layers is of course, it takes twice the vram. One layer would be better as then the memory requirements don't interfere with whatever else is going on as badly.

I've been thinking about this myself... if I come up with something, I'll probably make an attempt at it myself. Get enough of us all working on it and maybe someone will come up with something good. 8)

TmEE co.(TM)
Very interested
Posts: 2440
Joined: Tue Dec 05, 2006 1:37 pm
Location: Estonia, Rapla City
Contact:

Post by TmEE co.(TM) » Fri Jun 11, 2010 1:46 pm

A+B+sprite overlay allows for quite some fun.... 47 colors per tile is always interesting ^^ VRAM consumption is twice only if you don't do tile optimization... my GFX converter does tile optimization, sprite conversion, multipart sprite conversion, layer splitting... and quite a few more things... compression support must be added though :P
...and its got no UI nor command line :P

A+B+sprites :
http://www.fileden.com/files/2008/4/21/ ... Dtitle.png

Just A+B :
http://www.fileden.com/files/2008/4/21/ ... SMDmap.png
Mida sa loed ? Nagunii aru ei saa ;)
http://www.tmeeco.eu
Files of all broken links and images of mine are found here : http://www.tmeeco.eu/FileDen

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Fri Jun 11, 2010 7:56 pm

Right - you'd definitely want tile optimization for dual/triple layer displays. :)

Post Reply