Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / 256 color compression - saves 1/4 size of bmp

Author
Message
Emperor Baal
20
Years of Service
User Offline
Joined: 1st Dec 2003
Location: The Netherlands - Oudenbosch
Posted: 18th Nov 2004 03:56 Edited at: 18th Nov 2004 04:27
Ok, lets begin:

This is a color compression I've been working on. It saves 1/4 of a 32-bit bitmap size and around 1/3 of a 24-bit one.

Here's the manual version:


Here's the automatic version:



Manual:
Create a new one, type the image path and a filename. Next select a compression mode:

Standard, uses 217 color palette. Low / normal quality
Customize, select 256 colors to compile with. Best quality
Quick, finds 256 colors to use. Good / Very good quality, depends on color vibrance value. Default CV value = 20

Compiling takes some time though.


Automatic:
To create a new .256 file: Drag the image on the executable, the file handles the rest.

To view a .256 file: Drag the .256 file on the executable



Example of the automatic version:
256 colors


24-bit colors:


This shows the color vibrance value. When it's set too low, the image will not have all three main colors (R,G,B) but more tints of one/two color(s) like green in this one.

Setting it too high, will make the image compile with all colors, but not with enough tints. This causes the image to look horrific .

I don't know how to implent Dithering, but im sure it's a handy feature for this compression. Any clues?

Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 19th Nov 2004 00:21
What compression method does it use?

AKA teh great Pet Rat.
Peace sells...but who's buying??
Emperor Baal
20
Years of Service
User Offline
Joined: 1st Dec 2003
Location: The Netherlands - Oudenbosch
Posted: 20th Nov 2004 06:18
Currently it uses color replacement.

First it scans the image so it selects 256 suitable colors. Those colors are written to an array.
Then it opens a .256 and writes those 256 colors:

write byte 1, color(color number, 1)
write byte 1, color(color number, 2)
write byte 1, color(color number, 3)

1 = red
2 = green
3 = blue

Then it will compare every pixel in the image with a function I wrote. It will select the color with the smallest difference and writes:

write byte 1, color number


Example:

color(1,1)=255
color(1,2)=255
color(1,3)=255
color(2,1)=0
color(2,2)=0
color(2,3)=0

We've got 2 colors, white and black. When our image is scanned we found 4 pixels:

1 = rgb(255,0,0)
2 = rgb(255,255,0)
3 = rgb(255,0,255)
4 = rgb(0,50,200)

Now we only need to compare the 4 pixels with our 2 color pallete.

Pixel 1 looks like color 2: write byte 1, 2
Pixel 2 looks like color 1: write byte 1, 1
Pixel 3 looks like color 1: write byte 1, 1
Pixel 4 looks like color 2: write byte 1, 2

And when we want to view our image, you just read the colors and read the pixels. When you've read them, you just use the "dot" or "box" command and draw the image again.


24-bit images uses "write byte" 3 times for 1 pixel
32-bit images uses "write byte" 4 times for 1 pixel

our image uses "write byte" a single time. That usually means it will save 66% - 75% of space.

I'm not an expert on compression, otherwise I could have made it smaller. I started out with a 16-color compression but made it 256-colors instead.
16-colors can save more space, by using "write byte" for 2 pixels instead.

Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 1st Dec 2004 08:07
I hate to break it to you but that doesn't sound like compression to me, it just sounds like converting an image to a 256 color image.

AKA teh great Pet Rat.
Peace sells...but who's buying??

Login to post a reply

Server time is: 2024-11-23 17:08:35
Your offset time is: 2024-11-23 17:08:35