~lfaraone/ubuntu/maverick/imagemagick/graphviz-rebuild

« back to all changes in this revision

Viewing changes to coders/ycbcr.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2008-11-21 08:26:29 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20081121082629-iy01ycd87bs5fn2g
Tags: 7:6.4.5.4.dfsg1-1ubuntu1
* Merge with Debian; remaining changes:
  - (Build-)depend on libltdl7-dev instead of libltdl3-dev (the armel buildds
    currently have both available).

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
%                       Y     YYYC  BBBB    YYYC  R   R                       %
11
11
%                                                                             %
12
12
%                                                                             %
13
 
%                     Read/Write RAW YCbCr Image Format.                      %
 
13
%                     Read/Write Raw YCbCr Image Format                       %
14
14
%                                                                             %
15
15
%                              Software Design                                %
16
16
%                                John Cristy                                  %
52
52
#include "magick/magick.h"
53
53
#include "magick/memory_.h"
54
54
#include "magick/monitor.h"
55
 
#include "magick/quantum-private.h"
 
55
#include "magick/monitor-private.h"
 
56
#include "magick/pixel-private.h"
56
57
#include "magick/quantum-private.h"
57
58
#include "magick/static.h"
58
59
#include "magick/statistic.h"
77
78
%                                                                             %
78
79
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
79
80
%
80
 
%  ReadYCBCRImage() reads an image of raw Y, Cb, and Cr samples and returns
81
 
%  it.  It allocates the memory necessary for the new Image structure and
 
81
%  ReadYCBCRImage() reads an image of raw YCbCr or YCbCrA samples and returns
 
82
%  it. It allocates the memory necessary for the new Image structure and
82
83
%  returns a pointer to the new image.
83
84
%
84
85
%  The format of the ReadYCBCRImage method is:
88
89
%
89
90
%  A description of each parameter follows:
90
91
%
91
 
%    o image_info: The image info.
 
92
%    o image_info: the image info.
92
93
%
93
94
%    o exception: return any errors or warnings in this structure.
94
95
%
95
 
%
96
96
*/
97
97
static Image *ReadYCBCRImage(const ImageInfo *image_info,
98
98
  ExceptionInfo *exception)
99
99
{
100
100
  Image
 
101
    *canvas_image,
101
102
    *image;
102
103
 
103
104
  long
107
108
    status;
108
109
 
109
110
  MagickOffsetType
110
 
    offset;
 
111
    scene;
111
112
 
112
113
  QuantumInfo
113
 
    quantum_info;
 
114
    *quantum_info;
 
115
 
 
116
  QuantumType
 
117
    quantum_type;
 
118
 
 
119
  register const PixelPacket
 
120
    *p;
114
121
 
115
122
  register long
116
 
    i;
 
123
    i,
 
124
    x;
117
125
 
118
126
  register PixelPacket
119
127
    *q;
122
130
    count;
123
131
 
124
132
  size_t
125
 
    packet_size;
 
133
    length;
126
134
 
127
135
  unsigned char
128
136
    *pixels;
129
137
 
130
 
  unsigned long
131
 
    width;
132
 
 
 
138
  /*
 
139
    Open image file.
 
140
  */
133
141
  assert(image_info != (const ImageInfo *) NULL);
134
142
  assert(image_info->signature == MagickSignature);
135
143
  if (image_info->debug != MagickFalse)
137
145
      image_info->filename);
138
146
  assert(exception != (ExceptionInfo *) NULL);
139
147
  assert(exception->signature == MagickSignature);
140
 
  image=AllocateImage(image_info);
 
148
  image=AcquireImage(image_info);
141
149
  if ((image->columns == 0) || (image->rows == 0))
142
150
    ThrowReaderException(OptionError,"MustSpecifyImageSize");
 
151
  image->colorspace=YCbCrColorspace;
143
152
  if (image_info->interlace != PartitionInterlace)
144
153
    {
145
 
      /*
146
 
        Open image file.
147
 
      */
148
154
      status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
149
155
      if (status == MagickFalse)
150
156
        {
152
158
          return((Image *) NULL);
153
159
        }
154
160
      for (i=0; i < image->offset; i++)
155
 
        (void) ReadBlobByte(image);
 
161
        if (ReadBlobByte(image) == EOF)
 
162
          {
 
163
            ThrowFileException(exception,CorruptImageError,
 
164
              "UnexpectedEndOfFile",image->filename);
 
165
            break;
 
166
          }
156
167
    }
157
168
  /*
158
 
    Allocate memory for a pixels.
 
169
    Create virtual canvas to support cropping (i.e. image.rgb[100x100+10+20]).
159
170
  */
160
 
  packet_size=(size_t) ((3*image->depth+7)/8);
 
171
  canvas_image=CloneImage(image,image->extract_info.width,1,MagickTrue,
 
172
    exception);
 
173
  (void) SetImageVirtualPixelMethod(canvas_image,BlackVirtualPixelMethod);
 
174
  quantum_info=AcquireQuantumInfo(image_info,canvas_image);
 
175
  pixels=GetQuantumPixels(quantum_info);
 
176
  quantum_type=RGBQuantum;
161
177
  if (LocaleCompare(image_info->magick,"YCbCrA") == 0)
162
178
    {
163
 
      packet_size+=(image->depth+7)/8;
 
179
      quantum_type=RGBAQuantum;
164
180
      image->matte=MagickTrue;
165
181
    }
166
 
  pixels=(unsigned char *) AcquireQuantumMemory(image->extract_info.width,
167
 
    packet_size*sizeof(*pixels));
168
 
  if (pixels == (unsigned char *) NULL)
169
 
    ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
170
182
  if (image_info->number_scenes != 0)
171
183
    while (image->scene < image_info->scene)
172
184
    {
174
186
        Skip to next image.
175
187
      */
176
188
      image->scene++;
 
189
      length=GetQuantumExtent(canvas_image,quantum_info,quantum_type);
177
190
      for (y=0; y < (long) image->rows; y++)
178
 
        count=ReadBlob(image,packet_size*image->extract_info.width,pixels);
 
191
      {
 
192
        count=ReadBlob(image,length,pixels);
 
193
        if (count != (ssize_t) length)
 
194
          break;
 
195
      }
179
196
    }
180
 
  offset=(MagickOffsetType) (packet_size*image->extract_info.x);
 
197
  count=0;
 
198
  length=0;
 
199
  scene=0;
181
200
  do
182
201
  {
183
202
    /*
184
 
      Convert raster image to pixel packets.
 
203
      Read pixels to virtual canvas image then push to image.
185
204
    */
186
 
    GetQuantumInfo(image_info,&quantum_info);
 
205
    if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0))
 
206
      if (image->scene >= (image_info->scene+image_info->number_scenes-1))
 
207
        break;
187
208
    image->colorspace=YCbCrColorspace;
188
 
    if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0))
189
 
      if (image->scene >= (image_info->scene+image_info->number_scenes-1))
190
 
        break;
191
 
    if (SetImageExtent(image,0,0) == MagickFalse)
192
 
      {
193
 
        InheritException(exception,&image->exception);
194
 
        return(DestroyImageList(image));
195
 
      }
 
209
    if ((SetImageExtent(image,0,0) == MagickFalse) ||
 
210
        (SetImageExtent(canvas_image,0,0) == MagickFalse))
 
211
      break;
196
212
    switch (image_info->interlace)
197
213
    {
198
214
      case NoInterlace:
201
217
        /*
202
218
          No interlacing:  YCbCrYCbCrYCbCrYCbCrYCbCrYCbCr...
203
219
        */
204
 
        for (y=0; y < image->extract_info.y; y++)
205
 
          count=ReadBlob(image,packet_size*image->extract_info.width,pixels);
206
 
        for (y=0; y < (long) image->rows; y++)
 
220
        if (scene == 0)
 
221
          {
 
222
            length=GetQuantumExtent(canvas_image,quantum_info,quantum_type);
 
223
            count=ReadBlob(image,length,pixels);
 
224
            if (count != (ssize_t) length)
 
225
              break;
 
226
          }
 
227
        for (y=0; y < (long) image->extract_info.height; y++)
207
228
        {
208
 
          if ((y > 0) || (GetPreviousImageInList(image) == (Image *) NULL))
209
 
            count=ReadBlob(image,packet_size*image->extract_info.width,
210
 
              pixels);
211
 
          q=SetImagePixels(image,0,y,image->columns,1);
 
229
          q=GetImagePixels(canvas_image,0,0,canvas_image->columns,1);
212
230
          if (q == (PixelPacket *) NULL)
213
231
            break;
214
 
          if (image->matte == MagickFalse)
215
 
            (void) ExportQuantumPixels(image,&quantum_info,RGBQuantum,
216
 
              pixels+offset);
217
 
          else
218
 
            (void) ExportQuantumPixels(image,&quantum_info,RGBAQuantum,
219
 
              pixels+offset);
220
 
          if (SyncImagePixels(image) == MagickFalse)
 
232
          length=ImportQuantumPixels(canvas_image,quantum_info,quantum_type,
 
233
            pixels);
 
234
          if (SyncImagePixels(canvas_image) == MagickFalse)
221
235
            break;
222
 
          if (image->previous == (Image *) NULL)
223
 
            if ((image->progress_monitor != (MagickProgressMonitor) NULL) &&
224
 
                (QuantumTick(y,image->rows) != MagickFalse))
 
236
          if (((y-image->extract_info.y) >= 0) && 
 
237
              ((y-image->extract_info.y) < (long) image->rows))
 
238
            {
 
239
              p=AcquireImagePixels(canvas_image,canvas_image->extract_info.x,0,
 
240
                canvas_image->columns,1,exception);
 
241
              q=SetImagePixels(image,0,y-image->extract_info.y,image->columns,
 
242
                1);
 
243
              if ((p == (const PixelPacket *) NULL) ||
 
244
                  (q == (PixelPacket *) NULL))
 
245
                break;
 
246
              for (x=0; x < (long) image->columns; x++)
225
247
              {
226
 
                status=image->progress_monitor(LoadImageTag,y,image->rows,
227
 
                  image->client_data);
228
 
                if (status == MagickFalse)
229
 
                  break;
 
248
                q->red=p->red;
 
249
                q->green=p->green;
 
250
                q->blue=p->blue;
 
251
                if (image->matte != MagickFalse)
 
252
                  q->opacity=p->opacity;
 
253
                p++;
 
254
                q++;
230
255
              }
 
256
              if (SyncImagePixels(image) == MagickFalse)
 
257
                break;
 
258
            }
 
259
          if (image->previous == (Image *) NULL)
 
260
            {
 
261
              status=SetImageProgress(image,LoadImageTag,y,image->rows);
 
262
              if (status == MagickFalse)
 
263
                break;
 
264
            }
 
265
          count=ReadBlob(image,length,pixels);
 
266
          if (count != (ssize_t) length)
 
267
            break;
231
268
        }
232
 
        width=image->extract_info.height-image->rows-image->extract_info.y;
233
 
        for (i=0; i < (long) width; i++)
234
 
          count=ReadBlob(image,packet_size*image->extract_info.width,pixels);
235
269
        break;
236
270
      }
237
271
      case LineInterlace:
238
272
      {
 
273
        static QuantumType
 
274
          quantum_types[4] =
 
275
          {
 
276
            RedQuantum,
 
277
            GreenQuantum,
 
278
            BlueQuantum,
 
279
            OpacityQuantum
 
280
          };
 
281
 
239
282
        /*
240
283
          Line interlacing:  YYY...CbCbCb...CrCrCr...YYY...CbCbCb...CrCrCr...
241
284
        */
242
 
        packet_size=(size_t) ((image->depth+7)/8);
243
 
        for (y=0; y < image->extract_info.y; y++)
244
 
          count=ReadBlob(image,packet_size*image->extract_info.width,pixels);
245
 
        for (y=0; y < (long) image->rows; y++)
 
285
        if (scene == 0)
 
286
          {
 
287
            length=GetQuantumExtent(canvas_image,quantum_info,RedQuantum);
 
288
            count=ReadBlob(image,length,pixels);
 
289
            if (count != (ssize_t) length)
 
290
              break;
 
291
          }
 
292
        for (y=0; y < (long) image->extract_info.height; y++)
246
293
        {
247
 
          if ((y > 0) || (GetPreviousImageInList(image) == (Image *) NULL))
248
 
            count=ReadBlob(image,packet_size*image->extract_info.width,
 
294
          for (i=0; i < (image->matte != MagickFalse ? 4 : 3); i++)
 
295
          {
 
296
            quantum_type=quantum_types[i];
 
297
            q=GetImagePixels(canvas_image,0,0,canvas_image->columns,1);
 
298
            if (q == (PixelPacket *) NULL)
 
299
              break;
 
300
            length=ImportQuantumPixels(canvas_image,quantum_info,quantum_type,
249
301
              pixels);
250
 
          q=SetImagePixels(image,0,y,image->columns,1);
251
 
          if (q == (PixelPacket *) NULL)
252
 
            break;
253
 
          (void) ExportQuantumPixels(image,&quantum_info,RedQuantum,
254
 
            pixels+offset);
255
 
          count=ReadBlob(image,packet_size*image->extract_info.width,pixels);
256
 
          (void) ExportQuantumPixels(image,&quantum_info,GreenQuantum,
257
 
            pixels+offset);
258
 
          count=ReadBlob(image,packet_size*image->extract_info.width,pixels);
259
 
          (void) ExportQuantumPixels(image,&quantum_info,BlueQuantum,
260
 
            pixels+offset);
261
 
          if (image->matte != MagickFalse)
 
302
            if (SyncImagePixels(canvas_image) == MagickFalse)
 
303
              break;
 
304
            if (((y-image->extract_info.y) >= 0) && 
 
305
                ((y-image->extract_info.y) < (long) image->rows))
 
306
              {
 
307
                p=AcquireImagePixels(canvas_image,canvas_image->extract_info.x,
 
308
                  0,canvas_image->columns,1,exception);
 
309
                q=GetImagePixels(image,0,y-image->extract_info.y,image->columns,
 
310
                  1);
 
311
                if ((p == (const PixelPacket *) NULL) ||
 
312
                    (q == (PixelPacket *) NULL))
 
313
                  break;
 
314
                for (x=0; x < (long) image->columns; x++)
 
315
                {
 
316
                  switch (quantum_type)
 
317
                  {
 
318
                    case RedQuantum: q->red=p->red; break;
 
319
                    case GreenQuantum: q->green=p->green; break;
 
320
                    case BlueQuantum: q->blue=p->blue; break;
 
321
                    case OpacityQuantum: q->opacity=p->opacity; break;
 
322
                    default: break;
 
323
                  }
 
324
                  p++;
 
325
                  q++;
 
326
                }
 
327
                if (SyncImagePixels(image) == MagickFalse)
 
328
                  break;
 
329
              }
 
330
            count=ReadBlob(image,length,pixels);
 
331
            if (count != (ssize_t) length)
 
332
              break;
 
333
          }
 
334
          if (image->previous == (Image *) NULL)
262
335
            {
263
 
              count=ReadBlob(image,packet_size*image->extract_info.width,
264
 
                pixels);
265
 
              (void) ExportQuantumPixels(image,&quantum_info,AlphaQuantum,
266
 
                pixels+offset);
 
336
              status=SetImageProgress(image,LoadImageTag,y,image->rows);
 
337
              if (status == MagickFalse)
 
338
                break;
267
339
            }
268
 
          if (SyncImagePixels(image) == MagickFalse)
269
 
            break;
270
 
          if (image->previous == (Image *) NULL)
271
 
            if ((image->progress_monitor != (MagickProgressMonitor) NULL) &&
272
 
                (QuantumTick(y,image->rows) != MagickFalse))
273
 
              {
274
 
                status=image->progress_monitor(LoadImageTag,y,image->rows,
275
 
                  image->client_data);
276
 
                if (status == MagickFalse)
277
 
                  break;
278
 
              }
279
340
        }
280
 
        width=image->extract_info.height-image->rows-image->extract_info.y;
281
 
        for (i=0; i < (long) width; i++)
282
 
          count=ReadBlob(image,packet_size*image->extract_info.width,pixels);
283
341
        break;
284
342
      }
285
343
      case PlaneInterlace:
 
344
      {
 
345
        /*
 
346
          Plane interlacing:  YYYYYY...CbCbCbCbCbCb...CrCrCrCrCrCr...
 
347
        */
 
348
        if (scene == 0)
 
349
          {
 
350
            length=GetQuantumExtent(canvas_image,quantum_info,RedQuantum);
 
351
            count=ReadBlob(image,length,pixels);
 
352
            if (count != (ssize_t) length)
 
353
              break;
 
354
          }
 
355
        for (y=0; y < (long) image->extract_info.height; y++)
 
356
        {
 
357
          q=GetImagePixels(canvas_image,0,0,canvas_image->columns,1);
 
358
          if (q == (PixelPacket *) NULL)
 
359
            break;
 
360
          length=ImportQuantumPixels(canvas_image,quantum_info,RedQuantum,
 
361
            pixels);
 
362
          if (SyncImagePixels(canvas_image) == MagickFalse)
 
363
            break;
 
364
          if (((y-image->extract_info.y) >= 0) && 
 
365
              ((y-image->extract_info.y) < (long) image->rows))
 
366
            {
 
367
              p=AcquireImagePixels(canvas_image,canvas_image->extract_info.x,0,
 
368
                canvas_image->columns,1,exception);
 
369
              q=GetImagePixels(image,0,y-image->extract_info.y,image->columns,
 
370
                1);
 
371
              if ((p == (const PixelPacket *) NULL) ||
 
372
                  (q == (PixelPacket *) NULL))
 
373
                break;
 
374
              for (x=0; x < (long) image->columns; x++)
 
375
              {
 
376
                q->red=p->red;
 
377
                p++;
 
378
                q++;
 
379
              }
 
380
              if (SyncImagePixels(image) == MagickFalse)
 
381
                break;
 
382
            }
 
383
          count=ReadBlob(image,length,pixels);
 
384
          if (count != (ssize_t) length)
 
385
            break;
 
386
        }
 
387
        if (image->previous == (Image *) NULL)
 
388
          {
 
389
            status=SetImageProgress(image,LoadImageTag,1,5);
 
390
            if (status == MagickFalse)
 
391
              break;
 
392
          }
 
393
        for (y=0; y < (long) image->extract_info.height; y++)
 
394
        {
 
395
          q=GetImagePixels(canvas_image,0,0,canvas_image->columns,1);
 
396
          if (q == (PixelPacket *) NULL)
 
397
            break;
 
398
          length=ImportQuantumPixels(canvas_image,quantum_info,GreenQuantum,
 
399
            pixels);
 
400
          if (SyncImagePixels(canvas_image) == MagickFalse)
 
401
            break;
 
402
          if (((y-image->extract_info.y) >= 0) && 
 
403
              ((y-image->extract_info.y) < (long) image->rows))
 
404
            {
 
405
              p=AcquireImagePixels(canvas_image,canvas_image->extract_info.x,0,
 
406
                canvas_image->columns,1,exception);
 
407
              q=GetImagePixels(image,0,y-image->extract_info.y,image->columns,
 
408
                1);
 
409
              if ((p == (const PixelPacket *) NULL) ||
 
410
                  (q == (PixelPacket *) NULL))
 
411
                break;
 
412
              for (x=0; x < (long) image->columns; x++)
 
413
              {
 
414
                q->green=p->green;
 
415
                p++;
 
416
                q++;
 
417
              }
 
418
              if (SyncImagePixels(image) == MagickFalse)
 
419
                break;
 
420
           }
 
421
          count=ReadBlob(image,length,pixels);
 
422
          if (count != (ssize_t) length)
 
423
            break;
 
424
        }
 
425
        if (image->previous == (Image *) NULL)
 
426
          {
 
427
            status=SetImageProgress(image,LoadImageTag,2,5);
 
428
            if (status == MagickFalse)
 
429
              break;
 
430
          }
 
431
        for (y=0; y < (long) image->extract_info.height; y++)
 
432
        {
 
433
          q=GetImagePixels(canvas_image,0,0,canvas_image->columns,1);
 
434
          if (q == (PixelPacket *) NULL)
 
435
            break;
 
436
          length=ImportQuantumPixels(canvas_image,quantum_info,BlueQuantum,
 
437
            pixels);
 
438
          if (SyncImagePixels(canvas_image) == MagickFalse)
 
439
            break;
 
440
          if (((y-image->extract_info.y) >= 0) && 
 
441
              ((y-image->extract_info.y) < (long) image->rows))
 
442
            {
 
443
              p=AcquireImagePixels(canvas_image,canvas_image->extract_info.x,0,
 
444
                canvas_image->columns,1,exception);
 
445
              q=GetImagePixels(image,0,y-image->extract_info.y,image->columns,
 
446
                1);
 
447
              if ((p == (const PixelPacket *) NULL) ||
 
448
                  (q == (PixelPacket *) NULL))
 
449
                break;
 
450
              for (x=0; x < (long) image->columns; x++)
 
451
              {
 
452
                q->blue=p->blue;
 
453
                p++;
 
454
                q++;
 
455
              }
 
456
              if (SyncImagePixels(image) == MagickFalse)
 
457
                break;
 
458
            }
 
459
          count=ReadBlob(image,length,pixels);
 
460
          if (count != (ssize_t) length)
 
461
            break;
 
462
        }
 
463
        if (image->previous == (Image *) NULL)
 
464
          {
 
465
            status=SetImageProgress(image,LoadImageTag,3,5);
 
466
            if (status == MagickFalse)
 
467
              break;
 
468
          }
 
469
        if (image->matte != MagickFalse)
 
470
          {
 
471
            for (y=0; y < (long) image->extract_info.height; y++)
 
472
            {
 
473
              q=GetImagePixels(canvas_image,0,0,canvas_image->columns,1);
 
474
              if (q == (PixelPacket *) NULL)
 
475
                break;
 
476
              length=ImportQuantumPixels(canvas_image,quantum_info,AlphaQuantum,
 
477
                pixels);
 
478
              if (SyncImagePixels(canvas_image) == MagickFalse)
 
479
                break;
 
480
              if (((y-image->extract_info.y) >= 0) && 
 
481
                  ((y-image->extract_info.y) < (long) image->rows))
 
482
                {
 
483
                  p=AcquireImagePixels(canvas_image,
 
484
                    canvas_image->extract_info.x,0,canvas_image->columns,1,
 
485
                    exception);
 
486
                  q=GetImagePixels(image,0,y-image->extract_info.y,
 
487
                    image->columns,1);
 
488
                  if ((p == (const PixelPacket *) NULL) ||
 
489
                      (q == (PixelPacket *) NULL))
 
490
                    break;
 
491
                  for (x=0; x < (long) image->columns; x++)
 
492
                  {
 
493
                    q->opacity=p->opacity;
 
494
                    p++;
 
495
                    q++;
 
496
                  }
 
497
                  if (SyncImagePixels(image) == MagickFalse)
 
498
                    break;
 
499
                }
 
500
              count=ReadBlob(image,length,pixels);
 
501
              if (count != (ssize_t) length)
 
502
                break;
 
503
            }
 
504
            if (image->previous == (Image *) NULL)
 
505
              {
 
506
                status=SetImageProgress(image,LoadImageTag,4,5);
 
507
                if (status == MagickFalse)
 
508
                  break;
 
509
              }
 
510
          }
 
511
        if (image->previous == (Image *) NULL)
 
512
          {
 
513
            status=SetImageProgress(image,LoadImageTag,5,5);
 
514
            if (status == MagickFalse)
 
515
              break;
 
516
          }
 
517
        break;
 
518
      }
286
519
      case PartitionInterlace:
287
520
      {
288
 
        unsigned long
289
 
          span;
290
 
 
291
521
        /*
292
 
          Plane interlacing:  YYYYYY...CbCbCbCbCbCb...CrCrCrCrCrCr...
 
522
          Partition interlacing:  YYYYYY..., CbCbCbCbCbCb..., CrCrCrCrCrCr...
293
523
        */
294
 
        if (image_info->interlace == PartitionInterlace)
295
 
          {
296
 
            AppendImageFormat("Y",image->filename);
297
 
            status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
298
 
            if (status == MagickFalse)
299
 
              {
300
 
                image=DestroyImageList(image);
301
 
                return((Image *) NULL);
302
 
              }
303
 
          }
304
 
        packet_size=(size_t) ((image->depth+7)/8);
305
 
        for (y=0; y < image->extract_info.y; y++)
306
 
          count=ReadBlob(image,packet_size*image->extract_info.width,pixels);
307
 
        i=0;
308
 
        span=image->rows*(image->matte != MagickFalse ? 5 : 4);
309
 
        for (y=0; y < (long) image->rows; y++)
310
 
        {
311
 
          if ((y > 0) || (GetPreviousImageInList(image) == (Image *) NULL))
312
 
            count=ReadBlob(image,packet_size*image->extract_info.width,
313
 
              pixels);
314
 
          q=SetImagePixels(image,0,y,image->columns,1);
315
 
          if (q == (PixelPacket *) NULL)
316
 
            break;
317
 
          (void) ExportQuantumPixels(image,&quantum_info,RedQuantum,
318
 
            pixels+offset);
319
 
          if (SyncImagePixels(image) == MagickFalse)
320
 
            break;
321
 
          if (image->previous == (Image *) NULL)
322
 
            if ((image->progress_monitor != (MagickProgressMonitor) NULL) &&
323
 
                (QuantumTick(i,span) != MagickFalse))
324
 
              {
325
 
                status=image->progress_monitor(LoadImageTag,i,span,
326
 
                  image->client_data);
327
 
                if (status == MagickFalse)
328
 
                  break;
329
 
              }
330
 
          i++;
331
 
        }
332
 
        width=image->extract_info.height-image->rows-image->extract_info.y;
333
 
        for (i=0; i < (long) width; i++)
334
 
          count=ReadBlob(image,packet_size*image->extract_info.width,pixels);
335
 
        if (image_info->interlace == PartitionInterlace)
336
 
          {
337
 
            CloseBlob(image);
338
 
            AppendImageFormat("Cb",image->filename);
339
 
            status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
340
 
            if (status == MagickFalse)
341
 
              {
342
 
                image=DestroyImageList(image);
343
 
                return((Image *) NULL);
344
 
              }
345
 
          }
346
 
        for (y=0; y < image->extract_info.y; y++)
347
 
          count=ReadBlob(image,packet_size*image->extract_info.width,pixels);
348
 
        for (y=0; y < (long) image->rows; y++)
349
 
        {
350
 
          count=ReadBlob(image,packet_size*image->extract_info.width,pixels);
351
 
          q=GetImagePixels(image,0,y,image->columns,1);
352
 
          if (q == (PixelPacket *) NULL)
353
 
            break;
354
 
          (void) ExportQuantumPixels(image,&quantum_info,GreenQuantum,
355
 
            pixels+offset);
356
 
          if (SyncImagePixels(image) == MagickFalse)
357
 
            break;
358
 
          if (image->previous == (Image *) NULL)
359
 
            if ((image->progress_monitor != (MagickProgressMonitor) NULL) &&
360
 
                (QuantumTick(i,span) != MagickFalse))
361
 
              {
362
 
                status=image->progress_monitor(LoadImageTag,i,span,
363
 
                  image->client_data);
364
 
                if (status == MagickFalse)
365
 
                  break;
366
 
              }
367
 
          i++;
368
 
        }
369
 
        width=image->extract_info.height-image->rows-image->extract_info.y;
370
 
        for (i=0; i < (long) width; i++)
371
 
          count=ReadBlob(image,packet_size*image->extract_info.width,pixels);
372
 
        if (image_info->interlace == PartitionInterlace)
373
 
          {
374
 
            CloseBlob(image);
375
 
            AppendImageFormat("Cr",image->filename);
376
 
            status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
377
 
            if (status == MagickFalse)
378
 
              {
379
 
                image=DestroyImageList(image);
380
 
                return((Image *) NULL);
381
 
              }
382
 
          }
383
 
        for (y=0; y < image->extract_info.y; y++)
384
 
          count=ReadBlob(image,packet_size*image->extract_info.width,pixels);
385
 
        for (y=0; y < (long) image->rows; y++)
386
 
        {
387
 
          count=ReadBlob(image,packet_size*image->extract_info.width,pixels);
388
 
          q=GetImagePixels(image,0,y,image->columns,1);
389
 
          if (q == (PixelPacket *) NULL)
390
 
            break;
391
 
          (void) ExportQuantumPixels(image,&quantum_info,BlueQuantum,
392
 
            pixels+offset);
393
 
          if (SyncImagePixels(image) == MagickFalse)
394
 
            break;
395
 
          if (image->previous == (Image *) NULL)
396
 
            if ((image->progress_monitor != (MagickProgressMonitor) NULL) &&
397
 
                (QuantumTick(i,span) != MagickFalse))
398
 
              {
399
 
                status=image->progress_monitor(LoadImageTag,i,span,
400
 
                  image->client_data);
401
 
                if (status == MagickFalse)
402
 
                  break;
403
 
              }
404
 
          i++;
405
 
        }
406
 
        width=image->extract_info.height-image->rows-image->extract_info.y;
407
 
        for (i=0; i < (long) width; i++)
408
 
          count=ReadBlob(image,packet_size*image->extract_info.width,pixels);
 
524
        AppendImageFormat("Y",image->filename);
 
525
        status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
 
526
        if (status == MagickFalse)
 
527
          {
 
528
            canvas_image=DestroyImageList(canvas_image);
 
529
            image=DestroyImageList(image);
 
530
            return((Image *) NULL);
 
531
          }
 
532
        for (i=0; i < image->offset; i++)
 
533
          if (ReadBlobByte(image) == EOF)
 
534
            {
 
535
              ThrowFileException(exception,CorruptImageError,
 
536
                "UnexpectedEndOfFile",image->filename);
 
537
              break;
 
538
            }
 
539
        length=GetQuantumExtent(canvas_image,quantum_info,RedQuantum);
 
540
        for (i=0; i < (long) scene; i++)
 
541
          for (y=0; y < (long) image->extract_info.height; y++)
 
542
            if (ReadBlob(image,length,pixels) != (ssize_t) length)
 
543
              {
 
544
                ThrowFileException(exception,CorruptImageError,
 
545
                  "UnexpectedEndOfFile",image->filename);
 
546
                break;
 
547
              }
 
548
        count=ReadBlob(image,length,pixels);
 
549
        if (count != (ssize_t) length)
 
550
          break;
 
551
        for (y=0; y < (long) image->extract_info.height; y++)
 
552
        {
 
553
          q=GetImagePixels(canvas_image,0,0,canvas_image->columns,1);
 
554
          if (q == (PixelPacket *) NULL)
 
555
            break;
 
556
          length=ImportQuantumPixels(canvas_image,quantum_info,RedQuantum,
 
557
            pixels);
 
558
          if (SyncImagePixels(canvas_image) == MagickFalse)
 
559
            break;
 
560
          if (((y-image->extract_info.y) >= 0) && 
 
561
              ((y-image->extract_info.y) < (long) image->rows))
 
562
            {
 
563
              p=AcquireImagePixels(canvas_image,canvas_image->extract_info.x,0,
 
564
                canvas_image->columns,1,exception);
 
565
              q=GetImagePixels(image,0,y-image->extract_info.y,image->columns,
 
566
                1);
 
567
              if ((p == (const PixelPacket *) NULL) ||
 
568
                  (q == (PixelPacket *) NULL))
 
569
                break;
 
570
              for (x=0; x < (long) image->columns; x++)
 
571
              {
 
572
                q->red=p->red;
 
573
                p++;
 
574
                q++;
 
575
              }
 
576
              if (SyncImagePixels(image) == MagickFalse)
 
577
                break;
 
578
            }
 
579
          count=ReadBlob(image,length,pixels);
 
580
          if (count != (ssize_t) length)
 
581
            break;
 
582
        }
 
583
        if (image->previous == (Image *) NULL)
 
584
          {
 
585
            status=SetImageProgress(image,LoadImageTag,1,5);
 
586
            if (status == MagickFalse)
 
587
              break;
 
588
          }
 
589
        (void) CloseBlob(image);
 
590
        AppendImageFormat("Cb",image->filename);
 
591
        status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
 
592
        if (status == MagickFalse)
 
593
          {
 
594
            canvas_image=DestroyImageList(canvas_image);
 
595
            image=DestroyImageList(image);
 
596
            return((Image *) NULL);
 
597
          }
 
598
        length=GetQuantumExtent(canvas_image,quantum_info,GreenQuantum);
 
599
        for (i=0; i < (long) scene; i++)
 
600
          for (y=0; y < (long) image->extract_info.height; y++)
 
601
            if (ReadBlob(image,length,pixels) != (ssize_t) length)
 
602
              {
 
603
                ThrowFileException(exception,CorruptImageError,
 
604
                  "UnexpectedEndOfFile",image->filename);
 
605
                break;
 
606
              }
 
607
        count=ReadBlob(image,length,pixels);
 
608
        if (count != (ssize_t) length)
 
609
          break;
 
610
        for (y=0; y < (long) image->extract_info.height; y++)
 
611
        {
 
612
          q=GetImagePixels(canvas_image,0,0,canvas_image->columns,1);
 
613
          if (q == (PixelPacket *) NULL)
 
614
            break;
 
615
          length=ImportQuantumPixels(canvas_image,quantum_info,GreenQuantum,
 
616
            pixels);
 
617
          if (SyncImagePixels(canvas_image) == MagickFalse)
 
618
            break;
 
619
          if (((y-image->extract_info.y) >= 0) && 
 
620
              ((y-image->extract_info.y) < (long) image->rows))
 
621
            {
 
622
              p=AcquireImagePixels(canvas_image,canvas_image->extract_info.x,0,
 
623
                canvas_image->columns,1,exception);
 
624
              q=GetImagePixels(image,0,y-image->extract_info.y,image->columns,
 
625
                1);
 
626
              if ((p == (const PixelPacket *) NULL) ||
 
627
                  (q == (PixelPacket *) NULL))
 
628
                break;
 
629
              for (x=0; x < (long) image->columns; x++)
 
630
              {
 
631
                q->green=p->green;
 
632
                p++;
 
633
                q++;
 
634
              }
 
635
              if (SyncImagePixels(image) == MagickFalse)
 
636
                break;
 
637
           }
 
638
          count=ReadBlob(image,length,pixels);
 
639
          if (count != (ssize_t) length)
 
640
            break;
 
641
        }
 
642
        if (image->previous == (Image *) NULL)
 
643
          {
 
644
            status=SetImageProgress(image,LoadImageTag,2,5);
 
645
            if (status == MagickFalse)
 
646
              break;
 
647
          }
 
648
        (void) CloseBlob(image);
 
649
        AppendImageFormat("Cr",image->filename);
 
650
        status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
 
651
        if (status == MagickFalse)
 
652
          {
 
653
            canvas_image=DestroyImageList(canvas_image);
 
654
            image=DestroyImageList(image);
 
655
            return((Image *) NULL);
 
656
          }
 
657
        length=GetQuantumExtent(canvas_image,quantum_info,BlueQuantum);
 
658
        for (i=0; i < (long) scene; i++)
 
659
          for (y=0; y < (long) image->extract_info.height; y++)
 
660
            if (ReadBlob(image,length,pixels) != (ssize_t) length)
 
661
              {
 
662
                ThrowFileException(exception,CorruptImageError,
 
663
                  "UnexpectedEndOfFile",image->filename);
 
664
                break;
 
665
              }
 
666
        count=ReadBlob(image,length,pixels);
 
667
        if (count != (ssize_t) length)
 
668
          break;
 
669
        for (y=0; y < (long) image->extract_info.height; y++)
 
670
        {
 
671
          q=GetImagePixels(canvas_image,0,0,canvas_image->columns,1);
 
672
          if (q == (PixelPacket *) NULL)
 
673
            break;
 
674
          length=ImportQuantumPixels(canvas_image,quantum_info,BlueQuantum,
 
675
            pixels);
 
676
          if (SyncImagePixels(canvas_image) == MagickFalse)
 
677
            break;
 
678
          if (((y-image->extract_info.y) >= 0) && 
 
679
              ((y-image->extract_info.y) < (long) image->rows))
 
680
            {
 
681
              p=AcquireImagePixels(canvas_image,canvas_image->extract_info.x,0,
 
682
                canvas_image->columns,1,exception);
 
683
              q=GetImagePixels(image,0,y-image->extract_info.y,image->columns,
 
684
                1);
 
685
              if ((p == (const PixelPacket *) NULL) ||
 
686
                  (q == (PixelPacket *) NULL))
 
687
                break;
 
688
              for (x=0; x < (long) image->columns; x++)
 
689
              {
 
690
                q->blue=p->blue;
 
691
                p++;
 
692
                q++;
 
693
              }
 
694
              if (SyncImagePixels(image) == MagickFalse)
 
695
                break;
 
696
           }
 
697
          count=ReadBlob(image,length,pixels);
 
698
          if (count != (ssize_t) length)
 
699
            break;
 
700
        }
 
701
        if (image->previous == (Image *) NULL)
 
702
          {
 
703
            status=SetImageProgress(image,LoadImageTag,3,5);
 
704
            if (status == MagickFalse)
 
705
              break;
 
706
          }
409
707
        if (image->matte != MagickFalse)
410
708
          {
411
 
            /*
412
 
              Read matte channel.
413
 
            */
414
 
            if (image_info->interlace == PartitionInterlace)
 
709
            (void) CloseBlob(image);
 
710
            AppendImageFormat("A",image->filename);
 
711
            status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
 
712
            if (status == MagickFalse)
415
713
              {
416
 
                CloseBlob(image);
417
 
                AppendImageFormat("A",image->filename);
418
 
                status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
419
 
                if (status == MagickFalse)
 
714
                canvas_image=DestroyImageList(canvas_image);
 
715
                image=DestroyImageList(image);
 
716
                return((Image *) NULL);
 
717
              }
 
718
            length=GetQuantumExtent(canvas_image,quantum_info,AlphaQuantum);
 
719
            for (i=0; i < (long) scene; i++)
 
720
              for (y=0; y < (long) image->extract_info.height; y++)
 
721
                if (ReadBlob(image,length,pixels) != (ssize_t) length)
420
722
                  {
421
 
                    image=DestroyImageList(image);
422
 
                    return((Image *) NULL);
 
723
                    ThrowFileException(exception,CorruptImageError,
 
724
                      "UnexpectedEndOfFile",image->filename);
 
725
                    break;
423
726
                  }
424
 
              }
425
 
            for (y=0; y < image->extract_info.y; y++)
426
 
              count=ReadBlob(image,packet_size*image->extract_info.width,
427
 
                pixels);
428
 
            for (y=0; y < (long) image->rows; y++)
 
727
            count=ReadBlob(image,length,pixels);
 
728
            if (count != (ssize_t) length)
 
729
              break;
 
730
            for (y=0; y < (long) image->extract_info.height; y++)
429
731
            {
430
 
              count=ReadBlob(image,packet_size*image->extract_info.width,
431
 
                pixels);
432
 
              q=GetImagePixels(image,0,y,image->columns,1);
 
732
              q=GetImagePixels(canvas_image,0,0,canvas_image->columns,1);
433
733
              if (q == (PixelPacket *) NULL)
434
734
                break;
435
 
              (void) ExportQuantumPixels(image,&quantum_info,AlphaQuantum,
436
 
                pixels+offset);
437
 
              if (SyncImagePixels(image) == MagickFalse)
 
735
              length=ImportQuantumPixels(canvas_image,quantum_info,BlueQuantum,
 
736
                pixels);
 
737
              if (SyncImagePixels(canvas_image) == MagickFalse)
438
738
                break;
439
 
              if (image->previous == (Image *) NULL)
440
 
                if ((image->progress_monitor != (MagickProgressMonitor) NULL) &&
441
 
                    (QuantumTick(i,span) != MagickFalse))
 
739
              if (((y-image->extract_info.y) >= 0) && 
 
740
                  ((y-image->extract_info.y) < (long) image->rows))
 
741
                {
 
742
                  p=AcquireImagePixels(canvas_image,
 
743
                    canvas_image->extract_info.x,0,canvas_image->columns,1,
 
744
                    exception);
 
745
                  q=GetImagePixels(image,0,y-image->extract_info.y,
 
746
                    image->columns,1);
 
747
                  if ((p == (const PixelPacket *) NULL) ||
 
748
                      (q == (PixelPacket *) NULL))
 
749
                    break;
 
750
                  for (x=0; x < (long) image->columns; x++)
442
751
                  {
443
 
                    status=image->progress_monitor(LoadImageTag,i,span,
444
 
                      image->client_data);
445
 
                    if (status == MagickFalse)
446
 
                      break;
 
752
                    q->opacity=p->opacity;
 
753
                    p++;
 
754
                    q++;
447
755
                  }
448
 
              i++;
 
756
                  if (SyncImagePixels(image) == MagickFalse)
 
757
                    break;
 
758
               }
 
759
              count=ReadBlob(image,length,pixels);
 
760
              if (count != (ssize_t) length)
 
761
                break;
449
762
            }
450
 
            width=image->extract_info.height-image->rows-image->extract_info.y;
451
 
            for (i=0; i < (long) width; i++)
452
 
              count=ReadBlob(image,packet_size*image->extract_info.width,
453
 
                pixels);
454
 
          }
455
 
        if (image_info->interlace == PartitionInterlace)
456
 
          (void) CopyMagickString(image->filename,image_info->filename,
457
 
            MaxTextExtent);
 
763
            if (image->previous == (Image *) NULL)
 
764
              {
 
765
                status=SetImageProgress(image,LoadImageTag,4,5);
 
766
                if (status == MagickFalse)
 
767
                  break;
 
768
              }
 
769
          }
 
770
        if (image->previous == (Image *) NULL)
 
771
          {
 
772
            status=SetImageProgress(image,LoadImageTag,5,5);
 
773
            if (status == MagickFalse)
 
774
              break;
 
775
          }
458
776
        break;
459
777
      }
460
778
    }
461
 
    if (EOFBlob(image) != MagickFalse)
462
 
      {
463
 
        ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
464
 
          image->filename);
465
 
        break;
466
 
      }
 
779
    SetQuantumImageType(image,quantum_type);
467
780
    /*
468
781
      Proceed to next image.
469
782
    */
470
783
    if (image_info->number_scenes != 0)
471
784
      if (image->scene >= (image_info->scene+image_info->number_scenes-1))
472
785
        break;
473
 
    if (image_info->interlace == PartitionInterlace)
474
 
      break;
475
 
    count=ReadBlob(image,packet_size*image->extract_info.width,pixels);
476
 
    if (count != 0)
 
786
    if (count == (ssize_t) length)
477
787
      {
478
788
        /*
479
789
          Allocate next image structure.
480
790
        */
481
 
        AllocateNextImage(image_info,image);
 
791
        AcquireNextImage(image_info,image);
482
792
        if (GetNextImageInList(image) == (Image *) NULL)
483
793
          {
484
794
            image=DestroyImageList(image);
485
795
            return((Image *) NULL);
486
796
          }
487
797
        image=SyncNextImageInList(image);
488
 
        if (image->progress_monitor != (MagickProgressMonitor) NULL)
489
 
          {
490
 
            status=image->progress_monitor(LoadImagesTag,TellBlob(image),
491
 
              GetBlobSize(image),image->client_data);
492
 
            if (status == MagickFalse)
493
 
              break;
494
 
          }
 
798
        status=SetImageProgress(image,LoadImagesTag,TellBlob(image),
 
799
          GetBlobSize(image));
 
800
        if (status == MagickFalse)
 
801
          break;
495
802
      }
496
 
  } while (count != 0);
497
 
  pixels=(unsigned char *) RelinquishMagickMemory(pixels);
498
 
  CloseBlob(image);
 
803
    scene++;
 
804
  } while (count == (ssize_t) length);
 
805
  InheritException(exception,&image->exception);
 
806
  quantum_info=DestroyQuantumInfo(quantum_info);
 
807
  canvas_image=DestroyImage(canvas_image);
 
808
  (void) CloseBlob(image);
499
809
  return(GetFirstImageInList(image));
500
810
}
501
811
 
510
820
%                                                                             %
511
821
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
512
822
%
513
 
%  RegisterYCBCRImage() adds attributes for the YCbCr image format to
 
823
%  RegisterYCBCRImage() adds attributes for the YCbCr or YCbCrA image format to
514
824
%  the list of supported formats.  The attributes include the image format
515
825
%  tag, a method to read and/or write the format, whether the format
516
826
%  supports the saving of more than one frame to the same file or blob,
531
841
  entry->decoder=(DecodeImageHandler *) ReadYCBCRImage;
532
842
  entry->encoder=(EncodeImageHandler *) WriteYCBCRImage;
533
843
  entry->raw=MagickTrue;
 
844
  entry->endian_support=MagickTrue;
534
845
  entry->description=ConstantString("Raw Y, Cb, and Cr samples");
535
846
  entry->module=ConstantString("YCbCr");
536
847
  (void) RegisterMagickInfo(entry);
538
849
  entry->decoder=(DecodeImageHandler *) ReadYCBCRImage;
539
850
  entry->encoder=(EncodeImageHandler *) WriteYCBCRImage;
540
851
  entry->raw=MagickTrue;
541
 
  entry->description=ConstantString("Raw Y, Cb, Cr, and opacity samples");
 
852
  entry->endian_support=MagickTrue;
 
853
  entry->description=ConstantString("Raw Y, Cb, Cr, and alpha samples");
542
854
  entry->module=ConstantString("YCbCr");
543
855
  (void) RegisterMagickInfo(entry);
544
856
  return(MagickImageCoderSignature);
580
892
%                                                                             %
581
893
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
582
894
%
583
 
%  WriteYCBCRImage() writes an image to a file in the raw Y, Cb, and Cr
584
 
%  image format.
 
895
%  WriteYCBCRImage() writes an image to a file in the YCbCr or YCbCrA
 
896
%  rasterfile format.
585
897
%
586
898
%  The format of the WriteYCBCRImage method is:
587
899
%
590
902
%
591
903
%  A description of each parameter follows.
592
904
%
593
 
%    o image_info: The image info.
 
905
%    o image_info: the image info.
594
906
%
595
907
%    o image:  The image.
596
908
%
597
 
%
598
909
*/
599
910
static MagickBooleanType WriteYCBCRImage(const ImageInfo *image_info,
600
911
  Image *image)
609
920
    scene;
610
921
 
611
922
  QuantumInfo
612
 
    quantum_info;
 
923
    *quantum_info;
 
924
 
 
925
  QuantumType
 
926
    quantum_type;
613
927
 
614
928
  register const PixelPacket
615
929
    *p;
616
930
 
 
931
  ssize_t
 
932
    count;
 
933
 
617
934
  size_t
618
 
    packet_size;
 
935
    length;
619
936
 
620
937
  unsigned char
621
938
    *pixels;
629
946
  assert(image->signature == MagickSignature);
630
947
  if (image->debug != MagickFalse)
631
948
    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
632
 
  packet_size=(size_t) ((3*image->depth+7)/8);
633
 
  if (LocaleCompare(image_info->magick,"YCbCrA") == 0)
634
 
    packet_size+=(image->depth+7)/8;
635
 
  pixels=(unsigned char *) AcquireQuantumMemory(image->columns,packet_size*
636
 
    sizeof(*pixels));
637
 
  if (pixels == (unsigned char *) NULL)
638
 
    ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
639
949
  if (image_info->interlace != PartitionInterlace)
640
950
    {
641
951
      /*
645
955
      if (status == MagickFalse)
646
956
        return(status);
647
957
    }
 
958
  quantum_type=RGBQuantum;
 
959
  if (LocaleCompare(image_info->magick,"YCbCrA") == 0)
 
960
    {
 
961
      quantum_type=RGBAQuantum;
 
962
      image->matte=MagickTrue;
 
963
    }
648
964
  scene=0;
649
965
  do
650
966
  {
651
967
    /*
652
 
      Convert to YCbCr pixels.
 
968
      Convert MIFF to YCbCr raster pixels.
653
969
    */
654
 
    GetQuantumInfo(image_info,&quantum_info);
655
 
    if (image_info->colorspace == UndefinedColorspace)
 
970
    if (image->colorspace != YCbCrColorspace)
656
971
      (void) SetImageColorspace(image,YCbCrColorspace);
657
 
    if (LocaleCompare(image_info->magick,"YCbCrA") == 0)
658
 
      if (image->matte == MagickFalse)
659
 
        (void) SetImageOpacity(image,OpaqueOpacity);
 
972
    if ((LocaleCompare(image_info->magick,"YCbCrA") == 0) &&
 
973
        (image->matte == MagickFalse))
 
974
      (void) SetImageAlphaChannel(image,ResetAlphaChannel);
 
975
    quantum_info=AcquireQuantumInfo(image_info,image);
 
976
    pixels=GetQuantumPixels(quantum_info);
660
977
    switch (image_info->interlace)
661
978
    {
662
979
      case NoInterlace:
670
987
          p=AcquireImagePixels(image,0,y,image->columns,1,&image->exception);
671
988
          if (p == (const PixelPacket *) NULL)
672
989
            break;
673
 
          if (LocaleCompare(image_info->magick,"YCbCrA") != 0)
674
 
            {
675
 
              (void) ImportQuantumPixels(image,&quantum_info,RGBQuantum,pixels);
676
 
              (void) WriteBlob(image,packet_size*image->columns,pixels);
677
 
            }
678
 
          else
679
 
            {
680
 
              (void) ImportQuantumPixels(image,&quantum_info,RGBAQuantum,
681
 
                pixels);
682
 
              (void) WriteBlob(image,packet_size*image->columns,pixels);
683
 
            }
 
990
          length=ExportQuantumPixels(image,quantum_info,quantum_type,pixels);
 
991
          count=WriteBlob(image,length,pixels);
 
992
          if (count != (ssize_t) length)
 
993
            break;
684
994
          if (image->previous == (Image *) NULL)
685
 
            if ((image->progress_monitor != (MagickProgressMonitor) NULL) &&
686
 
                (QuantumTick(y,image->rows) != MagickFalse))
687
 
              {
688
 
                status=image->progress_monitor(SaveImageTag,y,image->rows,
689
 
                  image->client_data);
690
 
                if (status == MagickFalse)
691
 
                  break;
692
 
              }
 
995
            {
 
996
              status=SetImageProgress(image,SaveImageTag,y,image->rows);
 
997
              if (status == MagickFalse)
 
998
                break;
 
999
            }
693
1000
        }
694
1001
        break;
695
1002
      }
698
1005
        /*
699
1006
          Line interlacing:  YYY...CbCbCb...CrCrCr...YYY...CbCbCb...CrCrCr...
700
1007
        */
701
 
        packet_size=(image->depth+7)/8;
702
1008
        for (y=0; y < (long) image->rows; y++)
703
1009
        {
704
1010
          p=AcquireImagePixels(image,0,y,image->columns,1,&image->exception);
705
1011
          if (p == (const PixelPacket *) NULL)
706
1012
            break;
707
 
          (void) ImportQuantumPixels(image,&quantum_info,RedQuantum,pixels);
708
 
          (void) WriteBlob(image,packet_size*image->columns,pixels);
709
 
          (void) ImportQuantumPixels(image,&quantum_info,GreenQuantum,pixels);
710
 
          (void) WriteBlob(image,packet_size*image->columns,pixels);
711
 
          (void) ImportQuantumPixels(image,&quantum_info,BlueQuantum,pixels);
712
 
          (void) WriteBlob(image,packet_size*image->columns,pixels);
713
 
          if (LocaleCompare(image_info->magick,"YCbCrA") == 0)
 
1013
          length=ExportQuantumPixels(image,quantum_info,RedQuantum,pixels);
 
1014
          count=WriteBlob(image,length,pixels);
 
1015
          if (count != (ssize_t) length)
 
1016
            break;
 
1017
          length=ExportQuantumPixels(image,quantum_info,GreenQuantum,pixels);
 
1018
          count=WriteBlob(image,length,pixels);
 
1019
          if (count != (ssize_t) length)
 
1020
            break;
 
1021
          length=ExportQuantumPixels(image,quantum_info,BlueQuantum,pixels);
 
1022
          count=WriteBlob(image,length,pixels);
 
1023
          if (count != (ssize_t) length)
 
1024
            break;
 
1025
          if (quantum_type == RGBAQuantum)
714
1026
            {
715
 
              (void) ImportQuantumPixels(image,&quantum_info,AlphaQuantum,
 
1027
              length=ExportQuantumPixels(image,quantum_info,AlphaQuantum,
716
1028
                pixels);
717
 
              (void) WriteBlob(image,packet_size*image->columns,pixels);
 
1029
              count=WriteBlob(image,length,pixels);
 
1030
              if (count != (ssize_t) length)
 
1031
                break;
718
1032
            }
719
 
          if ((image->progress_monitor != (MagickProgressMonitor) NULL) &&
720
 
              (QuantumTick(y,image->rows) != MagickFalse))
 
1033
          if (image->previous == (Image *) NULL)
721
1034
            {
722
 
              status=image->progress_monitor(SaveImageTag,y,image->rows,
723
 
                image->client_data);
 
1035
              status=SetImageProgress(image,SaveImageTag,y,image->rows);
724
1036
              if (status == MagickFalse)
725
1037
                break;
726
1038
            }
728
1040
        break;
729
1041
      }
730
1042
      case PlaneInterlace:
731
 
      case PartitionInterlace:
732
1043
      {
733
1044
        /*
734
1045
          Plane interlacing:  YYYYYY...CbCbCbCbCbCb...CrCrCrCrCrCr...
735
1046
        */
736
 
        packet_size=(image->depth+7)/8;
737
 
        if (image_info->interlace == PartitionInterlace)
738
 
          {
739
 
            AppendImageFormat("Y",image->filename);
740
 
            status=
741
 
              OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);
742
 
            if (status == MagickFalse)
743
 
              return(status);
744
 
          }
745
 
        for (y=0; y < (long) image->rows; y++)
746
 
        {
747
 
          p=AcquireImagePixels(image,0,y,image->columns,1,&image->exception);
748
 
          if (p == (const PixelPacket *) NULL)
749
 
            break;
750
 
          (void) ImportQuantumPixels(image,&quantum_info,RedQuantum,pixels);
751
 
          (void) WriteBlob(image,packet_size*image->columns,pixels);
752
 
        }
753
 
        if (image_info->interlace == PartitionInterlace)
754
 
          {
755
 
            CloseBlob(image);
756
 
            AppendImageFormat("Cb",image->filename);
757
 
            status=OpenBlob(image_info,image,WriteBinaryBlobMode,
758
 
              &image->exception);
759
 
            if (status == MagickFalse)
760
 
              return(status);
761
 
          }
762
 
        if (image->progress_monitor != (MagickProgressMonitor) NULL)
763
 
          {
764
 
            status=image->progress_monitor(LoadImageTag,100,400,
765
 
              image->client_data);
766
 
            if (status == MagickFalse)
767
 
              break;
768
 
          }
769
 
        for (y=0; y < (long) image->rows; y++)
770
 
        {
771
 
          p=AcquireImagePixels(image,0,y,image->columns,1,&image->exception);
772
 
          if (p == (const PixelPacket *) NULL)
773
 
            break;
774
 
          (void) ImportQuantumPixels(image,&quantum_info,GreenQuantum,pixels);
775
 
          (void) WriteBlob(image,packet_size*image->columns,pixels);
776
 
        }
777
 
        if (image_info->interlace == PartitionInterlace)
778
 
          {
779
 
            CloseBlob(image);
780
 
            AppendImageFormat("Cr",image->filename);
781
 
            status=OpenBlob(image_info,image,WriteBinaryBlobMode,
782
 
              &image->exception);
783
 
            if (status == MagickFalse)
784
 
              return(status);
785
 
          }
786
 
        if (image->progress_monitor != (MagickProgressMonitor) NULL)
787
 
          {
788
 
            status=image->progress_monitor(LoadImageTag,200,400,
789
 
              image->client_data);
790
 
            if (status == MagickFalse)
791
 
              break;
792
 
          }
793
 
        for (y=0; y < (long) image->rows; y++)
794
 
        {
795
 
          p=AcquireImagePixels(image,0,y,image->columns,1,&image->exception);
796
 
          if (p == (const PixelPacket *) NULL)
797
 
            break;
798
 
          (void) ImportQuantumPixels(image,&quantum_info,BlueQuantum,pixels);
799
 
          (void) WriteBlob(image,packet_size*image->columns,pixels);
800
 
        }
801
 
        if (LocaleCompare(image_info->magick,"YCbCrA") == 0)
802
 
          {
803
 
            if (image->progress_monitor != (MagickProgressMonitor) NULL)
804
 
              {
805
 
                status=image->progress_monitor(LoadImageTag,300,400,
806
 
                  image->client_data);
807
 
                if (status == MagickFalse)
808
 
                  break;
809
 
              }
810
 
            if (image_info->interlace == PartitionInterlace)
811
 
              {
812
 
                CloseBlob(image);
813
 
                AppendImageFormat("A",image->filename);
814
 
                status=OpenBlob(image_info,image,WriteBinaryBlobMode,
815
 
                  &image->exception);
816
 
                if (status == MagickFalse)
817
 
                  return(status);
818
 
              }
 
1047
        for (y=0; y < (long) image->rows; y++)
 
1048
        {
 
1049
          p=AcquireImagePixels(image,0,y,image->columns,1,&image->exception);
 
1050
          if (p == (const PixelPacket *) NULL)
 
1051
            break;
 
1052
          length=ExportQuantumPixels(image,quantum_info,RedQuantum,pixels);
 
1053
          count=WriteBlob(image,length,pixels);
 
1054
          if (count != (ssize_t) length)
 
1055
            break;
 
1056
        }
 
1057
        if (image->previous == (Image *) NULL)
 
1058
          {
 
1059
            status=SetImageProgress(image,SaveImageTag,1,5);
 
1060
            if (status == MagickFalse)
 
1061
              break;
 
1062
          }
 
1063
        for (y=0; y < (long) image->rows; y++)
 
1064
        {
 
1065
          p=AcquireImagePixels(image,0,y,image->columns,1,&image->exception);
 
1066
          if (p == (const PixelPacket *) NULL)
 
1067
            break;
 
1068
          length=ExportQuantumPixels(image,quantum_info,GreenQuantum,pixels);
 
1069
          count=WriteBlob(image,length,pixels);
 
1070
          if (count != (ssize_t) length)
 
1071
            break;
 
1072
        }
 
1073
        if (image->previous == (Image *) NULL)
 
1074
          {
 
1075
            status=SetImageProgress(image,SaveImageTag,2,5);
 
1076
            if (status == MagickFalse)
 
1077
              break;
 
1078
          }
 
1079
        for (y=0; y < (long) image->rows; y++)
 
1080
        {
 
1081
          p=AcquireImagePixels(image,0,y,image->columns,1,&image->exception);
 
1082
          if (p == (const PixelPacket *) NULL)
 
1083
            break;
 
1084
          length=ExportQuantumPixels(image,quantum_info,BlueQuantum,pixels);
 
1085
          count=WriteBlob(image,length,pixels);
 
1086
          if (count != (ssize_t) length)
 
1087
            break;
 
1088
        }
 
1089
        if (image->previous == (Image *) NULL)
 
1090
          {
 
1091
            status=SetImageProgress(image,SaveImageTag,3,5);
 
1092
            if (status == MagickFalse)
 
1093
              break;
 
1094
          }
 
1095
        if (quantum_type == RGBAQuantum)
 
1096
          {
819
1097
            for (y=0; y < (long) image->rows; y++)
820
1098
            {
821
1099
              p=AcquireImagePixels(image,0,y,image->columns,1,
822
1100
                &image->exception);
823
1101
              if (p == (const PixelPacket *) NULL)
824
1102
                break;
825
 
              (void) ImportQuantumPixels(image,&quantum_info,AlphaQuantum,
 
1103
              length=ExportQuantumPixels(image,quantum_info,AlphaQuantum,
826
1104
                pixels);
827
 
              (void) WriteBlob(image,packet_size*image->columns,pixels);
 
1105
              count=WriteBlob(image,length,pixels);
 
1106
              if (count != (ssize_t) length)
 
1107
              break;
828
1108
            }
829
1109
          }
830
1110
        if (image_info->interlace == PartitionInterlace)
831
1111
          (void) CopyMagickString(image->filename,image_info->filename,
832
1112
            MaxTextExtent);
833
 
        if (image->progress_monitor != (MagickProgressMonitor) NULL)
834
 
          {
835
 
            status=image->progress_monitor(LoadImageTag,400,400,
836
 
              image->client_data);
 
1113
        if (image->previous == (Image *) NULL)
 
1114
          {
 
1115
            status=SetImageProgress(image,SaveImageTag,5,5);
 
1116
            if (status == MagickFalse)
 
1117
              break;
 
1118
          }
 
1119
        break;
 
1120
      }
 
1121
      case PartitionInterlace:
 
1122
      {
 
1123
        /*
 
1124
          Partition interlacing:  YYYYYY..., CbCbCbCbCbCb..., CrCrCrCrCrCr...
 
1125
        */
 
1126
        AppendImageFormat("Y",image->filename);
 
1127
        status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode :
 
1128
          AppendBinaryBlobMode,&image->exception);
 
1129
        if (status == MagickFalse)
 
1130
          return(status);
 
1131
        for (y=0; y < (long) image->rows; y++)
 
1132
        {
 
1133
          p=AcquireImagePixels(image,0,y,image->columns,1,&image->exception);
 
1134
          if (p == (const PixelPacket *) NULL)
 
1135
            break;
 
1136
          length=ExportQuantumPixels(image,quantum_info,RedQuantum,pixels);
 
1137
          count=WriteBlob(image,length,pixels);
 
1138
          if (count != (ssize_t) length)
 
1139
            break;
 
1140
        }
 
1141
        if (image->previous == (Image *) NULL)
 
1142
          {
 
1143
            status=SetImageProgress(image,SaveImageTag,1,5);
 
1144
            if (status == MagickFalse)
 
1145
              break;
 
1146
          }
 
1147
        (void) CloseBlob(image);
 
1148
        AppendImageFormat("Cb",image->filename);
 
1149
        status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode :
 
1150
          AppendBinaryBlobMode,&image->exception);
 
1151
        if (status == MagickFalse)
 
1152
          return(status);
 
1153
        for (y=0; y < (long) image->rows; y++)
 
1154
        {
 
1155
          p=AcquireImagePixels(image,0,y,image->columns,1,&image->exception);
 
1156
          if (p == (const PixelPacket *) NULL)
 
1157
            break;
 
1158
          length=ExportQuantumPixels(image,quantum_info,GreenQuantum,pixels);
 
1159
          count=WriteBlob(image,length,pixels);
 
1160
          if (count != (ssize_t) length)
 
1161
            break;
 
1162
        }
 
1163
        if (image->previous == (Image *) NULL)
 
1164
          {
 
1165
            status=SetImageProgress(image,SaveImageTag,2,5);
 
1166
            if (status == MagickFalse)
 
1167
              break;
 
1168
          }
 
1169
        (void) CloseBlob(image);
 
1170
        AppendImageFormat("Cr",image->filename);
 
1171
        status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode :
 
1172
          AppendBinaryBlobMode,&image->exception);
 
1173
        if (status == MagickFalse)
 
1174
          return(status);
 
1175
        for (y=0; y < (long) image->rows; y++)
 
1176
        {
 
1177
          p=AcquireImagePixels(image,0,y,image->columns,1,&image->exception);
 
1178
          if (p == (const PixelPacket *) NULL)
 
1179
            break;
 
1180
          length=ExportQuantumPixels(image,quantum_info,BlueQuantum,pixels);
 
1181
          count=WriteBlob(image,length,pixels);
 
1182
          if (count != (ssize_t) length)
 
1183
            break;
 
1184
        }
 
1185
        if (image->previous == (Image *) NULL)
 
1186
          {
 
1187
            status=SetImageProgress(image,SaveImageTag,3,5);
 
1188
            if (status == MagickFalse)
 
1189
              break;
 
1190
          }
 
1191
        if (quantum_type == RGBAQuantum)
 
1192
          {
 
1193
            (void) CloseBlob(image);
 
1194
            AppendImageFormat("A",image->filename);
 
1195
            status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode :
 
1196
              AppendBinaryBlobMode,&image->exception);
 
1197
            if (status == MagickFalse)
 
1198
              return(status);
 
1199
            for (y=0; y < (long) image->rows; y++)
 
1200
            {
 
1201
              p=AcquireImagePixels(image,0,y,image->columns,1,
 
1202
                &image->exception);
 
1203
              if (p == (const PixelPacket *) NULL)
 
1204
                break;
 
1205
              length=ExportQuantumPixels(image,quantum_info,AlphaQuantum,
 
1206
                pixels);
 
1207
              count=WriteBlob(image,length,pixels);
 
1208
              if (count != (ssize_t) length)
 
1209
                break;
 
1210
            }
 
1211
            if (image->previous == (Image *) NULL)
 
1212
              {
 
1213
                status=SetImageProgress(image,SaveImageTag,4,5);
 
1214
                if (status == MagickFalse)
 
1215
                  break;
 
1216
              }
 
1217
          }
 
1218
        (void) CloseBlob(image);
 
1219
        (void) CopyMagickString(image->filename,image_info->filename,
 
1220
          MaxTextExtent);
 
1221
        if (image->previous == (Image *) NULL)
 
1222
          {
 
1223
            status=SetImageProgress(image,SaveImageTag,5,5);
837
1224
            if (status == MagickFalse)
838
1225
              break;
839
1226
          }
840
1227
        break;
841
1228
      }
842
1229
    }
 
1230
    quantum_info=DestroyQuantumInfo(quantum_info);
843
1231
    if (GetNextImageInList(image) == (Image *) NULL)
844
1232
      break;
845
1233
    image=SyncNextImageInList(image);
846
 
    if (image->progress_monitor != (MagickProgressMonitor) NULL)
847
 
      {
848
 
        status=image->progress_monitor(SaveImagesTag,scene,
849
 
          GetImageListLength(image),image->client_data);
850
 
        if (status == MagickFalse)
851
 
          break;
852
 
      }
853
 
    scene++;
 
1234
    status=SetImageProgress(image,SaveImagesTag,scene++,
 
1235
      GetImageListLength(image));
 
1236
    if (status == MagickFalse)
 
1237
      break;
854
1238
  } while (image_info->adjoin != MagickFalse);
855
 
  pixels=(unsigned char *) RelinquishMagickMemory(pixels);
856
 
  CloseBlob(image);
 
1239
  (void) CloseBlob(image);
857
1240
  return(MagickTrue);
858
1241
}