Why do they do that?

Everything else that doesn't fall into one of the other PB categories.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8425
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Why do they do that?

Post by netmaestro »

I wrote some code a few years back that decodes gif files and plays them in a container. All the images in the decoder part of the project are rendered in 32 bits depth. For those frames using transparency, the alpha layer of the transparent color is filled with zeros. Works perfect, no issues. So recently, spurred on by Fred's foray into gif decoding, thank you very much Fred, I revisited my code and thought, why am I doing this at 32bits depth? All gifs are 256 colors and the colorbits are single bytes containing the index to use from the colortable. Why not go all 24bit? Transparency is easily accomplished in PureBasic with a drawing callback that, when it encounters the source color equal to the transparent color, returns the target color instead. All good, all works fine. Except for a very few gifs. "The Haberdasher's Puzzle" is one of these. With my 2013 code it renders fine, but with all-24bit code it leaves artifacts all over the screen. This stumped me for nearly 2 days until some intense investigation revealed the cause: In my all-24bit code, transparency is applied based on a specific color. In my original code it's based not on a color but on an index. This turns out to make all the difference because the diabolical subhuman that made this gif repeated the transparent color elsewhere in the colortable. The color at the transparency index is meant to be drawn transparent, the other equal color being meant for normal drawing. And so my 24bit version is checking the received color alone and it ends up drawing them both transparent. Hence the artifacts. Why would someone go out of their way to cause people grief like this? Maybe for the same reason people write viruses, I guess. I've never understood that motivation either.
BERESHEIT
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Why do they do that?

Post by Kwai chang caine »

I don't know anything, except when you and other master members of this forum, create something for the GIF, me and more members be really happy to have finally something for use Gif.
You say you have not choose a good way for create it...but me i say you have try, and allow to waiting fred decoder 8)
And nothing for that...i say thanks MASTERS 8)
What we become without persons like you :cry:
ImageThe happiness is a road...
Not a destination
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Re: Why do they do that?

Post by djes »

What I've learnt along these years of coding and... living is that if something could happen, it WILL. Maybe the person creating this GIF has evil reason, maybe not, if so, maybe it was simply to demonstrate that the index is the way to go. PNG could also be difficult to handle when it concerns transparency. Most people here don't really masters that subject, happily.

Another remarks while I'm on it. Back in the past, when I first tried to work with Java, doing java applet for a cd-rom, I spent a lot of time with GIF transparency. I discovered that for transparency to work, the very first pixel of the pixel had to be transparent. I let you imagine the time lost to discover this (and the hair).
User avatar
Keya
Addict
Addict
Posts: 1891
Joined: Thu Jun 04, 2015 7:10 am

Re: Why do they do that?

Post by Keya »

i think if you want the ability to move images like sprites though it's best to keep them 32-bit, otherwise you constantly have to manually redraw them against the new background. Not that movement is usually required! I would've guessed it's also slightly faster working on 32-bit, being able to I/O the pixel in the one operation instead of splitting it into two for 24bit (can't blindly write 32-bits and then go back one byte to overwrite the last one, as i found out the hard way that some 24bit bmps don't end nicely on 32-bit aligned buffer so the very last pixel can cause GPF with that approach, although i guess it's easy to do the last pixel separately)
User avatar
Tenaja
Addict
Addict
Posts: 1948
Joined: Tue Nov 09, 2010 10:15 pm

Re: Why do they do that?

Post by Tenaja »

They might go out of their way to do that as a form of digital signature...perhaps...
User avatar
Keya
Addict
Addict
Posts: 1891
Joined: Thu Jun 04, 2015 7:10 am

Re: Why do they do that?

Post by Keya »

Tenaja good thinking, there are some pretty funky ways to add watermarks and steganography etc hehe
freak
PureBasic Team
PureBasic Team
Posts: 5929
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Re: Why do they do that?

Post by freak »

I think its more along the lines of this:
Hanlon's razor wrote:Never attribute to malice that which is adequately explained by stupidity.
This quote explains the world of IT quite well in my opinion :)
quidquid Latine dictum sit altum videtur
DarkDragon
Addict
Addict
Posts: 2218
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Re: Why do they do that?

Post by DarkDragon »

netmaestro wrote:In my original code it's based not on a color but on an index. This turns out to make all the difference because the diabolical subhuman that made this gif repeated the transparent color elsewhere in the colortable. The color at the transparency index is meant to be drawn transparent, the other equal color being meant for normal drawing. And so my 24bit version is checking the received color alone and it ends up drawing them both transparent. Hence the artifacts.
Index is correct, color not. It's because you might want to scale a transparent picture. If you scale it and you want to scale it smooth (with interpolation), the transparent color should be the same as the non-transparent neighbor's pixel color. Otherwise you won't only interpolate the transparency, but also the color. So assume you have for example a green square on a pink background and you declare pink as transparent. If you now scale it up, the green square will get a pink border. So you have to create a lot of exceptions in every kind of algorithm you use for handling images. The better way would be to add a second green entry in the palette and declare it as transparent.
bye,
Daniel
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8425
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Why do they do that?

Post by netmaestro »

Good point, I didn't consider that.
BERESHEIT
User avatar
Blue
Addict
Addict
Posts: 864
Joined: Fri Oct 06, 2006 4:41 am
Location: Canada

Re: Why do they do that?

Post by Blue »

Very interesting detective work on your part, netmaestro. :shock:
Keep sharing such experiences and insights.
They're the best learning opportunities i know.
Many thanks.
"That's not a bug..." said the programmer. "it's a feature! "
"Oh! I see..." replied the blind man.
User avatar
Keya
Addict
Addict
Posts: 1891
Joined: Thu Jun 04, 2015 7:10 am

Re: Why do they do that?

Post by Keya »

btw where is this funky "The Haberdasher's Puzzle" image? there's quite a few versions on google images but im interested in this technically weird one
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Why do they do that?

Post by davido »

@Keya,
It was published by Henry E Dudeney, a prolific English puzzlist, in his book the Canterbury Puzzles in 1905. He claims he made a wooden version which was hinged.
DE AA EB
User avatar
Keya
Addict
Addict
Posts: 1891
Joined: Thu Jun 04, 2015 7:10 am

Re: Why do they do that?

Post by Keya »

thanks davido, very interesting, but i'm interested in the GIF file to look at the technical aspect of this problem and make sure i can parse it ok
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8425
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Why do they do that?

Post by netmaestro »

BERESHEIT
Post Reply