~ubuntu-branches/ubuntu/trusty/graphicsmagick/trusty-proposed

« back to all changes in this revision

Viewing changes to tests/rwfile.c

  • Committer: Package Import Robot
  • Author(s): Daniel Kobras
  • Date: 2012-06-11 20:49:01 UTC
  • mfrom: (11.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20120611204901-uv199xjsz0g20vl6
Tags: 1.3.15-1
* New upstream release 1.3.15. Closes: #672982
  + Fixes crash in psiconv. Closes: #611260
* debian/control: Change (Build-)Depends from libpng12-dev to
  libpng-dev. Closes: #662359
* debian/control: Add (Build-)Depends on libjbig-dev. Closes: #669947
* debian/libgraphicsmagick3.symbols: Add symbols from new upstream
  release.
* PerlMagick/MANIFEST, PerlMagick/typemap: Add build fix for Perl 5.16,
  cherry-picked from upstream VCS. Closes: #676265

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
 
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
 
5
 *
 
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.
2
9
 *
3
10
 * Test file encode/decode operations via write/read/write/read
4
11
 * sequence to detect any data corruption problems.  This does not
27
34
    *magick_info;
28
35
 
29
36
  char
 
37
    basefilespec[MaxTextExtent],
30
38
    filename[MaxTextExtent],
31
39
    format[MaxTextExtent],
32
40
    infile[MaxTextExtent],
36
44
  int
37
45
    arg = 1,
38
46
    exit_status = 0,
39
 
    rows = 0,
40
 
    columns = 0,
41
47
    pause = 0;
42
48
 
 
49
  unsigned long
 
50
    original_frames;
 
51
 
43
52
  MagickBool
44
 
    check = MagickTrue;
45
 
 
46
 
  double
47
 
    fuzz_factor = 0;
 
53
    check = MagickTrue,
 
54
    check_for_added_frames = MagickTrue;
48
55
 
49
56
  ImageInfo
50
57
    *imageInfo;
52
59
  ExceptionInfo
53
60
    exception;
54
61
 
 
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));
 
68
 
55
69
  if (LocaleNCompare("rwfile",argv[0],7) == 0)
56
70
    InitializeMagick((char *) NULL);
57
71
  else
59
73
 
60
74
  imageInfo=CloneImageInfo(0);
61
75
  GetExceptionInfo( &exception );
62
 
  strcpy(filespec,"out_%d.%s");
 
76
 
 
77
  (void) strcpy(basefilespec,"out_%d.%s");
63
78
 
64
79
  for (arg=1; arg < argc; arg++)
65
80
    {
107
122
                  exit_status = 1;
108
123
                  goto program_exit;
109
124
                }
110
 
              if(imageInfo->depth != 8 && imageInfo->depth != 16 && imageInfo->depth != 32)
 
125
              if(imageInfo->depth != 8 && imageInfo->depth != 16 &&
 
126
                 imageInfo->depth != 32)
111
127
                {
112
 
                  (void) printf("-depth (%ld) not 8, 16, or 32\n", imageInfo->depth);
 
128
                  (void) printf("-depth (%ld) not 8, 16, or 32\n",
 
129
                                imageInfo->depth);
113
130
                  (void) fflush(stdout);
114
131
                  exit_status = 1;
115
132
                  goto program_exit;
117
134
            }
118
135
          else if (LocaleCompare("filespec",option+1) == 0)
119
136
            {
120
 
              (void) strcpy(filespec,argv[++arg]);
121
 
              (void) strcat(filespec,".%s");
 
137
              (void) strcpy(basefilespec,argv[++arg]);
122
138
            }
123
139
          else if (LocaleCompare("log",option+1) == 0)
124
140
            {
157
173
  if (arg != argc-2)
158
174
    {
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);
162
180
      exit_status = 1;
163
181
      goto program_exit;
167
185
  arg++;
168
186
  (void) strncpy( format, argv[arg], MaxTextExtent-1 );
169
187
 
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)
 
190
    {
 
191
      fprintf(stderr, "No support for \"%s\" format.\n",format);
 
192
      exit(1);
 
193
    }
 
194
 
 
195
  /*
 
196
    Some formats intentionally modify the number of frames.
 
197
    FAX & JBIG write multiple frames, but read only one frame.
 
198
  */
 
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;
174
205
 
175
206
  /*
176
207
   * Read original image
177
208
   */
178
209
 
179
210
  imageInfo->dither = 0;
 
211
 
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 );
 
218
 
185
219
  if (exception.severity != UndefinedException)
186
220
    {
187
221
      CatchException(&exception);
190
224
    }
191
225
  if ( original == (Image *)NULL )
192
226
    {
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);
195
230
      exit_status = 1;
196
231
      goto program_exit;
197
232
    }
198
233
 
199
234
  /*
200
 
   * Obtain original image size if format requires it
201
 
   */
202
 
  rows    = original->rows;
203
 
  columns = original->columns;
 
235
    Save first input file number of frames for later verifications.
 
236
  */
 
237
  original_frames=GetImageListLength(original);
 
238
 
 
239
  /*
 
240
    Get file format information.
 
241
  */
204
242
  size[0] = '\0';
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);
 
245
 
 
246
  if (magick_info->raw)
 
247
    {
 
248
      /*
 
249
       * Specify original image size if format requires it
 
250
       */
 
251
      FormatString( size, "%lux%lu", original->columns, original->rows );
 
252
    }
 
253
  if (IgnoreExtensionTreatment == magick_info->extension_treatment)
 
254
    {
 
255
      /*
 
256
        Prepend magic specifier if extension will be ignored.
 
257
      */
 
258
      (void) strcpy(filespec,format);
 
259
      (void) strcat(filespec,":");
 
260
      (void) strcat(filespec,basefilespec);
 
261
    }
 
262
  else
 
263
    {
 
264
      (void) strcat(filespec,".%s");
 
265
    }
 
266
 
 
267
  (void) sprintf( filename, basefilespec, 1, format );
 
268
  (void) remove(filename);
208
269
 
209
270
  /*
210
271
   * Save image to file
253
314
  /*
254
315
   * Save image to file
255
316
   */
 
317
  (void) sprintf( filename, basefilespec, 2, format );
 
318
  (void) remove(filename);
 
319
 
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 );
296
360
      /*
297
361
       * Check final output
298
362
       */
 
363
      double
 
364
        fuzz_factor = 0;
299
365
 
 
366
      /*
 
367
        Some formats are lossy.
 
368
      */
300
369
      if ((!strcmp( "CIN", format ) && (QuantumDepth == 8)) ||
301
370
          (!strcmp( "CMYK", format )) ||
302
371
          (!strcmp( "GRAY", format )) ||
313
382
          (final->compression == JPEGCompression))
314
383
        fuzz_factor = 0.06;
315
384
 
316
 
      if ( !IsImagesEqual(original, final ) &&
317
 
           (original->error.normalized_mean_error > fuzz_factor) )
318
 
        {
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);
324
 
          exit_status = 1;
325
 
          goto program_exit;
326
 
        }
 
385
      {
 
386
        Image
 
387
          *o,
 
388
          *f;
 
389
        
 
390
        unsigned long
 
391
          frame=0;
 
392
 
 
393
        /*
 
394
          Verify that frame pixels are identical (or close enough).
 
395
        */
 
396
        for (o=original, f=final, frame=0;
 
397
             ((o != (Image *) NULL) && (f != (Image *) NULL)) ;
 
398
             o = o->next, f = f->next, frame++)
 
399
          {
 
400
            printf("Checking frame %ld...\n",frame);
 
401
            if ( !IsImagesEqual(o, f ) &&
 
402
                 (original->error.normalized_mean_error > fuzz_factor) )
 
403
              {
 
404
                (void) printf( "R/W file check for format \"%s\" failed "
 
405
                               "(frame = %ld): %.6f/%.6f/%.6fe\n",
 
406
                               format,frame,
 
407
                               original->error.mean_error_per_pixel,
 
408
                               original->error.normalized_mean_error,
 
409
                               original->error.normalized_maximum_error);
 
410
                (void) fflush(stdout);
 
411
                exit_status = 1;
 
412
                goto program_exit;
 
413
              }
 
414
          }
 
415
 
 
416
        if (check_for_added_frames)
 
417
          {
 
418
            /*
 
419
              Verify that reads from file R/W #1 and file R/W #2 did
 
420
              return the same number of frames.
 
421
            */
 
422
            if ((o != (Image *) NULL) && (f != (Image *) NULL))
 
423
              {
 
424
                (void) printf("R/W file check for format \"%s\" failed due to "
 
425
                              "differing number of returned frames (%ld vs %ld)\n",
 
426
                              format,
 
427
                              GetImageListLength(original),
 
428
                              GetImageListLength(final));
 
429
                exit_status = 1;
 
430
                goto program_exit;
 
431
              }
 
432
 
 
433
            /*
 
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.
 
437
            */
 
438
            if (magick_info->adjoin)
 
439
              {
 
440
                unsigned long
 
441
                  final_frames;
 
442
 
 
443
                final_frames=GetImageListLength(final);
 
444
                if (original_frames != final_frames)
 
445
                  {
 
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);
 
450
                    exit_status = 1;
 
451
                    goto program_exit;
 
452
                  }
 
453
              }
 
454
          }
 
455
      }
327
456
    }
328
457
 
329
458
 program_exit: