Solved

How to display Gif89a with transparent color other than black

Posted on 2000-02-28
3
245 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
ID: 2568380
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
ID: 2569083
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
ID: 2569148
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Web design prices 4 398
I want to find a font for a Boxing logo 6 1,069
D3, SVG, dragging a star. 2 133
Saving html pages from the web 5 86
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…
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Learn how to create interesting presentations by including videos to keep your audience engaged using Prezi. Select "Insert" from the top menu in your Prezi editor: Select "YouTube Video": Paste the video URL into the prompt: "Select "Insert":…

920 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