2
* Copyright (C) 2003 - 2011 GraphicsMagick Group
3
* Copyright (C) 2003 ImageMagick Studio
4
* Copyright 1991-1999 E. I. du Pont de Nemours and Company
6
* This program is covered by multiple licenses, which are described in
7
* Copyright.txt. You should have received a copy of Copyright.txt with this
8
* package; otherwise see http://www.graphicsmagick.org/www/Copyright.html.
3
10
* Test file encode/decode operations via write/read/write/read
4
11
* sequence to detect any data corruption problems. This does not
62
(void) memset(basefilespec,0,sizeof(basefilespec));
63
(void) memset(filename,0,sizeof(filename));
64
(void) memset(format,0,sizeof(format));
65
(void) memset(infile,0,sizeof(infile));
66
(void) memset(size,0,sizeof(size));
67
(void) memset(filespec,0,sizeof(filespec));
55
69
if (LocaleNCompare("rwfile",argv[0],7) == 0)
56
70
InitializeMagick((char *) NULL);
60
74
imageInfo=CloneImageInfo(0);
61
75
GetExceptionInfo( &exception );
62
strcpy(filespec,"out_%d.%s");
77
(void) strcpy(basefilespec,"out_%d.%s");
64
79
for (arg=1; arg < argc; arg++)
108
123
goto program_exit;
110
if(imageInfo->depth != 8 && imageInfo->depth != 16 && imageInfo->depth != 32)
125
if(imageInfo->depth != 8 && imageInfo->depth != 16 &&
126
imageInfo->depth != 32)
112
(void) printf("-depth (%ld) not 8, 16, or 32\n", imageInfo->depth);
128
(void) printf("-depth (%ld) not 8, 16, or 32\n",
113
130
(void) fflush(stdout);
115
132
goto program_exit;
118
135
else if (LocaleCompare("filespec",option+1) == 0)
120
(void) strcpy(filespec,argv[++arg]);
121
(void) strcat(filespec,".%s");
137
(void) strcpy(basefilespec,argv[++arg]);
123
139
else if (LocaleCompare("log",option+1) == 0)
157
173
if (arg != argc-2)
159
175
(void) printf("arg=%d, argc=%d\n", arg, argc);
160
(void) printf ( "Usage: %s [-compress algorithm -debug events -depth integer -filespec spec -log format -nocheck -size geometry -verbose] infile format\n", argv[0] );
176
(void) printf ( "Usage: %s [-compress algorithm -debug events -depth "
177
"integer -filespec spec -log format -nocheck "
178
"-size geometry -verbose] infile format\n", argv[0] );
161
179
(void) fflush(stdout);
163
181
goto program_exit;
168
186
(void) strncpy( format, argv[arg], MaxTextExtent-1 );
170
/* for (arg=0; arg < argc; arg++) */
171
/* (void) printf("%s ", argv[arg]); */
172
/* (void) printf("\n"); */
173
/* (void) fflush(stdout); */
188
magick_info=GetMagickInfo(format,&exception);
189
if (magick_info == (MagickInfo *) NULL)
191
fprintf(stderr, "No support for \"%s\" format.\n",format);
196
Some formats intentionally modify the number of frames.
197
FAX & JBIG write multiple frames, but read only one frame.
199
if ((!strcmp( "FAX", format )) ||
200
(!strcmp( "JBIG", format )) ||
201
(!strcmp( "MNG", format )) ||
202
(!strcmp( "PSD", format )) ||
203
(!strcmp( "PTIF", format )) )
204
check_for_added_frames = MagickFalse;
176
207
* Read original image
179
210
imageInfo->dither = 0;
180
212
(void) strncpy( imageInfo->filename, infile, MaxTextExtent-1 );
181
(void) fflush(stdout);
213
if (!magick_info->adjoin || !check_for_added_frames)
214
(void) strcat( imageInfo->filename, "[0]" );
182
215
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
183
"Reading image %s", imageInfo->filename);
216
"Reading image %s", imageInfo->filename);
184
217
original = ReadImage ( imageInfo, &exception );
185
219
if (exception.severity != UndefinedException)
187
221
CatchException(&exception);
191
225
if ( original == (Image *)NULL )
193
(void) printf ( "Failed to read original image %s\n", imageInfo->filename );
227
(void) printf ( "Failed to read original image %s\n",
228
imageInfo->filename );
194
229
(void) fflush(stdout);
196
231
goto program_exit;
200
* Obtain original image size if format requires it
202
rows = original->rows;
203
columns = original->columns;
235
Save first input file number of frames for later verifications.
237
original_frames=GetImageListLength(original);
240
Get file format information.
205
243
magick_info=GetMagickInfo(format,&exception);
206
if (magick_info && magick_info->raw)
207
FormatString( size, "%dx%d", columns, rows );
244
strcpy(filespec,basefilespec);
246
if (magick_info->raw)
249
* Specify original image size if format requires it
251
FormatString( size, "%lux%lu", original->columns, original->rows );
253
if (IgnoreExtensionTreatment == magick_info->extension_treatment)
256
Prepend magic specifier if extension will be ignored.
258
(void) strcpy(filespec,format);
259
(void) strcat(filespec,":");
260
(void) strcat(filespec,basefilespec);
264
(void) strcat(filespec,".%s");
267
(void) sprintf( filename, basefilespec, 1, format );
268
(void) remove(filename);
210
271
* Save image to file
254
315
* Save image to file
317
(void) sprintf( filename, basefilespec, 2, format );
318
(void) remove(filename);
256
320
(void) sprintf( filename, filespec, 2, format );
257
321
(void) strncpy( original->magick, format, MaxTextExtent-1 );
258
322
(void) strncpy( original->filename, filename, MaxTextExtent-1 );
313
382
(final->compression == JPEGCompression))
314
383
fuzz_factor = 0.06;
316
if ( !IsImagesEqual(original, final ) &&
317
(original->error.normalized_mean_error > fuzz_factor) )
319
(void) printf( "R/W file check for format \"%s\" failed: %u/%.6f/%.6fe\n",
320
format,(unsigned int) original->error.mean_error_per_pixel,
321
original->error.normalized_mean_error,
322
original->error.normalized_maximum_error);
323
(void) fflush(stdout);
394
Verify that frame pixels are identical (or close enough).
396
for (o=original, f=final, frame=0;
397
((o != (Image *) NULL) && (f != (Image *) NULL)) ;
398
o = o->next, f = f->next, frame++)
400
printf("Checking frame %ld...\n",frame);
401
if ( !IsImagesEqual(o, f ) &&
402
(original->error.normalized_mean_error > fuzz_factor) )
404
(void) printf( "R/W file check for format \"%s\" failed "
405
"(frame = %ld): %.6f/%.6f/%.6fe\n",
407
original->error.mean_error_per_pixel,
408
original->error.normalized_mean_error,
409
original->error.normalized_maximum_error);
410
(void) fflush(stdout);
416
if (check_for_added_frames)
419
Verify that reads from file R/W #1 and file R/W #2 did
420
return the same number of frames.
422
if ((o != (Image *) NULL) && (f != (Image *) NULL))
424
(void) printf("R/W file check for format \"%s\" failed due to "
425
"differing number of returned frames (%ld vs %ld)\n",
427
GetImageListLength(original),
428
GetImageListLength(final));
434
If format supports multiple frames, then we should expect
435
that frames are not lost (or spuriously added) due to
436
read/write of format.
438
if (magick_info->adjoin)
443
final_frames=GetImageListLength(final);
444
if (original_frames != final_frames)
446
(void) printf("R/W file check for format \"%s\" failed due "
447
"to differing number of returned frames (%ld "
448
"vs %ld) from original file\n",
449
format,original_frames,final_frames);