3 use ExtUtils::MakeMaker;
7 my $verbose = $ENV{IM_VERBOSE};
11 GetOptions("incpath=s", \@incpaths,
12 "libpath=s" => \@libpaths,
13 "verbose|v" => \$verbose);
18 my $MM_ver = eval $ExtUtils::MakeMaker::VERSION;
22 NAME => 'Imager::File::GIF',
23 VERSION_FROM => 'GIF.pm',
24 OBJECT => 'GIF.o imgif.o',
25 clean => { FILES => 'testout' },
29 if ($BUILDING_IMAGER) {
31 unshift @INC, "../lib";
35 print "GIF: building independently\n";
36 require Imager::ExtUtils;
37 push @inc, Imager::ExtUtils->includes;
38 $opts{TYPEMAPS} = [ Imager::ExtUtils->typemap ];
40 # Imager required configure through use
41 my @Imager_req = ( Imager => "0.94" );
42 if ($MM_ver >= 6.46) {
52 "Test::More" => "0.47",
56 homepage => "http://imager.perl.org/",
57 repository => "git://git.imager.perl.org/imager.git",
58 bugtracker => "http://rt.cpan.org/NoAuth/Bugs.html?Dist=Imager",
69 require Imager::Probe;
74 inccheck => sub { -e File::Spec->catfile($_[0], "gif_lib.h") },
76 testcode => _gif_test_code(),
77 testcodeheaders => [ "stddef.h", "gif_lib.h", "stdio.h", "errno.h", "string.h" ],
78 incpath => \@incpaths,
79 libpath => \@libpaths,
83 my $probe_res = Imager::Probe->probe(\%probe);
85 $IMAGER_LIBS{GIF} = 1;
87 push @inc, $probe_res->{INC};
88 $opts{LIBS} = $probe_res->{LIBS};
89 $opts{DEFINE} = $probe_res->{DEFINE};
93 $opts{AUTHOR} = 'Tony Cook <tonyc@cpan.org>';
94 $opts{ABSTRACT} = 'GIF Image file support';
100 $IMAGER_LIBS{GIF} = 0;
102 if ($BUILDING_IMAGER) {
103 ExtUtils::MakeMaker::WriteEmptyMakefile(%opts);
107 die "OS unsupported: GIF libraries or headers not found\n";
113 /* TODO: test DGifOpen() and processing with callbacks */
115 #ifdef GIF_LIB_VERSION
116 const char vers[] = GIF_LIB_VERSION;
117 const char *versp = vers;
121 int ver_maj = GIFLIB_MAJOR;
122 int ver_min = GIFLIB_MINOR;
124 GifColorType colors[2];
130 #if defined(GIFLIB_MAJOR) && GIFLIB_MAJOR >= 5
131 gf=DGifOpenFileName("testimg/expected.gif", &error);
133 gf=DGifOpenFileName("testimg/expected.gif");
136 fprintf(stderr, "GIF: Cannot open testimg/expected.gif\n");
139 if (gf->SWidth != 16 || gf->SHeight != 16) {
140 fprintf(stderr, "GIF: bad screen description (%d x %d)\n", gf->SWidth, gf->SHeight);
143 #if !defined(GIFLIB_MAJOR) || GIFLIB_MAJOR < 5
144 /* crashes in older versions of giflib, not used in giflib 5 */
145 EGifSetGifVersion("89a");
146 EGifSetGifVersion("87a");
149 #ifdef GIF_LIB_VERSION
150 /* skip the " Version " */
151 while (*versp && (*versp < '0' || *versp > '9'))
154 fprintf(stderr, "GIF: Cannot find version number in '%s'\n", vers);
158 while (*versp && *versp >= '0' && *versp <= '9') {
160 ver_maj += *versp++ - '0';
162 if (*versp != '.' || versp[1] < '0' || versp[1] > '9') {
163 fprintf(stderr, "Cannot parse major version number in '%s'\n", vers);
166 ++versp; /* skip '.' */
168 while (*versp && *versp >= '0' && *versp <= '9') {
170 ver_min += *versp++ - '0';
174 fprintf(stderr, "GIF: gif lib version 3 is no longer supported\n");
177 if (ver_maj == 4 && ver_min < 1) {
178 fprintf(stderr, "GIF: you need at least giflib 4.1\n");
182 /* test we write both GIF87a and GIF89a files */
183 for (mode = 0; mode < 2; ++mode) {
184 #if defined(GIFLIB_MAJOR) && GIFLIB_MAJOR >= 5
185 gf=EGifOpenFileName("probe.gif", 0, &error);
186 EGifSetGifVersion(gf, mode);
189 gf=EGifOpenFileName("probe.gif", 0);
190 EGifSetGifVersion(mode ? "89a" : "87a");
193 fprintf(stderr, "GIF: cannot create probe.gif for testing\n");
196 colors[0].Red = colors[0].Green = colors[0].Blue = 0;
197 colors[1].Red = colors[1].Green = colors[1].Blue = 0;
198 #if defined(GIFLIB_MAJOR) && GIFLIB_MAJOR >= 5
199 map = GifMakeMapObject(2, colors);
201 map = MakeMapObject(2, colors);
203 EGifPutScreenDesc(gf, 1, 1, 1, 0, map);
204 EGifPutImageDesc(gf, 0, 0, 1, 1, 0, NULL);
206 #if defined(GIFLIB_MAJOR) && ((GIFLIB_MAJOR >= 5 && GIFLIB_MINOR >= 1) || GIFLIB_MAJOR >= 6)
207 EGifCloseFile(gf, &error);
212 fh = fopen("probe.gif", "r");
214 fprintf(stderr, "GIF: cannot open probe.gif for reading\n");
218 memset(buf, 0, sizeof(buf));
219 if (fread(buf, 1, 6, fh) != 6) {
220 fprintf(stderr, "GIF: cannot read probe.gif header (%d)\n", errno);
225 if (memcmp(buf, mode ? "GIF89a" : "GIF87a", 6)) {
226 fprintf(stderr, "GIF: incorrect header on test - 4.2.0 bug? (mode %d, buf %-6s)\n", mode, buf);
231 fprintf(stderr, "GIF: Major %d, Minor %d\n", ver_maj, ver_min);