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/color.h"
00046
#include "magick/color_private.h"
00047
#include "magick/colorspace.h"
00048
#include "magick/error.h"
00049
#include "magick/error_private.h"
00050
#include "magick/image.h"
00051
#include "magick/image_private.h"
00052
#include "magick/list.h"
00053
#include "magick/magick.h"
00054
#include "magick/memory_.h"
00055
#include "magick/static.h"
00056
#include "magick/string_.h"
00057
00058
00059
00060
00061
static MagickBooleanType
00062
WriteMAPImage(
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 static Image *
ReadMAPImage(
const ImageInfo *image_info,
ExceptionInfo *
exception)
00092 {
00093
Image
00094 *image;
00095
00096
IndexPacket
00097 index;
00098
00099
long
00100 y;
00101
00102
MagickBooleanType
00103 status;
00104
00105
register IndexPacket
00106 *indexes;
00107
00108
register long
00109 x;
00110
00111
register PixelPacket
00112 *q;
00113
00114
register long
00115 i;
00116
00117
register unsigned char
00118 *p;
00119
00120 size_t
00121 packet_size;
00122
00123
unsigned char
00124 *colormap,
00125 *pixels;
00126
00127
unsigned long
00128 depth;
00129
00130
00131
00132
00133
assert(image_info != (
const ImageInfo *) NULL);
00134
assert(image_info->
signature ==
MagickSignature);
00135
if (image_info->
debug !=
MagickFalse)
00136 (
void)
LogMagickEvent(
TraceEvent,
GetMagickModule(),image_info->
filename);
00137
assert(exception != (
ExceptionInfo *) NULL);
00138
assert(exception->
signature ==
MagickSignature);
00139 image=
AllocateImage(image_info);
00140
if ((image->
columns == 0) || (image->
rows == 0))
00141
ThrowReaderException(
OptionError,
"MustSpecifyImageSize");
00142 status=
OpenBlob(image_info,image,
ReadBinaryBlobMode,exception);
00143
if (status ==
MagickFalse)
00144 {
00145
DestroyImageList(image);
00146
return((
Image *) NULL);
00147 }
00148
00149
00150
00151 image->
storage_class=
PseudoClass;
00152 status=
AllocateImageColormap(image,(
unsigned long)
00153 (image->
offset != 0 ? image->
offset : 256));
00154
if (status ==
MagickFalse)
00155
ThrowReaderException(
ResourceLimitError,
"MemoryAllocationFailed");
00156 depth=
GetImageQuantumDepth(image,
MagickTrue);
00157 packet_size=(size_t) (depth/8);
00158 pixels=(
unsigned char *)
AcquireMagickMemory(packet_size*image->
columns);
00159 packet_size=(size_t) (image->
colors > 256 ? 6 : 3);
00160 colormap=(
unsigned char *)
AcquireMagickMemory(packet_size*image->
colors);
00161
if ((pixels == (
unsigned char *) NULL) ||
00162 (colormap == (
unsigned char *) NULL))
00163
ThrowReaderException(
ResourceLimitError,
"MemoryAllocationFailed");
00164
00165
00166
00167 (
void)
ReadBlob(image,packet_size*image->
colors,colormap);
00168 p=colormap;
00169
if (image->
depth <= 8)
00170
for (i=0; i < (
long) image->
colors; i++)
00171 {
00172 image->
colormap[i].
red=
ScaleCharToQuantum(*p++);
00173 image->
colormap[i].
green=
ScaleCharToQuantum(*p++);
00174 image->
colormap[i].
blue=
ScaleCharToQuantum(*p++);
00175 }
00176
else
00177
for (i=0; i < (
long) image->
colors; i++)
00178 {
00179 image->
colormap[i].
red=(
Quantum) (*p++ << 8);
00180 image->
colormap[i].
red|=(*p++);
00181 image->
colormap[i].
green=(
Quantum) (*p++ << 8);
00182 image->
colormap[i].
green|=(*p++);
00183 image->
colormap[i].
blue=(
Quantum) (*p++ << 8);
00184 image->
colormap[i].
blue|=(*p++);
00185 }
00186 colormap=(
unsigned char *)
RelinquishMagickMemory(colormap);
00187
if (image_info->
ping !=
MagickFalse)
00188 {
00189
CloseBlob(image);
00190
return(
GetFirstImageInList(image));
00191 }
00192
00193
00194
00195 packet_size=(size_t) (depth/8);
00196
for (y=0; y < (
long) image->
rows; y++)
00197 {
00198 p=pixels;
00199 q=
SetImagePixels(image,0,y,image->
columns,1);
00200
if (q == (
PixelPacket *) NULL)
00201
break;
00202 indexes=
GetIndexes(image);
00203 (
void)
ReadBlob(image,(size_t) packet_size*image->
columns,pixels);
00204
for (x=0; x < (
long) image->
columns; x++)
00205 {
00206 index=
ConstrainColormapIndex(image,*p);
00207 p++;
00208
if (image->
colors > 256)
00209 {
00210 index=
ConstrainColormapIndex(image,((
int) (index << 8)+(
int) (*p)));
00211 p++;
00212 }
00213 indexes[x]=(
IndexPacket) index;
00214 *q++=image->
colormap[index];
00215 }
00216
if (
SyncImagePixels(image) ==
MagickFalse)
00217
break;
00218 }
00219 pixels=(
unsigned char *)
RelinquishMagickMemory(pixels);
00220
if (
EOFBlob(image) !=
MagickFalse)
00221
ThrowFileException(exception,
CorruptImageError,
"UnexpectedEndOfFile",
00222 image->
filename);
00223
CloseBlob(image);
00224
return(
GetFirstImageInList(image));
00225 }
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250 ModuleExport void RegisterMAPImage(
void)
00251 {
00252
MagickInfo
00253 *entry;
00254
00255 entry=
SetMagickInfo(
"MAP");
00256 entry->
decoder=(
DecoderHandler *)
ReadMAPImage;
00257 entry->
encoder=(
EncoderHandler *)
WriteMAPImage;
00258 entry->
adjoin=
MagickFalse;
00259 entry->
raw=
MagickTrue;
00260 entry->
endian_support=
MagickTrue;
00261 entry->
description=
AcquireString(
"Colormap intensities and indices");
00262 entry->
module=
AcquireString(
"MAP");
00263 (
void)
RegisterMagickInfo(entry);
00264 }
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285 ModuleExport void UnregisterMAPImage(
void)
00286 {
00287 (
void)
UnregisterMagickInfo(
"MAP");
00288 }
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316 static MagickBooleanType WriteMAPImage(
const ImageInfo *image_info,
Image *image)
00317 {
00318
long
00319 y;
00320
00321
MagickBooleanType
00322 status;
00323
00324
register IndexPacket
00325 *indexes;
00326
00327
register const PixelPacket
00328 *p;
00329
00330
register long
00331 i,
00332 x;
00333
00334
register unsigned char
00335 *q;
00336
00337 size_t
00338 packet_size;
00339
00340
unsigned char
00341 *colormap,
00342 *pixels;
00343
00344
unsigned long
00345 depth;
00346
00347
00348
00349
00350
assert(image_info != (
const ImageInfo *) NULL);
00351
assert(image_info->
signature ==
MagickSignature);
00352
assert(image != (
Image *) NULL);
00353
assert(image->
signature ==
MagickSignature);
00354
if (image->
debug !=
MagickFalse)
00355 (
void)
LogMagickEvent(
TraceEvent,
GetMagickModule(),image->
filename);
00356 status=
OpenBlob(image_info,image,
WriteBinaryBlobMode,&image->
exception);
00357
if (status ==
MagickFalse)
00358
return(status);
00359 (
void)
SetImageColorspace(image,
RGBColorspace);
00360
00361
00362
00363
if (
IsPaletteImage(image,&image->
exception) ==
MagickFalse)
00364 (
void)
SetImageType(image,
PaletteType);
00365 depth=
GetImageQuantumDepth(image,
MagickTrue);
00366 packet_size=(size_t) (depth/8);
00367 pixels=(
unsigned char *)
AcquireMagickMemory(packet_size*image->
columns);
00368 packet_size=(size_t) (image->
colors > 256 ? 6 : 3);
00369 colormap=(
unsigned char *)
AcquireMagickMemory(packet_size*image->
colors);
00370
if ((pixels == (
unsigned char *) NULL) ||
00371 (colormap == (
unsigned char *) NULL))
00372
ThrowWriterException(
ResourceLimitError,
"MemoryAllocationFailed");
00373
00374
00375
00376 q=colormap;
00377
if (image->
depth <= 8)
00378
for (i=0; i < (
long) image->
colors; i++)
00379 {
00380 *q++=(
unsigned char) image->
colormap[i].
red;
00381 *q++=(
unsigned char) image->
colormap[i].
green;
00382 *q++=(
unsigned char) image->
colormap[i].
blue;
00383 }
00384
else
00385
for (i=0; i < (
long) image->
colors; i++)
00386 {
00387 *q++=(
unsigned char) (image->
colormap[i].
red >> 8);
00388 *q++=(
unsigned char) image->
colormap[i].
red;
00389 *q++=(
unsigned char) (image->
colormap[i].
green >> 8);
00390 *q++=(
unsigned char) image->
colormap[i].
green;
00391 *q++=(
unsigned char) (image->
colormap[i].
blue >> 8);
00392 *q++=(
unsigned char) image->
colormap[i].
blue;
00393 }
00394 (
void)
WriteBlob(image,packet_size*image->
colors,colormap);
00395 colormap=(
unsigned char *)
RelinquishMagickMemory(colormap);
00396
00397
00398
00399
for (y=0; y < (
long) image->
rows; y++)
00400 {
00401 p=
AcquireImagePixels(image,0,y,image->
columns,1,&image->
exception);
00402
if (p == (
const PixelPacket *) NULL)
00403
break;
00404 indexes=
GetIndexes(image);
00405 q=pixels;
00406
for (x=0; x < (
long) image->
columns; x++)
00407 {
00408
if (image->
colors > 256)
00409 *q++=(
unsigned char) (indexes[x] >> 8);
00410 *q++=(
unsigned char) indexes[x];
00411 }
00412 (
void)
WriteBlob(image,(size_t) (q-pixels),pixels);
00413 }
00414 pixels=(
unsigned char *)
RelinquishMagickMemory(pixels);
00415
CloseBlob(image);
00416
return(status);
00417 }