Skip to content

Commit b481525

Browse files
author
Lawrence D'Oliveiro
committed
Fix PNG subtitles with GraphicsMagick > 1.3.7, thanks to Ville Skyttä and Maurizio Paolini.
Also, whether to use the "old" or "new" RGBA behavior of ImageMagick and GraphicsMagick is now made at runtime, removing a dependency on the compile time *Magick version.
1 parent 0aa6d93 commit b481525

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

src/subgen-image.c

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,22 @@ static void createimage(pict *s, int w, int h)
164164
} /*createimage*/
165165

166166
#if defined(HAVE_MAGICK) || defined(HAVE_GMAGICK)
167+
// meaning of A in RGBA swapped in ImageMagick 6.0.0 and GraphicsMagick 1.3.8
168+
#if defined(HAVE_MAGICK)
169+
#define XMAGICK_NEW_RGBA_MINVER 0x600
170+
#else // HAVE_GMAGICK
171+
#define XMAGICK_NEW_RGBA_MINVER 0x060300
172+
#define ExportImagePixels DispatchImage
173+
#endif
167174
static int read_magick(pict *s)
168175
/* uses ImageMagick/GraphicsMagick to read image s from s->fname. */
169176
{
170177
Image *im;
171178
ImageInfo *ii;
172179
ExceptionInfo ei;
173180
int x,y;
181+
unsigned long magickver;
182+
unsigned char amask;
174183

175184
GetExceptionInfo(&ei);
176185
ii=CloneImageInfo(NULL);
@@ -188,16 +197,12 @@ static int read_magick(pict *s)
188197
return -1;
189198
}
190199
createimage(s,im->columns,im->rows);
200+
GetMagickVersion(&magickver);
201+
amask = magickver < XMAGICK_NEW_RGBA_MINVER ? 255 : 0;
191202
for( y=0; y<im->rows; y++ ) {
192203
char pdata[MAXX*4];
193204

194-
if(!
195-
#ifdef HAVE_MAGICK
196-
ExportImagePixels
197-
#else // HAVE_GMAGICK
198-
DispatchImage
199-
#endif
200-
(im,0,y,im->columns,1,"RGBA",CharPixel,pdata,&ei)) {
205+
if(!ExportImagePixels(im,0,y,im->columns,1,"RGBA",CharPixel,pdata,&ei)) {
201206
fprintf(stderr,"ERR: Extracting row %d from %s (%s,%s)\n",y,s->fname,ei.reason,ei.description);
202207
CatchException(&ei);
203208
MagickError(ei.severity,ei.reason,ei.description);
@@ -209,13 +214,7 @@ static int read_magick(pict *s)
209214
p.r=pdata[x*4];
210215
p.g=pdata[x*4+1];
211216
p.b=pdata[x*4+2];
212-
// the meaning of RGBA swapped with ImageMagick 6.0.0...
213-
// ...but not with GraphicsMagick
214-
#if defined(HAVE_MAGICK) && MagickLibVersion >= 0x600
215-
p.a=pdata[x*4+3];
216-
#else
217-
p.a=255-pdata[x*4+3];
218-
#endif
217+
p.a = pdata[x*4+3] ^ amask;
219218
putpixel(s,y*s->width+x,&p);
220219
}
221220
}

0 commit comments

Comments
 (0)