comparison libmpdemux/demux_gif.c @ 21895:5d9486bbc156

Implement gif transparency
author reimar
date Sat, 13 Jan 2007 12:56:02 +0000
parents 449b9fb6f67b
children b2640a639ac7
comparison
equal deleted inserted replaced
21894:449b9fb6f67b 21895:5d9486bbc156
51 int len = 0; 51 int len = 0;
52 demux_packet_t *dp = NULL; 52 demux_packet_t *dp = NULL;
53 ColorMapObject *effective_map = NULL; 53 ColorMapObject *effective_map = NULL;
54 char *buf = NULL; 54 char *buf = NULL;
55 int refmode = 0; 55 int refmode = 0;
56 int transparency = 0;
57 uint8_t transparent_col;
56 58
57 while (type != IMAGE_DESC_RECORD_TYPE) { 59 while (type != IMAGE_DESC_RECORD_TYPE) {
58 if (DGifGetRecordType(gif, &type) == GIF_ERROR) { 60 if (DGifGetRecordType(gif, &type) == GIF_ERROR) {
59 PrintGifError(); 61 PrintGifError();
60 return 0; // oops 62 return 0; // oops
76 } 78 }
77 if (code == 0xF9) { 79 if (code == 0xF9) {
78 int frametime = 0; 80 int frametime = 0;
79 if (p[0] == 4) // is the length correct? 81 if (p[0] == 4) // is the length correct?
80 { 82 {
83 transparency = p[1] & 1;
81 frametime = (p[3] << 8) | p[2]; // set the time, centiseconds 84 frametime = (p[3] << 8) | p[2]; // set the time, centiseconds
82 refmode = (p[1] >> 2) & 3; 85 refmode = (p[1] >> 2) & 3;
86 transparent_col = p[4];
83 } 87 }
84 priv->current_pts += frametime; 88 priv->current_pts += frametime;
85 } else if ((code == 0xFE) && (verbose)) { // comment extension 89 } else if ((code == 0xFE) && (verbose)) { // comment extension
86 // print iff verbose 90 // print iff verbose
87 printf("GIF comment: "); 91 printf("GIF comment: ");
142 priv->palette[(y * 4) + 1] = effective_map->Colors[y].Green; 146 priv->palette[(y * 4) + 1] = effective_map->Colors[y].Green;
143 priv->palette[(y * 4) + 2] = effective_map->Colors[y].Red; 147 priv->palette[(y * 4) + 2] = effective_map->Colors[y].Red;
144 priv->palette[(y * 4) + 3] = 0; 148 priv->palette[(y * 4) + 3] = 0;
145 } 149 }
146 150
151 if (transparency) {
152 uint8_t *dpos = dest, *spos = buf;
153 int hleft = h;
154 while (hleft-- > 0) {
155 int wleft = w;
156 while (wleft-- > 0) {
157 if (*spos != transparent_col)
158 *dpos = *spos;
159 dpos++; spos++;
160 }
161 dpos += priv->w - w;
162 spos += gif->Image.Width - w;
163 }
164 } else
147 memcpy_pic(dest, buf, w, h, priv->w, gif->Image.Width); 165 memcpy_pic(dest, buf, w, h, priv->w, gif->Image.Width);
148 166
149 if (refmode == 1) memcpy(priv->refimg, dp->buffer, priv->w * priv->h); 167 if (refmode == 1) memcpy(priv->refimg, dp->buffer, priv->w * priv->h);
150 if (refmode == 2 && priv->useref) { 168 if (refmode == 2 && priv->useref) {
151 dest = priv->refimg + priv->w * t + l; 169 dest = priv->refimg + priv->w * t + l;