~ubuntu-branches/ubuntu/quantal/imagemagick/quantal

« back to all changes in this revision

Viewing changes to wand/compare.c

  • Committer: Bazaar Package Importer
  • Author(s): Muharem Hrnjadovic
  • Date: 2009-06-04 13:01:13 UTC
  • mfrom: (1.1.5 upstream) (6.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20090604130113-my9114jxmafpwew3
Tags: 7:6.5.1.0-1.1ubuntu1
* Merge from debian unstable, remaining changes:
  - (Build-)depend on libltdl7-dev instead of libltdl3-dev (the armel buildds
    currently have both available).
  - Don't build-dep on librsvg, it brings in excessive dependencies

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
%                               December 2003                                 %
18
18
%                                                                             %
19
19
%                                                                             %
20
 
%  Copyright 1999-2008 ImageMagick Studio LLC, a non-profit organization      %
 
20
%  Copyright 1999-2009 ImageMagick Studio LLC, a non-profit organization      %
21
21
%  dedicated to making software imaging solutions freely available.           %
22
22
%                                                                             %
23
23
%  You may not use this file except in compliance with the License.  You may  %
74
74
%
75
75
%    o metadata: any metadata is returned here.
76
76
%
77
 
%    o exception: Return any errors or warnings in this structure.
 
77
%    o exception: return any errors or warnings in this structure.
78
78
%
79
79
*/
80
80
 
81
 
static void CompareUsage(void)
 
81
static MagickBooleanType CompareUsage(void)
82
82
{
83
83
  const char
84
84
    **p;
125
125
      "-quiet               suppress all warning messages",
126
126
      "-quantize colorspace reduce colors in this colorspace",
127
127
      "-regard-warnings     pay attention to warning messages",
128
 
      "-respect-parenthesis settings remain in effect until parenthesis boundary",
 
128
      "-respect-parentheses settings remain in effect until parenthesis boundary",
129
129
      "-sampling-factor geometry",
130
130
      "                     horizontal and vertical sampling factor",
131
131
      "-seed value          seed a new sequence of pseudo-random numbers",
160
160
  (void) printf(
161
161
    "image type as the filename suffix (i.e. image.ps).  Specify 'file' as\n");
162
162
  (void) printf("'-' for standard input or output.\n");
163
 
  exit(0);
 
163
  return(MagickFalse);
164
164
}
165
165
 
166
166
WandExport MagickBooleanType CompareImageCommand(ImageInfo *image_info,
184
184
#define ThrowCompareInvalidArgumentException(option,argument) \
185
185
{ \
186
186
  (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
187
 
    "InvalidArgument","`%s': %s",argument,option); \
 
187
    "InvalidArgument","`%s': %s",option,argument); \
188
188
  DestroyCompare(); \
189
189
  return(MagickFalse); \
190
190
}
205
205
  Image
206
206
    *difference_image,
207
207
    *image,
208
 
    *reconstruct_image;
 
208
    *reconstruct_image,
 
209
    *subimage;
209
210
 
210
211
  ImageStack
211
212
    image_stack[MaxImageStackDepth+1];
248
249
        }
249
250
    }
250
251
  if (argc < 3)
251
 
    CompareUsage();
 
252
    {
 
253
      (void) CompareUsage();
 
254
      return(MagickTrue);
 
255
    }
252
256
  channels=AllChannels;
253
257
  difference_image=NewImageList();
254
258
  distortion=0.0;
546
550
      {
547
551
        if ((LocaleCompare("help",option+1) == 0) ||
548
552
            (LocaleCompare("-help",option+1) == 0))
549
 
          CompareUsage();
 
553
          return(CompareUsage());
550
554
        if (LocaleCompare("highlight-color",option+1) == 0)
551
555
          {
552
556
            if (*option == '+')
588
592
            char
589
593
              *p;
590
594
 
 
595
            double
 
596
              value;
 
597
 
591
598
            long
592
599
              resource;
593
600
 
604
611
            i++;
605
612
            if (i == (long) argc)
606
613
              ThrowCompareException(OptionError,"MissingArgument",option);
607
 
            (void) strtod(argv[i],&p);
 
614
            value=strtod(argv[i],&p);
608
615
            if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
609
616
              ThrowCompareInvalidArgumentException(option,argv[i]);
610
617
            break;
611
618
          }
 
619
        if (LocaleCompare("list",option+1) == 0)
 
620
          {
 
621
            long
 
622
              list;
 
623
 
 
624
            if (*option == '+')
 
625
              break;
 
626
            i++;
 
627
            if (i == (long) argc)
 
628
              ThrowCompareException(OptionError,"MissingArgument",option);
 
629
            list=ParseMagickOption(MagickListOptions,MagickFalse,argv[i]);
 
630
            if (list < 0)
 
631
              ThrowCompareException(OptionError,"UnrecognizedListType",argv[i]);
 
632
            (void) MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
 
633
              argv+j,exception);
 
634
            DestroyCompare();
 
635
            return(MagickTrue);
 
636
          }
612
637
        if (LocaleCompare("log",option+1) == 0)
613
638
          {
614
639
            if (*option == '+')
712
737
      {
713
738
        if (LocaleCompare("regard-warnings",option+1) == 0)
714
739
          break;
715
 
        if (LocaleCompare("respect-parenthesis",option+1) == 0)
 
740
        if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
716
741
          {
717
742
            respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
718
743
            break;
833
858
      default:
834
859
        ThrowCompareException(OptionError,"UnrecognizedOption",option)
835
860
    }
836
 
    fire=ParseMagickOption(MagickImageListOptions,MagickFalse,option+1) < 0 ? 
 
861
    fire=ParseMagickOption(MagickImageListOptions,MagickFalse,option+1) < 0 ?
837
862
      MagickFalse : MagickTrue;
838
863
    if (fire != MagickFalse)
839
864
      FireImageStack(MagickTrue,MagickTrue,MagickTrue);
848
873
  FinalizeImageSettings(image_info,image);
849
874
  image=GetImageFromList(image,0);
850
875
  reconstruct_image=GetImageFromList(image,1);
851
 
  difference_image=CompareImageChannels(image,reconstruct_image,channels,
852
 
    metric,&distortion,exception);
 
876
  subimage=ExtractSubimageFromImage(image,reconstruct_image,exception);
 
877
  if (subimage == (Image *) NULL)
 
878
    difference_image=CompareImageChannels(image,reconstruct_image,channels,
 
879
      metric,&distortion,exception);
 
880
  else
 
881
    {
 
882
      difference_image=CompareImageChannels(subimage,reconstruct_image,channels,
 
883
        metric,&distortion,exception);
 
884
      subimage=DestroyImage(subimage);
 
885
    }
853
886
  if (difference_image == (Image *) NULL)
854
887
    status=0;
855
888
  else
856
889
    {
857
890
      if (image_info->verbose != MagickFalse)
858
891
        (void) IsImagesEqual(image,reconstruct_image);
 
892
      if (*difference_image->magick == '\0')
 
893
        (void) CopyMagickString(difference_image->magick,image->magick,
 
894
          MaxTextExtent);
859
895
      status&=WriteImages(image_info,difference_image,argv[argc-1],exception);
860
896
      if ((metadata != (char **) NULL) && (format != (char *) NULL))
861
897
        {
870
906
          (void) ConcatenateString(&(*metadata),"\n");
871
907
          text=DestroyString(text);
872
908
        }
873
 
      difference_image=DestroyImageList(difference_image);
874
909
      if (image_info->verbose == MagickFalse)
875
 
        switch (metric)
876
910
        {
877
 
          case MeanAbsoluteErrorMetric:
878
 
          case MeanSquaredErrorMetric:
879
 
          case RootMeanSquaredErrorMetric:
880
 
          case PeakAbsoluteErrorMetric:
881
 
          {
882
 
            (void) fprintf(stderr,"%g (%g)\n",distortion,(double) (QuantumScale*
883
 
              distortion));
884
 
            break;
885
 
          }
886
 
          case AbsoluteErrorMetric:
887
 
          case PeakSignalToNoiseRatioMetric:
888
 
          {
889
 
            (void) fprintf(stderr,"%g\n",distortion);
890
 
            break;
891
 
          }
892
 
          case MeanErrorPerPixelMetric:
893
 
          {
894
 
            (void) fprintf(stderr,"%g (%g, %g)\n",distortion,
895
 
              image->error.normalized_mean_error,
896
 
              image->error.normalized_maximum_error);
897
 
            break;
898
 
          }
899
 
          case UndefinedMetric:
900
 
            break;
 
911
          switch (metric)
 
912
          {
 
913
            case MeanAbsoluteErrorMetric:
 
914
            case MeanSquaredErrorMetric:
 
915
            case RootMeanSquaredErrorMetric:
 
916
            case PeakAbsoluteErrorMetric:
 
917
            {
 
918
              (void) fprintf(stderr,"%g (%g)",distortion,(double)
 
919
                (QuantumScale*distortion));
 
920
              break;
 
921
            }
 
922
            case AbsoluteErrorMetric:
 
923
            case PeakSignalToNoiseRatioMetric:
 
924
            {
 
925
              (void) fprintf(stderr,"%g",distortion);
 
926
              break;
 
927
            }
 
928
            case MeanErrorPerPixelMetric:
 
929
            {
 
930
              (void) fprintf(stderr,"%g (%g, %g)",distortion,
 
931
                image->error.normalized_mean_error,
 
932
                image->error.normalized_maximum_error);
 
933
              break;
 
934
            }
 
935
            case UndefinedMetric:
 
936
              break;
 
937
          }
 
938
          (void) fprintf(stderr," @ %ld,%ld\n",difference_image->page.x,
 
939
            difference_image->page.y);
901
940
        }
902
941
      else
903
942
        {
904
943
          double
905
944
            *channel_distortion;
906
945
 
907
 
 
908
946
          channel_distortion=GetImageChannelDistortions(image,reconstruct_image,
909
947
            metric,&image->exception);
910
948
          (void) fprintf(stderr,"Image: %s\n",image->filename);
 
949
          (void) fprintf(stderr,"Offset: %ld,%ld\n",difference_image->page.x,
 
950
            difference_image->page.y);
911
951
          (void) fprintf(stderr,"  Channel distortion: %s\n",
912
952
            MagickOptionToMnemonic(MagickMetricOptions,(long) metric));
913
953
          switch (metric)
1036
1076
          channel_distortion=(double *) RelinquishMagickMemory(
1037
1077
            channel_distortion);
1038
1078
        }
 
1079
      difference_image=DestroyImageList(difference_image);
1039
1080
    }
1040
1081
  DestroyCompare();
1041
1082
  return(status != 0 ? MagickTrue : MagickFalse);