~ubuntu-branches/ubuntu/natty/imagemagick/natty-security

« back to all changes in this revision

Viewing changes to coders/jpeg.c

  • Committer: Bazaar Package Importer
  • Author(s): Luke Yelavich
  • Date: 2009-11-27 09:32:04 UTC
  • mfrom: (6.2.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091127093204-m038t8kmxk6uvc25
Tags: 7:6.5.7.8-1ubuntu1
* Merge from debian testing.  Remaining changes:
  - Don't build-dep on librsvg, it brings in excessive dependencies
  - Don't build-dep on liblqr-1-0-dev, it is in universe

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
#include "magick/blob-private.h"
49
49
#include "magick/cache.h"
50
50
#include "magick/color.h"
 
51
#include "magick/colormap-private.h"
51
52
#include "magick/color-private.h"
52
53
#include "magick/colorspace.h"
53
54
#include "magick/constitute.h"
271
272
  source->start_of_blob=TRUE;
272
273
}
273
274
 
 
275
static MagickBooleanType IsITUFaxImage(const Image *image)
 
276
{
 
277
  const StringInfo
 
278
    *profile;
 
279
 
 
280
  const unsigned char
 
281
    *datum;
 
282
 
 
283
  profile=GetImageProfile(image,"8bim");
 
284
  if (profile == (const StringInfo *) NULL)
 
285
    return(MagickFalse);
 
286
  if (GetStringInfoLength(profile) < 5)
 
287
    return(MagickFalse);
 
288
  datum=GetStringInfoDatum(profile);
 
289
  if ((datum[0] == 0x47) && (datum[1] == 0x33) && (datum[2] == 0x46) &&
 
290
      (datum[3] == 0x41) && (datum[4] == 0x58))
 
291
    return(MagickTrue);
 
292
  return(MagickFalse);
 
293
}
 
294
 
274
295
static void JPEGErrorHandler(j_common_ptr jpeg_info)
275
296
{
276
297
  ErrorManager
848
869
  char
849
870
    value[MaxTextExtent];
850
871
 
 
872
  const char
 
873
    *option;
 
874
 
851
875
  ErrorManager
852
876
    error_manager;
853
877
 
924
948
      number_pixels=(MagickSizeType) image->columns*image->rows;
925
949
      if (number_pixels != 0)
926
950
        return(GetFirstImageInList(image));
 
951
      InheritException(exception,&image->exception);
927
952
      return(DestroyImage(image));
928
953
    }
929
954
  jpeg_info.client_data=(void *) &error_manager;
936
961
    if ((i != 2) && (i != 13) && (i != 14))
937
962
      jpeg_set_marker_processor(&jpeg_info,(int) (JPEG_APP0+i),ReadProfile);
938
963
  i=jpeg_read_header(&jpeg_info,MagickTrue);
939
 
  if ((image->colorspace == YCbCrColorspace) ||
940
 
      (image->colorspace == Rec601YCbCrColorspace) ||
941
 
      (image->colorspace == Rec709YCbCrColorspace))
 
964
  if ((image_info->colorspace == YCbCrColorspace) ||
 
965
      (image_info->colorspace == Rec601YCbCrColorspace) ||
 
966
      (image_info->colorspace == Rec709YCbCrColorspace))
942
967
    jpeg_info.out_color_space=JCS_YCbCr;
 
968
  if (IsITUFaxImage(image) != MagickFalse)
 
969
    {
 
970
      image->colorspace=LabColorspace;
 
971
      jpeg_info.out_color_space=JCS_YCbCr;
 
972
    }
 
973
  else
 
974
    if (jpeg_info.out_color_space == JCS_CMYK)
 
975
      image->colorspace=CMYKColorspace;
943
976
  /*
944
977
    Set image resolution.
945
978
  */
956
989
  if (units == 2)
957
990
    image->units=PixelsPerCentimeterResolution;
958
991
  number_pixels=(MagickSizeType) image->columns*image->rows;
959
 
  if (image_info->size != (char *) NULL)
 
992
  option=GetImageOption(image_info,"jpeg:size");
 
993
  if (option != (const char *) NULL)
960
994
    {
961
995
      double
962
996
        scale_factor;
963
997
 
 
998
      GeometryInfo
 
999
        geometry_info;
 
1000
 
 
1001
      int
 
1002
        flags;
 
1003
 
964
1004
      /*
965
 
        Let the JPEG library subsample for us.
 
1005
        Scale the image.
966
1006
      */
 
1007
      flags=ParseGeometry(option,&geometry_info);
 
1008
      if ((flags & SigmaValue) == 0)
 
1009
        geometry_info.sigma=geometry_info.rho;
967
1010
      jpeg_calc_output_dimensions(&jpeg_info);
968
1011
      image->magick_columns=jpeg_info.output_width;
969
1012
      image->magick_rows=jpeg_info.output_height;
970
 
      scale_factor=(double) jpeg_info.output_width/image->columns;
971
 
      if (scale_factor > ((double) jpeg_info.output_height/image->rows))
972
 
        scale_factor=(double) jpeg_info.output_height/image->rows;
 
1013
      scale_factor=1.0;
 
1014
      if (geometry_info.rho != 0.0)
 
1015
        scale_factor=jpeg_info.output_width/geometry_info.rho;
 
1016
      if ((geometry_info.sigma != 0.0) &&
 
1017
          (scale_factor > (jpeg_info.output_height/geometry_info.sigma)))
 
1018
        scale_factor=jpeg_info.output_height/geometry_info.sigma;
973
1019
      jpeg_info.scale_num=1U;
974
1020
      jpeg_info.scale_denom=(unsigned int) scale_factor;
975
1021
      jpeg_calc_output_dimensions(&jpeg_info);
1007
1053
      jpeg_info.quantize_colors=MagickTrue;
1008
1054
      jpeg_info.desired_number_of_colors=(int) image_info->colors;
1009
1055
    }
 
1056
  option=GetImageOption(image_info,"jpeg:block-smoothing");
 
1057
  if (option != (const char *) NULL)
 
1058
    {
 
1059
      jpeg_info.do_block_smoothing=MagickFalse;
 
1060
      if (IsMagickTrue(option) != MagickFalse)
 
1061
        jpeg_info.do_block_smoothing=MagickTrue;
 
1062
    }
 
1063
  option=GetImageOption(image_info,"jpeg:fancy-upsampling");
 
1064
  if (option != (const char *) NULL)
 
1065
    {
 
1066
      jpeg_info.do_fancy_upsampling=MagickFalse;
 
1067
      if (IsMagickTrue(option) != MagickFalse)
 
1068
        jpeg_info.do_fancy_upsampling=MagickTrue;
 
1069
    }
1010
1070
  (void) jpeg_start_decompress(&jpeg_info);
1011
1071
  image->columns=jpeg_info.output_width;
1012
1072
  image->rows=jpeg_info.output_height;
1239
1299
    *entry;
1240
1300
 
1241
1301
  static const char
1242
 
    *description = "Joint Photographic Experts Group JFIF format";
 
1302
    description[] = "Joint Photographic Experts Group JFIF format";
1243
1303
 
1244
1304
  *version='\0';
1245
1305
#if defined(JPEG_LIB_VERSION)