1 /*
2  *  probe_im.c
3  *
4  *  Copyright (C) Thomas Oestreich - June 2001
5  *
6  *  This file is part of transcode, a video stream processing tool
7  *
8  *  transcode is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2, or (at your option)
11  *  any later version.
12  *
13  *  transcode is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with GNU Make; see the file COPYING.  If not, write to
20  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
21  *
22  */
23 
24 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
27 
28 #include <stdlib.h>
29 #include <stdio.h>
30 
31 #ifdef HAVE_IMAGEMAGICK
32 /* Note: because of ImageMagick bogosity, this must be included first, so
33  * we can undefine the PACKAGE_* symbols it splats into our namespace.
34  * However, since we need config.h to find out whether we can include it
35  * in the first place, we also have to undefine the symbols beforehand. */
36 # undef PACKAGE_BUGREPORT
37 # undef PACKAGE_NAME
38 # undef PACKAGE_STRING
39 # undef PACKAGE_TARNAME
40 # undef PACKAGE_VERSION
41 
42 # ifdef HAVE_BROKEN_WAND
43 # include <wand/magick-wand.h>
44 # else /* we have a SANE wand header */
45 # include <wand/MagickWand.h>
46 # endif /* HAVE_BROKEN_WAND */
47 
48 # undef PACKAGE_BUGREPORT
49 # undef PACKAGE_NAME
50 # undef PACKAGE_STRING
51 # undef PACKAGE_TARNAME
52 # undef PACKAGE_VERSION
53 #endif
54 
55 #include "transcode.h"
56 #include "tcinfo.h"
57 #include "ioaux.h"
58 #include "tc.h"
59 #include "libtc/libtc.h"
60 
61 #ifdef HAVE_IMAGEMAGICK
62 
63 
probe_im(info_t * ipipe)64 void probe_im(info_t *ipipe)
65 {
66     MagickWand *wand = NULL;
67     MagickBooleanType status;
68 
69     MagickWandGenesis();
70     wand = NewMagickWand();
71 
72     if (wand == NULL) {
73         tc_log_error(__FILE__, "cannot create magick wand");
74         ipipe->error = 1;
75         return;
76     }
77 
78     status = MagickReadImage(wand, ipipe->name);
79     if (status == MagickFalse) {
80         ExceptionType severity;
81         const char *description = MagickGetException(wand, &severity);
82 
83         tc_log_error(__FILE__, "%s", description);
84 
85         MagickRelinquishMemory((void*)description);
86         ipipe->error = 1;
87         return;
88     }
89     MagickSetLastIterator(wand);
90 
91 
92 	/* read all video parameter from input file */
93 	ipipe->probe_info->width = MagickGetImageWidth(wand);
94 	ipipe->probe_info->height = MagickGetImageHeight(wand);
95 
96 	/* slide show? */
97 	ipipe->probe_info->frc = 9;   /* FRC for 1 fps */
98 	ipipe->probe_info->fps = 1.0;
99 
100 	ipipe->probe_info->magic = ipipe->magic;
101 	ipipe->probe_info->codec = TC_CODEC_RGB;
102 
103     DestroyMagickWand(wand);
104     MagickWandTerminus();
105 
106 	return;
107 }
108 
109 #else   // HAVE_IMAGEMAGICK
110 
probe_im(info_t * ipipe)111 void probe_im(info_t *ipipe)
112 {
113 	tc_log_error(__FILE__, "no support for ImageMagick compiled - exit.");
114 	ipipe->error = 1;
115 	return;
116 }
117 
118 #endif
119 
120 /*************************************************************************/
121 
122 /*
123  * Local variables:
124  *   c-file-style: "stroustrup"
125  *   c-file-offsets: ((case-label . *) (statement-case-intro . *))
126  *   indent-tabs-mode: nil
127  * End:
128  *
129  * vim: expandtab shiftwidth=4:
130  */
131