Why do they do that?
- netmaestro
- PureBasic Bullfrog
- Posts: 8425
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Why do they do that?
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
- Kwai chang caine
- Always Here
- Posts: 5342
- Joined: Sun Nov 05, 2006 11:42 pm
- Location: Lyon - France
Re: Why do they do that?
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
And nothing for that...i say thanks MASTERS
What we become without persons like you
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
And nothing for that...i say thanks MASTERS
What we become without persons like you
The happiness is a road...
Not a destination
Not a destination
Re: Why do they do that?
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).
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).
Re: Why do they do that?
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)
Re: Why do they do that?
They might go out of their way to do that as a form of digital signature...perhaps...
Re: Why do they do that?
Tenaja good thinking, there are some pretty funky ways to add watermarks and steganography etc hehe
Re: Why do they do that?
I think its more along the lines of this:
This quote explains the world of IT quite well in my opinionHanlon's razor wrote:Never attribute to malice that which is adequately explained by stupidity.
quidquid Latine dictum sit altum videtur
-
- Addict
- Posts: 2218
- Joined: Mon Jun 02, 2003 9:16 am
- Location: Germany
- Contact:
Re: Why do they do that?
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.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.
bye,
Daniel
Daniel
- netmaestro
- PureBasic Bullfrog
- Posts: 8425
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: Why do they do that?
Very interesting detective work on your part, netmaestro.
Keep sharing such experiences and insights.
They're the best learning opportunities i know.
Many thanks.
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.
"Oh! I see..." replied the blind man.
Re: Why do they do that?
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
Re: Why do they do that?
@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.
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
Re: Why do they do that?
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
- netmaestro
- PureBasic Bullfrog
- Posts: 8425
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada