00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
#include "magick/studio.h"
00043
#include "magick/blob.h"
00044
#include "magick/blob_private.h"
00045
#include "magick/colorspace.h"
00046
#include "magick/constitute.h"
00047
#include "magick/error.h"
00048
#include "magick/error_private.h"
00049
#include "magick/image.h"
00050
#include "magick/image_private.h"
00051
#include "magick/list.h"
00052
#include "magick/magick.h"
00053
#include "magick/memory_.h"
00054
#include "magick/monitor.h"
00055
#include "magick/static.h"
00056
#include "magick/string_.h"
00057
00058
00059
00060
00061
static MagickBooleanType
00062
WriteGRAYImage(
const ImageInfo *,
Image *);
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092 static Image *
ReadGRAYImage(
const ImageInfo *image_info,
00093
ExceptionInfo *
exception)
00094 {
00095
Image
00096 *image;
00097
00098
long
00099 j,
00100 y;
00101
00102
MagickBooleanType
00103 status;
00104
00105
MagickOffsetType
00106 offset;
00107
00108
register long
00109 i,
00110 x;
00111
00112
register PixelPacket
00113 *q;
00114
00115
ssize_t
00116 count;
00117
00118 size_t
00119 packet_size;
00120
00121
unsigned char
00122 *scanline;
00123
00124
unsigned long
00125 depth,
00126 width;
00127
00128
00129
00130
00131
assert(image_info != (
const ImageInfo *) NULL);
00132
assert(image_info->
signature ==
MagickSignature);
00133
if (image_info->
debug !=
MagickFalse)
00134 (
void)
LogMagickEvent(
TraceEvent,
GetMagickModule(),image_info->
filename);
00135
assert(exception != (
ExceptionInfo *) NULL);
00136
assert(exception->
signature ==
MagickSignature);
00137 image=
AllocateImage(image_info);
00138
if ((image->
columns == 0) || (image->
rows == 0))
00139
ThrowReaderException(
OptionError,
"MustSpecifyImageSize");
00140 status=
OpenBlob(image_info,image,
ReadBinaryBlobMode,exception);
00141
if (status ==
MagickFalse)
00142 {
00143
DestroyImageList(image);
00144
return((
Image *) NULL);
00145 }
00146
for (i=0; i < image->
offset; i++)
00147 (
void)
ReadBlobByte(image);
00148
00149
00150
00151 depth=
GetImageQuantumDepth(image,
MagickTrue);
00152 packet_size=(size_t) (depth/8);
00153 scanline=(
unsigned char *)
00154
AcquireMagickMemory(packet_size*image->
extract_info.
width);
00155
if (scanline == (
unsigned char *) NULL)
00156
ThrowReaderException(
ResourceLimitError,
"MemoryAllocationFailed");
00157
if (image_info->
number_scenes != 0)
00158
while (image->
scene < image_info->
scene)
00159 {
00160
00161
00162
00163 image->
scene++;
00164
for (y=0; y < (
long) image->
rows; y++)
00165 (
void)
ReadBlob(image,packet_size*image->
extract_info.
width,scanline);
00166 }
00167 offset=(
MagickOffsetType) (packet_size*image->
extract_info.
x);
00168
do
00169 {
00170
00171
00172
00173
if ((image->
depth <=
QuantumDepth) && (image->
depth <= 16))
00174
if (
AllocateImageColormap(image,1UL << image->
depth) ==
MagickFalse)
00175
ThrowReaderException(
ResourceLimitError,
"MemoryAllocationFailed");
00176
if ((image_info->
ping !=
MagickFalse) && (image_info->
number_scenes != 0))
00177
if (image->
scene >= (image_info->
scene+image_info->
number_scenes-1))
00178
break;
00179
for (y=0; y < image->
extract_info.
y; y++)
00180 (
void)
ReadBlob(image,packet_size*image->
extract_info.
width,scanline);
00181
for (y=0; y < (
long) image->
rows; y++)
00182 {
00183
if ((y > 0) || (image->
previous == (
Image *) NULL))
00184 (
void)
ReadBlob(image,packet_size*image->
extract_info.
width,scanline);
00185 q=
SetImagePixels(image,0,y,image->
columns,1);
00186
if (q == (
PixelPacket *) NULL)
00187
break;
00188
if ((image->
depth <=
QuantumDepth) && (image->
depth <= 16))
00189 (
void)
PushImagePixels(image,
GrayQuantum,scanline+offset);
00190
else
00191 {
00192 (
void)
PushImagePixels(image,
RedQuantum,scanline+offset);
00193
for (x=0; x < (
long) image->
columns; x++)
00194 {
00195 q->
green=q->
red;
00196 q->
blue=q->
red;
00197 q++;
00198 }
00199 }
00200
if (
SyncImagePixels(image) ==
MagickFalse)
00201
break;
00202
if (image->
previous == (
Image *) NULL)
00203
if ((image->
progress_monitor != (
MagickProgressMonitor) NULL) &&
00204 (
QuantumTick(y,image->
rows) !=
MagickFalse))
00205 {
00206 status=image->
progress_monitor(
LoadImageTag,y,image->
rows,
00207 image->
client_data);
00208
if (status ==
MagickFalse)
00209
break;
00210 }
00211 }
00212 width=image->
extract_info.
height-image->
rows-image->
extract_info.
y;
00213
for (j=0; j < (
long) width; j++)
00214 (
void)
ReadBlob(image,packet_size*image->
extract_info.
width,scanline);
00215
if (
EOFBlob(image) !=
MagickFalse)
00216 {
00217
ThrowFileException(exception,
CorruptImageError,
"UnexpectedEndOfFile",
00218 image->
filename);
00219
break;
00220 }
00221
00222
00223
00224
if (image_info->
number_scenes != 0)
00225
if (image->
scene >= (image_info->
scene+image_info->
number_scenes-1))
00226
break;
00227 count=
ReadBlob(image,packet_size*image->
extract_info.
width,scanline);
00228
if (count != 0)
00229 {
00230
00231
00232
00233
AllocateNextImage(image_info,image);
00234
if (image->
next == (
Image *) NULL)
00235 {
00236
DestroyImageList(image);
00237
return((
Image *) NULL);
00238 }
00239 image=
SyncNextImageInList(image);
00240
if (image->
progress_monitor != (
MagickProgressMonitor) NULL)
00241 {
00242 status=image->
progress_monitor(
LoadImagesTag,
TellBlob(image),
00243
GetBlobSize(image),image->
client_data);
00244
if (status ==
MagickFalse)
00245
break;
00246 }
00247 }
00248 }
while (count != 0);
00249 scanline=(
unsigned char *)
RelinquishMagickMemory(scanline);
00250
CloseBlob(image);
00251
return(
GetFirstImageInList(image));
00252 }
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277 ModuleExport void RegisterGRAYImage(
void)
00278 {
00279
MagickInfo
00280 *entry;
00281
00282 entry=
SetMagickInfo(
"GRAY");
00283 entry->
decoder=(
DecoderHandler *)
ReadGRAYImage;
00284 entry->
encoder=(
EncoderHandler *)
WriteGRAYImage;
00285 entry->
raw=
MagickTrue;
00286 entry->
endian_support=
MagickTrue;
00287 entry->
description=
AcquireString(
"Raw gray samples");
00288 entry->
module=
AcquireString(
"GRAY");
00289 (
void)
RegisterMagickInfo(entry);
00290 }
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311 ModuleExport void UnregisterGRAYImage(
void)
00312 {
00313 (
void)
UnregisterMagickInfo(
"GRAY");
00314 }
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342 static MagickBooleanType WriteGRAYImage(
const ImageInfo *image_info,
00343
Image *image)
00344 {
00345
long
00346 y;
00347
00348
MagickBooleanType
00349 status;
00350
00351
MagickOffsetType
00352 scene;
00353
00354
register const PixelPacket
00355 *p;
00356
00357 size_t
00358 packet_size;
00359
00360
unsigned char
00361 *scanline;
00362
00363
unsigned long
00364 depth;
00365
00366
00367
00368
00369
assert(image_info != (
const ImageInfo *) NULL);
00370
assert(image_info->
signature ==
MagickSignature);
00371
assert(image != (
Image *) NULL);
00372
assert(image->
signature ==
MagickSignature);
00373
if (image->
debug !=
MagickFalse)
00374 (
void)
LogMagickEvent(
TraceEvent,
GetMagickModule(),image->
filename);
00375 status=
OpenBlob(image_info,image,
WriteBinaryBlobMode,&image->
exception);
00376
if (status ==
MagickFalse)
00377
return(status);
00378
00379
00380
00381 scene=0;
00382
do
00383 {
00384
00385
00386
00387 (
void)
SetImageColorspace(image,
RGBColorspace);
00388 depth=
GetImageQuantumDepth(image,
MagickTrue);
00389 packet_size=(size_t) (depth/8);
00390 scanline=(
unsigned char *)
00391
AcquireMagickMemory(packet_size*image->
columns);
00392
if (scanline == (
unsigned char *) NULL)
00393
ThrowWriterException(
ResourceLimitError,
"MemoryAllocationFailed");
00394
00395
00396
00397
for (y=0; y < (
long) image->
rows; y++)
00398 {
00399 p=
AcquireImagePixels(image,0,y,image->
columns,1,&image->
exception);
00400
if (p == (
const PixelPacket *) NULL)
00401
break;
00402 (
void)
PopImagePixels(image,
GrayQuantum,scanline);
00403 (
void)
WriteBlob(image,packet_size*image->
columns,scanline);
00404
if (image->
previous == (
Image *) NULL)
00405
if ((image->
progress_monitor != (
MagickProgressMonitor) NULL) &&
00406 (
QuantumTick(y,image->
rows) !=
MagickFalse))
00407 {
00408 status=image->
progress_monitor(
SaveImageTag,y,image->
rows,
00409 image->
client_data);
00410
if (status ==
MagickFalse)
00411
break;
00412 }
00413 }
00414 scanline=(
unsigned char *)
RelinquishMagickMemory(scanline);
00415
if (image->
next == (
Image *) NULL)
00416
break;
00417 image=
SyncNextImageInList(image);
00418
if (image->
progress_monitor != (
MagickProgressMonitor) NULL)
00419 {
00420 status=image->
progress_monitor(
SaveImagesTag,scene,
00421
GetImageListLength(image),image->
client_data);
00422
if (status ==
MagickFalse)
00423
break;
00424 }
00425 scene++;
00426 }
while (image_info->
adjoin !=
MagickFalse);
00427
CloseBlob(image);
00428
return(
MagickTrue);
00429 }