Solved

How to display Gif89a with transparent color other than black

Posted on 2000-02-28
3
241 Views
Last Modified: 2010-04-06
I would like to know how can I display a GIF89a file with tranparent color other than black. The popular browsers do it but I want to do this in my own program written in C++ for Windows 95 (and higher). If transparent color is black I made a mask for image replacing all black pixels by white ones and the others by the white ones and next I used two BitBlt's, the first with the mask and AND ROP-code and the second with the image and the OR ROP-code. But if a transparent color is other than black this method obviously doesn't work. Nevertheless the browsers know how to resolve this problem.  Do you know any method for C++ Windows program ?
Thank you in advance for any response
0
Comment
Question by:rainette
  • 2
3 Comments
 
LVL 4

Accepted Solution

by:
nils pipenbrinck earned 100 total points
Comment Utility
Yes, you can do that.

I don't know how you load your gif-files.. I think you use a third party library for that.. take a look at the documentation how to get the transparent color index.

If the library don't support this, you can write a code which opens the gif yourself.. just scan the header for the extension flag and extract the transparent color index (if present). You only need the header, the hard part (decoding the image data) can still be done by your existing code.

here is a documentation of the fileformat:

http://www.cubic.org/source/archive/fileform/graphic/gif/gif89a.txt

After you know which of the 256 colors is your transparent color, you can simply build your and/or mask based on that color. It's nothing more than a simple loop which iterates over the pixels and sets the pixel in the mask based on the pixel color... A quite easy job I think.

Hope that helps.. I cannot give you sourcecode, because I've never dealed with transparent gif files myself..

Regards,

  Nils Pipenbrinck
0
 

Author Comment

by:rainette
Comment Utility
I load GIF-files with my own procedure which is slightly modified code from Nabayoti Barcacati's book on Borland C++ programming. But WHAT IS "A THIRD PARTY LIBRARY" ? Thanks to your hint I think that I found a better one: instead to change pixels I will change color values in appropriate color palette place.
( GIF-files I know always use color palettes. )
For image I'll change color value for transparent color index to black ( RGB(0,0,0) ), for mask - I'll change this value to white( RGB(255,255,255) ) and all the other values to black. Is it a good idea ?
0
 
LVL 4

Expert Comment

by:nils pipenbrinck
Comment Utility
changing the palette-entry is a good idea.. and it'll always work since there aren't any gif files without palette.

what's a third party library? that's a library you buy don't write yourself but buy somewhere... Like for example you want to use a library that handles thousands of fileformats you'll better buy something instead of spending a year developing and debugging it yourself.

Nils
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Keep your audience engaged and get the most out of your next presentation with these quick Prezi tips.
Many programs have tried to outwit PowerPoint in terms of technology and skill. These programs, however, still lack several characteristics that PowerPoint has possessed from the start. Here's why PowerPoint replacements won't entirely work for desi…
In this tutorial viewers will learn how to create blended and gradiated shapes in Illustrator using the blend tool Draw two shapes, one of them in a different color: Select both and create a blend by going to Object > Blend > Make: Blends can also b…
It’s easy to embed any of your public Prezi presentations on your website or social network to share with others. Learn how simple it is in this tutorial.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now