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.

Work in Progress / Lossless image compression in DB! It works!

Author
Message
David T
Retired Moderator
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: England
Posted: 22nd Aug 2003 14:15 Edited at: 22nd Aug 2003 16:29
Edit: updated

I've managed to write an image compression routing in DBPro that actually works. I've saved a 197 x 211 BMP which was 124kb down to a 85kb file.

The code works by finding repeatedly used colours nad replacing each colours with a "token", pointing to a colour in the image palette. That way if you only used two colours then the data stored would be two colours and lots of smaller token values.

The top picture is loaded from my format (85k), the bottom from BMP (124k).



The size of file also depends on the number of colours used in the image - the image above used only 290 colours so was a smaller file.




I'm now working to get it to work quicker and with more compression

Here's my current code. This will load "testimg2.bmp" (has to be 198x212) and save it is "finalimg.dif".

The compression is slighly lossy (it wasn't at the time of writing the post, hence the title "lossless image ocmpression"), though only once (ie. after saving once there will be no more loss of detail for further saves until the image is modified).

My next step is to catch repeated entries in the image data (ie. 0000000001000000) and replace it with something like 0(9) 1(1) 0(6).



There's no place like 127.0.0.1

There are 10 people in this world, those who understand binary and those who don't.
David T
Retired Moderator
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: England
Posted: 22nd Aug 2003 15:40
OK that code is a bit, wel, useless and buggy. I'm working on it though, I got 124kb down to 119kb.

There's no place like 127.0.0.1

There are 10 people in this world, those who understand binary and those who don't.
Andy Igoe
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: United Kingdom
Posted: 22nd Aug 2003 16:37
Good luck, there's a fair way to go though. Saving your test picture as a jpg at 100% quality I got the file to 34.7kb. I'll be watching your progress with keen interest

Pneumatic Dryll
David T
Retired Moderator
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: England
Posted: 22nd Aug 2003 16:50
Thanks what did the image look like in terms of quality?

There's no place like 127.0.0.1

There are 10 people in this world, those who understand binary and those who don't.
Andy Igoe
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: United Kingdom
Posted: 22nd Aug 2003 17:09
I save it at 100% quality, it was a replica. Not all programs allow control of the .jpg quality when you export and consequently many of us dont realise that it can compress so well, better than .png infact. I've not looked at DBPro's patch 5 exporter yet but GuyS's one does and Paintshop Pro also does 100% exports (you click on options when you save). I used PSP.

I'm not absolutely sure but there may still be some loosey loss, but I zoomed in just now and I couldn't see any difference.

Pneumatic Dryll
Yarbles
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Toronto
Posted: 23rd Aug 2003 06:16
Why not just use the PCX format for lossless compression and save yourself a bunch of work?

David T
Retired Moderator
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: England
Posted: 23rd Aug 2003 13:50
Why not just use the PCX format for lossless compression and save yourself a bunch of work?

Because I want to try it myself You could tell every coder here to go and buy a commercial game it'll save them work too

There's no place like 127.0.0.1

There are 10 people in this world, those who understand binary and those who don't.
TheCyborg
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Denmark
Posted: 25th Aug 2003 13:05
Very interesting... I'll be following this thread with high interest as i have tried similar stuff myself...

You could change this so i can compress all kinds of files and make your own version of WinZIP (or whatever)...


Not up yet --> http://thecyborg.t35.com/
"You cannot fight your enemy if you cannot find him...." -Aliens vs. Predator 2
David T
Retired Moderator
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: England
Posted: 27th Aug 2003 21:47
You could change this so i can compress all kinds of files and make your own version of WinZIP (or whatever)...

hmm hidden agenda?

Here's the code. It's by no means the cleanest and most efficient code, but it works nontheless.

It will load an image (has to be 197 x 212 in size sorry), compress it and save to "finalimage.dif". Then the image will be loaded and displayed on screen.

quality 1 means no colour loss
quality 2 means 50% colour loss, though eye can't detect this (ie. palette of rgb 256,256,256 reduced to 128,128,128
etc.

There's no place like 127.0.0.1

There are 10 people in this world, those who understand binary and those who don't.
David T
Retired Moderator
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: England
Posted: 27th Aug 2003 21:47 Edited at: 27th Aug 2003 21:48
ps my best compression is a photo from 128kb to 15, and still decent quality.

pps a file called "log.txt" will be created for you viewnig pleasure

ppps you need to delete bother files created before running it again, DBP won't tell you that the file already exists.

There's no place like 127.0.0.1

There are 10 people in this world, those who understand binary and those who don't.

Login to post a reply

Server time is: 2024-04-19 14:09:55
Your offset time is: 2024-04-19 14:09:55