Coverage Report

Created: 2026-07-20 07:19

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/imagemagick/coders/dpx.c
Line
Count
Source
1
/*
2
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3
%                                                                             %
4
%                                                                             %
5
%                                                                             %
6
%                            DDDD   PPPP   X   X                              %
7
%                            D   D  P   P   X X                               %
8
%                            D   D  PPPP    XXX                               %
9
%                            D   D  P       X X                               %
10
%                            DDDD   P      X   X                              %
11
%                                                                             %
12
%                                                                             %
13
%                     Read/Write SMTPE DPX Image Format                       %
14
%                                                                             %
15
%                              Software Design                                %
16
%                                   Cristy                                    %
17
%                                March 2001                                   %
18
%                                                                             %
19
%                                                                             %
20
%  Copyright @ 1999 ImageMagick Studio LLC, a non-profit organization         %
21
%  dedicated to making software imaging solutions freely available.           %
22
%                                                                             %
23
%  You may not use this file except in compliance with the License.  You may  %
24
%  obtain a copy of the License at                                            %
25
%                                                                             %
26
%    https://imagemagick.org/license/                                         %
27
%                                                                             %
28
%  Unless required by applicable law or agreed to in writing, software        %
29
%  distributed under the License is distributed on an "AS IS" BASIS,          %
30
%  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   %
31
%  See the License for the specific language governing permissions and        %
32
%  limitations under the License.                                             %
33
%                                                                             %
34
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35
%
36
%
37
*/
38

39
/*
40
  Include declarations.
41
*/
42
#include "MagickCore/studio.h"
43
#include "MagickCore/attribute.h"
44
#include "MagickCore/artifact.h"
45
#include "MagickCore/blob.h"
46
#include "MagickCore/blob-private.h"
47
#include "MagickCore/cache.h"
48
#include "MagickCore/colorspace.h"
49
#include "MagickCore/colorspace-private.h"
50
#include "MagickCore/exception.h"
51
#include "MagickCore/exception-private.h"
52
#include "MagickCore/geometry.h"
53
#include "MagickCore/image.h"
54
#include "MagickCore/image-private.h"
55
#include "MagickCore/list.h"
56
#include "MagickCore/magick.h"
57
#include "MagickCore/memory_.h"
58
#include "MagickCore/module.h"
59
#include "MagickCore/monitor.h"
60
#include "MagickCore/monitor-private.h"
61
#include "MagickCore/option.h"
62
#include "MagickCore/pixel-accessor.h"
63
#include "MagickCore/profile-private.h"
64
#include "MagickCore/property.h"
65
#include "MagickCore/quantum-private.h"
66
#include "MagickCore/static.h"
67
#include "MagickCore/string_.h"
68
#include "MagickCore/string-private.h"
69
#include "MagickCore/timer-private.h"
70
#include "coders/coders-private.h"
71

72
/*
73
  Define declaration.
74
*/
75
2.26k
#define MaxNumberImageElements  8
76

77
/*
78
  Typedef declaration.
79
*/
80
typedef enum
81
{
82
  UserDefinedColorimetric = 0,
83
  PrintingDensityColorimetric = 1,
84
  LinearColorimetric = 2,
85
  LogarithmicColorimetric = 3,
86
  UnspecifiedVideoColorimetric = 4,
87
  SMTPE_274MColorimetric = 5,
88
  ITU_R709Colorimetric = 6,
89
  ITU_R601_625LColorimetric = 7,
90
  ITU_R601_525LColorimetric = 8,
91
  NTSCCompositeVideoColorimetric = 9,
92
  PALCompositeVideoColorimetric = 10,
93
  ZDepthLinearColorimetric = 11,
94
  DepthHomogeneousColorimetric = 12
95
} DPXColorimetric;
96
97
typedef enum
98
{
99
  UndefinedComponentType = 0,
100
  RedComponentType = 1,
101
  GreenComponentType = 2,
102
  BlueComponentType = 3,
103
  AlphaComponentType = 4,
104
  LumaComponentType = 6,
105
  ColorDifferenceCbCrComponentType = 7,
106
  DepthComponentType = 8,
107
  CompositeVideoComponentType = 9,
108
  RGBComponentType = 50,
109
  RGBAComponentType = 51,
110
  ABGRComponentType = 52,
111
  CbYCrY422ComponentType = 100,
112
  CbYACrYA4224ComponentType = 101,
113
  CbYCr444ComponentType = 102,
114
  CbYCrA4444ComponentType = 103,
115
  UserDef2ElementComponentType = 150,
116
  UserDef3ElementComponentType = 151,
117
  UserDef4ElementComponentType = 152,
118
  UserDef5ElementComponentType = 153,
119
  UserDef6ElementComponentType = 154,
120
  UserDef7ElementComponentType = 155,
121
  UserDef8ElementComponentType = 156
122
} DPXComponentType;
123
124
typedef enum
125
{
126
  TransferCharacteristicUserDefined = 0,
127
  TransferCharacteristicPrintingDensity = 1,
128
  TransferCharacteristicLinear = 2,
129
  TransferCharacteristicLogarithmic = 3,
130
  TransferCharacteristicUnspecifiedVideo = 4,
131
  TransferCharacteristicSMTPE274M = 5,     /* 1920x1080 TV */
132
  TransferCharacteristicITU_R709 = 6,      /* ITU R709 */
133
  TransferCharacteristicITU_R601_625L = 7, /* 625 Line */
134
  TransferCharacteristicITU_R601_525L = 8, /* 525 Line */
135
  TransferCharacteristicNTSCCompositeVideo = 9,
136
  TransferCharacteristicPALCompositeVideo = 10,
137
  TransferCharacteristicZDepthLinear = 11,
138
  TransferCharacteristicZDepthHomogeneous = 12
139
} DPXTransferCharacteristic;
140
141
typedef struct _DPXFileInfo
142
{
143
  unsigned int
144
    magic,
145
    image_offset;
146
147
  char
148
    version[8];
149
150
  unsigned int
151
    file_size,
152
    ditto_key,
153
    generic_size,
154
    industry_size,
155
    user_size;
156
157
  char
158
    filename[100],
159
    timestamp[24],
160
    creator[100],
161
    project[200],
162
    copyright[200];
163
164
  unsigned int
165
    encrypt_key;
166
167
  char
168
    reserve[104];
169
} DPXFileInfo;
170
171
typedef struct _DPXFilmInfo
172
{
173
  char
174
    id[2],
175
    type[2],
176
    offset[2],
177
    prefix[6],
178
    count[4],
179
    format[32];
180
181
  unsigned int
182
    frame_position,
183
    sequence_extent,
184
    held_count;
185
186
  float
187
    frame_rate,
188
    shutter_angle;
189
190
  char
191
    frame_id[32],
192
    slate[100],
193
    reserve[56];
194
} DPXFilmInfo;
195
196
typedef struct _DPXImageElement
197
{
198
  unsigned int
199
    data_sign,
200
    low_data;
201
202
  float
203
    low_quantity;
204
205
  unsigned int
206
    high_data;
207
208
  float
209
    high_quantity;
210
211
  unsigned char
212
    descriptor,
213
    transfer_characteristic,
214
    colorimetric,
215
    bit_size;
216
217
  unsigned short
218
    packing,
219
    encoding;
220
221
  unsigned int
222
    data_offset,
223
    end_of_line_padding,
224
    end_of_image_padding;
225
226
  unsigned char
227
    description[32];
228
} DPXImageElement;
229
230
typedef struct _DPXImageInfo
231
{
232
  unsigned short
233
    orientation,
234
    number_elements;
235
236
  unsigned int
237
    pixels_per_line,
238
    lines_per_element;
239
240
  DPXImageElement
241
    image_element[MaxNumberImageElements];
242
243
  unsigned char
244
    reserve[52];
245
} DPXImageInfo;
246
247
typedef struct _DPXOrientationInfo
248
{
249
  unsigned int
250
    x_offset,
251
    y_offset;
252
253
  float
254
    x_center,
255
    y_center;
256
257
  unsigned int
258
    x_size,
259
    y_size;
260
261
  char
262
    filename[100],
263
    timestamp[24],
264
    device[32],
265
    serial[32];
266
267
  unsigned short
268
    border[4];
269
270
  unsigned int
271
    aspect_ratio[2];
272
273
  unsigned char
274
    reserve[28];
275
} DPXOrientationInfo;
276
277
typedef struct _DPXTelevisionInfo
278
{
279
  unsigned int
280
    time_code,
281
    user_bits;
282
283
  unsigned char
284
    interlace,
285
    field_number,
286
    video_signal,
287
    padding;
288
289
  float
290
    horizontal_sample_rate,
291
    vertical_sample_rate,
292
    frame_rate,
293
    time_offset,
294
    gamma,
295
    black_level,
296
    black_gain,
297
    break_point,
298
    white_level,
299
    integration_times;
300
301
  char
302
    reserve[76];
303
} DPXTelevisionInfo;
304
305
typedef struct _DPXUserInfo
306
{
307
  char
308
    id[32];
309
} DPXUserInfo;
310
311
typedef struct DPXInfo
312
{
313
  DPXFileInfo
314
    file;
315
316
  DPXImageInfo
317
    image;
318
319
  DPXOrientationInfo
320
    orientation;
321
322
  DPXFilmInfo
323
    film;
324
325
  DPXTelevisionInfo
326
    television;
327
328
  DPXUserInfo
329
    user;
330
} DPXInfo;
331

332
/*
333
  Forward declarations.
334
*/
335
static MagickBooleanType
336
  WriteDPXImage(const ImageInfo *,Image *,ExceptionInfo *);
337

338
/*
339
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
340
%                                                                             %
341
%                                                                             %
342
%                                                                             %
343
%   I s D P X                                                                 %
344
%                                                                             %
345
%                                                                             %
346
%                                                                             %
347
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
348
%
349
%  IsDPX() returns MagickTrue if the image format type, identified by the
350
%  magick string, is DPX.
351
%
352
%  The format of the IsDPX method is:
353
%
354
%      MagickBooleanType IsDPX(const unsigned char *magick,const size_t extent)
355
%
356
%  A description of each parameter follows:
357
%
358
%    o magick: compare image format pattern against these bytes.
359
%
360
%    o extent: Specifies the extent of the magick string.
361
%
362
*/
363
static MagickBooleanType IsDPX(const unsigned char *magick,const size_t extent)
364
0
{
365
0
  if (extent < 4)
366
0
    return(MagickFalse);
367
0
  if (memcmp(magick,"SDPX",4) == 0)
368
0
    return(MagickTrue);
369
0
  if (memcmp(magick,"XPDS",4) == 0)
370
0
    return(MagickTrue);
371
0
  return(MagickFalse);
372
0
}
373

374
/*
375
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
376
%                                                                             %
377
%                                                                             %
378
%                                                                             %
379
%   R e a d D P X I m a g e                                                   %
380
%                                                                             %
381
%                                                                             %
382
%                                                                             %
383
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
384
%
385
%  ReadDPXImage() reads an DPX X image file and returns it.  It
386
%  allocates the memory necessary for the new Image structure and returns a
387
%  pointer to the new image.
388
%
389
%  The format of the ReadDPXImage method is:
390
%
391
%      Image *ReadDPXImage(const ImageInfo *image_info,ExceptionInfo *exception)
392
%
393
%  A description of each parameter follows:
394
%
395
%    o image_info: the image info.
396
%
397
%    o exception: return any errors or warnings in this structure.
398
%
399
*/
400
401
static size_t GetBytesPerRow(const size_t columns,
402
  const size_t samples_per_pixel,const size_t bits_per_pixel,
403
  const MagickBooleanType pad)
404
5.83k
{
405
5.83k
  size_t
406
5.83k
    bytes_per_row;
407
408
5.83k
  switch (bits_per_pixel)
409
5.83k
  {
410
792
    case 1:
411
792
    {
412
792
      bytes_per_row=4*(((size_t) samples_per_pixel*columns*bits_per_pixel+31)/
413
792
        32);
414
792
      break;
415
0
    }
416
442
    case 8:
417
2.12k
    default:
418
2.12k
    {
419
2.12k
      bytes_per_row=4*(((size_t) samples_per_pixel*columns*bits_per_pixel+31)/
420
2.12k
        32);
421
2.12k
      break;
422
442
    }
423
1.08k
    case 10:
424
1.08k
    {
425
1.08k
      if (pad == MagickFalse)
426
280
        {
427
280
          bytes_per_row=4*(((size_t) samples_per_pixel*columns*bits_per_pixel+
428
280
            31)/32);
429
280
          break;
430
280
        }
431
808
      bytes_per_row=4*(((size_t) (32*((samples_per_pixel*columns+2)/3))+31)/32);
432
808
      break;
433
1.08k
    }
434
849
    case 12:
435
849
    {
436
849
      if (pad == MagickFalse)
437
278
        {
438
278
          bytes_per_row=4*(((size_t) samples_per_pixel*columns*bits_per_pixel+
439
278
            31)/32);
440
278
          break;
441
278
        }
442
571
      bytes_per_row=2*(((size_t) (16*samples_per_pixel*columns)+15)/16);
443
571
      break;
444
849
    }
445
539
    case 16:
446
539
    {
447
539
      if (pad == MagickFalse)
448
196
        {
449
196
          bytes_per_row=2*(((size_t) samples_per_pixel*columns*bits_per_pixel+
450
196
            15)/16);
451
196
          break;
452
196
        }
453
343
      bytes_per_row=4*(((size_t) samples_per_pixel*columns*bits_per_pixel+31)/
454
343
        32);
455
343
      break;
456
539
    }
457
442
    case 32:
458
442
    {
459
442
      bytes_per_row=4*(((size_t) samples_per_pixel*columns*bits_per_pixel+31)/
460
442
        32);
461
442
      break;
462
539
    }
463
0
    case 64:
464
0
    {
465
0
      bytes_per_row=8*(((size_t) samples_per_pixel*columns*bits_per_pixel+63)/
466
0
        64);
467
0
      break;
468
539
    }
469
5.83k
  }
470
5.83k
  return(bytes_per_row);
471
5.83k
}
472
473
static const char *GetImageTransferCharacteristic(
474
  const DPXTransferCharacteristic characteristic)
475
17.9k
{
476
17.9k
  const char
477
17.9k
    *transfer;
478
479
  /*
480
    Get the element transfer characteristic.
481
  */
482
17.9k
  switch(characteristic)
483
17.9k
  {
484
4.87k
    case TransferCharacteristicUserDefined:
485
4.87k
    {
486
4.87k
      transfer="UserDefined";
487
4.87k
      break;
488
0
    }
489
926
    case TransferCharacteristicPrintingDensity:
490
926
    {
491
926
      transfer="PrintingDensity";
492
926
      break;
493
0
    }
494
151
    case TransferCharacteristicLinear:
495
151
    {
496
151
      transfer="Linear";
497
151
      break;
498
0
    }
499
252
    case TransferCharacteristicLogarithmic:
500
252
    {
501
252
      transfer="Logarithmic";
502
252
      break;
503
0
    }
504
200
    case TransferCharacteristicUnspecifiedVideo:
505
200
    {
506
200
      transfer="UnspecifiedVideo";
507
200
      break;
508
0
    }
509
141
    case TransferCharacteristicSMTPE274M:
510
141
    {
511
141
      transfer="SMTPE274M";
512
141
      break;
513
0
    }
514
41
    case TransferCharacteristicITU_R709:
515
41
    {
516
41
      transfer="ITU-R709";
517
41
      break;
518
0
    }
519
39
    case TransferCharacteristicITU_R601_625L:
520
39
    {
521
39
      transfer="ITU-R601-625L";
522
39
      break;
523
0
    }
524
115
    case TransferCharacteristicITU_R601_525L:
525
115
    {
526
115
      transfer="ITU-R601-525L";
527
115
      break;
528
0
    }
529
65
    case TransferCharacteristicNTSCCompositeVideo:
530
65
    {
531
65
      transfer="NTSCCompositeVideo";
532
65
      break;
533
0
    }
534
147
    case TransferCharacteristicPALCompositeVideo:
535
147
    {
536
147
      transfer="PALCompositeVideo";
537
147
      break;
538
0
    }
539
17
    case TransferCharacteristicZDepthLinear:
540
17
    {
541
17
      transfer="ZDepthLinear";
542
17
      break;
543
0
    }
544
74
    case TransferCharacteristicZDepthHomogeneous:
545
74
    {
546
74
      transfer="ZDepthHomogeneous";
547
74
      break;
548
0
    }
549
10.9k
    default:
550
10.9k
      transfer="Reserved";
551
17.9k
  }
552
17.9k
  return(transfer);
553
17.9k
}
554
555
static inline MagickBooleanType IsFloatDefined(const float value)
556
16.8k
{
557
16.8k
  union
558
16.8k
  {
559
16.8k
    unsigned int
560
16.8k
      unsigned_value;
561
562
16.8k
    float
563
16.8k
      float_value;
564
16.8k
  } quantum;
565
566
16.8k
  quantum.unsigned_value=(~0U);
567
16.8k
  quantum.float_value=(float) value;
568
16.8k
  if (quantum.unsigned_value == ~0U)
569
610
    return(MagickFalse);
570
16.2k
  return(MagickTrue);
571
16.8k
}
572
573
static void SetPrimaryChromaticity(const DPXColorimetric colorimetric,
574
  ChromaticityInfo *chromaticity_info)
575
5.01k
{
576
5.01k
  switch(colorimetric)
577
5.01k
  {
578
63
    case SMTPE_274MColorimetric:
579
127
    case ITU_R709Colorimetric:
580
127
    {
581
127
      chromaticity_info->red_primary.x=0.640;
582
127
      chromaticity_info->red_primary.y=0.330;
583
127
      chromaticity_info->red_primary.z=0.030;
584
127
      chromaticity_info->green_primary.x=0.300;
585
127
      chromaticity_info->green_primary.y=0.600;
586
127
      chromaticity_info->green_primary.z=0.100;
587
127
      chromaticity_info->blue_primary.x=0.150;
588
127
      chromaticity_info->blue_primary.y=0.060;
589
127
      chromaticity_info->blue_primary.z=0.790;
590
127
      chromaticity_info->white_point.x=0.3127;
591
127
      chromaticity_info->white_point.y=0.3290;
592
127
      chromaticity_info->white_point.z=0.3582;
593
127
      break;
594
63
    }
595
6
    case NTSCCompositeVideoColorimetric:
596
6
    {
597
6
      chromaticity_info->red_primary.x=0.67;
598
6
      chromaticity_info->red_primary.y=0.33;
599
6
      chromaticity_info->red_primary.z=0.00;
600
6
      chromaticity_info->green_primary.x=0.21;
601
6
      chromaticity_info->green_primary.y=0.71;
602
6
      chromaticity_info->green_primary.z=0.08;
603
6
      chromaticity_info->blue_primary.x=0.14;
604
6
      chromaticity_info->blue_primary.y=0.08;
605
6
      chromaticity_info->blue_primary.z=0.78;
606
6
      chromaticity_info->white_point.x=0.310;
607
6
      chromaticity_info->white_point.y=0.316;
608
6
      chromaticity_info->white_point.z=0.374;
609
6
      break;
610
63
    }
611
38
    case PALCompositeVideoColorimetric:
612
38
    {
613
38
      chromaticity_info->red_primary.x=0.640;
614
38
      chromaticity_info->red_primary.y=0.330;
615
38
      chromaticity_info->red_primary.z=0.030;
616
38
      chromaticity_info->green_primary.x=0.290;
617
38
      chromaticity_info->green_primary.y=0.600;
618
38
      chromaticity_info->green_primary.z=0.110;
619
38
      chromaticity_info->blue_primary.x=0.150;
620
38
      chromaticity_info->blue_primary.y=0.060;
621
38
      chromaticity_info->blue_primary.z=0.790;
622
38
      chromaticity_info->white_point.x=0.3127;
623
38
      chromaticity_info->white_point.y=0.3290;
624
38
      chromaticity_info->white_point.z=0.3582;
625
38
      break;
626
63
    }
627
4.84k
    default:
628
4.84k
      break;
629
5.01k
  }
630
5.01k
}
631
632
static void TimeCodeToString(const size_t timestamp,char *code)
633
2.37k
{
634
33.2k
#define TimeFields  7
635
636
2.37k
  unsigned int
637
2.37k
    shift;
638
639
2.37k
  ssize_t
640
2.37k
    i;
641
642
2.37k
  *code='\0';
643
2.37k
  shift=4*TimeFields;
644
21.3k
  for (i=0; i <= TimeFields; i++)
645
19.0k
  {
646
19.0k
    (void) FormatLocaleString(code,MagickPathExtent-strlen(code),"%x",
647
19.0k
      (unsigned int) ((timestamp >> shift) & 0x0fU));
648
19.0k
    code++;
649
19.0k
    if (((i % 2) != 0) && (i < TimeFields))
650
7.12k
      *code++=':';
651
19.0k
    shift-=4;
652
19.0k
    *code='\0';
653
19.0k
  }
654
2.37k
}
655
656
static Image *ReadDPXImage(const ImageInfo *image_info,ExceptionInfo *exception)
657
2.49k
{
658
2.49k
  char
659
2.49k
    magick[4],
660
2.49k
    value[MagickPathExtent];
661
662
2.49k
  DPXInfo
663
2.49k
    dpx;
664
665
2.49k
  Image
666
2.49k
    *image;
667
668
2.49k
  MagickBooleanType
669
2.49k
    status;
670
671
2.49k
  MagickOffsetType
672
2.49k
    offset;
673
674
2.49k
  QuantumInfo
675
2.49k
    *quantum_info;
676
677
2.49k
  QuantumType
678
2.49k
    quantum_type;
679
680
2.49k
  ssize_t
681
2.49k
    i;
682
683
2.49k
  size_t
684
2.49k
    extent,
685
2.49k
    samples_per_pixel;
686
687
2.49k
  ssize_t
688
2.49k
    count,
689
2.49k
    n,
690
2.49k
    row,
691
2.49k
    y;
692
693
2.49k
  unsigned char
694
2.49k
    component_type;
695
696
  /*
697
    Open image file.
698
  */
699
2.49k
  assert(image_info != (const ImageInfo *) NULL);
700
2.49k
  assert(image_info->signature == MagickCoreSignature);
701
2.49k
  assert(exception != (ExceptionInfo *) NULL);
702
2.49k
  assert(exception->signature == MagickCoreSignature);
703
2.49k
  if (IsEventLogging() != MagickFalse)
704
0
    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
705
0
      image_info->filename);
706
2.49k
  image=AcquireImage(image_info,exception);
707
2.49k
  status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
708
2.49k
  if (status == MagickFalse)
709
0
    {
710
0
      image=DestroyImageList(image);
711
0
      return((Image *) NULL);
712
0
    }
713
  /*
714
    Read DPX file header.
715
  */
716
2.49k
  offset=0;
717
2.49k
  count=ReadBlob(image,4,(unsigned char *) magick);
718
2.49k
  offset+=count;
719
2.49k
  if ((count != 4) || ((LocaleNCompare(magick,"SDPX",4) != 0) &&
720
1.49k
      (LocaleNCompare((char *) magick,"XPDS",4) != 0)))
721
2.46k
    ThrowReaderException(CorruptImageError,"ImproperImageHeader");
722
2.46k
  image->endian=LSBEndian;
723
2.46k
  if (LocaleNCompare(magick,"SDPX",4) == 0)
724
1.00k
    image->endian=MSBEndian;
725
2.46k
  (void) memset(&dpx,0,sizeof(dpx));
726
2.46k
  dpx.file.image_offset=ReadBlobLong(image);
727
2.46k
  offset+=4;
728
2.46k
  offset+=ReadBlob(image,sizeof(dpx.file.version),(unsigned char *)
729
2.46k
    dpx.file.version);
730
2.46k
  (void) FormatImageProperty(image,"dpx:file.version","%.8s",dpx.file.version);
731
2.46k
  dpx.file.file_size=ReadBlobLong(image);
732
2.46k
  offset+=4;
733
2.46k
  dpx.file.ditto_key=ReadBlobLong(image);
734
2.46k
  offset+=4;
735
2.46k
  if (dpx.file.ditto_key != ~0U)
736
2.24k
    (void) FormatImageProperty(image,"dpx:file.ditto.key","%u",
737
2.24k
      dpx.file.ditto_key);
738
2.46k
  dpx.file.generic_size=ReadBlobLong(image);
739
2.46k
  offset+=4;
740
2.46k
  dpx.file.industry_size=ReadBlobLong(image);
741
2.46k
  offset+=4;
742
2.46k
  dpx.file.user_size=ReadBlobLong(image);
743
2.46k
  offset+=4;
744
2.46k
  offset+=ReadBlob(image,sizeof(dpx.file.filename),(unsigned char *)
745
2.46k
    dpx.file.filename);
746
2.46k
  (void) FormatImageProperty(image,"dpx:file.filename","%.100s",
747
2.46k
    dpx.file.filename);
748
2.46k
  (void) FormatImageProperty(image,"document","%.100s",dpx.file.filename);
749
2.46k
  offset+=ReadBlob(image,sizeof(dpx.file.timestamp),(unsigned char *)
750
2.46k
    dpx.file.timestamp);
751
2.46k
  if (*dpx.file.timestamp != '\0')
752
1.48k
    (void) FormatImageProperty(image,"dpx:file.timestamp","%.24s",
753
1.48k
      dpx.file.timestamp);
754
2.46k
  offset+=ReadBlob(image,sizeof(dpx.file.creator),(unsigned char *)
755
2.46k
    dpx.file.creator);
756
2.46k
  if (*dpx.file.creator != '\0')
757
1.42k
    {
758
1.42k
      (void) FormatImageProperty(image,"dpx:file.creator","%.100s",
759
1.42k
        dpx.file.creator);
760
1.42k
      (void) FormatImageProperty(image,"software","%.100s",dpx.file.creator);
761
1.42k
    }
762
2.46k
  offset+=ReadBlob(image,sizeof(dpx.file.project),(unsigned char *)
763
2.46k
    dpx.file.project);
764
2.46k
  if (*dpx.file.project != '\0')
765
1.56k
    {
766
1.56k
      (void) FormatImageProperty(image,"dpx:file.project","%.200s",
767
1.56k
        dpx.file.project);
768
1.56k
      (void) FormatImageProperty(image,"comment","%.100s",dpx.file.project);
769
1.56k
    }
770
2.46k
  offset+=ReadBlob(image,sizeof(dpx.file.copyright),(unsigned char *)
771
2.46k
    dpx.file.copyright);
772
2.46k
  if (*dpx.file.copyright != '\0')
773
1.42k
    {
774
1.42k
      (void) FormatImageProperty(image,"dpx:file.copyright","%.200s",
775
1.42k
        dpx.file.copyright);
776
1.42k
      (void) FormatImageProperty(image,"copyright","%.100s",
777
1.42k
        dpx.file.copyright);
778
1.42k
    }
779
2.46k
  dpx.file.encrypt_key=ReadBlobLong(image);
780
2.46k
  offset+=4;
781
2.46k
  if (dpx.file.encrypt_key != ~0U)
782
2.29k
    (void) FormatImageProperty(image,"dpx:file.encrypt_key","%u",
783
2.29k
      dpx.file.encrypt_key);
784
2.46k
  offset+=ReadBlob(image,sizeof(dpx.file.reserve),(unsigned char *)
785
2.46k
    dpx.file.reserve);
786
  /*
787
    Read DPX image header.
788
  */
789
2.46k
  dpx.image.orientation=ReadBlobShort(image);
790
2.46k
  if (dpx.image.orientation > 7)
791
2.44k
    ThrowReaderException(CorruptImageError,"ImproperImageHeader");
792
2.44k
  offset+=2;
793
2.44k
  if (dpx.image.orientation != (unsigned short) ~0)
794
2.44k
    (void) FormatImageProperty(image,"dpx:image.orientation","%d",
795
2.44k
      dpx.image.orientation);
796
2.44k
  switch (dpx.image.orientation)
797
2.44k
  {
798
0
    default:
799
1.64k
    case 0: image->orientation=TopLeftOrientation; break;
800
462
    case 1: image->orientation=TopRightOrientation; break;
801
15
    case 2: image->orientation=BottomLeftOrientation; break;
802
31
    case 3: image->orientation=BottomRightOrientation; break;
803
31
    case 4: image->orientation=LeftTopOrientation; break;
804
31
    case 5: image->orientation=RightTopOrientation; break;
805
31
    case 6: image->orientation=LeftBottomOrientation; break;
806
196
    case 7: image->orientation=RightBottomOrientation; break;
807
2.44k
  }
808
2.44k
  dpx.image.number_elements=ReadBlobShort(image);
809
2.44k
  if ((dpx.image.number_elements < 1) ||
810
2.26k
      (dpx.image.number_elements > MaxNumberImageElements))
811
2.24k
    ThrowReaderException(CorruptImageError,"ImproperImageHeader");
812
2.24k
  offset+=2;
813
2.24k
  dpx.image.pixels_per_line=ReadBlobLong(image);
814
2.24k
  offset+=4;
815
2.24k
  image->columns=dpx.image.pixels_per_line;
816
2.24k
  dpx.image.lines_per_element=ReadBlobLong(image);
817
2.24k
  offset+=4;
818
2.24k
  image->rows=dpx.image.lines_per_element;
819
20.2k
  for (i=0; i < 8; i++)
820
17.9k
  {
821
17.9k
    char
822
17.9k
      property[MagickPathExtent];
823
824
17.9k
    dpx.image.image_element[i].data_sign=ReadBlobLong(image);
825
17.9k
    offset+=4;
826
17.9k
    dpx.image.image_element[i].low_data=ReadBlobLong(image);
827
17.9k
    offset+=4;
828
17.9k
    dpx.image.image_element[i].low_quantity=ReadBlobFloat(image);
829
17.9k
    offset+=4;
830
17.9k
    dpx.image.image_element[i].high_data=ReadBlobLong(image);
831
17.9k
    offset+=4;
832
17.9k
    dpx.image.image_element[i].high_quantity=ReadBlobFloat(image);
833
17.9k
    offset+=4;
834
17.9k
    dpx.image.image_element[i].descriptor=(unsigned char) ReadBlobByte(image);
835
17.9k
    offset++;
836
17.9k
    dpx.image.image_element[i].transfer_characteristic=(unsigned char)
837
17.9k
      ReadBlobByte(image);
838
17.9k
    (void) FormatLocaleString(property,MagickPathExtent,
839
17.9k
      "dpx:image.element[%lu].transfer-characteristic",(long) i);
840
17.9k
    (void) FormatImageProperty(image,property,"%s",
841
17.9k
      GetImageTransferCharacteristic((DPXTransferCharacteristic)
842
17.9k
      dpx.image.image_element[i].transfer_characteristic));
843
17.9k
    offset++;
844
17.9k
    dpx.image.image_element[i].colorimetric=(unsigned char) ReadBlobByte(image);
845
17.9k
    offset++;
846
17.9k
    dpx.image.image_element[i].bit_size=(unsigned char) ReadBlobByte(image);
847
17.9k
    offset++;
848
17.9k
    dpx.image.image_element[i].packing=ReadBlobShort(image);
849
17.9k
    offset+=2;
850
17.9k
    dpx.image.image_element[i].encoding=ReadBlobShort(image);
851
17.9k
    offset+=2;
852
17.9k
    dpx.image.image_element[i].data_offset=ReadBlobLong(image);
853
17.9k
    offset+=4;
854
17.9k
    dpx.image.image_element[i].end_of_line_padding=ReadBlobLong(image);
855
17.9k
    offset+=4;
856
17.9k
    dpx.image.image_element[i].end_of_image_padding=ReadBlobLong(image);
857
17.9k
    offset+=4;
858
17.9k
    offset+=ReadBlob(image,sizeof(dpx.image.image_element[i].description),
859
17.9k
      (unsigned char *) dpx.image.image_element[i].description);
860
17.9k
  }
861
2.24k
  (void) SetImageColorspace(image,RGBColorspace,exception);
862
2.24k
  offset+=ReadBlob(image,sizeof(dpx.image.reserve),(unsigned char *)
863
2.24k
    dpx.image.reserve);
864
2.24k
  if (dpx.file.image_offset >= 1664U)
865
1.28k
    {
866
      /*
867
        Read DPX orientation header.
868
      */
869
1.28k
      dpx.orientation.x_offset=ReadBlobLong(image);
870
1.28k
      offset+=4;
871
1.28k
      if (dpx.orientation.x_offset != ~0U)
872
1.18k
        (void) FormatImageProperty(image,"dpx:orientation.x_offset","%u",
873
1.18k
          dpx.orientation.x_offset);
874
1.28k
      dpx.orientation.y_offset=ReadBlobLong(image);
875
1.28k
      offset+=4;
876
1.28k
      if (dpx.orientation.y_offset != ~0U)
877
1.17k
        (void) FormatImageProperty(image,"dpx:orientation.y_offset","%u",
878
1.17k
          dpx.orientation.y_offset);
879
1.28k
      dpx.orientation.x_center=ReadBlobFloat(image);
880
1.28k
      offset+=4;
881
1.28k
      if (IsFloatDefined(dpx.orientation.x_center) != MagickFalse)
882
1.19k
        (void) FormatImageProperty(image,"dpx:orientation.x_center","%g",
883
1.19k
          (double) dpx.orientation.x_center);
884
1.28k
      dpx.orientation.y_center=ReadBlobFloat(image);
885
1.28k
      offset+=4;
886
1.28k
      if (IsFloatDefined(dpx.orientation.y_center) != MagickFalse)
887
1.18k
        (void) FormatImageProperty(image,"dpx:orientation.y_center","%g",
888
1.18k
          (double) dpx.orientation.y_center);
889
1.28k
      dpx.orientation.x_size=ReadBlobLong(image);
890
1.28k
      offset+=4;
891
1.28k
      if (dpx.orientation.x_size != ~0U)
892
1.20k
        (void) FormatImageProperty(image,"dpx:orientation.x_size","%u",
893
1.20k
          dpx.orientation.x_size);
894
1.28k
      dpx.orientation.y_size=ReadBlobLong(image);
895
1.28k
      offset+=4;
896
1.28k
      if (dpx.orientation.y_size != ~0U)
897
1.20k
        (void) FormatImageProperty(image,"dpx:orientation.y_size","%u",
898
1.20k
          dpx.orientation.y_size);
899
1.28k
      offset+=ReadBlob(image,sizeof(dpx.orientation.filename),(unsigned char *)
900
1.28k
        dpx.orientation.filename);
901
1.28k
      if (*dpx.orientation.filename != '\0')
902
558
        (void) FormatImageProperty(image,"dpx:orientation.filename","%.100s",
903
558
          dpx.orientation.filename);
904
1.28k
      offset+=ReadBlob(image,sizeof(dpx.orientation.timestamp),(unsigned char *)
905
1.28k
        dpx.orientation.timestamp);
906
1.28k
      if (*dpx.orientation.timestamp != '\0')
907
542
        (void) FormatImageProperty(image,"dpx:orientation.timestamp","%.24s",
908
542
          dpx.orientation.timestamp);
909
1.28k
      offset+=ReadBlob(image,sizeof(dpx.orientation.device),(unsigned char *)
910
1.28k
        dpx.orientation.device);
911
1.28k
      if (*dpx.orientation.device != '\0')
912
586
        (void) FormatImageProperty(image,"dpx:orientation.device","%.32s",
913
586
          dpx.orientation.device);
914
1.28k
      offset+=ReadBlob(image,sizeof(dpx.orientation.serial),(unsigned char *)
915
1.28k
        dpx.orientation.serial);
916
1.28k
      if (*dpx.orientation.serial != '\0')
917
564
        (void) FormatImageProperty(image,"dpx:orientation.serial","%.32s",
918
564
          dpx.orientation.serial);
919
6.40k
      for (i=0; i < 4; i++)
920
5.12k
      {
921
5.12k
        dpx.orientation.border[i]=ReadBlobShort(image);
922
5.12k
        offset+=2;
923
5.12k
      }
924
1.28k
      if ((dpx.orientation.border[0] != (unsigned short) (~0)) &&
925
1.16k
          (dpx.orientation.border[1] != (unsigned short) (~0)))
926
1.11k
        (void) FormatImageProperty(image,"dpx:orientation.border","%dx%d%+d%+d",
927
1.11k
          dpx.orientation.border[0],dpx.orientation.border[1],
928
1.11k
          dpx.orientation.border[2],dpx.orientation.border[3]);
929
3.84k
      for (i=0; i < 2; i++)
930
2.56k
      {
931
2.56k
        dpx.orientation.aspect_ratio[i]=ReadBlobLong(image);
932
2.56k
        offset+=4;
933
2.56k
      }
934
1.28k
      if ((dpx.orientation.aspect_ratio[0] != ~0U) &&
935
1.21k
          (dpx.orientation.aspect_ratio[1] != ~0U))
936
1.17k
        (void) FormatImageProperty(image,"dpx:orientation.aspect_ratio",
937
1.17k
          "%ux%u",dpx.orientation.aspect_ratio[0],
938
1.17k
          dpx.orientation.aspect_ratio[1]);
939
1.28k
      offset+=ReadBlob(image,sizeof(dpx.orientation.reserve),(unsigned char *)
940
1.28k
        dpx.orientation.reserve);
941
1.28k
    }
942
2.24k
  if (dpx.file.image_offset >= 1920U)
943
1.21k
    {
944
      /*
945
        Read DPX film header.
946
      */
947
1.21k
      offset+=ReadBlob(image,sizeof(dpx.film.id),(unsigned char *) dpx.film.id);
948
1.21k
      if (*dpx.film.id != '\0')
949
486
        (void) FormatImageProperty(image,"dpx:film.id","%.2s",dpx.film.id);
950
1.21k
      offset+=ReadBlob(image,sizeof(dpx.film.type),(unsigned char *)
951
1.21k
        dpx.film.type);
952
1.21k
      if (*dpx.film.type != '\0')
953
466
        (void) FormatImageProperty(image,"dpx:film.type","%.2s",dpx.film.type);
954
1.21k
      offset+=ReadBlob(image,sizeof(dpx.film.offset),(unsigned char *)
955
1.21k
        dpx.film.offset);
956
1.21k
      if (*dpx.film.offset != '\0')
957
462
        (void) FormatImageProperty(image,"dpx:film.offset","%.2s",
958
462
          dpx.film.offset);
959
1.21k
      offset+=ReadBlob(image,sizeof(dpx.film.prefix),(unsigned char *)
960
1.21k
        dpx.film.prefix);
961
1.21k
      if (*dpx.film.prefix != '\0')
962
465
        (void) FormatImageProperty(image,"dpx:film.prefix","%.6s",
963
465
          dpx.film.prefix);
964
1.21k
      offset+=ReadBlob(image,sizeof(dpx.film.count),(unsigned char *)
965
1.21k
        dpx.film.count);
966
1.21k
      if (*dpx.film.count != '\0')
967
479
        (void) FormatImageProperty(image,"dpx:film.count","%.4s",
968
479
          dpx.film.count);
969
1.21k
      offset+=ReadBlob(image,sizeof(dpx.film.format),(unsigned char *)
970
1.21k
        dpx.film.format);
971
1.21k
      if (*dpx.film.format != '\0')
972
452
        (void) FormatImageProperty(image,"dpx:film.format","%.4s",
973
452
          dpx.film.format);
974
1.21k
      dpx.film.frame_position=ReadBlobLong(image);
975
1.21k
      offset+=4;
976
1.21k
      if (dpx.film.frame_position != ~0U)
977
1.13k
        (void) FormatImageProperty(image,"dpx:film.frame_position","%u",
978
1.13k
          dpx.film.frame_position);
979
1.21k
      dpx.film.sequence_extent=ReadBlobLong(image);
980
1.21k
      offset+=4;
981
1.21k
      if (dpx.film.sequence_extent != ~0U)
982
1.13k
        (void) FormatImageProperty(image,"dpx:film.sequence_extent","%u",
983
1.13k
          dpx.film.sequence_extent);
984
1.21k
      dpx.film.held_count=ReadBlobLong(image);
985
1.21k
      offset+=4;
986
1.21k
      if (dpx.film.held_count != ~0U)
987
1.13k
        (void) FormatImageProperty(image,"dpx:film.held_count","%u",
988
1.13k
          dpx.film.held_count);
989
1.21k
      dpx.film.frame_rate=ReadBlobFloat(image);
990
1.21k
      offset+=4;
991
1.21k
      if (IsFloatDefined(dpx.film.frame_rate) != MagickFalse)
992
1.14k
        (void) FormatImageProperty(image,"dpx:film.frame_rate","%g",
993
1.14k
          (double) dpx.film.frame_rate);
994
1.21k
      dpx.film.shutter_angle=ReadBlobFloat(image);
995
1.21k
      offset+=4;
996
1.21k
      if (IsFloatDefined(dpx.film.shutter_angle) != MagickFalse)
997
1.14k
        (void) FormatImageProperty(image,"dpx:film.shutter_angle","%g",
998
1.14k
          (double) dpx.film.shutter_angle);
999
1.21k
      offset+=ReadBlob(image,sizeof(dpx.film.frame_id),(unsigned char *)
1000
1.21k
        dpx.film.frame_id);
1001
1.21k
      if (*dpx.film.frame_id != '\0')
1002
391
        (void) FormatImageProperty(image,"dpx:film.frame_id","%.32s",
1003
391
          dpx.film.frame_id);
1004
1.21k
      offset+=ReadBlob(image,sizeof(dpx.film.slate),(unsigned char *)
1005
1.21k
        dpx.film.slate);
1006
1.21k
      if (*dpx.film.slate != '\0')
1007
350
        (void) FormatImageProperty(image,"dpx:film.slate","%.100s",
1008
350
          dpx.film.slate);
1009
1.21k
      offset+=ReadBlob(image,sizeof(dpx.film.reserve),(unsigned char *)
1010
1.21k
        dpx.film.reserve);
1011
1.21k
    }
1012
2.24k
  if (dpx.file.image_offset >= 2048U)
1013
1.18k
    {
1014
      /*
1015
        Read DPX television header.
1016
      */
1017
1.18k
      dpx.television.time_code=(unsigned int) ReadBlobLong(image);
1018
1.18k
      offset+=4;
1019
1.18k
      TimeCodeToString(dpx.television.time_code,value);
1020
1.18k
      (void) SetImageProperty(image,"dpx:television.time.code",value,exception);
1021
1.18k
      dpx.television.user_bits=(unsigned int) ReadBlobLong(image);
1022
1.18k
      offset+=4;
1023
1.18k
      TimeCodeToString(dpx.television.user_bits,value);
1024
1.18k
      (void) SetImageProperty(image,"dpx:television.user.bits",value,exception);
1025
1.18k
      dpx.television.interlace=(unsigned char) ReadBlobByte(image);
1026
1.18k
      offset++;
1027
1.18k
      if (dpx.television.interlace != 0)
1028
1.02k
        (void) FormatImageProperty(image,"dpx:television.interlace","%.17g",
1029
1.02k
          (double) dpx.television.interlace);
1030
1.18k
      dpx.television.field_number=(unsigned char) ReadBlobByte(image);
1031
1.18k
      offset++;
1032
1.18k
      if (dpx.television.field_number != 0)
1033
1.01k
        (void) FormatImageProperty(image,"dpx:television.field_number","%.17g",
1034
1.01k
          (double) dpx.television.field_number);
1035
1.18k
      dpx.television.video_signal=(unsigned char) ReadBlobByte(image);
1036
1.18k
      offset++;
1037
1.18k
      if (dpx.television.video_signal != 0)
1038
1.03k
        (void) FormatImageProperty(image,"dpx:television.video_signal","%.17g",
1039
1.03k
          (double) dpx.television.video_signal);
1040
1.18k
      dpx.television.padding=(unsigned char) ReadBlobByte(image);
1041
1.18k
      offset++;
1042
1.18k
      if (dpx.television.padding != 0)
1043
1.03k
        (void) FormatImageProperty(image,"dpx:television.padding","%d",
1044
1.03k
          dpx.television.padding);
1045
1.18k
      dpx.television.horizontal_sample_rate=ReadBlobFloat(image);
1046
1.18k
      offset+=4;
1047
1.18k
      if (IsFloatDefined(dpx.television.horizontal_sample_rate) != MagickFalse)
1048
1.13k
        (void) FormatImageProperty(image,
1049
1.13k
          "dpx:television.horizontal_sample_rate","%g",
1050
1.13k
          (double) dpx.television.horizontal_sample_rate);
1051
1.18k
      dpx.television.vertical_sample_rate=ReadBlobFloat(image);
1052
1.18k
      offset+=4;
1053
1.18k
      if (IsFloatDefined(dpx.television.vertical_sample_rate) != MagickFalse)
1054
1.14k
        (void) FormatImageProperty(image,"dpx:television.vertical_sample_rate",
1055
1.14k
          "%g",(double) dpx.television.vertical_sample_rate);
1056
1.18k
      dpx.television.frame_rate=ReadBlobFloat(image);
1057
1.18k
      offset+=4;
1058
1.18k
      if (IsFloatDefined(dpx.television.frame_rate) != MagickFalse)
1059
1.14k
        (void) FormatImageProperty(image,"dpx:television.frame_rate","%g",
1060
1.14k
          (double) dpx.television.frame_rate);
1061
1.18k
      dpx.television.time_offset=ReadBlobFloat(image);
1062
1.18k
      offset+=4;
1063
1.18k
      if (IsFloatDefined(dpx.television.time_offset) != MagickFalse)
1064
1.15k
        (void) FormatImageProperty(image,"dpx:television.time_offset","%g",
1065
1.15k
          (double) dpx.television.time_offset);
1066
1.18k
      dpx.television.gamma=ReadBlobFloat(image);
1067
1.18k
      offset+=4;
1068
1.18k
      if (IsFloatDefined(dpx.television.gamma) != MagickFalse)
1069
1.15k
        (void) FormatImageProperty(image,"dpx:television.gamma","%g",
1070
1.15k
          (double) dpx.television.gamma);
1071
1.18k
      dpx.television.black_level=ReadBlobFloat(image);
1072
1.18k
      offset+=4;
1073
1.18k
      if (IsFloatDefined(dpx.television.black_level) != MagickFalse)
1074
1.15k
        (void) FormatImageProperty(image,"dpx:television.black_level","%g",
1075
1.15k
          (double) dpx.television.black_level);
1076
1.18k
      dpx.television.black_gain=ReadBlobFloat(image);
1077
1.18k
      offset+=4;
1078
1.18k
      if (IsFloatDefined(dpx.television.black_gain) != MagickFalse)
1079
1.17k
        (void) FormatImageProperty(image,"dpx:television.black_gain","%g",
1080
1.17k
          (double) dpx.television.black_gain);
1081
1.18k
      dpx.television.break_point=ReadBlobFloat(image);
1082
1.18k
      offset+=4;
1083
1.18k
      if (IsFloatDefined(dpx.television.break_point) != MagickFalse)
1084
1.17k
        (void) FormatImageProperty(image,"dpx:television.break_point","%g",
1085
1.17k
          (double) dpx.television.break_point);
1086
1.18k
      dpx.television.white_level=ReadBlobFloat(image);
1087
1.18k
      offset+=4;
1088
1.18k
      if (IsFloatDefined(dpx.television.white_level) != MagickFalse)
1089
1.17k
        (void) FormatImageProperty(image,"dpx:television.white_level","%g",
1090
1.17k
          (double) dpx.television.white_level);
1091
1.18k
      dpx.television.integration_times=ReadBlobFloat(image);
1092
1.18k
      offset+=4;
1093
1.18k
      if (IsFloatDefined(dpx.television.integration_times) != MagickFalse)
1094
1.17k
        (void) FormatImageProperty(image,"dpx:television.integration_times",
1095
1.17k
          "%g",(double) dpx.television.integration_times);
1096
1.18k
      offset+=ReadBlob(image,sizeof(dpx.television.reserve),(unsigned char *)
1097
1.18k
        dpx.television.reserve);
1098
1.18k
    }
1099
2.24k
  if (dpx.file.image_offset > 2080U)
1100
1.10k
    {
1101
      /*
1102
        Read DPX user header.
1103
      */
1104
1.10k
      offset+=ReadBlob(image,sizeof(dpx.user.id),(unsigned char *) dpx.user.id);
1105
1.10k
      if (*dpx.user.id != '\0')
1106
61
        (void) FormatImageProperty(image,"dpx:user.id","%.32s",dpx.user.id);
1107
1.10k
      if ((dpx.file.user_size != ~0U) &&
1108
1.00k
          ((size_t) dpx.file.user_size > sizeof(dpx.user.id)))
1109
893
        {
1110
893
          size_t
1111
893
            length;
1112
1113
893
          StringInfo
1114
893
            *profile;
1115
1116
893
          length=dpx.file.user_size-sizeof(dpx.user.id);
1117
893
          if ((MagickSizeType) length > GetBlobSize(image))
1118
640
            ThrowReaderException(CorruptImageError,
1119
893
              "InsufficientImageDataInFile");
1120
253
          profile=AcquireProfileStringInfo("dpx:user-data",length,exception);
1121
253
          if (profile == (StringInfo *) NULL)
1122
0
            offset=SeekBlob(image,(MagickOffsetType) length,SEEK_CUR);
1123
253
          else
1124
253
            {
1125
253
              offset+=ReadBlob(image,length,GetStringInfoDatum(profile));
1126
253
              (void) SetImageProfilePrivate(image,profile,exception);
1127
253
            }
1128
253
        }
1129
1.10k
    }
1130
8.96k
  for ( ; offset < (MagickOffsetType) dpx.file.image_offset; offset++)
1131
7.88k
    if (ReadBlobByte(image) == EOF)
1132
527
      break;
1133
1.60k
  if (EOFBlob(image) != MagickFalse)
1134
590
    {
1135
590
      ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
1136
590
        image->filename);
1137
590
      return(DestroyImageList(image));
1138
590
    }
1139
1.01k
  if (image_info->ping != MagickFalse)
1140
2
    {
1141
2
      (void) CloseBlob(image);
1142
2
      return(GetFirstImageInList(image));
1143
2
    }
1144
1.01k
  status=SetImageExtent(image,image->columns,image->rows,exception);
1145
1.01k
  if (status == MagickFalse)
1146
34
    return(DestroyImageList(image));
1147
982
  status=ResetImagePixels(image,exception);
1148
982
  if (status == MagickFalse)
1149
0
    return(DestroyImageList(image));
1150
5.91k
  for (n=0; n < (ssize_t) dpx.image.number_elements; n++)
1151
5.09k
  {
1152
5.09k
    unsigned char
1153
5.09k
      *pixels;
1154
1155
    /*
1156
      Convert DPX raster image to pixel packets.
1157
    */
1158
5.09k
    if ((dpx.image.image_element[n].data_offset != ~0U) &&
1159
4.71k
        (dpx.image.image_element[n].data_offset != 0U))
1160
3.76k
      {
1161
3.76k
         MagickOffsetType
1162
3.76k
           data_offset;
1163
1164
3.76k
         data_offset=(MagickOffsetType) dpx.image.image_element[n].data_offset;
1165
3.76k
         if (data_offset < offset)
1166
2.31k
           offset=SeekBlob(image,data_offset,SEEK_SET);
1167
1.44k
         else
1168
237k
           for ( ; offset < data_offset; offset++)
1169
235k
             if (ReadBlobByte(image) == EOF)
1170
72
               break;
1171
3.76k
          if (offset != data_offset)
1172
3.68k
            ThrowReaderException(CorruptImageError,"UnableToReadImageData");
1173
3.68k
       }
1174
5.01k
    SetPrimaryChromaticity((DPXColorimetric)
1175
5.01k
      dpx.image.image_element[n].colorimetric,&image->chromaticity);
1176
5.01k
    image->depth=dpx.image.image_element[n].bit_size;
1177
5.01k
    if ((image->depth == 0) || (image->depth > 32))
1178
5.01k
      ThrowReaderException(CorruptImageError,"ImproperImageHeader");
1179
5.01k
    samples_per_pixel=1;
1180
5.01k
    quantum_type=GrayQuantum;
1181
5.01k
    component_type=dpx.image.image_element[n].descriptor;
1182
5.01k
    switch (component_type)
1183
5.01k
    {
1184
315
      case CbYCrY422ComponentType:
1185
315
      {
1186
315
        samples_per_pixel=2;
1187
315
        quantum_type=CbYCrYQuantum;
1188
315
        break;
1189
0
      }
1190
121
      case CbYACrYA4224ComponentType:
1191
208
      case CbYCr444ComponentType:
1192
208
      {
1193
208
        samples_per_pixel=3;
1194
208
        quantum_type=CbYCrQuantum;
1195
208
        break;
1196
121
      }
1197
632
      case RGBComponentType:
1198
632
      {
1199
632
        samples_per_pixel=3;
1200
632
        quantum_type=RGBQuantum;
1201
632
        break;
1202
121
      }
1203
172
      case ABGRComponentType:
1204
351
      case RGBAComponentType:
1205
351
      {
1206
351
        image->alpha_trait=BlendPixelTrait;
1207
351
        samples_per_pixel=4;
1208
351
        quantum_type=RGBAQuantum;
1209
351
        break;
1210
172
      }
1211
3.50k
      default:
1212
3.50k
        break;
1213
5.01k
    }
1214
5.01k
    switch (component_type)
1215
5.01k
    {
1216
315
      case CbYCrY422ComponentType:
1217
436
      case CbYACrYA4224ComponentType:
1218
523
      case CbYCr444ComponentType:
1219
523
      {
1220
523
        (void) SetImageColorspace(image,Rec709YCbCrColorspace,exception);
1221
523
        break;
1222
436
      }
1223
299
      case LumaComponentType:
1224
299
      {
1225
299
        (void) SetImageColorspace(image,GRAYColorspace,exception);
1226
299
        break;
1227
436
      }
1228
4.19k
      default:
1229
4.19k
      {
1230
4.19k
        (void) SetImageColorspace(image,sRGBColorspace,exception);
1231
4.19k
        if (dpx.image.image_element[n].transfer_characteristic == LogarithmicColorimetric)
1232
154
          (void) SetImageColorspace(image,LogColorspace,exception);
1233
4.19k
        if (dpx.image.image_element[n].transfer_characteristic == PrintingDensityColorimetric)
1234
489
          (void) SetImageColorspace(image,LogColorspace,exception);
1235
4.19k
        break;
1236
436
      }
1237
5.01k
    }
1238
5.01k
    extent=GetBytesPerRow(image->columns,samples_per_pixel,image->depth,
1239
5.01k
      dpx.image.image_element[n].packing == 0 ? MagickFalse : MagickTrue);
1240
    /*
1241
      DPX any-bit pixel format.
1242
    */
1243
5.01k
    row=0;
1244
5.01k
    quantum_info=AcquireQuantumInfo(image_info,image);
1245
5.01k
    if (quantum_info == (QuantumInfo *) NULL)
1246
5.01k
      ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
1247
5.01k
    SetQuantumQuantum(quantum_info,32);
1248
5.01k
    SetQuantumPack(quantum_info,dpx.image.image_element[n].packing == 0 ?
1249
3.46k
      MagickTrue : MagickFalse);
1250
5.01k
    pixels=GetQuantumPixels(quantum_info);
1251
82.7k
    for (y=0; y < (ssize_t) image->rows; y++)
1252
77.7k
    {
1253
77.7k
      const void
1254
77.7k
        *stream;
1255
1256
77.7k
      MagickBooleanType
1257
77.7k
        sync;
1258
1259
77.7k
      Quantum
1260
77.7k
        *q;
1261
1262
77.7k
      size_t
1263
77.7k
        length;
1264
1265
77.7k
      ssize_t
1266
77.7k
        row_offset;
1267
1268
77.7k
      stream=ReadBlobStream(image,extent,pixels,&count);
1269
77.7k
      if (count != (ssize_t) extent)
1270
83
        break;
1271
77.7k
      if ((image->progress_monitor != (MagickProgressMonitor) NULL) &&
1272
0
          (image->previous == (Image *) NULL))
1273
0
        {
1274
0
          MagickBooleanType
1275
0
            proceed;
1276
1277
0
          proceed=SetImageProgress(image,LoadImageTag,(MagickOffsetType) row,
1278
0
            image->rows);
1279
0
          if (proceed == MagickFalse)
1280
0
            break;
1281
0
        }
1282
77.7k
      row_offset=row++;
1283
77.7k
      q=QueueAuthenticPixels(image,0,row_offset,image->columns,1,exception);
1284
77.7k
      if (q == (Quantum *) NULL)
1285
0
        break;
1286
77.7k
      length=ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
1287
77.7k
        quantum_type,(unsigned char *) stream,exception);
1288
77.7k
      (void) length;
1289
77.7k
      sync=SyncAuthenticPixels(image,exception);
1290
77.7k
      if (sync == MagickFalse)
1291
0
        break;
1292
77.7k
    }
1293
5.01k
    quantum_info=DestroyQuantumInfo(quantum_info);
1294
5.01k
    if (y < (ssize_t) image->rows)
1295
4.92k
      ThrowReaderException(CorruptImageError,"UnableToReadImageData");
1296
4.92k
    SetQuantumImageType(image,quantum_type);
1297
4.92k
    if (EOFBlob(image) != MagickFalse)
1298
0
      ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
1299
4.92k
        image->filename);
1300
4.92k
    if ((i+1) < (ssize_t) dpx.image.number_elements)
1301
203
      {
1302
        /*
1303
          Allocate next image structure.
1304
        */
1305
203
        AcquireNextImage(image_info,image,exception);
1306
203
        if (GetNextImageInList(image) == (Image *) NULL)
1307
0
          {
1308
0
            status=MagickFalse;
1309
0
            break;
1310
0
          }
1311
203
        image=SyncNextImageInList(image);
1312
203
        image->columns=dpx.image.pixels_per_line;
1313
203
        image->rows=dpx.image.lines_per_element;
1314
203
        status=SetImageProgress(image,LoadImagesTag,TellBlob(image),
1315
203
          GetBlobSize(image));
1316
203
        if (status == MagickFalse)
1317
0
          break;
1318
203
      }
1319
4.92k
  }
1320
820
  if (CloseBlob(image) == MagickFalse)
1321
0
    status=MagickFalse;
1322
820
  if (status == MagickFalse)
1323
0
    return(DestroyImageList(image));
1324
820
  return(GetFirstImageInList(image));
1325
820
}
1326

1327
/*
1328
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1329
%                                                                             %
1330
%                                                                             %
1331
%                                                                             %
1332
%   R e g i s t e r D P X I m a g e                                           %
1333
%                                                                             %
1334
%                                                                             %
1335
%                                                                             %
1336
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1337
%
1338
%  RegisterDPXImage() adds properties for the DPX image format to
1339
%  the list of supported formats.  The properties include the image format
1340
%  tag, a method to read and/or write the format, whether the format
1341
%  supports the saving of more than one frame to the same file or blob,
1342
%  whether the format supports native in-memory I/O, and a brief
1343
%  description of the format.
1344
%
1345
%  The format of the RegisterDPXImage method is:
1346
%
1347
%      size_t RegisterDPXImage(void)
1348
%
1349
*/
1350
ModuleExport size_t RegisterDPXImage(void)
1351
10
{
1352
10
  MagickInfo
1353
10
    *entry;
1354
1355
10
  static const char
1356
10
    *DPXNote =
1357
10
    {
1358
10
      "Digital Moving Picture Exchange Bitmap, Version 2.0.\n"
1359
10
      "See SMPTE 268M-2003 specification at http://www.smtpe.org\n"
1360
10
    };
1361
1362
10
  entry=AcquireMagickInfo("DPX","DPX","SMPTE 268M-2003 (DPX 2.0)");
1363
10
  entry->decoder=(DecodeImageHandler *) ReadDPXImage;
1364
10
  entry->encoder=(EncodeImageHandler *) WriteDPXImage;
1365
10
  entry->magick=(IsImageFormatHandler *) IsDPX;
1366
10
  entry->flags^=CoderAdjoinFlag;
1367
10
  entry->flags|=CoderDecoderSeekableStreamFlag;
1368
10
  entry->flags|=CoderEndianSupportFlag;
1369
10
  entry->note=ConstantString(DPXNote);
1370
10
  (void) RegisterMagickInfo(entry);
1371
10
  return(MagickImageCoderSignature);
1372
10
}
1373

1374
/*
1375
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1376
%                                                                             %
1377
%                                                                             %
1378
%                                                                             %
1379
%   U n r e g i s t e r D P X I m a g e                                       %
1380
%                                                                             %
1381
%                                                                             %
1382
%                                                                             %
1383
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1384
%
1385
%  UnregisterDPXImage() removes format registrations made by the
1386
%  DPX module from the list of supported formats.
1387
%
1388
%  The format of the UnregisterDPXImage method is:
1389
%
1390
%      UnregisterDPXImage(void)
1391
%
1392
*/
1393
ModuleExport void UnregisterDPXImage(void)
1394
0
{
1395
0
  (void) UnregisterMagickInfo("DPX");
1396
0
}
1397

1398
/*
1399
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1400
%                                                                             %
1401
%                                                                             %
1402
%                                                                             %
1403
%   W r i t e D P X I m a g e                                                 %
1404
%                                                                             %
1405
%                                                                             %
1406
%                                                                             %
1407
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1408
%
1409
%  WriteDPXImage() writes an image in DPX encoded image format.
1410
%
1411
%  The format of the WriteDPXImage method is:
1412
%
1413
%      MagickBooleanType WriteDPXImage(const ImageInfo *image_info,
1414
%        Image *image,ExceptionInfo *exception)
1415
%
1416
%  A description of each parameter follows.
1417
%
1418
%    o image_info: the image info.
1419
%
1420
%    o image:  The image.
1421
%
1422
%    o exception: return any errors or warnings in this structure.
1423
%
1424
*/
1425
1426
static unsigned int StringToTimeCode(const char *key)
1427
156
{
1428
156
  char
1429
156
    buffer[2];
1430
1431
156
  ssize_t
1432
156
    i;
1433
1434
156
  unsigned int
1435
156
    shift,
1436
156
    value;
1437
1438
156
  value=0;
1439
156
  shift=28;
1440
156
  buffer[1]='\0';
1441
1.87k
  for (i=0; (*key != 0) && (i < 11); i++)
1442
1.71k
  {
1443
1.71k
    if (isxdigit((int) ((unsigned char) *key)) == 0)
1444
468
      {
1445
468
        key++;
1446
468
        continue;
1447
468
      }
1448
1.24k
    buffer[0]=(*key++);
1449
1.24k
    value|=(unsigned int) ((strtol(buffer,(char **) NULL,16)) << shift);
1450
1.24k
    shift-=4;
1451
1.24k
  }
1452
156
  return(value);
1453
156
}
1454
1455
static inline const char *GetDPXProperty(const Image *image,
1456
  const char *property,ExceptionInfo *exception)
1457
36.9k
{
1458
36.9k
  const char
1459
36.9k
    *value;
1460
1461
36.9k
  value=GetImageArtifact(image,property);
1462
36.9k
  if (value != (const char *) NULL)
1463
0
    return(value);
1464
36.9k
  return(GetImageProperty(image,property,exception));
1465
36.9k
}
1466
1467
static MagickBooleanType WriteDPXImage(const ImageInfo *image_info,Image *image,
1468
  ExceptionInfo *exception)
1469
820
{
1470
820
  const char
1471
820
    *value;
1472
1473
820
  const StringInfo
1474
820
    *profile;
1475
1476
820
  DPXInfo
1477
820
    dpx;
1478
1479
820
  GeometryInfo
1480
820
    geometry_info;
1481
1482
820
  MagickBooleanType
1483
820
    status;
1484
1485
820
  MagickOffsetType
1486
820
    offset;
1487
1488
820
  MagickStatusType
1489
820
    flags;
1490
1491
820
  QuantumInfo
1492
820
    *quantum_info;
1493
1494
820
  QuantumType
1495
820
    quantum_type;
1496
1497
820
  const Quantum
1498
820
    *p;
1499
1500
820
  ssize_t
1501
820
    i;
1502
1503
820
  size_t
1504
820
    channels,
1505
820
    extent,
1506
820
    samples_per_pixel;
1507
1508
820
  ssize_t
1509
820
    count,
1510
820
    horizontal_factor,
1511
820
    vertical_factor,
1512
820
    y;
1513
1514
820
  time_t
1515
820
    seconds;
1516
1517
820
  unsigned char
1518
820
    component_type,
1519
820
    *pixels;
1520
1521
  /*
1522
    Open output image file.
1523
  */
1524
820
  assert(image_info != (const ImageInfo *) NULL);
1525
820
  assert(image_info->signature == MagickCoreSignature);
1526
820
  assert(image != (Image *) NULL);
1527
820
  assert(image->signature == MagickCoreSignature);
1528
820
  if (IsEventLogging() != MagickFalse)
1529
0
    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1530
820
  horizontal_factor=4;
1531
820
  vertical_factor=4;
1532
820
  if (image_info->sampling_factor != (char *) NULL)
1533
0
    {
1534
0
      flags=ParseGeometry(image_info->sampling_factor,&geometry_info);
1535
0
      if ((flags & RhoValue) != 0)
1536
0
        horizontal_factor=(ssize_t) geometry_info.rho;
1537
0
      vertical_factor=horizontal_factor;
1538
0
      if ((flags & SigmaValue) != 0)
1539
0
        vertical_factor=(ssize_t) geometry_info.sigma;
1540
0
      if ((horizontal_factor != 1) && (horizontal_factor != 2) &&
1541
0
          (horizontal_factor != 4) && (vertical_factor != 1) &&
1542
0
          (vertical_factor != 2) && (vertical_factor != 4))
1543
0
        ThrowWriterException(CorruptImageError,"UnexpectedSamplingFactor");
1544
0
    }
1545
820
  if ((IsYCbCrCompatibleColorspace(image->colorspace) != MagickFalse) &&
1546
96
      ((horizontal_factor == 2) || (vertical_factor == 2)))
1547
0
    if ((image->columns % 2) != 0)
1548
0
      image->columns++;
1549
820
  assert(exception != (ExceptionInfo *) NULL);
1550
820
  assert(exception->signature == MagickCoreSignature);
1551
820
  status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
1552
820
  if (status == MagickFalse)
1553
0
    return(status);
1554
  /*
1555
    Write file header.
1556
  */
1557
820
  (void) memset(&dpx,0,sizeof(dpx));
1558
820
  offset=0;
1559
820
  dpx.file.magic=0x53445058U;
1560
820
  offset+=WriteBlobLong(image,dpx.file.magic);
1561
820
  dpx.file.image_offset=0x2000U;
1562
820
  profile=GetImageProfile(image,"dpx:user-data");
1563
820
  if (profile != (StringInfo *) NULL)
1564
43
    {
1565
43
      if (GetStringInfoLength(profile) > 1048576)
1566
43
        ThrowWriterException(ImageError,"WidthOrHeightExceedsLimit");
1567
43
      dpx.file.image_offset+=(unsigned int) GetStringInfoLength(profile);
1568
43
      dpx.file.image_offset=(((dpx.file.image_offset+0x2000-1)/0x2000)*0x2000);
1569
43
    }
1570
820
  offset+=WriteBlobLong(image,dpx.file.image_offset);
1571
820
  (void) CopyMagickString(dpx.file.version,"V2.0",sizeof(dpx.file.version));
1572
820
  offset+=WriteBlob(image,8,(unsigned char *) &dpx.file.version);
1573
820
  channels=1;
1574
820
  if (IsImageGray(image) == MagickFalse)
1575
399
    channels=3;
1576
820
  if (image->alpha_trait != UndefinedPixelTrait)
1577
203
    channels++;
1578
820
  dpx.file.file_size=(unsigned int) (channels*image->columns*image->rows+
1579
820
    dpx.file.image_offset);
1580
820
  offset+=WriteBlobLong(image,dpx.file.file_size);
1581
820
  dpx.file.ditto_key=1U;  /* new frame */
1582
820
  offset+=WriteBlobLong(image,dpx.file.ditto_key);
1583
820
  dpx.file.generic_size=0x00000680U;
1584
820
  offset+=WriteBlobLong(image,dpx.file.generic_size);
1585
820
  dpx.file.industry_size=0x00000180U;
1586
820
  offset+=WriteBlobLong(image,dpx.file.industry_size);
1587
820
  dpx.file.user_size=0;
1588
820
  if (profile != (StringInfo *) NULL)
1589
43
    {
1590
43
      dpx.file.user_size+=(unsigned int) GetStringInfoLength(profile);
1591
43
      dpx.file.user_size=(((dpx.file.user_size+0x2000-1)/0x2000)*0x2000);
1592
43
    }
1593
820
  offset+=WriteBlobLong(image,dpx.file.user_size);
1594
820
  value=GetDPXProperty(image,"dpx:file.filename",exception);
1595
820
  if (value != (const char *) NULL)
1596
820
    (void) CopyMagickString(dpx.file.filename,value,sizeof(dpx.file.filename));
1597
820
  offset+=WriteBlob(image,sizeof(dpx.file.filename),(unsigned char *)
1598
820
    dpx.file.filename);
1599
820
  seconds=GetMagickTime();
1600
820
  (void) FormatMagickTime(seconds,sizeof(dpx.file.timestamp),
1601
820
    dpx.file.timestamp);
1602
820
  offset+=WriteBlob(image,sizeof(dpx.file.timestamp),(unsigned char *)
1603
820
    dpx.file.timestamp);
1604
820
  (void) CopyMagickString(dpx.file.creator,MagickAuthoritativeURL,
1605
820
    sizeof(dpx.file.creator));
1606
820
  value=GetDPXProperty(image,"dpx:file.creator",exception);
1607
820
  if (value != (const char *) NULL)
1608
490
    (void) CopyMagickString(dpx.file.creator,value,sizeof(dpx.file.creator));
1609
820
  offset+=WriteBlob(image,sizeof(dpx.file.creator),(unsigned char *)
1610
820
    dpx.file.creator);
1611
820
  value=GetDPXProperty(image,"dpx:file.project",exception);
1612
820
  if (value != (const char *) NULL)
1613
525
    (void) CopyMagickString(dpx.file.project,value,sizeof(dpx.file.project));
1614
820
  offset+=WriteBlob(image,sizeof(dpx.file.project),(unsigned char *)
1615
820
    dpx.file.project);
1616
820
  value=GetDPXProperty(image,"dpx:file.copyright",exception);
1617
820
  if (value != (const char *) NULL)
1618
477
    (void) CopyMagickString(dpx.file.copyright,value,
1619
477
      sizeof(dpx.file.copyright));
1620
820
  offset+=WriteBlob(image,sizeof(dpx.file.copyright),(unsigned char *)
1621
820
    dpx.file.copyright);
1622
820
  dpx.file.encrypt_key=(~0U);
1623
820
  offset+=WriteBlobLong(image,dpx.file.encrypt_key);
1624
820
  offset+=WriteBlob(image,sizeof(dpx.file.reserve),(unsigned char *)
1625
820
    dpx.file.reserve);
1626
  /*
1627
    Write image header.
1628
  */
1629
820
  switch (image->orientation)
1630
820
  {
1631
0
    default:
1632
389
    case TopLeftOrientation: dpx.image.orientation=0; break;
1633
271
    case TopRightOrientation: dpx.image.orientation=1; break;
1634
1
    case BottomLeftOrientation: dpx.image.orientation=2; break;
1635
9
    case BottomRightOrientation: dpx.image.orientation=3; break;
1636
3
    case LeftTopOrientation: dpx.image.orientation=4; break;
1637
19
    case RightTopOrientation: dpx.image.orientation=5; break;
1638
6
    case LeftBottomOrientation: dpx.image.orientation=6; break;
1639
122
    case RightBottomOrientation: dpx.image.orientation=7; break;
1640
820
  }
1641
820
  offset+=WriteBlobShort(image,dpx.image.orientation);
1642
820
  dpx.image.number_elements=1;
1643
820
  offset+=WriteBlobShort(image,dpx.image.number_elements);
1644
820
  if ((image->columns != (unsigned int) image->columns) ||
1645
820
      (image->rows != (unsigned int) image->rows))
1646
820
    ThrowWriterException(ImageError,"WidthOrHeightExceedsLimit");
1647
820
  offset+=WriteBlobLong(image,(unsigned int) image->columns);
1648
820
  offset+=WriteBlobLong(image,(unsigned int) image->rows);
1649
7.38k
  for (i=0; i < 8; i++)
1650
6.56k
  {
1651
6.56k
    dpx.image.image_element[i].data_sign=0U;
1652
6.56k
    offset+=WriteBlobLong(image,dpx.image.image_element[i].data_sign);
1653
6.56k
    dpx.image.image_element[i].low_data=0U;
1654
6.56k
    offset+=WriteBlobLong(image,dpx.image.image_element[i].low_data);
1655
6.56k
    dpx.image.image_element[i].low_quantity=0.0f;
1656
6.56k
    offset+=WriteBlobFloat(image,dpx.image.image_element[i].low_quantity);
1657
6.56k
    dpx.image.image_element[i].high_data=0U;
1658
6.56k
    offset+=WriteBlobLong(image,dpx.image.image_element[i].high_data);
1659
6.56k
    dpx.image.image_element[i].high_quantity=0.0f;
1660
6.56k
    offset+=WriteBlobFloat(image,dpx.image.image_element[i].high_quantity);
1661
6.56k
    dpx.image.image_element[i].descriptor=0;
1662
6.56k
    if (i == 0)
1663
820
      switch (image->colorspace)
1664
820
      {
1665
0
        case Rec601YCbCrColorspace:
1666
96
        case Rec709YCbCrColorspace:
1667
96
        case YCbCrColorspace:
1668
96
        {
1669
96
          dpx.image.image_element[i].descriptor=CbYCr444ComponentType;
1670
96
          if (image->alpha_trait != UndefinedPixelTrait)
1671
31
            dpx.image.image_element[i].descriptor=CbYCrA4444ComponentType;
1672
96
          break;
1673
96
        }
1674
724
        default:
1675
724
        {
1676
724
          dpx.image.image_element[i].descriptor=RGBComponentType;
1677
724
          if (image->alpha_trait != UndefinedPixelTrait)
1678
172
            dpx.image.image_element[i].descriptor=RGBAComponentType;
1679
724
          if ((image_info->type != TrueColorType) &&
1680
724
              ((image->alpha_trait & BlendPixelTrait) == 0) &&
1681
552
              (IdentifyImageCoderGray(image,exception) != MagickFalse))
1682
404
            dpx.image.image_element[i].descriptor=LumaComponentType;
1683
724
          break;
1684
96
        }
1685
820
      }
1686
6.56k
    offset+=WriteBlobByte(image,dpx.image.image_element[i].descriptor);
1687
6.56k
    dpx.image.image_element[i].transfer_characteristic=0;
1688
6.56k
    if (image->colorspace == LogColorspace)
1689
440
      dpx.image.image_element[0].transfer_characteristic=
1690
440
        PrintingDensityColorimetric;
1691
6.56k
    offset+=WriteBlobByte(image,
1692
6.56k
      dpx.image.image_element[i].transfer_characteristic);
1693
6.56k
    dpx.image.image_element[i].colorimetric=0;
1694
6.56k
    offset+=WriteBlobByte(image,dpx.image.image_element[i].colorimetric);
1695
6.56k
    dpx.image.image_element[i].bit_size=0;
1696
6.56k
    if (i == 0)
1697
820
      dpx.image.image_element[i].bit_size=(unsigned char) image->depth;
1698
6.56k
    offset+=WriteBlobByte(image,dpx.image.image_element[i].bit_size);
1699
6.56k
    dpx.image.image_element[i].packing=0;
1700
6.56k
    if ((image->depth == 10) || (image->depth == 12))
1701
1.92k
      dpx.image.image_element[i].packing=1;
1702
6.56k
    offset+=WriteBlobShort(image,dpx.image.image_element[i].packing);
1703
6.56k
    dpx.image.image_element[i].encoding=0;
1704
6.56k
    offset+=WriteBlobShort(image,dpx.image.image_element[i].encoding);
1705
6.56k
    dpx.image.image_element[i].data_offset=0U;
1706
6.56k
    if (i == 0)
1707
820
      dpx.image.image_element[i].data_offset=dpx.file.image_offset;
1708
6.56k
    offset+=WriteBlobLong(image,dpx.image.image_element[i].data_offset);
1709
6.56k
    dpx.image.image_element[i].end_of_line_padding=0U;
1710
6.56k
    offset+=WriteBlobLong(image,dpx.image.image_element[i].end_of_line_padding);
1711
6.56k
    offset+=WriteBlobLong(image,
1712
6.56k
      dpx.image.image_element[i].end_of_image_padding);
1713
6.56k
    offset+=WriteBlob(image,sizeof(dpx.image.image_element[i].description),
1714
6.56k
      (unsigned char *) dpx.image.image_element[i].description);
1715
6.56k
  }
1716
820
  offset+=WriteBlob(image,sizeof(dpx.image.reserve),(unsigned char *)
1717
820
    dpx.image.reserve);
1718
  /*
1719
    Write orientation header.
1720
  */
1721
820
  if ((image->rows != image->magick_rows) ||
1722
820
      (image->columns != image->magick_columns))
1723
0
    {
1724
      /*
1725
        These properties are not valid if image size changed.
1726
      */
1727
0
      (void) DeleteImageProperty(image,"dpx:orientation.x_offset");
1728
0
      (void) DeleteImageProperty(image,"dpx:orientation.y_offset");
1729
0
      (void) DeleteImageProperty(image,"dpx:orientation.x_center");
1730
0
      (void) DeleteImageProperty(image,"dpx:orientation.y_center");
1731
0
      (void) DeleteImageProperty(image,"dpx:orientation.x_size");
1732
0
      (void) DeleteImageProperty(image,"dpx:orientation.y_size");
1733
0
    }
1734
820
  dpx.orientation.x_offset=0U;
1735
820
  value=GetDPXProperty(image,"dpx:orientation.x_offset",exception);
1736
820
  if (value != (const char *) NULL)
1737
100
    dpx.orientation.x_offset=(unsigned int) StringToUnsignedLong(value);
1738
820
  offset+=WriteBlobLong(image,dpx.orientation.x_offset);
1739
820
  dpx.orientation.y_offset=0U;
1740
820
  value=GetDPXProperty(image,"dpx:orientation.y_offset",exception);
1741
820
  if (value != (const char *) NULL)
1742
98
    dpx.orientation.y_offset=(unsigned int) StringToUnsignedLong(value);
1743
820
  offset+=WriteBlobLong(image,dpx.orientation.y_offset);
1744
820
  dpx.orientation.x_center=0.0f;
1745
820
  value=GetDPXProperty(image,"dpx:orientation.x_center",exception);
1746
820
  if (value != (const char *) NULL)
1747
106
    dpx.orientation.x_center=StringToFloat(value,(char **) NULL);
1748
820
  offset+=WriteBlobFloat(image,dpx.orientation.x_center);
1749
820
  dpx.orientation.y_center=0.0f;
1750
820
  value=GetDPXProperty(image,"dpx:orientation.y_center",exception);
1751
820
  if (value != (const char *) NULL)
1752
104
    dpx.orientation.y_center=StringToFloat(value,(char **) NULL);
1753
820
  offset+=WriteBlobFloat(image,dpx.orientation.y_center);
1754
820
  dpx.orientation.x_size=0U;
1755
820
  value=GetDPXProperty(image,"dpx:orientation.x_size",exception);
1756
820
  if (value != (const char *) NULL)
1757
104
    dpx.orientation.x_size=(unsigned int) StringToUnsignedLong(value);
1758
820
  offset+=WriteBlobLong(image,dpx.orientation.x_size);
1759
820
  dpx.orientation.y_size=0U;
1760
820
  value=GetDPXProperty(image,"dpx:orientation.y_size",exception);
1761
820
  if (value != (const char *) NULL)
1762
105
    dpx.orientation.y_size=(unsigned int) StringToUnsignedLong(value);
1763
820
  offset+=WriteBlobLong(image,dpx.orientation.y_size);
1764
820
  value=GetDPXProperty(image,"dpx:orientation.filename",exception);
1765
820
  if (value != (const char *) NULL)
1766
87
    (void) CopyMagickString(dpx.orientation.filename,value,
1767
87
      sizeof(dpx.orientation.filename));
1768
820
  offset+=WriteBlob(image,sizeof(dpx.orientation.filename),(unsigned char *)
1769
820
    dpx.orientation.filename);
1770
820
  offset+=WriteBlob(image,sizeof(dpx.orientation.timestamp),(unsigned char *)
1771
820
    dpx.orientation.timestamp);
1772
820
  value=GetDPXProperty(image,"dpx:orientation.device",exception);
1773
820
  if (value != (const char *) NULL)
1774
86
    (void) CopyMagickString(dpx.orientation.device,value,
1775
86
      sizeof(dpx.orientation.device));
1776
820
  offset+=WriteBlob(image,sizeof(dpx.orientation.device),(unsigned char *)
1777
820
    dpx.orientation.device);
1778
820
  value=GetDPXProperty(image,"dpx:orientation.serial",exception);
1779
820
  if (value != (const char *) NULL)
1780
78
    (void) CopyMagickString(dpx.orientation.serial,value,
1781
78
      sizeof(dpx.orientation.serial));
1782
820
  offset+=WriteBlob(image,sizeof(dpx.orientation.serial),(unsigned char *)
1783
820
    dpx.orientation.serial);
1784
4.10k
  for (i=0; i < 4; i++)
1785
3.28k
    dpx.orientation.border[i]=0;
1786
820
  value=GetDPXProperty(image,"dpx:orientation.border",exception);
1787
820
  if (value != (const char *) NULL)
1788
103
    {
1789
103
      flags=ParseGeometry(value,&geometry_info);
1790
103
      if ((flags & SigmaValue) == 0)
1791
0
        geometry_info.sigma=geometry_info.rho;
1792
103
      dpx.orientation.border[0]=(unsigned short) (geometry_info.rho+0.5);
1793
103
      dpx.orientation.border[1]=(unsigned short) (geometry_info.sigma+0.5);
1794
103
      dpx.orientation.border[2]=(unsigned short) (geometry_info.xi+0.5);
1795
103
      dpx.orientation.border[3]=(unsigned short) (geometry_info.psi+0.5);
1796
103
    }
1797
4.10k
  for (i=0; i < 4; i++)
1798
3.28k
    offset+=WriteBlobShort(image,dpx.orientation.border[i]);
1799
2.46k
  for (i=0; i < 2; i++)
1800
1.64k
    dpx.orientation.aspect_ratio[i]=0U;
1801
820
  value=GetDPXProperty(image,"dpx:orientation.aspect_ratio",exception);
1802
820
  if (value != (const char *) NULL)
1803
106
    {
1804
106
      flags=ParseGeometry(value,&geometry_info);
1805
106
      if ((flags & SigmaValue) == 0)
1806
0
        geometry_info.sigma=geometry_info.rho;
1807
106
      dpx.orientation.aspect_ratio[0]=(unsigned int) (geometry_info.rho+0.5);
1808
106
      dpx.orientation.aspect_ratio[1]=(unsigned int) (geometry_info.sigma+0.5);
1809
106
    }
1810
2.46k
  for (i=0; i < 2; i++)
1811
1.64k
    offset+=WriteBlobLong(image,dpx.orientation.aspect_ratio[i]);
1812
820
  offset+=WriteBlob(image,sizeof(dpx.orientation.reserve),(unsigned char *)
1813
820
    dpx.orientation.reserve);
1814
  /*
1815
    Write film header.
1816
  */
1817
820
  (void) memset(dpx.film.id,0,sizeof(dpx.film.id));
1818
820
  value=GetDPXProperty(image,"dpx:film.id",exception);
1819
820
  if (value != (const char *) NULL)
1820
65
    (void) CopyMagickString(dpx.film.id,value,sizeof(dpx.film.id));
1821
820
  offset+=WriteBlob(image,sizeof(dpx.film.id),(unsigned char *) dpx.film.id);
1822
820
  (void) memset(dpx.film.type,0,sizeof(dpx.film.type));
1823
820
  value=GetDPXProperty(image,"dpx:film.type",exception);
1824
820
  if (value != (const char *) NULL)
1825
50
    (void) CopyMagickString(dpx.film.type,value,sizeof(dpx.film.type));
1826
820
  offset+=WriteBlob(image,sizeof(dpx.film.type),(unsigned char *)
1827
820
    dpx.film.type);
1828
820
  (void) memset(dpx.film.offset,0,sizeof(dpx.film.offset));
1829
820
  value=GetDPXProperty(image,"dpx:film.offset",exception);
1830
820
  if (value != (const char *) NULL)
1831
59
    (void) CopyMagickString(dpx.film.offset,value,sizeof(dpx.film.offset));
1832
820
  offset+=WriteBlob(image,sizeof(dpx.film.offset),(unsigned char *)
1833
820
    dpx.film.offset);
1834
820
  (void) memset(dpx.film.prefix,0,sizeof(dpx.film.prefix));
1835
820
  value=GetDPXProperty(image,"dpx:film.prefix",exception);
1836
820
  if (value != (const char *) NULL)
1837
63
    (void) CopyMagickString(dpx.film.prefix,value,sizeof(dpx.film.prefix));
1838
820
  offset+=WriteBlob(image,sizeof(dpx.film.prefix),(unsigned char *)
1839
820
    dpx.film.prefix);
1840
820
  (void) memset(dpx.film.count,0,sizeof(dpx.film.count));
1841
820
  value=GetDPXProperty(image,"dpx:film.count",exception);
1842
820
  if (value != (const char *) NULL)
1843
62
    (void) CopyMagickString(dpx.film.count,value,sizeof(dpx.film.count));
1844
820
  offset+=WriteBlob(image,sizeof(dpx.film.count),(unsigned char *)
1845
820
    dpx.film.count);
1846
820
  (void) memset(dpx.film.format,0,sizeof(dpx.film.format));
1847
820
  value=GetDPXProperty(image,"dpx:film.format",exception);
1848
820
  if (value != (const char *) NULL)
1849
51
    (void) CopyMagickString(dpx.film.format,value,sizeof(dpx.film.format));
1850
820
  offset+=WriteBlob(image,sizeof(dpx.film.format),(unsigned char *)
1851
820
    dpx.film.format);
1852
820
  dpx.film.frame_position=0U;
1853
820
  value=GetDPXProperty(image,"dpx:film.frame_position",exception);
1854
820
  if (value != (const char *) NULL)
1855
78
    dpx.film.frame_position=(unsigned int) StringToUnsignedLong(value);
1856
820
  offset+=WriteBlobLong(image,dpx.film.frame_position);
1857
820
  dpx.film.sequence_extent=0U;
1858
820
  value=GetDPXProperty(image,"dpx:film.sequence_extent",exception);
1859
820
  if (value != (const char *) NULL)
1860
80
    dpx.film.sequence_extent=(unsigned int) StringToUnsignedLong(value);
1861
820
  offset+=WriteBlobLong(image,dpx.film.sequence_extent);
1862
820
  dpx.film.held_count=0U;
1863
820
  value=GetDPXProperty(image,"dpx:film.held_count",exception);
1864
820
  if (value != (const char *) NULL)
1865
78
    dpx.film.held_count=(unsigned int) StringToUnsignedLong(value);
1866
820
  offset+=WriteBlobLong(image,dpx.film.held_count);
1867
820
  dpx.film.frame_rate=0.0f;
1868
820
  value=GetDPXProperty(image,"dpx:film.frame_rate",exception);
1869
820
  if (value != (const char *) NULL)
1870
79
    dpx.film.frame_rate=StringToFloat(value,(char **) NULL);
1871
820
  offset+=WriteBlobFloat(image,dpx.film.frame_rate);
1872
820
  dpx.film.shutter_angle=0.0f;
1873
820
  value=GetDPXProperty(image,"dpx:film.shutter_angle",exception);
1874
820
  if (value != (const char *) NULL)
1875
76
    dpx.film.shutter_angle=StringToFloat(value,(char **) NULL);
1876
820
  offset+=WriteBlobFloat(image,dpx.film.shutter_angle);
1877
820
  (void) memset(dpx.film.frame_id,0,sizeof(dpx.film.frame_id));
1878
820
  value=GetDPXProperty(image,"dpx:film.frame_id",exception);
1879
820
  if (value != (const char *) NULL)
1880
56
    (void) CopyMagickString(dpx.film.frame_id,value,sizeof(dpx.film.frame_id));
1881
820
  offset+=WriteBlob(image,sizeof(dpx.film.frame_id),(unsigned char *)
1882
820
    dpx.film.frame_id);
1883
820
  value=GetDPXProperty(image,"dpx:film.slate",exception);
1884
820
  if (value != (const char *) NULL)
1885
63
    (void) CopyMagickString(dpx.film.slate,value,sizeof(dpx.film.slate));
1886
820
  offset+=WriteBlob(image,sizeof(dpx.film.slate),(unsigned char *)
1887
820
    dpx.film.slate);
1888
820
  offset+=WriteBlob(image,sizeof(dpx.film.reserve),(unsigned char *)
1889
820
    dpx.film.reserve);
1890
  /*
1891
    Write television header.
1892
  */
1893
820
  value=GetDPXProperty(image,"dpx:television.time.code",exception);
1894
820
  if (value != (const char *) NULL)
1895
78
    dpx.television.time_code=StringToTimeCode(value);
1896
820
  offset+=WriteBlobLong(image,dpx.television.time_code);
1897
820
  value=GetDPXProperty(image,"dpx:television.user.bits",exception);
1898
820
  if (value != (const char *) NULL)
1899
78
    dpx.television.user_bits=StringToTimeCode(value);
1900
820
  offset+=WriteBlobLong(image,dpx.television.user_bits);
1901
820
  value=GetDPXProperty(image,"dpx:television.interlace",exception);
1902
820
  if (value != (const char *) NULL)
1903
48
    dpx.television.interlace=(unsigned char) StringToLong(value);
1904
820
  offset+=WriteBlobByte(image,dpx.television.interlace);
1905
820
  value=GetDPXProperty(image,"dpx:television.field_number",exception);
1906
820
  if (value != (const char *) NULL)
1907
49
    dpx.television.field_number=(unsigned char) StringToLong(value);
1908
820
  offset+=WriteBlobByte(image,dpx.television.field_number);
1909
820
  dpx.television.video_signal=0;
1910
820
  value=GetDPXProperty(image,"dpx:television.video_signal",exception);
1911
820
  if (value != (const char *) NULL)
1912
50
    dpx.television.video_signal=(unsigned char) StringToLong(value);
1913
820
  offset+=WriteBlobByte(image,dpx.television.video_signal);
1914
820
  dpx.television.padding=0;
1915
820
  value=GetDPXProperty(image,"dpx:television.padding",exception);
1916
820
  if (value != (const char *) NULL)
1917
44
    dpx.television.padding=(unsigned char) StringToLong(value);
1918
820
  offset+=WriteBlobByte(image,dpx.television.padding);
1919
820
  dpx.television.horizontal_sample_rate=0.0f;
1920
820
  value=GetDPXProperty(image,"dpx:television.horizontal_sample_rate",
1921
820
    exception);
1922
820
  if (value != (const char *) NULL)
1923
71
    dpx.television.horizontal_sample_rate=StringToFloat(value,(char **) NULL);
1924
820
  offset+=WriteBlobFloat(image,dpx.television.horizontal_sample_rate);
1925
820
  dpx.television.vertical_sample_rate=0.0f;
1926
820
  value=GetDPXProperty(image,"dpx:television.vertical_sample_rate",exception);
1927
820
  if (value != (const char *) NULL)
1928
68
    dpx.television.vertical_sample_rate=StringToFloat(value,(char **) NULL);
1929
820
  offset+=WriteBlobFloat(image,dpx.television.vertical_sample_rate);
1930
820
  dpx.television.frame_rate=0.0f;
1931
820
  value=GetDPXProperty(image,"dpx:television.frame_rate",exception);
1932
820
  if (value != (const char *) NULL)
1933
71
    dpx.television.frame_rate=StringToFloat(value,(char **) NULL);
1934
820
  offset+=WriteBlobFloat(image,dpx.television.frame_rate);
1935
820
  dpx.television.time_offset=0.0f;
1936
820
  value=GetDPXProperty(image,"dpx:television.time_offset",exception);
1937
820
  if (value != (const char *) NULL)
1938
75
    dpx.television.time_offset=StringToFloat(value,(char **) NULL);
1939
820
  offset+=WriteBlobFloat(image,dpx.television.time_offset);
1940
820
  dpx.television.gamma=0.0f;
1941
820
  value=GetDPXProperty(image,"dpx:television.gamma",exception);
1942
820
  if (value != (const char *) NULL)
1943
75
    dpx.television.gamma=StringToFloat(value,(char **) NULL);
1944
820
  offset+=WriteBlobFloat(image,dpx.television.gamma);
1945
820
  dpx.television.black_level=0.0f;
1946
820
  value=GetDPXProperty(image,"dpx:television.black_level",exception);
1947
820
  if (value != (const char *) NULL)
1948
73
    dpx.television.black_level=StringToFloat(value,(char **) NULL);
1949
820
  offset+=WriteBlobFloat(image,dpx.television.black_level);
1950
820
  dpx.television.black_gain=0.0f;
1951
820
  value=GetDPXProperty(image,"dpx:television.black_gain",exception);
1952
820
  if (value != (const char *) NULL)
1953
71
    dpx.television.black_gain=StringToFloat(value,(char **) NULL);
1954
820
  offset+=WriteBlobFloat(image,dpx.television.black_gain);
1955
820
  dpx.television.break_point=0.0f;
1956
820
  value=GetDPXProperty(image,"dpx:television.break_point",exception);
1957
820
  if (value != (const char *) NULL)
1958
73
    dpx.television.break_point=StringToFloat(value,(char **) NULL);
1959
820
  offset+=WriteBlobFloat(image,dpx.television.break_point);
1960
820
  dpx.television.white_level=0.0f;
1961
820
  value=GetDPXProperty(image,"dpx:television.white_level",exception);
1962
820
  if (value != (const char *) NULL)
1963
73
    dpx.television.white_level=StringToFloat(value,(char **) NULL);
1964
820
  offset+=WriteBlobFloat(image,dpx.television.white_level);
1965
820
  dpx.television.integration_times=0.0f;
1966
820
  value=GetDPXProperty(image,"dpx:television.integration_times",exception);
1967
820
  if (value != (const char *) NULL)
1968
73
    dpx.television.integration_times=StringToFloat(value,(char **) NULL);
1969
820
  offset+=WriteBlobFloat(image,dpx.television.integration_times);
1970
820
  offset+=WriteBlob(image,sizeof(dpx.television.reserve),(unsigned char *)
1971
820
    dpx.television.reserve);
1972
  /*
1973
    Write user header.
1974
  */
1975
820
  value=GetDPXProperty(image,"dpx:user.id",exception);
1976
820
  if (value != (const char *) NULL)
1977
31
    (void) CopyMagickString(dpx.user.id,value,sizeof(dpx.user.id));
1978
820
  offset+=WriteBlob(image,sizeof(dpx.user.id),(unsigned char *) dpx.user.id);
1979
820
  if (profile != (StringInfo *) NULL)
1980
43
    offset+=WriteBlob(image,GetStringInfoLength(profile),
1981
43
      GetStringInfoDatum(profile));
1982
5.34M
  while (offset < (MagickOffsetType) dpx.image.image_element[0].data_offset)
1983
5.34M
  {
1984
5.34M
    count=WriteBlobByte(image,0x00);
1985
5.34M
    if (count != 1)
1986
0
      {
1987
0
        ThrowFileException(exception,FileOpenError,"UnableToWriteFile",
1988
0
          image->filename);
1989
0
        break;
1990
0
      }
1991
5.34M
    offset+=count;
1992
5.34M
  }
1993
  /*
1994
    Convert pixel packets to DPX raster image.
1995
  */
1996
820
  quantum_info=AcquireQuantumInfo(image_info,image);
1997
820
  if (quantum_info == (QuantumInfo *) NULL)
1998
820
    ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
1999
820
  SetQuantumQuantum(quantum_info,32);
2000
820
  SetQuantumPack(quantum_info,dpx.image.image_element[0].packing == 0 ?
2001
579
    MagickTrue : MagickFalse);
2002
820
  samples_per_pixel=1;
2003
820
  quantum_type=GrayQuantum;
2004
820
  component_type=dpx.image.image_element[0].descriptor;
2005
820
  switch (component_type)
2006
820
  {
2007
0
    case CbYCrY422ComponentType:
2008
0
    {
2009
0
      samples_per_pixel=2;
2010
0
      quantum_type=CbYCrYQuantum;
2011
0
      break;
2012
0
    }
2013
0
    case CbYACrYA4224ComponentType:
2014
65
    case CbYCr444ComponentType:
2015
65
    {
2016
65
      samples_per_pixel=3;
2017
65
      quantum_type=CbYCrQuantum;
2018
65
      break;
2019
0
    }
2020
148
    case RGBComponentType:
2021
148
    {
2022
148
      samples_per_pixel=3;
2023
148
      quantum_type=RGBQuantum;
2024
148
      break;
2025
0
    }
2026
0
    case ABGRComponentType:
2027
172
    case RGBAComponentType:
2028
172
    {
2029
172
      samples_per_pixel=4;
2030
172
      quantum_type=RGBAQuantum;
2031
172
      break;
2032
0
    }
2033
435
    default:
2034
435
    {
2035
435
      if (channels == 1)
2036
360
        break;
2037
75
      quantum_type=RGBAQuantum;
2038
75
      if (image->alpha_trait != UndefinedPixelTrait)
2039
31
        quantum_type=RGBQuantum;
2040
75
      if (IsYCbCrCompatibleColorspace(image->colorspace) != MagickFalse)
2041
31
        {
2042
31
          quantum_type=CbYCrQuantum;
2043
31
          if (image->alpha_trait != UndefinedPixelTrait)
2044
31
            quantum_type=CbYCrAQuantum;
2045
31
          if ((horizontal_factor == 2) || (vertical_factor == 2))
2046
0
            quantum_type=CbYCrYQuantum;
2047
31
        }
2048
75
      break;
2049
435
    }
2050
820
  }
2051
820
  extent=GetBytesPerRow(image->columns,samples_per_pixel,image->depth,
2052
820
    dpx.image.image_element[0].packing == 0 ? MagickFalse : MagickTrue);
2053
820
  pixels=(unsigned char *) GetQuantumPixels(quantum_info);
2054
25.0k
  for (y=0; y < (ssize_t) image->rows; y++)
2055
24.2k
  {
2056
24.2k
    size_t
2057
24.2k
      length;
2058
2059
24.2k
    p=GetVirtualPixels(image,0,y,image->columns,1,exception);
2060
24.2k
    if (p == (const Quantum *) NULL)
2061
0
      break;
2062
24.2k
    length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
2063
24.2k
      quantum_type,pixels,exception);
2064
24.2k
    if (length == 0)
2065
0
      break;
2066
24.2k
    count=WriteBlob(image,extent,pixels);
2067
24.2k
    if (count != (ssize_t) extent)
2068
0
      break;
2069
24.2k
    status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
2070
24.2k
      image->rows);
2071
24.2k
    if (status == MagickFalse)
2072
0
      break;
2073
24.2k
  }
2074
820
  quantum_info=DestroyQuantumInfo(quantum_info);
2075
820
  if (y < (ssize_t) image->rows)
2076
820
    ThrowWriterException(CorruptImageError,"UnableToWriteImageData");
2077
820
  if (CloseBlob(image) == MagickFalse)
2078
0
    status=MagickFalse;
2079
820
  return(status);
2080
820
}