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

« back to all changes in this revision

Viewing changes to coders/dpx.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:
42
42
#include "magick/studio.h"
43
43
#include "magick/blob.h"
44
44
#include "magick/blob-private.h"
 
45
#include "magick/cache.h"
45
46
#include "magick/colorspace.h"
46
47
#include "magick/exception.h"
47
48
#include "magick/exception-private.h"
111
112
 
112
113
typedef struct _DPXFileInfo
113
114
{
114
 
  unsigned long
 
115
  unsigned int
115
116
    magic,
116
117
    image_offset;
117
118
 
118
119
  char
119
120
    version[8];
120
121
 
121
 
  unsigned long
 
122
  unsigned int
122
123
    file_size,
123
124
    ditto_key,
124
125
    generic_size,
132
133
    project[200],
133
134
    copyright[200];
134
135
 
135
 
  unsigned long
 
136
  unsigned int
136
137
    encrypt_key;
137
138
 
138
139
  char
149
150
    count[4],
150
151
    format[32];
151
152
 
152
 
  unsigned long
 
153
  unsigned int
153
154
    frame_position,
154
 
    sequence_length,
 
155
    sequence_extent,
155
156
    held_count;
156
157
 
157
158
  float
166
167
 
167
168
typedef struct _DPXImageElement
168
169
{
169
 
  unsigned long
 
170
  unsigned int
170
171
    data_sign,
171
172
    low_data;
172
173
 
173
174
  float
174
175
    low_quantity;
175
176
 
176
 
  unsigned long
 
177
  unsigned int
177
178
    high_data;
178
179
 
179
180
  float
189
190
    packing,
190
191
    encoding;
191
192
 
192
 
  unsigned long
 
193
  unsigned int
193
194
    data_offset,
194
195
    end_of_line_padding,
195
196
    end_of_image_padding;
204
205
    orientation,
205
206
    number_elements;
206
207
 
207
 
  unsigned long
 
208
  unsigned int
208
209
    pixels_per_line,
209
210
    lines_per_element;
210
211
 
217
218
 
218
219
typedef struct _DPXOrientationInfo
219
220
{
220
 
  unsigned long
 
221
  unsigned int
221
222
    x_offset,
222
223
    y_offset;
223
224
 
225
226
    x_center,
226
227
    y_center;
227
228
 
228
 
  unsigned long
 
229
  unsigned int
229
230
    x_size,
230
231
    y_size;
231
232
 
238
239
  unsigned short
239
240
    border[4];
240
241
 
241
 
  unsigned long
 
242
  unsigned int
242
243
    aspect_ratio[2];
243
244
 
244
245
  unsigned char
247
248
 
248
249
typedef struct _DPXTelevisionInfo
249
250
{
250
 
  unsigned long
 
251
  unsigned int
251
252
    time_code,
252
253
    user_bits;
253
254
 
322
323
%
323
324
%  The format of the IsDPX method is:
324
325
%
325
 
%      MagickBooleanType IsDPX(const unsigned char *magick,const size_t length)
 
326
%      MagickBooleanType IsDPX(const unsigned char *magick,const size_t extent)
326
327
%
327
328
%  A description of each parameter follows:
328
329
%
329
330
%    o magick: This string is generally the first few bytes of an image file
330
331
%      or blob.
331
332
%
332
 
%    o length: Specifies the length of the magick string.
 
333
%    o extent: Specifies the extent of the magick string.
333
334
%
334
335
*/
335
 
static MagickBooleanType IsDPX(const unsigned char *magick,const size_t length)
 
336
static MagickBooleanType IsDPX(const unsigned char *magick,const size_t extent)
336
337
{
337
 
  if (length < 4)
 
338
  if (extent < 4)
338
339
    return(MagickFalse);
339
340
  if (memcmp(magick,"SDPX",4) == 0)
340
341
    return(MagickTrue);
447
448
      float_value;
448
449
  } quantum;
449
450
 
 
451
  quantum.unsigned_value=0UL;
450
452
  quantum.float_value=value;
451
 
  if (quantum.unsigned_value == 0U)
 
453
  if (quantum.unsigned_value == 0UL)
452
454
    return(MagickFalse);
453
455
  return(MagickTrue);
454
456
}
557
559
  MagickOffsetType
558
560
    offset;
559
561
 
560
 
  QuantumInfo
561
 
    *quantum_info;
562
 
 
563
562
  QuantumType
564
563
    quantum_type;
565
564
 
573
572
    count;
574
573
 
575
574
  size_t
576
 
    length;
 
575
    extent;
577
576
 
578
577
  unsigned char
579
 
    component_type,
580
 
    *pixels;
 
578
    component_type;
581
579
 
582
580
  unsigned long
583
581
    samples_per_pixel;
616
614
  offset+=4;
617
615
  offset+=ReadBlob(image,sizeof(dpx.file.version),(unsigned char *)
618
616
    dpx.file.version);
619
 
  (void) SetImageProperty(image,"dpx:file.version",dpx.file.version);
 
617
  (void) FormatImageProperty(image,"dpx:file.version","%.8s",dpx.file.version);
620
618
  dpx.file.file_size=ReadBlobLong(image);
621
619
  offset+=4;
622
620
  dpx.file.ditto_key=ReadBlobLong(image);
623
621
  offset+=4;
624
 
  if (dpx.file.ditto_key != ~0UL)
625
 
    (void) FormatImageProperty(image,"dpx:file.ditto.key","%lu",
 
622
  if (dpx.file.ditto_key != ~0U)
 
623
    (void) FormatImageProperty(image,"dpx:file.ditto.key","%u",
626
624
      dpx.file.ditto_key);
627
625
  dpx.file.generic_size=ReadBlobLong(image);
628
626
  offset+=4;
632
630
  offset+=4;
633
631
  offset+=ReadBlob(image,sizeof(dpx.file.filename),(unsigned char *)
634
632
    dpx.file.filename);
635
 
  (void) SetImageProperty(image,"dpx:file.filename",dpx.file.filename);
636
 
  if (*dpx.file.filename != '\0')
637
 
    {
638
 
      (void) FormatImageProperty(image,"dpx:file.filename","%.100s",
639
 
        dpx.file.filename);
640
 
      (void) FormatImageProperty(image,"document","%.100s",dpx.file.filename);
641
 
    }
 
633
  (void) FormatImageProperty(image,"dpx:file.filename","%.100s",
 
634
    dpx.file.filename);
 
635
  (void) FormatImageProperty(image,"document","%.100s",dpx.file.filename);
642
636
  offset+=ReadBlob(image,sizeof(dpx.file.timestamp),(unsigned char *)
643
637
    dpx.file.timestamp);
644
638
  if (*dpx.file.timestamp != '\0')
671
665
    }
672
666
  dpx.file.encrypt_key=ReadBlobLong(image);
673
667
  offset+=4;
674
 
  if (dpx.file.encrypt_key != ~0UL)
675
 
    (void) FormatImageProperty(image,"dpx:file.encrypt_key","%lu",
 
668
  if (dpx.file.encrypt_key != ~0U)
 
669
    (void) FormatImageProperty(image,"dpx:file.encrypt_key","%u",
676
670
      dpx.file.encrypt_key);
677
671
  offset+=ReadBlob(image,sizeof(dpx.file.reserve),(unsigned char *)
678
672
    dpx.file.reserve);
743
737
    dpx.image.reserve);
744
738
  component_type=dpx.image.image_element[0].descriptor;
745
739
  image->depth=dpx.image.image_element[0].bit_size;
746
 
  if (dpx.file.image_offset >= 1664UL)
 
740
  if (dpx.file.image_offset >= 1664U)
747
741
    {
748
742
      /*
749
743
        Read DPX orientation header.
750
744
      */
751
745
      dpx.orientation.x_offset=ReadBlobLong(image);
752
746
      offset+=4;
753
 
      if (dpx.orientation.x_offset != ~0UL)
754
 
        (void) FormatImageProperty(image,"dpx:orientation.x_offset","%lu",
 
747
      if (dpx.orientation.x_offset != ~0U)
 
748
        (void) FormatImageProperty(image,"dpx:orientation.x_offset","%u",
755
749
          dpx.orientation.x_offset);
756
750
      dpx.orientation.y_offset=ReadBlobLong(image);
757
751
      offset+=4;
758
 
      if (dpx.orientation.y_offset != ~0UL)
759
 
        (void) FormatImageProperty(image,"dpx:orientation.y_offset","%lu",
 
752
      if (dpx.orientation.y_offset != ~0U)
 
753
        (void) FormatImageProperty(image,"dpx:orientation.y_offset","%u",
760
754
          dpx.orientation.y_offset);
761
755
      dpx.orientation.x_center=ReadBlobFloat(image);
762
756
      offset+=4;
770
764
          dpx.orientation.y_center);
771
765
      dpx.orientation.x_size=ReadBlobLong(image);
772
766
      offset+=4;
773
 
      if (dpx.orientation.x_size != ~0UL)
774
 
        (void) FormatImageProperty(image,"dpx:orientation.x_size","%lu",
 
767
      if (dpx.orientation.x_size != ~0U)
 
768
        (void) FormatImageProperty(image,"dpx:orientation.x_size","%u",
775
769
          dpx.orientation.x_size);
776
770
      dpx.orientation.y_size=ReadBlobLong(image);
777
771
      offset+=4;
778
 
      if (dpx.orientation.y_size != ~0UL)
779
 
        (void) FormatImageProperty(image,"dpx:orientation.y_size","%lu",
 
772
      if (dpx.orientation.y_size != ~0U)
 
773
        (void) FormatImageProperty(image,"dpx:orientation.y_size","%u",
780
774
          dpx.orientation.y_size);
781
775
      offset+=ReadBlob(image,sizeof(dpx.orientation.filename),(unsigned char *)
782
776
        dpx.orientation.filename);
812
806
        dpx.orientation.aspect_ratio[i]=ReadBlobLong(image);
813
807
        offset+=4;
814
808
      }
815
 
      if ((dpx.orientation.aspect_ratio[0] != ~0UL) &&
816
 
          (dpx.orientation.aspect_ratio[1] != ~0UL))
 
809
      if ((dpx.orientation.aspect_ratio[0] != ~0U) &&
 
810
          (dpx.orientation.aspect_ratio[1] != ~0U))
817
811
        (void) FormatImageProperty(image,"dpx:orientation.aspect_ratio",
818
 
          "%lux%lu",dpx.orientation.aspect_ratio[0],
 
812
          "%ux%u",dpx.orientation.aspect_ratio[0],
819
813
          dpx.orientation.aspect_ratio[1]);
820
814
      offset+=ReadBlob(image,sizeof(dpx.orientation.reserve),(unsigned char *)
821
815
        dpx.orientation.reserve);
822
816
    }
823
 
  if (dpx.file.image_offset >= 1920UL)
 
817
  if (dpx.file.image_offset >= 1920U)
824
818
    {
825
819
      /*
826
820
        Read DPX film header.
854
848
          dpx.film.format);
855
849
      dpx.film.frame_position=ReadBlobLong(image);
856
850
      offset+=4;
857
 
      if (dpx.film.frame_position != ~0UL)
858
 
        (void) FormatImageProperty(image,"dpx:file.frame_position","%lu",
 
851
      if (dpx.film.frame_position != ~0U)
 
852
        (void) FormatImageProperty(image,"dpx:film.frame_position","%u",
859
853
          dpx.film.frame_position);
860
 
      dpx.film.sequence_length=ReadBlobLong(image);
 
854
      dpx.film.sequence_extent=ReadBlobLong(image);
861
855
      offset+=4;
862
 
      if (dpx.film.sequence_length != ~0UL)
863
 
        (void) FormatImageProperty(image,"dpx:file.sequence_length","%lu",
864
 
          dpx.film.sequence_length);
 
856
      if (dpx.film.sequence_extent != ~0U)
 
857
        (void) FormatImageProperty(image,"dpx:film.sequence_extent","%u",
 
858
          dpx.film.sequence_extent);
865
859
      dpx.film.held_count=ReadBlobLong(image);
866
860
      offset+=4;
867
 
      if (dpx.film.held_count != ~0UL)
868
 
        (void) FormatImageProperty(image,"dpx:file.held_count","%lu",
 
861
      if (dpx.film.held_count != ~0U)
 
862
        (void) FormatImageProperty(image,"dpx:film.held_count","%u",
869
863
          dpx.film.held_count);
870
864
      dpx.film.frame_rate=ReadBlobFloat(image);
871
865
      offset+=4;
890
884
      offset+=ReadBlob(image,sizeof(dpx.film.reserve),(unsigned char *)
891
885
        dpx.film.reserve);
892
886
    }
893
 
  if (dpx.file.image_offset >= 2048UL)
 
887
  if (dpx.file.image_offset >= 2048U)
894
888
    {
895
889
      /*
896
890
        Read DPX television header.
977
971
      offset+=ReadBlob(image,sizeof(dpx.television.reserve),(unsigned char *)
978
972
        dpx.television.reserve);
979
973
    }
980
 
  if (dpx.file.image_offset > 2080UL)
 
974
  if (dpx.file.image_offset > 2080U)
981
975
    {
982
976
      /*
983
977
        Read DPX user header.
985
979
      offset+=ReadBlob(image,sizeof(dpx.user.id),(unsigned char *) dpx.user.id);
986
980
      if (*dpx.user.id != '\0')
987
981
        (void) FormatImageProperty(image,"dpx:user.id","%.32s",dpx.user.id);
988
 
      if ((dpx.file.user_size != ~0UL) &&
989
 
          (dpx.file.user_size > sizeof(dpx.user.id)))
 
982
      if ((dpx.file.user_size != ~0U) &&
 
983
          ((size_t) dpx.file.user_size > sizeof(dpx.user.id)))
990
984
        {
991
985
          StringInfo
992
986
            *profile;
1011
1005
  /*
1012
1006
    Convert DPX raster image to pixel packets.
1013
1007
  */
1014
 
  if (SetImageExtent(image,0,0) == MagickFalse)
1015
 
    {
1016
 
      InheritException(exception,&image->exception);
1017
 
      return(DestroyImageList(image));
1018
 
    }
1019
 
  quantum_info=AcquireQuantumInfo(image_info,image);
1020
 
  quantum_info->quantum=32;
1021
 
  quantum_info->pack=dpx.image.image_element[0].packing == 0 ? MagickTrue :
1022
 
    MagickFalse;
1023
1008
  samples_per_pixel=1;
1024
1009
  quantum_type=GrayQuantum;
1025
1010
  switch (component_type)
1027
1012
    case CbYCrY422ComponentType:
1028
1013
    {
1029
1014
      samples_per_pixel=2;
 
1015
      quantum_type=CbYCrYQuantum;
1030
1016
      break;
1031
1017
    }
1032
1018
    case CbYACrYA4224ComponentType:
1050
1036
  }
1051
1037
  switch (component_type)
1052
1038
  {
 
1039
    case CbYCrY422ComponentType:
 
1040
    case CbYACrYA4224ComponentType:
1053
1041
    case CbYCr444ComponentType:
1054
1042
    {
1055
1043
      image->colorspace=Rec709YCbCrColorspace;
1063
1051
    default:
1064
1052
    {
1065
1053
      image->colorspace=RGBColorspace;
 
1054
      if (dpx.image.image_element[0].transfer == LogarithmicColorimetric)
 
1055
        image->colorspace=LogColorspace;
1066
1056
      if (dpx.image.image_element[0].transfer == PrintingDensityColorimetric)
1067
1057
        image->colorspace=LogColorspace;
1068
1058
      break;
1069
1059
    }
1070
1060
  }
1071
 
  if (image->colorspace != UndefinedColorspace)
1072
 
    image->colorspace=image->colorspace;
1073
 
  length=GetBytesPerRow(image->columns,samples_per_pixel,image->depth,
 
1061
  extent=GetBytesPerRow(image->columns,samples_per_pixel,image->depth,
1074
1062
    dpx.image.image_element[0].packing == 0 ? MagickFalse : MagickTrue);
1075
 
  pixels=GetQuantumPixels(quantum_info);
1076
 
  if ((quantum_type == GrayQuantum) && (quantum_info->pack == MagickFalse) &&
1077
 
      (image->depth == 10) && (image->endian == MSBEndian))
 
1063
  if ((quantum_type == GrayQuantum) &&
 
1064
      (dpx.image.image_element[0].packing != 0) && (image->depth == 10) &&
 
1065
      (image->endian == MSBEndian))
1078
1066
    {
1079
1067
      QuantumAny
1080
 
        scale;
 
1068
        range;
 
1069
 
 
1070
      QuantumInfo
 
1071
        *quantum_info;
1081
1072
 
1082
1073
      register long
1083
1074
        x;
1084
1075
 
 
1076
      unsigned char
 
1077
        *pixels;
 
1078
 
1085
1079
      unsigned long
1086
1080
        pixel;
1087
1081
 
1088
 
      pixel=0UL;
 
1082
      quantum_info=AcquireQuantumInfo(image_info,image);
 
1083
      if (quantum_info == (QuantumInfo *) NULL)
 
1084
        ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
 
1085
      SetQuantumQuantum(quantum_info,32);
 
1086
      SetQuantumPack(quantum_info,dpx.image.image_element[0].packing == 0 ?
 
1087
        MagickTrue : MagickFalse);
 
1088
      pixels=GetQuantumPixels(quantum_info);
 
1089
      pixel=0U;
1089
1090
      i=0;
1090
 
      scale=GetQuantumScale(image->depth);
 
1091
      range=GetQuantumRange(image->depth);
1091
1092
      for (y=0; y < (long) image->rows; y++)
1092
1093
      {
1093
 
        q=SetImagePixels(image,0,y,image->columns,1);
 
1094
        q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
1094
1095
        if (q == (PixelPacket *) NULL)
1095
1096
          break;
1096
1097
        for (x=0; x < (long) image->columns; x++)
1100
1101
            case 0:
1101
1102
            {
1102
1103
              pixel=ReadBlobMSBLong(image);
1103
 
              q->red=ScaleAnyToQuantum((pixel >> 0) & 0x3ff,image->depth,scale);
 
1104
              q->red=ScaleAnyToQuantum((pixel >> 0) & 0x3ff,range);
1104
1105
              break;
1105
1106
            }
1106
1107
            case 1:
1107
1108
            {
1108
 
              q->red=ScaleAnyToQuantum((pixel >> 10) & 0x3ff,image->depth,
1109
 
                scale);
 
1109
              q->red=ScaleAnyToQuantum((pixel >> 10) & 0x3ff,range);
1110
1110
              break;
1111
1111
            }
1112
1112
            case 2:
1113
1113
            {
1114
 
              q->red=ScaleAnyToQuantum((pixel >> 20) & 0x3ff,image->depth,
1115
 
                scale);
 
1114
              q->red=ScaleAnyToQuantum((pixel >> 20) & 0x3ff,range);
1116
1115
              break;
1117
1116
            }
1118
1117
          }
1120
1119
          q->blue=q->red;
1121
1120
          q++;
1122
1121
        }
1123
 
        if (SyncImagePixels(image) == MagickFalse)
 
1122
        if (SyncAuthenticPixels(image,exception) == MagickFalse)
1124
1123
          break;
1125
1124
        status=SetImageProgress(image,LoadImageTag,y,image->rows);
1126
1125
        if (status == MagickFalse)
1127
1126
          break;
1128
1127
      }
 
1128
      quantum_info=DestroyQuantumInfo(quantum_info);
1129
1129
    }
1130
1130
  else
1131
 
    for (y=0; y < (long) image->rows; y++)
1132
1131
    {
 
1132
      long
 
1133
        row;
 
1134
 
 
1135
      QuantumInfo
 
1136
        *quantum_info;
 
1137
 
 
1138
      ViewInfo
 
1139
        *image_view;
 
1140
 
1133
1141
      /*
1134
1142
        DPX any-bit pixel format.
1135
1143
      */
1136
 
      q=SetImagePixels(image,0,y,image->columns,1);
1137
 
      if (q == (PixelPacket *) NULL)
1138
 
        break;
1139
 
      count=ReadBlob(image,length,pixels);
1140
 
      if ((size_t) count != length)
1141
 
        break;
1142
 
      (void) ImportQuantumPixels(image,quantum_info,quantum_type,pixels);
1143
 
      if (SyncImagePixels(image) == MagickFalse)
1144
 
        break;
1145
 
      status=SetImageProgress(image,LoadImageTag,y,image->rows);
 
1144
      status=MagickTrue;
 
1145
      row=0;
 
1146
      quantum_info=AcquireQuantumInfo(image_info,image);
 
1147
      if (quantum_info == (QuantumInfo *) NULL)
 
1148
        ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
 
1149
      SetQuantumQuantum(quantum_info,32);
 
1150
      SetQuantumPack(quantum_info,dpx.image.image_element[0].packing == 0 ?
 
1151
        MagickTrue : MagickFalse);
 
1152
      image_view=AcquireCacheView(image);
 
1153
#if defined(MAGICKCORE_OPENMP_SUPPORT)
 
1154
  #pragma omp parallel for schedule(dynamic,1) shared(row,status,quantum_type)
 
1155
#endif
 
1156
      for (y=0; y < (long) image->rows; y++)
 
1157
      {
 
1158
        long
 
1159
          offset;
 
1160
 
 
1161
        MagickBooleanType
 
1162
          sync;
 
1163
 
 
1164
        register PixelPacket
 
1165
          *q;
 
1166
 
 
1167
        ssize_t
 
1168
          count;
 
1169
 
 
1170
        size_t
 
1171
          length;
 
1172
 
 
1173
        unsigned char
 
1174
          *pixels;
 
1175
 
 
1176
        if (status == MagickFalse)
 
1177
          continue;
 
1178
        pixels=GetQuantumPixels(quantum_info);
 
1179
#if defined(MAGICKCORE_OPENMP_SUPPORT)
 
1180
  #pragma omp critical (MagickCore_ReadDPXImage)
 
1181
#endif
 
1182
        {
 
1183
          count=ReadBlob(image,extent,pixels);
 
1184
          if ((image->progress_monitor != (MagickProgressMonitor) NULL) &&
 
1185
              (image->previous == (Image *) NULL))
 
1186
            {
 
1187
              MagickBooleanType
 
1188
                proceed;
 
1189
 
 
1190
              proceed=SetImageProgress(image,LoadImageTag,row,image->rows);
 
1191
              if (proceed == MagickFalse)
 
1192
                status=MagickFalse;
 
1193
            }
 
1194
          offset=row++;
 
1195
        }
 
1196
        if (count != (ssize_t) extent)
 
1197
          status=MagickFalse;
 
1198
        q=QueueCacheViewAuthenticPixels(image_view,0,offset,image->columns,
 
1199
          1,exception);
 
1200
        if (q == (PixelPacket *) NULL)
 
1201
          {
 
1202
            status=MagickFalse;
 
1203
            continue;
 
1204
          }
 
1205
        length=ImportQuantumPixels(image,image_view,quantum_info,quantum_type,
 
1206
          pixels,exception);
 
1207
        sync=SyncCacheViewAuthenticPixels(image_view,exception);
 
1208
        if (sync == MagickFalse)
 
1209
          status=MagickFalse;
 
1210
      }
 
1211
      image_view=DestroyCacheView(image_view);
 
1212
      quantum_info=DestroyQuantumInfo(quantum_info);
1146
1213
      if (status == MagickFalse)
1147
 
        break;
 
1214
        ThrowReaderException(CorruptImageError,"UnableToReadImageData");
1148
1215
    }
1149
1216
  SetQuantumImageType(image,quantum_type);
1150
 
  quantum_info=DestroyQuantumInfo(quantum_info);
1151
1217
  if (EOFBlob(image) != MagickFalse)
1152
1218
    ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
1153
1219
      image->filename);
1262
1328
  return(GetImageProperty(image,property));
1263
1329
}
1264
1330
 
1265
 
static unsigned long DecodeSMPTEBits(const char *key)
 
1331
static unsigned int DecodeSMPTEBits(const char *key)
1266
1332
{
1267
1333
  char
1268
1334
    buffer[2];
1270
1336
  register long
1271
1337
    i;
1272
1338
 
1273
 
  unsigned long
 
1339
  unsigned int
1274
1340
    shift,
1275
1341
    value;
1276
1342
 
1285
1351
        continue;
1286
1352
      }
1287
1353
    buffer[0]=(*key++);
1288
 
    value|=(unsigned long) ((strtol(buffer,(char **) NULL,10)) << shift);
 
1354
    value|=(unsigned int) ((strtol(buffer,(char **) NULL,10)) << shift);
1289
1355
    shift-=4;
1290
1356
  }
1291
1357
  return(value);
1330
1396
    i;
1331
1397
 
1332
1398
  size_t
1333
 
    length;
 
1399
    extent;
1334
1400
 
1335
1401
  ssize_t
1336
1402
    count;
1358
1424
  */
1359
1425
  (void) ResetMagickMemory(&dpx,0,sizeof(dpx));
1360
1426
  offset=0;
1361
 
  dpx.file.magic=0x53445058UL;
 
1427
  dpx.file.magic=0x53445058U;
1362
1428
  offset+=WriteBlobLong(image,dpx.file.magic);
1363
 
  dpx.file.image_offset=0x2000UL;
 
1429
  dpx.file.image_offset=0x2000U;
1364
1430
  profile=GetImageProfile(image,"dpx:user.data");
1365
1431
  if (profile != (StringInfo *) NULL)
1366
1432
    {
1367
 
      dpx.file.image_offset+=(unsigned long) GetStringInfoLength(profile);
 
1433
      dpx.file.image_offset+=(unsigned int) GetStringInfoLength(profile);
1368
1434
      dpx.file.image_offset=(((dpx.file.image_offset+0x2000-1)/0x2000)*0x2000);
1369
1435
    }
1370
1436
  offset+=WriteBlobLong(image,dpx.file.image_offset);
1371
 
  (void) CopyMagickString(dpx.file.version,"V2.0",MaxTextExtent);
 
1437
  (void) strncpy(dpx.file.version,"V2.0",sizeof(dpx.file.version));
1372
1438
  offset+=WriteBlob(image,8,(unsigned char *) &dpx.file.version);
1373
 
  dpx.file.file_size=4UL*image->columns*image->rows+dpx.file.image_offset;
 
1439
  dpx.file.file_size=(unsigned int) (4U*image->columns*image->rows+
 
1440
    dpx.file.image_offset);
1374
1441
  offset+=WriteBlobLong(image,dpx.file.file_size);
1375
 
  dpx.file.ditto_key=1UL;  /* new frame */
 
1442
  dpx.file.ditto_key=1U;  /* new frame */
1376
1443
  offset+=WriteBlobLong(image,dpx.file.ditto_key);
1377
 
  dpx.file.generic_size=0x00000680UL;
 
1444
  dpx.file.generic_size=0x00000680U;
1378
1445
  offset+=WriteBlobLong(image,dpx.file.generic_size);
1379
 
  dpx.file.industry_size=0x00000180UL;
 
1446
  dpx.file.industry_size=0x00000180U;
1380
1447
  offset+=WriteBlobLong(image,dpx.file.industry_size);
1381
1448
  dpx.file.user_size=0;
1382
1449
  if (profile != (StringInfo *) NULL)
1383
1450
    {
1384
 
      dpx.file.user_size+=(unsigned long) GetStringInfoLength(profile);
 
1451
      dpx.file.user_size+=(unsigned int) GetStringInfoLength(profile);
1385
1452
      dpx.file.user_size=(((dpx.file.user_size+0x2000-1)/0x2000)*0x2000);
1386
1453
    }
1387
1454
  offset+=WriteBlobLong(image,dpx.file.user_size);
1388
 
  (void) CopyMagickString(dpx.file.filename,"V2.0",sizeof(dpx.file.filename));
1389
1455
  value=GetDPXProperty(image_info,image,"dpx:file.filename");
1390
1456
  if (value != (const char *) NULL)
1391
 
    (void) CopyMagickString(dpx.file.filename,value,sizeof(dpx.file.filename));
 
1457
    (void) strncpy(dpx.file.filename,value,sizeof(dpx.file.filename));
1392
1458
  offset+=WriteBlob(image,sizeof(dpx.file.filename),(unsigned char *)
1393
1459
    dpx.file.filename);
1394
1460
  seconds=time((time_t *) NULL);
1396
1462
    dpx.file.timestamp);
1397
1463
  offset+=WriteBlob(image,sizeof(dpx.file.timestamp),(unsigned char *)
1398
1464
    dpx.file.timestamp);
1399
 
  (void) CopyMagickString(dpx.file.creator,GetMagickVersion((unsigned long *)
1400
 
    NULL),sizeof(dpx.file.creator));
 
1465
  (void) strncpy(dpx.file.creator,GetMagickVersion((unsigned long *) NULL),
 
1466
    sizeof(dpx.file.creator));
1401
1467
  value=GetDPXProperty(image_info,image,"dpx:file.creator");
1402
1468
  if (value != (const char *) NULL)
1403
 
    (void) CopyMagickString(dpx.file.creator,value,sizeof(dpx.file.creator));
 
1469
    (void) strncpy(dpx.file.creator,value,sizeof(dpx.file.creator));
1404
1470
  offset+=WriteBlob(image,sizeof(dpx.file.creator),(unsigned char *)
1405
1471
    dpx.file.creator);
1406
1472
  value=GetDPXProperty(image_info,image,"dpx:file.project");
1407
1473
  if (value != (const char *) NULL)
1408
 
    (void) CopyMagickString(dpx.file.project,value,sizeof(dpx.file.project));
 
1474
    (void) strncpy(dpx.file.project,value,sizeof(dpx.file.project));
1409
1475
  offset+=WriteBlob(image,sizeof(dpx.file.project),(unsigned char *)
1410
1476
    dpx.file.project);
1411
1477
  value=GetDPXProperty(image_info,image,"dpx:file.copyright");
1412
1478
  if (value != (const char *) NULL)
1413
 
    (void) CopyMagickString(dpx.file.copyright,value,
 
1479
    (void) strncpy(dpx.file.copyright,value,
1414
1480
      sizeof(dpx.file.copyright));
1415
1481
  offset+=WriteBlob(image,sizeof(dpx.file.copyright),(unsigned char *)
1416
1482
    dpx.file.copyright);
1417
 
  dpx.file.encrypt_key=(~0UL);
 
1483
  dpx.file.encrypt_key=(~0U);
1418
1484
  offset+=WriteBlobLong(image,dpx.file.encrypt_key);
1419
1485
  offset+=WriteBlob(image,sizeof(dpx.file.reserve),(unsigned char *)
1420
1486
    dpx.file.reserve);
1425
1491
  offset+=WriteBlobShort(image,dpx.image.orientation);
1426
1492
  dpx.image.number_elements=1;
1427
1493
  offset+=WriteBlobShort(image,dpx.image.number_elements);
1428
 
  offset+=WriteBlobLong(image,image->columns);
1429
 
  offset+=WriteBlobLong(image,image->rows);
 
1494
  offset+=WriteBlobLong(image,(unsigned int) image->columns);
 
1495
  offset+=WriteBlobLong(image,(unsigned int) image->rows);
1430
1496
  for (i=0; i < 8; i++)
1431
1497
  {
1432
 
    dpx.image.image_element[i].data_sign=0UL;
 
1498
    dpx.image.image_element[i].data_sign=0U;
1433
1499
    offset+=WriteBlobLong(image,dpx.image.image_element[i].data_sign);
1434
 
    dpx.image.image_element[i].low_data=0UL;
 
1500
    dpx.image.image_element[i].low_data=0U;
1435
1501
    offset+=WriteBlobLong(image,dpx.image.image_element[i].low_data);
1436
1502
    dpx.image.image_element[i].low_quantity=0.0f;
1437
1503
    offset+=WriteBlobFloat(image,dpx.image.image_element[i].low_quantity);
1438
 
    dpx.image.image_element[i].high_data=0UL;
 
1504
    dpx.image.image_element[i].high_data=0U;
1439
1505
    offset+=WriteBlobLong(image,dpx.image.image_element[i].high_data);
1440
1506
    dpx.image.image_element[i].high_quantity=0.0f;
1441
1507
    offset+=WriteBlobFloat(image,dpx.image.image_element[i].high_quantity);
1459
1525
    offset+=WriteBlobShort(image,dpx.image.image_element[i].packing);
1460
1526
    dpx.image.image_element[i].encoding=0;
1461
1527
    offset+=WriteBlobShort(image,dpx.image.image_element[i].encoding);
1462
 
    dpx.image.image_element[i].data_offset=0UL;
 
1528
    dpx.image.image_element[i].data_offset=0U;
1463
1529
    if (i == 0)
1464
1530
      dpx.image.image_element[i].data_offset=dpx.file.image_offset;
1465
1531
    offset+=WriteBlobLong(image,dpx.image.image_element[i].data_offset);
1466
 
    dpx.image.image_element[i].end_of_line_padding=0UL;
 
1532
    dpx.image.image_element[i].end_of_line_padding=0U;
1467
1533
    offset+=WriteBlobLong(image,dpx.image.image_element[i].end_of_line_padding);
1468
1534
    offset+=WriteBlobLong(image,
1469
1535
      dpx.image.image_element[i].end_of_image_padding);
1488
1554
      (void) DeleteImageProperty(image,"dpx:orientation.x_size");
1489
1555
      (void) DeleteImageProperty(image,"dpx:orientation.y_size");
1490
1556
    }
1491
 
  dpx.orientation.x_offset=0UL;
 
1557
  dpx.orientation.x_offset=0U;
1492
1558
  value=GetDPXProperty(image_info,image,"dpx:orientation.x_offset");
1493
1559
  if (value != (const char *) NULL)
1494
 
    dpx.orientation.x_offset=(unsigned long) atol(value);
 
1560
    dpx.orientation.x_offset=(unsigned int) atoi(value);
1495
1561
  offset+=WriteBlobLong(image,dpx.orientation.x_offset);
1496
 
  dpx.orientation.y_offset=0UL;
 
1562
  dpx.orientation.y_offset=0U;
1497
1563
  value=GetDPXProperty(image_info,image,"dpx:orientation.y_offset");
1498
1564
  if (value != (const char *) NULL)
1499
 
    dpx.orientation.y_offset=(unsigned long) atol(value);
 
1565
    dpx.orientation.y_offset=(unsigned int) atoi(value);
1500
1566
  offset+=WriteBlobLong(image,dpx.orientation.y_offset);
1501
1567
  dpx.orientation.x_center=0.0f;
1502
1568
  value=GetDPXProperty(image_info,image,"dpx:orientation.x_center");
1508
1574
  if (value != (const char *) NULL)
1509
1575
    dpx.orientation.y_center=atof(value);
1510
1576
  offset+=WriteBlobFloat(image,dpx.orientation.y_center);
1511
 
  dpx.orientation.x_size=0UL;
 
1577
  dpx.orientation.x_size=0U;
1512
1578
  value=GetDPXProperty(image_info,image,"dpx:orientation.x_size");
1513
1579
  if (value != (const char *) NULL)
1514
 
    dpx.orientation.x_size=(unsigned long) atol(value);
 
1580
    dpx.orientation.x_size=(unsigned int) atoi(value);
1515
1581
  offset+=WriteBlobLong(image,dpx.orientation.x_size);
1516
 
  dpx.orientation.y_size=0UL;
 
1582
  dpx.orientation.y_size=0U;
1517
1583
  value=GetDPXProperty(image_info,image,"dpx:orientation.y_size");
1518
1584
  if (value != (const char *) NULL)
1519
 
    dpx.orientation.y_size=(unsigned long) atol(value);
 
1585
    dpx.orientation.y_size=(unsigned int) atoi(value);
1520
1586
  offset+=WriteBlobLong(image,dpx.orientation.y_size);
1521
1587
  value=GetDPXProperty(image_info,image,"dpx:orientation.filename");
1522
1588
  if (value != (const char *) NULL)
1523
 
    (void) CopyMagickString(dpx.orientation.filename,value,
 
1589
    (void) strncpy(dpx.orientation.filename,value,
1524
1590
      sizeof(dpx.orientation.filename));
1525
1591
  offset+=WriteBlob(image,sizeof(dpx.orientation.filename),(unsigned char *)
1526
1592
    dpx.orientation.filename);
1528
1594
    dpx.orientation.timestamp);
1529
1595
  value=GetDPXProperty(image_info,image,"dpx:orientation.device");
1530
1596
  if (value != (const char *) NULL)
1531
 
    (void) CopyMagickString(dpx.orientation.device,value,
 
1597
    (void) strncpy(dpx.orientation.device,value,
1532
1598
      sizeof(dpx.orientation.device));
1533
1599
  offset+=WriteBlob(image,sizeof(dpx.orientation.device),(unsigned char *)
1534
1600
    dpx.orientation.device);
1550
1616
  for (i=0; i < 4; i++)
1551
1617
    offset+=WriteBlobShort(image,dpx.orientation.border[i]);
1552
1618
  for (i=0; i < 2; i++)
1553
 
    dpx.orientation.aspect_ratio[i]=0UL;
 
1619
    dpx.orientation.aspect_ratio[i]=0U;
1554
1620
  value=GetDPXProperty(image_info,image,"dpx:orientation.aspect_ratio");
1555
1621
  if (value != (const char *) NULL)
1556
1622
    {
1557
1623
      flags=ParseGeometry(value,&geometry_info);
1558
1624
      if ((flags & SigmaValue) == 0)
1559
1625
        geometry_info.sigma=geometry_info.rho;
1560
 
      dpx.orientation.aspect_ratio[0]=(unsigned long) (geometry_info.rho+0.5);
1561
 
      dpx.orientation.aspect_ratio[1]=(unsigned long) (geometry_info.sigma+0.5);
 
1626
      dpx.orientation.aspect_ratio[0]=(unsigned int) (geometry_info.rho+0.5);
 
1627
      dpx.orientation.aspect_ratio[1]=(unsigned int) (geometry_info.sigma+0.5);
1562
1628
    }
1563
1629
  for (i=0; i < 2; i++)
1564
1630
    offset+=WriteBlobLong(image,dpx.orientation.aspect_ratio[i]);
1570
1636
  *dpx.film.id='\0';
1571
1637
  value=GetDPXProperty(image_info,image,"dpx:film.id");
1572
1638
  if (value != (const char *) NULL)
1573
 
    (void) CopyMagickString(dpx.film.id,value,sizeof(dpx.film.id));
 
1639
    (void) strncpy(dpx.film.id,value,sizeof(dpx.film.id));
1574
1640
  offset+=WriteBlob(image,sizeof(dpx.film.id),(unsigned char *) dpx.film.id);
1575
1641
  *dpx.film.type='\0';
1576
1642
  value=GetDPXProperty(image_info,image,"dpx:film.type");
1577
1643
  if (value != (const char *) NULL)
1578
 
    (void) CopyMagickString(dpx.film.type,value,sizeof(dpx.film.type));
1579
 
  offset+=WriteBlob(image,sizeof(dpx.film.type),(unsigned char *) dpx.film.type);
 
1644
    (void) strncpy(dpx.film.type,value,sizeof(dpx.film.type));
 
1645
  offset+=WriteBlob(image,sizeof(dpx.film.type),(unsigned char *)
 
1646
    dpx.film.type);
1580
1647
  *dpx.film.offset='\0';
1581
1648
  value=GetDPXProperty(image_info,image,"dpx:film.offset");
1582
1649
  if (value != (const char *) NULL)
1583
 
    (void) CopyMagickString(dpx.film.offset,value,sizeof(dpx.film.offset));
 
1650
    (void) strncpy(dpx.film.offset,value,sizeof(dpx.film.offset));
1584
1651
  offset+=WriteBlob(image,sizeof(dpx.film.offset),(unsigned char *)
1585
1652
    dpx.film.offset);
1586
1653
  *dpx.film.prefix='\0';
1587
1654
  value=GetDPXProperty(image_info,image,"dpx:film.prefix");
1588
1655
  if (value != (const char *) NULL)
1589
 
    (void) CopyMagickString(dpx.film.prefix,value,sizeof(dpx.film.prefix));
 
1656
    (void) strncpy(dpx.film.prefix,value,sizeof(dpx.film.prefix));
1590
1657
  offset+=WriteBlob(image,sizeof(dpx.film.prefix),(unsigned char *)
1591
1658
    dpx.film.prefix);
1592
1659
  *dpx.film.count='\0';
1593
1660
  value=GetDPXProperty(image_info,image,"dpx:film.count");
1594
1661
  if (value != (const char *) NULL)
1595
 
    (void) CopyMagickString(dpx.film.count,value,sizeof(dpx.film.count));
 
1662
    (void) strncpy(dpx.film.count,value,sizeof(dpx.film.count));
1596
1663
  offset+=WriteBlob(image,sizeof(dpx.film.count),(unsigned char *)
1597
1664
    dpx.film.count);
1598
1665
  *dpx.film.format='\0';
1599
1666
  value=GetDPXProperty(image_info,image,"dpx:film.format");
1600
1667
  if (value != (const char *) NULL)
1601
 
    (void) CopyMagickString(dpx.film.format,value,sizeof(dpx.film.format));
 
1668
    (void) strncpy(dpx.film.format,value,sizeof(dpx.film.format));
1602
1669
  offset+=WriteBlob(image,sizeof(dpx.film.format),(unsigned char *)
1603
1670
    dpx.film.format);
1604
 
  dpx.film.frame_position=0UL;
 
1671
  dpx.film.frame_position=0U;
1605
1672
  value=GetDPXProperty(image_info,image,"dpx:film.frame_position");
1606
1673
  if (value != (const char *) NULL)
1607
 
    dpx.film.frame_position=(unsigned long) atol(value);
 
1674
    dpx.film.frame_position=(unsigned int) atoi(value);
1608
1675
  offset+=WriteBlobLong(image,dpx.film.frame_position);
1609
 
  dpx.film.sequence_length=0UL;
1610
 
  value=GetDPXProperty(image_info,image,"dpx:film.sequence_length");
 
1676
  dpx.film.sequence_extent=0U;
 
1677
  value=GetDPXProperty(image_info,image,"dpx:film.sequence_extent");
1611
1678
  if (value != (const char *) NULL)
1612
 
    dpx.film.sequence_length=(unsigned long) atol(value);
1613
 
  offset+=WriteBlobLong(image,dpx.film.sequence_length);
1614
 
  dpx.film.held_count=0UL;
 
1679
    dpx.film.sequence_extent=(unsigned int) atoi(value);
 
1680
  offset+=WriteBlobLong(image,dpx.film.sequence_extent);
 
1681
  dpx.film.held_count=0U;
1615
1682
  value=GetDPXProperty(image_info,image,"dpx:film.held_count");
1616
1683
  if (value != (const char *) NULL)
1617
 
    dpx.film.held_count=(unsigned long) atol(value);
 
1684
    dpx.film.held_count=(unsigned int) atoi(value);
1618
1685
  offset+=WriteBlobLong(image,dpx.film.held_count);
1619
1686
  dpx.film.frame_rate=0.0f;
1620
1687
  value=GetDPXProperty(image_info,image,"dpx:film.frame_rate");
1629
1696
  *dpx.film.frame_id='\0';
1630
1697
  value=GetDPXProperty(image_info,image,"dpx:film.frame_id");
1631
1698
  if (value != (const char *) NULL)
1632
 
    (void) CopyMagickString(dpx.film.frame_id,value,sizeof(dpx.film.frame_id));
 
1699
    (void) strncpy(dpx.film.frame_id,value,sizeof(dpx.film.frame_id));
1633
1700
  offset+=WriteBlob(image,sizeof(dpx.film.frame_id),(unsigned char *)
1634
1701
    dpx.film.frame_id);
1635
1702
  value=GetDPXProperty(image_info,image,"dpx:film.slate");
1636
1703
  if (value != (const char *) NULL)
1637
 
    (void) CopyMagickString(dpx.film.slate,value,sizeof(dpx.film.slate));
 
1704
    (void) strncpy(dpx.film.slate,value,sizeof(dpx.film.slate));
1638
1705
  offset+=WriteBlob(image,sizeof(dpx.film.slate),(unsigned char *)
1639
1706
    dpx.film.slate);
1640
1707
  offset+=WriteBlob(image,sizeof(dpx.film.reserve),(unsigned char *)
1726
1793
  */
1727
1794
  value=GetDPXProperty(image_info,image,"dpx:user.id");
1728
1795
  if (value != (const char *) NULL)
1729
 
    (void) CopyMagickString(dpx.user.id,value,sizeof(dpx.user.id));
 
1796
    (void) strncpy(dpx.user.id,value,sizeof(dpx.user.id));
1730
1797
  offset+=WriteBlob(image,sizeof(dpx.user.id),(unsigned char *) dpx.user.id);
1731
1798
  if (profile != (StringInfo *) NULL)
1732
1799
    offset+=WriteBlob(image,GetStringInfoLength(profile),
1741
1808
  quantum_info->pack=dpx.image.image_element[0].packing == 0 ? MagickTrue :
1742
1809
    MagickFalse;
1743
1810
  quantum_type=RGBQuantum;
1744
 
  length=GetBytesPerRow(image->columns,3,image->depth,MagickTrue);
 
1811
  extent=GetBytesPerRow(image->columns,3,image->depth,MagickTrue);
1745
1812
  if (0)
1746
1813
    {
1747
1814
      quantum_type=GrayQuantum;
1748
 
      length=GetBytesPerRow(image->columns,3,image->depth,MagickTrue);
 
1815
      extent=GetBytesPerRow(image->columns,3,image->depth,MagickTrue);
1749
1816
    }
1750
1817
  pixels=GetQuantumPixels(quantum_info);
1751
1818
  for (y=0; y < (long) image->rows; y++)
1752
1819
  {
1753
 
    p=AcquireImagePixels(image,0,y,image->columns,1,&image->exception);
 
1820
    p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
1754
1821
    if (p == (const PixelPacket *) NULL)
1755
1822
      break;
1756
 
    (void) ExportQuantumPixels(image,quantum_info,quantum_type,pixels);
1757
 
    count=WriteBlob(image,length,pixels);
1758
 
    if (count != (ssize_t) length)
 
1823
    (void) ExportQuantumPixels(image,(const ViewInfo *) NULL,quantum_info,
 
1824
      quantum_type,pixels,&image->exception);
 
1825
    count=WriteBlob(image,extent,pixels);
 
1826
    if (count != (ssize_t) extent)
1759
1827
      break;
1760
1828
    status=SetImageProgress(image,SaveImageTag,y,image->rows);
1761
1829
    if (status == MagickFalse)