Packing bytes: a little help from my friends

Just starting out? Need help? Post your questions and find answers here.
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Packing bytes: a little help from my friends

Post by luis »

@KCC

I don't think there is anything that can be done. The original image has 78636 unique colors, the second one 256.
You can't expect miracles. The image can't be the same. It's awesome it can look as it looks now.
The forehead of the woman is a marked high brightness zone in the original so it can't be avoided.
The only difference can result from the algo used for dithering (which is used after the quantization), a different algo can give you a subjective better/worst result for this specific image, or you could edit the original image reducing the hilight.
"Have you tried turning it off and on again ?"
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Packing bytes: a little help from my friends

Post by netmaestro »

I agree with luis on all points. If someone has an alternative dither that could be added to this project that would be fantastic. But I'm not going down that road for now. For the processing time, the neuquant routine suffers terribly from the debugger being on and the encoder isn't much different. It won't matter for smaller simpler images but for big complex ones like the singer you need to have the debugger off, otherwise you could go to the store while it's running.

You can improve the result slightly by finding this line:

Code: Select all

*palette.PALETTE = CreatePalette_NeuQuant(*colorbits)
and change it to this:

Code: Select all

*palette.PALETTE = CreatePalette_NeuQuant(*colorbits, 1)
where the NeuQuant routine is asked to take more time and do its very best.

It won't make a huge difference, but it does make a noticeable difference.

I'm glad you brought this up because it's a good time to talk about frames in the GIF format. As you know you can have many frames and specify a disposal method and delay time etc. for each. Mostly this is used for animation, but you can use frames in an alternate way too. In your singer image all the dark colors are affecting the quality of the much lighter face. If you use an editor and crop all but her head you will see that the GIF encoder does a near-perfect job with the highlight on her forehead. In the GUI version of this workshop I'm going to make a quality setting available for images such as this. It will work by cutting the image into four, eight or sixteen parts, each of which will be processed individually through NeuQuant/Dither and will be hung at the appropriate x,y in the final image to reconstruct the original. Because local color tables will be used, the resulting image will have many more than 256 colors. Once this is ready, you will be able to select a higher quality setting for your singer and she will be effectively "unsquawed".

Maybe I'll call the setting "squaw defense level" :mrgreen:
BERESHEIT
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Packing bytes: a little help from my friends

Post by luis »

That's a clever idea, but are you sure the "clients" will display the image (composed by subimages) properly ?
I superficially know what you say should be possible but I wonder if programs around are compliant with that kind of format... did you ever see a gif built this way, did you try to see if it's really supported enough ? Maybe it is and I'm just ignorant about this. I never saw one in my life I have to admit.

EDIT: oh wait, I just found one on wikipedia -> http://upload.wikimedia.org/wikipedia/c ... ourGIF.gif

And it works on firefox, so maybe my fears are unjustified... very interesting, it would be a very powerful solution indeed.
Last edited by luis on Sun Nov 24, 2013 1:14 am, edited 1 time in total.
"Have you tried turning it off and on again ?"
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Packing bytes: a little help from my friends

Post by netmaestro »

Yes, should work without problems. I might actually make a special test version of the code and test it with KCC's image as "proof of concept", though the Wikipedia sample is pretty good proof! The resulting image will be larger of course to the tune of 768 bytes per colortable. So improving the quality at the lowest setting would increase the size by 3*768, or around 2k. Should be OK.
BERESHEIT
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Packing bytes: a little help from my friends

Post by netmaestro »

Another interesting idea is to allow quality improvements to a selectable area by the user. So KCC creates the singer gif and says, crap. gotta fix the face. So he can go to the gui, call up the original image and select a rectangle around the head. The encoder will create one frame with the whole picture and another small one with just the head. The disposal method will be set on 'leave as is' and so the second one will be drawn onto the first one, in the resulting gif all looks perfect with minimal size increase.
BERESHEIT
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Packing bytes: a little help from my friends

Post by netmaestro »

Here is the resulting image with enhancement idea #2 applied:

Image
BERESHEIT
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3943
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Packing bytes: a little help from my friends

Post by wilbert »

netmaestro wrote:If someone has an alternative dither that could be added to this project that would be fantastic.
Sierra Lite is faster compared to Floyd-Steinberg and still produces good images
http://www.tannerhelland.com/4660/dithe ... urce-code/
This PB source is an implementation of Sierra Lite to create 1 bit images
http://www.purebasic.fr/english/viewtop ... 56#p413156


Also for animated gifs, it's good to have an ordered dither as well.
The quality of an ordered dither is not as good but it often looks better when animating multiple frames.
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Packing bytes: a little help from my friends

Post by netmaestro »

Not sure that one is suited to the purpose. Here is a set of screenshots of the three options available in the coming workshop:

First image: Dither + localized quality enhancement (discussed above, actually uses 512 colors)
Middle image: Dither alone (Floyd-Steinberg)
Last image: No dither or enhancement

Image

Of course if it weren't for the hectares of dark colors in the full image, all faces would look like the one on the left.

Friggin' flashbulbs anyway :evil:
BERESHEIT
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5502
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Packing bytes: a little help from my friends

Post by Kwai chang caine »

@LUIS
Thanks for your explanation 8)
FrogMaster wrote:Maybe I'll call the setting "squaw defense level"
:lol: :lol:
You can, you can..it's an honor...they are no copyright for that :lol:
NetMaestro wrote:So KCC creates the singer gif and says, crap. gotta fix the face. So he can go to the gui, call up the original image and select a rectangle around the head.
Yes it's a good idea :D
In the normal time, i don't like cut head of splendid woman....even if it is easier to carry :lol: , i prefer keep her the full size :mrgreen:
But for a GIF the mainly is finally have a good result 8)
FrogMaster wrote:I'm glad you brought this up because it's a good time to talk about frames in the GIF format
I'm so happy the little KCC can help a very very little bit masters like you all :shock: 8)

So it's not a surprise...
Kcc is the better user for find bugs Image
Because even if a code works for everybody, KCC is the one to ask question "How use it ??? :cry: "

See this thread, again here, KCC find a bug, just take randomly one of his favorite GIF, and that not works correctly :cry:
http://www.purebasic.fr/english/viewtop ... 65#p390565

Decidedly...at the time of the super production of 3D games....where reality is mixing with picture...
The little GIF is always also hard to manage :cry:

But i hope that with your great knowledge ....the GIF must shake now, to be captured by the great frog master :mrgreen: :lol: :lol:
Image

Thanks a lot NETAMESTRO to have put your interest on this splendid type of image 8)


Image
Long life to the GIF !!!
ImageThe happiness is a road...
Not a destination
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Packing bytes: a little help from my friends

Post by davido »

Pure MAGIC!!

Nice work, guys. :lol:
DE AA EB
Post Reply