Packing bytes: a little help from my friends
Re: Packing bytes: a little help from my friends
@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.
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 ?"
- netmaestro
- 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
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:
and change it to this:
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"
You can improve the result slightly by finding this line:
Code: Select all
*palette.PALETTE = CreatePalette_NeuQuant(*colorbits)Code: Select all
*palette.PALETTE = CreatePalette_NeuQuant(*colorbits, 1)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"
BERESHEIT
Re: Packing bytes: a little help from my friends
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.
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 ?"
- netmaestro
- 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
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
- netmaestro
- 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
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
- netmaestro
- 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
Here is the resulting image with enhancement idea #2 applied:


BERESHEIT
Re: Packing bytes: a little help from my friends
Sierra Lite is faster compared to Floyd-Steinberg and still produces good imagesnetmaestro wrote:If someone has an alternative dither that could be added to this project that would be fantastic.
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)
Raspberry Pi OS (Arm64)
- netmaestro
- 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
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

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
First image: Dither + localized quality enhancement (discussed above, actually uses 512 colors)
Middle image: Dither alone (Floyd-Steinberg)
Last image: No dither or enhancement

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
BERESHEIT
- Kwai chang caine
- Always Here

- Posts: 5502
- Joined: Sun Nov 05, 2006 11:42 pm
- Location: Lyon - France
Re: Packing bytes: a little help from my friends
@LUIS
Thanks for your explanation
You can, you can..it's an honor...they are no copyright for that

In the normal time, i don't like cut head of splendid woman....even if it is easier to carry
, i prefer keep her the full size
But for a GIF the mainly is finally have a good result

So it's not a surprise...
Kcc is the better user for find bugs
Because even if a code works for everybody, KCC is the one to ask question "How use it ???
"
See this thread, again here, KCC find a bug, just take randomly one of his favorite GIF, and that not works correctly
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
But i hope that with your great knowledge ....the GIF must shake now, to be captured by the great frog master

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

Long life to the GIF !!!
Thanks for your explanation
FrogMaster wrote:Maybe I'll call the setting "squaw defense level"
You can, you can..it's an honor...they are no copyright for that
Yes it's a good ideaNetMaestro 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.
In the normal time, i don't like cut head of splendid woman....even if it is easier to carry
But for a GIF the mainly is finally have a good result
I'm so happy the little KCC can help a very very little bit masters like you allFrogMaster wrote:I'm glad you brought this up because it's a good time to talk about frames in the GIF format
So it's not a surprise...
Kcc is the better user for find bugs

Because even if a code works for everybody, KCC is the one to ask question "How use it ???
See this thread, again here, KCC find a bug, just take randomly one of his favorite GIF, and that not works correctly
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
But i hope that with your great knowledge ....the GIF must shake now, to be captured by the great frog master

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

Long life to the GIF !!!
The happiness is a road...Not a destination
