43#include "MagickCore/studio.h"
44#include "MagickCore/blob.h"
45#include "MagickCore/blob-private.h"
46#include "MagickCore/cache.h"
47#include "MagickCore/cache-private.h"
48#include "MagickCore/color-private.h"
49#include "MagickCore/composite-private.h"
50#include "MagickCore/constitute.h"
51#include "MagickCore/exception.h"
52#include "MagickCore/exception-private.h"
53#include "MagickCore/geometry.h"
54#include "MagickCore/memory_.h"
55#include "MagickCore/memory-private.h"
56#include "MagickCore/pixel.h"
57#include "MagickCore/pixel-accessor.h"
58#include "MagickCore/pixel-private.h"
59#include "MagickCore/policy.h"
60#include "MagickCore/quantum.h"
61#include "MagickCore/quantum-private.h"
62#include "MagickCore/semaphore.h"
63#include "MagickCore/stream.h"
64#include "MagickCore/stream-private.h"
65#include "MagickCore/string_.h"
112#if defined(__cplusplus) || defined(c_plusplus)
117 *GetVirtualPixelStream(
const Image *,
const VirtualPixelMethod,
const ssize_t,
120static MagickBooleanType
125 *QueueAuthenticPixelsStream(
Image *,
const ssize_t,
const ssize_t,
const size_t,
128#if defined(__cplusplus) || defined(c_plusplus)
163 stream_info=(
StreamInfo *) AcquireCriticalMemory(
sizeof(*stream_info));
164 (void) memset(stream_info,0,
sizeof(*stream_info));
165 stream_info->pixels=(
unsigned char *) MagickAssumeAligned(
166 AcquireAlignedMemory(1,
sizeof(*stream_info->pixels)));
167 if (stream_info->pixels == (
unsigned char *) NULL)
168 ThrowFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed");
169 stream_info->map=ConstantString(
"RGB");
170 stream_info->storage_type=CharPixel;
171 stream_info->stream=AcquireImage(image_info,exception);
172 stream_info->signature=MagickCoreSignature;
199static inline void RelinquishStreamPixels(
CacheInfo *cache_info)
201 assert(cache_info != (
CacheInfo *) NULL);
202 if (cache_info->pixels != (Quantum *) NULL)
204 if (cache_info->mapped == MagickFalse)
205 cache_info->pixels=(Quantum *) RelinquishAlignedMemory(
209 (void) UnmapBlob(cache_info->pixels,(
size_t) cache_info->length);
210 cache_info->pixels=(Quantum *) NULL;
213 cache_info->mapped=MagickFalse;
214 cache_info->metacontent=(
void *) NULL;
215 cache_info->length=0;
218static void DestroyPixelStream(
Image *image)
226 assert(image != (
Image *) NULL);
227 assert(image->signature == MagickCoreSignature);
228 if (IsEventLogging() != MagickFalse)
229 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
231 assert(cache_info->signature == MagickCoreSignature);
233 LockSemaphoreInfo(cache_info->semaphore);
234 cache_info->reference_count--;
235 if (cache_info->reference_count == 0)
237 UnlockSemaphoreInfo(cache_info->semaphore);
238 if (destroy == MagickFalse)
240 RelinquishStreamPixels(cache_info);
241 if (cache_info->nexus_info != (
NexusInfo **) NULL)
242 cache_info->nexus_info=DestroyPixelCacheNexus(cache_info->nexus_info,
243 cache_info->number_threads);
245 RelinquishSemaphoreInfo(&cache_info->file_semaphore);
247 RelinquishSemaphoreInfo(&cache_info->semaphore);
248 cache_info=(
CacheInfo *) RelinquishAlignedMemory(cache_info);
277 assert(stream_info->signature == MagickCoreSignature);
278 if (IsEventLogging() != MagickFalse)
279 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
280 if (stream_info->map != (
char *) NULL)
281 stream_info->map=DestroyString(stream_info->map);
282 if (stream_info->pixels != (
unsigned char *) NULL)
283 stream_info->pixels=(
unsigned char *) RelinquishAlignedMemory(
284 stream_info->pixels);
285 if (stream_info->stream != (
Image *) NULL)
287 (void) CloseBlob(stream_info->stream);
288 stream_info->stream=DestroyImage(stream_info->stream);
290 if (stream_info->quantum_info != (
QuantumInfo *) NULL)
291 stream_info->quantum_info=DestroyQuantumInfo(stream_info->quantum_info);
292 stream_info->signature=(~MagickCoreSignature);
293 stream_info=(
StreamInfo *) RelinquishMagickMemory(stream_info);
321static void *GetAuthenticMetacontentFromStream(
const Image *image)
326 assert(image != (
Image *) NULL);
327 assert(image->signature == MagickCoreSignature);
328 if (IsEventLogging() != MagickFalse)
329 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
331 assert(cache_info->signature == MagickCoreSignature);
332 return(cache_info->metacontent);
367static Quantum *GetAuthenticPixelsStream(
Image *image,
const ssize_t x,
368 const ssize_t y,
const size_t columns,
const size_t rows,
374 assert(image != (
Image *) NULL);
375 assert(image->signature == MagickCoreSignature);
376 if (IsEventLogging() != MagickFalse)
377 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
378 pixels=QueueAuthenticPixelsStream(image,x,y,columns,rows,exception);
405static Quantum *GetAuthenticPixelsFromStream(
const Image *image)
410 assert(image != (
Image *) NULL);
411 assert(image->signature == MagickCoreSignature);
412 if (IsEventLogging() != MagickFalse)
413 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
415 assert(cache_info->signature == MagickCoreSignature);
416 return(cache_info->pixels);
450static MagickBooleanType GetOneAuthenticPixelFromStream(
Image *image,
451 const ssize_t x,
const ssize_t y,Quantum *pixel,
ExceptionInfo *exception)
459 assert(image != (
Image *) NULL);
460 assert(image->signature == MagickCoreSignature);
461 (void) memset(pixel,0,MaxPixelChannels*
sizeof(*pixel));
462 p=GetAuthenticPixelsStream(image,x,y,1,1,exception);
463 if (p == (Quantum *) NULL)
465 pixel[RedPixelChannel]=ClampToQuantum(image->background_color.red);
466 pixel[GreenPixelChannel]=ClampToQuantum(image->background_color.green);
467 pixel[BluePixelChannel]=ClampToQuantum(image->background_color.blue);
468 pixel[BlackPixelChannel]=ClampToQuantum(image->background_color.black);
469 pixel[AlphaPixelChannel]=ClampToQuantum(image->background_color.alpha);
472 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
474 PixelChannel channel = GetPixelChannelChannel(image,i);
513static MagickBooleanType GetOneVirtualPixelFromStream(
const Image *image,
514 const VirtualPixelMethod virtual_pixel_method,
const ssize_t x,
const ssize_t y,
523 assert(image != (
Image *) NULL);
524 assert(image->signature == MagickCoreSignature);
525 (void) memset(pixel,0,MaxPixelChannels*
sizeof(*pixel));
526 p=GetVirtualPixelStream(image,virtual_pixel_method,x,y,1,1,exception);
527 if (p == (
const Quantum *) NULL)
529 pixel[RedPixelChannel]=ClampToQuantum(image->background_color.red);
530 pixel[GreenPixelChannel]=ClampToQuantum(image->background_color.green);
531 pixel[BluePixelChannel]=ClampToQuantum(image->background_color.blue);
532 pixel[BlackPixelChannel]=ClampToQuantum(image->background_color.black);
533 pixel[AlphaPixelChannel]=ClampToQuantum(image->background_color.alpha);
536 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
538 PixelChannel channel = GetPixelChannelChannel(image,i);
566MagickPrivate
const void *GetStreamInfoClientData(
StreamInfo *stream_info)
569 assert(stream_info->signature == MagickCoreSignature);
570 return(stream_info->client_data);
599static const Quantum *GetVirtualPixelsStream(
const Image *image)
604 assert(image != (
Image *) NULL);
605 assert(image->signature == MagickCoreSignature);
606 if (IsEventLogging() != MagickFalse)
607 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
609 assert(cache_info->signature == MagickCoreSignature);
610 return(cache_info->pixels);
637static const void *GetVirtualMetacontentFromStream(
const Image *image)
642 assert(image != (
Image *) NULL);
643 assert(image->signature == MagickCoreSignature);
644 if (IsEventLogging() != MagickFalse)
645 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
647 assert(cache_info->signature == MagickCoreSignature);
648 return(cache_info->metacontent);
687static inline MagickBooleanType AcquireStreamPixels(
CacheInfo *cache_info,
690 if (cache_info->length != (MagickSizeType) ((
size_t) cache_info->length))
692 cache_info->pixels=(Quantum *) MagickAssumeAligned(AcquireAlignedMemory(1,
693 (
size_t) cache_info->length));
694 if (cache_info->pixels != (Quantum *) NULL)
695 (void) memset(cache_info->pixels,0,(
size_t) cache_info->length);
698 (void) ThrowMagickException(exception,GetMagickModule(),
699 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
700 cache_info->filename);
706static const Quantum *GetVirtualPixelStream(
const Image *image,
707 const VirtualPixelMethod magick_unused(virtual_pixel_method),
const ssize_t x,
708 const ssize_t y,
const size_t columns,
const size_t rows,
723 magick_unreferenced(virtual_pixel_method);
728 assert(image != (
const Image *) NULL);
729 assert(image->signature == MagickCoreSignature);
730 if (IsEventLogging() != MagickFalse)
731 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
732 if ((x < 0) || (y < 0) ||
733 ((x+(ssize_t) columns) > (ssize_t) image->columns) ||
734 ((y+(ssize_t) rows) > (ssize_t) image->rows) ||
735 (columns == 0) || (rows == 0))
737 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
738 "ImageDoesNotContainTheStreamGeometry",
"`%s'",image->filename);
739 return((Quantum *) NULL);
742 assert(cache_info->signature == MagickCoreSignature);
746 number_pixels=(MagickSizeType) columns*rows;
747 length=(size_t) number_pixels*cache_info->number_channels*
sizeof(Quantum);
748 if (cache_info->number_channels == 0)
749 length=(size_t) number_pixels*
sizeof(Quantum);
750 if (cache_info->metacontent_extent != 0)
751 length+=number_pixels*cache_info->metacontent_extent;
752 if (cache_info->pixels == (Quantum *) NULL)
754 cache_info->length=length;
755 status=AcquireStreamPixels(cache_info,exception);
756 if (status == MagickFalse)
758 cache_info->length=0;
759 return((Quantum *) NULL);
763 if (cache_info->length < length)
765 RelinquishStreamPixels(cache_info);
766 cache_info->length=length;
767 status=AcquireStreamPixels(cache_info,exception);
768 if (status == MagickFalse)
770 cache_info->length=0;
771 return((Quantum *) NULL);
774 cache_info->metacontent=(
void *) NULL;
775 if (cache_info->metacontent_extent != 0)
776 cache_info->metacontent=(
void *) (cache_info->pixels+number_pixels*
777 cache_info->number_channels);
778 return(cache_info->pixels);
810MagickExport MagickBooleanType OpenStream(
const ImageInfo *image_info,
816 (void) CopyMagickString(stream_info->stream->filename,filename,
818 status=OpenBlob(image_info,stream_info->stream,WriteBinaryBlobMode,exception);
854static inline MagickBooleanType ValidatePixelCacheMorphology(
855 const Image *magick_restrict image)
858 *magick_restrict cache_info;
868 p=image->channel_map;
869 q=cache_info->channel_map;
870 if ((image->storage_class != cache_info->storage_class) ||
871 (image->colorspace != cache_info->colorspace) ||
872 (image->alpha_trait != cache_info->alpha_trait) ||
873 (image->channels != cache_info->channels) ||
874 (image->columns != cache_info->columns) ||
875 (image->rows != cache_info->rows) ||
876 (image->number_channels != cache_info->number_channels) ||
877 (memcmp(p,q,image->number_channels*
sizeof(*p)) != 0) ||
878 (image->metacontent_extent != cache_info->metacontent_extent) ||
879 (cache_info->nexus_info == (
NexusInfo **) NULL))
884static Quantum *QueueAuthenticPixelsStream(
Image *image,
const ssize_t x,
885 const ssize_t y,
const size_t columns,
const size_t rows,
906 assert(image != (
Image *) NULL);
907 if ((image->columns == 0) || (image->rows == 0) || (x < 0) ||
908 (y < 0) || (x >= (ssize_t) image->columns) ||
909 (y >= (ssize_t) image->rows))
911 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
912 "ImageDoesNotContainTheStreamGeometry",
"`%s'",image->filename);
913 return((Quantum *) NULL);
915 stream_handler=GetBlobStreamHandler(image);
916 if (stream_handler == (StreamHandler) NULL)
918 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
919 "NoStreamHandlerIsDefined",
"`%s'",image->filename);
920 return((Quantum *) NULL);
923 assert(cache_info->signature == MagickCoreSignature);
924 if (ValidatePixelCacheMorphology(image) == MagickFalse)
926 if (cache_info->storage_class == UndefinedClass)
927 (void) stream_handler(image,(
const void *) NULL,(
size_t)
928 cache_info->columns);
929 cache_info->storage_class=image->storage_class;
930 cache_info->colorspace=image->colorspace;
931 cache_info->alpha_trait=image->alpha_trait;
932 cache_info->channels=image->channels;
933 cache_info->columns=image->columns;
934 cache_info->rows=image->rows;
935 cache_info->number_channels=image->number_channels;
936 status=ResetPixelChannelMap(image,exception);
937 if (status == MagickFalse)
938 return((Quantum *) NULL);
939 ResetPixelCacheChannels(image);
940 image->cache=cache_info;
945 cache_info->columns=columns;
946 cache_info->rows=rows;
947 number_pixels=(MagickSizeType) columns*rows;
948 length=(size_t) number_pixels*cache_info->number_channels*
sizeof(Quantum);
949 if (cache_info->number_channels == 0)
950 length=(size_t) number_pixels*
sizeof(Quantum);
951 if (cache_info->metacontent_extent != 0)
952 length+=number_pixels*cache_info->metacontent_extent;
953 if (cache_info->pixels == (Quantum *) NULL)
955 cache_info->length=length;
956 status=AcquireStreamPixels(cache_info,exception);
957 if (status == MagickFalse)
959 cache_info->length=0;
960 return((Quantum *) NULL);
964 if (cache_info->length < length)
966 RelinquishStreamPixels(cache_info);
967 cache_info->length=length;
968 status=AcquireStreamPixels(cache_info,exception);
969 if (status == MagickFalse)
971 cache_info->length=0;
972 return((Quantum *) NULL);
975 cache_info->metacontent=(
void *) NULL;
976 if (cache_info->metacontent_extent != 0)
977 cache_info->metacontent=(
void *) (cache_info->pixels+number_pixels*
978 cache_info->number_channels);
979 return(cache_info->pixels);
1010MagickExport
Image *ReadStream(
const ImageInfo *image_info,StreamHandler stream,
1025 assert(image_info != (
ImageInfo *) NULL);
1026 assert(image_info->signature == MagickCoreSignature);
1028 assert(exception->signature == MagickCoreSignature);
1029 if (IsEventLogging() != MagickFalse)
1030 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
1031 image_info->filename);
1032 read_info=CloneImageInfo(image_info);
1033 read_info->cache=AcquirePixelCache(0);
1034 GetPixelCacheMethods(&cache_methods);
1035 cache_methods.get_virtual_pixel_handler=GetVirtualPixelStream;
1036 cache_methods.get_virtual_pixels_handler=GetVirtualPixelsStream;
1037 cache_methods.get_virtual_metacontent_from_handler=
1038 GetVirtualMetacontentFromStream;
1039 cache_methods.get_authentic_pixels_handler=GetAuthenticPixelsStream;
1040 cache_methods.queue_authentic_pixels_handler=QueueAuthenticPixelsStream;
1041 cache_methods.sync_authentic_pixels_handler=SyncAuthenticPixelsStream;
1042 cache_methods.get_authentic_pixels_from_handler=GetAuthenticPixelsFromStream;
1043 cache_methods.get_authentic_metacontent_from_handler=
1044 GetAuthenticMetacontentFromStream;
1045 cache_methods.get_one_virtual_pixel_from_handler=GetOneVirtualPixelFromStream;
1046 cache_methods.get_one_authentic_pixel_from_handler=
1047 GetOneAuthenticPixelFromStream;
1048 cache_methods.destroy_pixel_handler=DestroyPixelStream;
1049 SetPixelCacheMethods(read_info->cache,&cache_methods);
1050 read_info->stream=stream;
1051 image=ReadImage(read_info,exception);
1052 read_info=DestroyImageInfo(read_info);
1053 if (image != (
Image *) NULL)
1055 MagickBooleanType status = ResetPixelChannelMap(image,exception);
1056 if (status == MagickFalse)
1057 return(DestroyImage(image));
1058 ResetPixelCacheChannels(image);
1081MagickPrivate
void ResetStreamAnonymousMemory(
void)
1110MagickPrivate
void SetStreamInfoClientData(
StreamInfo *stream_info,
1111 const void *client_data)
1114 assert(stream_info->signature == MagickCoreSignature);
1115 stream_info->client_data=client_data;
1142MagickExport
void SetStreamInfoMap(
StreamInfo *stream_info,
const char *map)
1145 assert(stream_info->signature == MagickCoreSignature);
1146 (void) CloneString(&stream_info->map,map);
1174MagickExport
void SetStreamInfoStorageType(
StreamInfo *stream_info,
1175 const StorageType storage_type)
1178 assert(stream_info->signature == MagickCoreSignature);
1179 stream_info->storage_type=storage_type;
1211#if defined(__cplusplus) || defined(c_plusplus)
1215static size_t WriteStreamImage(
const Image *image,
const void *pixels,
1216 const size_t columns)
1235 stream_info=(
StreamInfo *) image->client_data;
1236 switch (stream_info->storage_type)
1238 default: packet_size=
sizeof(
unsigned char);
break;
1239 case CharPixel: packet_size=
sizeof(
unsigned char);
break;
1240 case DoublePixel: packet_size=
sizeof(double);
break;
1241 case FloatPixel: packet_size=
sizeof(float);
break;
1242 case LongPixel: packet_size=
sizeof(
unsigned int);
break;
1243 case LongLongPixel: packet_size=
sizeof(MagickSizeType);
break;
1244 case QuantumPixel: packet_size=
sizeof(Quantum);
break;
1245 case ShortPixel: packet_size=
sizeof(
unsigned short);
break;
1248 assert(cache_info->signature == MagickCoreSignature);
1249 packet_size*=strlen(stream_info->map);
1250 length=packet_size*cache_info->columns*cache_info->rows;
1251 if (image != stream_info->image)
1259 (void) RelinquishAlignedMemory(stream_info->pixels);
1260 stream_info->pixels=(
unsigned char *) AcquireAlignedMemory(1,length);
1261 if (stream_info->pixels == (
unsigned char *) NULL)
1263 (void) memset(stream_info->pixels,0,length);
1264 stream_info->image=image;
1265 write_info=CloneImageInfo(stream_info->image_info);
1266 (void) SetImageInfo(write_info,1,stream_info->exception);
1267 if (write_info->extract != (
char *) NULL)
1268 (void) ParseAbsoluteGeometry(write_info->extract,
1269 &stream_info->extract_info);
1271 write_info=DestroyImageInfo(write_info);
1273 extract_info=stream_info->extract_info;
1274 if ((extract_info.width == 0) || (extract_info.height == 0))
1279 (void) StreamImagePixels(stream_info,image,stream_info->exception);
1280 count=WriteBlob(stream_info->stream,length,stream_info->pixels);
1282 return(count == 0 ? 0 : columns);
1284 if ((stream_info->y < extract_info.y) ||
1285 (stream_info->y >= (extract_info.y+(ssize_t) extract_info.height)))
1293 (void) StreamImagePixels(stream_info,image,stream_info->exception);
1294 length=packet_size*extract_info.width;
1295 count=WriteBlob(stream_info->stream,length,stream_info->pixels+(ssize_t)
1296 packet_size*extract_info.x);
1298 return(count == 0 ? 0 : columns);
1301#if defined(__cplusplus) || defined(c_plusplus)
1314 assert(image_info != (
const ImageInfo *) NULL);
1315 assert(image_info->signature == MagickCoreSignature);
1317 assert(stream_info->signature == MagickCoreSignature);
1319 if (IsEventLogging() != MagickFalse)
1320 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
1321 image_info->filename);
1322 read_info=CloneImageInfo(image_info);
1323 stream_info->image_info=image_info;
1324 stream_info->quantum_info=AcquireQuantumInfo(image_info,(
Image *) NULL);
1325 if (stream_info->quantum_info == (
QuantumInfo *) NULL)
1327 read_info=DestroyImageInfo(read_info);
1328 return((
Image *) NULL);
1330 stream_info->exception=exception;
1331 read_info->client_data=(
void *) stream_info;
1332 image=ReadStream(read_info,&WriteStreamImage,exception);
1333 read_info=DestroyImageInfo(read_info);
1334 stream_info->quantum_info=DestroyQuantumInfo(stream_info->quantum_info);
1335 stream_info->quantum_info=AcquireQuantumInfo(image_info,image);
1336 if (stream_info->quantum_info == (
QuantumInfo *) NULL)
1337 image=DestroyImage(image);
1370static MagickBooleanType StreamImagePixels(
const StreamInfo *stream_info,
1390 assert(stream_info->signature == MagickCoreSignature);
1391 assert(image != (
Image *) NULL);
1392 assert(image->signature == MagickCoreSignature);
1393 if (IsEventLogging() != MagickFalse)
1394 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1395 length=strlen(stream_info->map);
1396 quantum_map=(QuantumType *) AcquireQuantumMemory(length,
sizeof(*quantum_map));
1397 if (quantum_map == (QuantumType *) NULL)
1399 (void) ThrowMagickException(exception,GetMagickModule(),
1400 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",image->filename);
1401 return(MagickFalse);
1403 (void) memset(quantum_map,0,length*
sizeof(*quantum_map));
1404 for (i=0; i < (ssize_t) length; i++)
1406 switch (stream_info->map[i])
1411 quantum_map[i]=AlphaQuantum;
1417 quantum_map[i]=BlueQuantum;
1423 quantum_map[i]=CyanQuantum;
1424 if (image->colorspace == CMYKColorspace)
1426 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1427 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1428 "ColorSeparatedImageRequired",
"`%s'",stream_info->map);
1429 return(MagickFalse);
1434 quantum_map[i]=GreenQuantum;
1440 quantum_map[i]=IndexQuantum;
1446 quantum_map[i]=BlackQuantum;
1447 if (image->colorspace == CMYKColorspace)
1449 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1450 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1451 "ColorSeparatedImageRequired",
"`%s'",stream_info->map);
1452 return(MagickFalse);
1457 quantum_map[i]=MagentaQuantum;
1458 if (image->colorspace == CMYKColorspace)
1460 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1461 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1462 "ColorSeparatedImageRequired",
"`%s'",stream_info->map);
1463 return(MagickFalse);
1468 quantum_map[i]=OpacityQuantum;
1474 quantum_map[i]=UndefinedQuantum;
1480 quantum_map[i]=RedQuantum;
1486 quantum_map[i]=YellowQuantum;
1487 if (image->colorspace == CMYKColorspace)
1489 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1490 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1491 "ColorSeparatedImageRequired",
"`%s'",stream_info->map);
1492 return(MagickFalse);
1496 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
1497 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1498 "UnrecognizedPixelMap",
"`%s'",stream_info->map);
1499 return(MagickFalse);
1503 quantum_info=stream_info->quantum_info;
1504 switch (stream_info->storage_type)
1511 q=(
unsigned char *) stream_info->pixels;
1512 if (LocaleCompare(stream_info->map,
"BGR") == 0)
1514 p=GetAuthenticPixelQueue(image);
1515 if (p == (
const Quantum *) NULL)
1517 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1519 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1520 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1521 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1522 p+=(ptrdiff_t) GetPixelChannels(image);
1526 if (LocaleCompare(stream_info->map,
"BGRA") == 0)
1528 p=GetAuthenticPixelQueue(image);
1529 if (p == (
const Quantum *) NULL)
1531 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1533 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1534 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1535 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1536 *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
1537 p+=(ptrdiff_t) GetPixelChannels(image);
1541 if (LocaleCompare(stream_info->map,
"BGRP") == 0)
1543 p=GetAuthenticPixelQueue(image);
1544 if (p == (
const Quantum *) NULL)
1546 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1548 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1549 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1550 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1551 *q++=ScaleQuantumToChar((Quantum) 0);
1552 p+=(ptrdiff_t) GetPixelChannels(image);
1556 if (LocaleCompare(stream_info->map,
"I") == 0)
1558 p=GetAuthenticPixelQueue(image);
1559 if (p == (
const Quantum *) NULL)
1561 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1563 *q++=ScaleQuantumToChar(ClampToQuantum(GetPixelIntensity(image,p)));
1564 p+=(ptrdiff_t) GetPixelChannels(image);
1568 if (LocaleCompare(stream_info->map,
"RGB") == 0)
1570 p=GetAuthenticPixelQueue(image);
1571 if (p == (
const Quantum *) NULL)
1573 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1575 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1576 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1577 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1578 p+=(ptrdiff_t) GetPixelChannels(image);
1582 if (LocaleCompare(stream_info->map,
"RGBA") == 0)
1584 p=GetAuthenticPixelQueue(image);
1585 if (p == (
const Quantum *) NULL)
1587 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1589 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1590 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1591 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1592 *q++=ScaleQuantumToChar(GetPixelAlpha(image,p));
1593 p+=(ptrdiff_t) GetPixelChannels(image);
1597 if (LocaleCompare(stream_info->map,
"RGBP") == 0)
1599 p=GetAuthenticPixelQueue(image);
1600 if (p == (
const Quantum *) NULL)
1602 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1604 *q++=ScaleQuantumToChar(GetPixelRed(image,p));
1605 *q++=ScaleQuantumToChar(GetPixelGreen(image,p));
1606 *q++=ScaleQuantumToChar(GetPixelBlue(image,p));
1607 *q++=ScaleQuantumToChar((Quantum) 0);
1608 p+=(ptrdiff_t) GetPixelChannels(image);
1612 p=GetAuthenticPixelQueue(image);
1613 if (p == (
const Quantum *) NULL)
1615 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1617 for (i=0; i < (ssize_t) length; i++)
1620 switch (quantum_map[i])
1625 *q=ScaleQuantumToChar(GetPixelRed(image,p));
1629 case MagentaQuantum:
1631 *q=ScaleQuantumToChar(GetPixelGreen(image,p));
1637 *q=ScaleQuantumToChar(GetPixelBlue(image,p));
1642 *q=ScaleQuantumToChar(GetPixelAlpha(image,p));
1645 case OpacityQuantum:
1647 *q=ScaleQuantumToChar(GetPixelOpacity(image,p));
1652 if (image->colorspace == CMYKColorspace)
1653 *q=ScaleQuantumToChar(GetPixelBlack(image,p));
1658 *q=ScaleQuantumToChar(ClampToQuantum(GetPixelIntensity(image,p)));
1666 p+=(ptrdiff_t) GetPixelChannels(image);
1675 q=(
double *) stream_info->pixels;
1676 if (LocaleCompare(stream_info->map,
"BGR") == 0)
1678 p=GetAuthenticPixelQueue(image);
1679 if (p == (
const Quantum *) NULL)
1681 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1683 *q++=(double) ((QuantumScale*(
double) GetPixelBlue(image,p))*
1684 quantum_info->scale+quantum_info->minimum);
1685 *q++=(double) ((QuantumScale*(
double) GetPixelGreen(image,p))*
1686 quantum_info->scale+quantum_info->minimum);
1687 *q++=(double) ((QuantumScale*(
double) GetPixelRed(image,p))*
1688 quantum_info->scale+quantum_info->minimum);
1689 p+=(ptrdiff_t) GetPixelChannels(image);
1693 if (LocaleCompare(stream_info->map,
"BGRA") == 0)
1695 p=GetAuthenticPixelQueue(image);
1696 if (p == (
const Quantum *) NULL)
1698 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1700 *q++=(double) ((QuantumScale*(
double) GetPixelBlue(image,p))*
1701 quantum_info->scale+quantum_info->minimum);
1702 *q++=(double) ((QuantumScale*(
double) GetPixelGreen(image,p))*
1703 quantum_info->scale+quantum_info->minimum);
1704 *q++=(double) ((QuantumScale*(
double) GetPixelRed(image,p))*
1705 quantum_info->scale+quantum_info->minimum);
1706 *q++=(double) ((QuantumScale*(
double) GetPixelAlpha(image,p))*
1707 quantum_info->scale+quantum_info->minimum);
1708 p+=(ptrdiff_t) GetPixelChannels(image);
1712 if (LocaleCompare(stream_info->map,
"BGRP") == 0)
1714 p=GetAuthenticPixelQueue(image);
1715 if (p == (
const Quantum *) NULL)
1717 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1719 *q++=(double) ((QuantumScale*(
double) GetPixelBlue(image,p))*
1720 quantum_info->scale+quantum_info->minimum);
1721 *q++=(double) ((QuantumScale*(
double) GetPixelGreen(image,p))*
1722 quantum_info->scale+quantum_info->minimum);
1723 *q++=(double) ((QuantumScale*(
double) GetPixelRed(image,p))*
1724 quantum_info->scale+quantum_info->minimum);
1726 p+=(ptrdiff_t) GetPixelChannels(image);
1730 if (LocaleCompare(stream_info->map,
"I") == 0)
1732 p=GetAuthenticPixelQueue(image);
1733 if (p == (
const Quantum *) NULL)
1735 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1737 *q++=(double) ((QuantumScale*(
double) GetPixelIntensity(image,p))*
1738 quantum_info->scale+quantum_info->minimum);
1739 p+=(ptrdiff_t) GetPixelChannels(image);
1743 if (LocaleCompare(stream_info->map,
"RGB") == 0)
1745 p=GetAuthenticPixelQueue(image);
1746 if (p == (
const Quantum *) NULL)
1748 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1750 *q++=(double) ((QuantumScale*(
double) GetPixelRed(image,p))*
1751 quantum_info->scale+quantum_info->minimum);
1752 *q++=(double) ((QuantumScale*(
double) GetPixelGreen(image,p))*
1753 quantum_info->scale+quantum_info->minimum);
1754 *q++=(double) ((QuantumScale*(
double) GetPixelBlue(image,p))*
1755 quantum_info->scale+quantum_info->minimum);
1756 p+=(ptrdiff_t) GetPixelChannels(image);
1760 if (LocaleCompare(stream_info->map,
"RGBA") == 0)
1762 p=GetAuthenticPixelQueue(image);
1763 if (p == (
const Quantum *) NULL)
1765 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1767 *q++=(double) ((QuantumScale*(
double) GetPixelRed(image,p))*
1768 quantum_info->scale+quantum_info->minimum);
1769 *q++=(double) ((QuantumScale*(
double) GetPixelGreen(image,p))*
1770 quantum_info->scale+quantum_info->minimum);
1771 *q++=(double) ((QuantumScale*(
double) GetPixelBlue(image,p))*
1772 quantum_info->scale+quantum_info->minimum);
1773 *q++=(double) ((QuantumScale*(
double) GetPixelAlpha(image,p))*
1774 quantum_info->scale+quantum_info->minimum);
1775 p+=(ptrdiff_t) GetPixelChannels(image);
1779 if (LocaleCompare(stream_info->map,
"RGBP") == 0)
1781 p=GetAuthenticPixelQueue(image);
1782 if (p == (
const Quantum *) NULL)
1784 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1786 *q++=(double) ((QuantumScale*(
double) GetPixelRed(image,p))*
1787 quantum_info->scale+quantum_info->minimum);
1788 *q++=(double) ((QuantumScale*(
double) GetPixelGreen(image,p))*
1789 quantum_info->scale+quantum_info->minimum);
1790 *q++=(double) ((QuantumScale*(
double) GetPixelBlue(image,p))*
1791 quantum_info->scale+quantum_info->minimum);
1793 p+=(ptrdiff_t) GetPixelChannels(image);
1797 p=GetAuthenticPixelQueue(image);
1798 if (p == (
const Quantum *) NULL)
1800 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1802 for (i=0; i < (ssize_t) length; i++)
1805 switch (quantum_map[i])
1810 *q=(double) ((QuantumScale*(
double) GetPixelRed(image,p))*
1811 quantum_info->scale+quantum_info->minimum);
1815 case MagentaQuantum:
1817 *q=(double) ((QuantumScale*(
double) GetPixelGreen(image,p))*
1818 quantum_info->scale+quantum_info->minimum);
1824 *q=(double) ((QuantumScale*(
double) GetPixelBlue(image,p))*
1825 quantum_info->scale+quantum_info->minimum);
1830 *q=(double) ((QuantumScale*(
double) GetPixelAlpha(image,p))*
1831 quantum_info->scale+quantum_info->minimum);
1834 case OpacityQuantum:
1836 *q=(double) ((QuantumScale*(
double) GetPixelOpacity(image,p))*
1837 quantum_info->scale+quantum_info->minimum);
1842 if (image->colorspace == CMYKColorspace)
1843 *q=(double) ((QuantumScale*(
double) GetPixelBlack(image,p))*
1844 quantum_info->scale+quantum_info->minimum);
1849 *q=(double) ((QuantumScale*(
double) GetPixelIntensity(image,p))*
1850 quantum_info->scale+quantum_info->minimum);
1858 p+=(ptrdiff_t) GetPixelChannels(image);
1867 q=(
float *) stream_info->pixels;
1868 if (LocaleCompare(stream_info->map,
"BGR") == 0)
1870 p=GetAuthenticPixelQueue(image);
1871 if (p == (
const Quantum *) NULL)
1873 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1875 *q++=(float) ((QuantumScale*(
double) GetPixelBlue(image,p))*
1876 quantum_info->scale+quantum_info->minimum);
1877 *q++=(float) ((QuantumScale*(
double) GetPixelGreen(image,p))*
1878 quantum_info->scale+quantum_info->minimum);
1879 *q++=(float) ((QuantumScale*(
double) GetPixelRed(image,p))*
1880 quantum_info->scale+quantum_info->minimum);
1881 p+=(ptrdiff_t) GetPixelChannels(image);
1885 if (LocaleCompare(stream_info->map,
"BGRA") == 0)
1887 p=GetAuthenticPixelQueue(image);
1888 if (p == (
const Quantum *) NULL)
1890 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1892 *q++=(float) ((QuantumScale*(
double) GetPixelBlue(image,p))*
1893 quantum_info->scale+quantum_info->minimum);
1894 *q++=(float) ((QuantumScale*(
double) GetPixelGreen(image,p))*
1895 quantum_info->scale+quantum_info->minimum);
1896 *q++=(float) ((QuantumScale*(
double) GetPixelRed(image,p))*
1897 quantum_info->scale+quantum_info->minimum);
1898 *q++=(float) ((QuantumScale*(
double) GetPixelAlpha(image,p))*
1899 quantum_info->scale+quantum_info->minimum);
1900 p+=(ptrdiff_t) GetPixelChannels(image);
1904 if (LocaleCompare(stream_info->map,
"BGRP") == 0)
1906 p=GetAuthenticPixelQueue(image);
1907 if (p == (
const Quantum *) NULL)
1909 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1911 *q++=(float) ((QuantumScale*(
double) GetPixelBlue(image,p))*
1912 quantum_info->scale+quantum_info->minimum);
1913 *q++=(float) ((QuantumScale*(
double) GetPixelGreen(image,p))*
1914 quantum_info->scale+quantum_info->minimum);
1915 *q++=(float) ((QuantumScale*(
double) GetPixelRed(image,p))*
1916 quantum_info->scale+quantum_info->minimum);
1918 p+=(ptrdiff_t) GetPixelChannels(image);
1922 if (LocaleCompare(stream_info->map,
"I") == 0)
1924 p=GetAuthenticPixelQueue(image);
1925 if (p == (
const Quantum *) NULL)
1927 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1929 *q++=(float) ((QuantumScale*(
double) GetPixelIntensity(image,p))*
1930 quantum_info->scale+quantum_info->minimum);
1931 p+=(ptrdiff_t) GetPixelChannels(image);
1935 if (LocaleCompare(stream_info->map,
"RGB") == 0)
1937 p=GetAuthenticPixelQueue(image);
1938 if (p == (
const Quantum *) NULL)
1940 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1942 *q++=(float) ((QuantumScale*(
double) GetPixelRed(image,p))*
1943 quantum_info->scale+quantum_info->minimum);
1944 *q++=(float) ((QuantumScale*(
double) GetPixelGreen(image,p))*
1945 quantum_info->scale+quantum_info->minimum);
1946 *q++=(float) ((QuantumScale*(
double) GetPixelBlue(image,p))*
1947 quantum_info->scale+quantum_info->minimum);
1948 p+=(ptrdiff_t) GetPixelChannels(image);
1952 if (LocaleCompare(stream_info->map,
"RGBA") == 0)
1954 p=GetAuthenticPixelQueue(image);
1955 if (p == (
const Quantum *) NULL)
1957 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1959 *q++=(float) ((QuantumScale*(
double) GetPixelRed(image,p))*
1960 quantum_info->scale+quantum_info->minimum);
1961 *q++=(float) ((QuantumScale*(
double) GetPixelGreen(image,p))*
1962 quantum_info->scale+quantum_info->minimum);
1963 *q++=(float) ((QuantumScale*(
double) GetPixelBlue(image,p))*
1964 quantum_info->scale+quantum_info->minimum);
1965 *q++=(float) ((QuantumScale*(
double) GetPixelAlpha(image,p))*
1966 quantum_info->scale+quantum_info->minimum);
1967 p+=(ptrdiff_t) GetPixelChannels(image);
1971 if (LocaleCompare(stream_info->map,
"RGBP") == 0)
1973 p=GetAuthenticPixelQueue(image);
1974 if (p == (
const Quantum *) NULL)
1976 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1978 *q++=(float) ((QuantumScale*(
double) GetPixelRed(image,p))*
1979 quantum_info->scale+quantum_info->minimum);
1980 *q++=(float) ((QuantumScale*(
double) GetPixelGreen(image,p))*
1981 quantum_info->scale+quantum_info->minimum);
1982 *q++=(float) ((QuantumScale*(
double) GetPixelBlue(image,p))*
1983 quantum_info->scale+quantum_info->minimum);
1985 p+=(ptrdiff_t) GetPixelChannels(image);
1989 p=GetAuthenticPixelQueue(image);
1990 if (p == (
const Quantum *) NULL)
1992 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
1994 for (i=0; i < (ssize_t) length; i++)
1997 switch (quantum_map[i])
2002 *q=(float) ((QuantumScale*(
double) GetPixelRed(image,p))*
2003 quantum_info->scale+quantum_info->minimum);
2007 case MagentaQuantum:
2009 *q=(float) ((QuantumScale*(
double) GetPixelGreen(image,p))*
2010 quantum_info->scale+quantum_info->minimum);
2016 *q=(float) ((QuantumScale*(
double) GetPixelBlue(image,p))*
2017 quantum_info->scale+quantum_info->minimum);
2022 *q=(float) ((QuantumScale*(
double) GetPixelAlpha(image,p))*
2023 quantum_info->scale+quantum_info->minimum);
2026 case OpacityQuantum:
2028 *q=(float) ((QuantumScale*(
double) GetPixelOpacity(image,p))*
2029 quantum_info->scale+quantum_info->minimum);
2034 if (image->colorspace == CMYKColorspace)
2035 *q=(float) ((QuantumScale*(
double) GetPixelBlack(image,p))*
2036 quantum_info->scale+quantum_info->minimum);
2041 *q=(float) ((QuantumScale*(
double) GetPixelIntensity(image,p))*
2042 quantum_info->scale+quantum_info->minimum);
2050 p+=(ptrdiff_t) GetPixelChannels(image);
2059 q=(
unsigned int *) stream_info->pixels;
2060 if (LocaleCompare(stream_info->map,
"BGR") == 0)
2062 p=GetAuthenticPixelQueue(image);
2063 if (p == (
const Quantum *) NULL)
2065 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2067 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2068 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2069 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2070 p+=(ptrdiff_t) GetPixelChannels(image);
2074 if (LocaleCompare(stream_info->map,
"BGRA") == 0)
2076 p=GetAuthenticPixelQueue(image);
2077 if (p == (
const Quantum *) NULL)
2079 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2081 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2082 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2083 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2084 *q++=ScaleQuantumToLong(GetPixelAlpha(image,p));
2085 p+=(ptrdiff_t) GetPixelChannels(image);
2089 if (LocaleCompare(stream_info->map,
"BGRP") == 0)
2091 p=GetAuthenticPixelQueue(image);
2092 if (p == (
const Quantum *) NULL)
2094 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2096 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2097 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2098 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2100 p+=(ptrdiff_t) GetPixelChannels(image);
2104 if (LocaleCompare(stream_info->map,
"I") == 0)
2106 p=GetAuthenticPixelQueue(image);
2107 if (p == (
const Quantum *) NULL)
2109 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2111 *q++=ScaleQuantumToLong(ClampToQuantum(GetPixelIntensity(image,p)));
2112 p+=(ptrdiff_t) GetPixelChannels(image);
2116 if (LocaleCompare(stream_info->map,
"RGB") == 0)
2118 p=GetAuthenticPixelQueue(image);
2119 if (p == (
const Quantum *) NULL)
2121 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2123 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2124 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2125 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2126 p+=(ptrdiff_t) GetPixelChannels(image);
2130 if (LocaleCompare(stream_info->map,
"RGBA") == 0)
2132 p=GetAuthenticPixelQueue(image);
2133 if (p == (
const Quantum *) NULL)
2135 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2137 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2138 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2139 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2140 *q++=ScaleQuantumToLong(GetPixelAlpha(image,p));
2141 p+=(ptrdiff_t) GetPixelChannels(image);
2145 if (LocaleCompare(stream_info->map,
"RGBP") == 0)
2147 p=GetAuthenticPixelQueue(image);
2148 if (p == (
const Quantum *) NULL)
2150 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2152 *q++=ScaleQuantumToLong(GetPixelRed(image,p));
2153 *q++=ScaleQuantumToLong(GetPixelGreen(image,p));
2154 *q++=ScaleQuantumToLong(GetPixelBlue(image,p));
2156 p+=(ptrdiff_t) GetPixelChannels(image);
2160 p=GetAuthenticPixelQueue(image);
2161 if (p == (
const Quantum *) NULL)
2163 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2165 for (i=0; i < (ssize_t) length; i++)
2168 switch (quantum_map[i])
2173 *q=ScaleQuantumToLong(GetPixelRed(image,p));
2177 case MagentaQuantum:
2179 *q=ScaleQuantumToLong(GetPixelGreen(image,p));
2185 *q=ScaleQuantumToLong(GetPixelBlue(image,p));
2190 *q=ScaleQuantumToLong(GetPixelAlpha(image,p));
2193 case OpacityQuantum:
2195 *q=ScaleQuantumToLong(GetPixelOpacity(image,p));
2200 if (image->colorspace == CMYKColorspace)
2201 *q=ScaleQuantumToLong(GetPixelBlack(image,p));
2206 *q=ScaleQuantumToLong(ClampToQuantum(GetPixelIntensity(image,p)));
2214 p+=(ptrdiff_t) GetPixelChannels(image);
2223 q=(MagickSizeType *) stream_info->pixels;
2224 if (LocaleCompare(stream_info->map,
"BGR") == 0)
2226 p=GetAuthenticPixelQueue(image);
2227 if (p == (
const Quantum *) NULL)
2229 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2231 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2232 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2233 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
2234 p+=(ptrdiff_t) GetPixelChannels(image);
2238 if (LocaleCompare(stream_info->map,
"BGRA") == 0)
2240 p=GetAuthenticPixelQueue(image);
2241 if (p == (
const Quantum *) NULL)
2243 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2245 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2246 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2247 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
2248 *q++=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
2249 p+=(ptrdiff_t) GetPixelChannels(image);
2253 if (LocaleCompare(stream_info->map,
"BGRP") == 0)
2255 p=GetAuthenticPixelQueue(image);
2256 if (p == (
const Quantum *) NULL)
2258 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2260 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2261 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2262 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
2264 p+=(ptrdiff_t) GetPixelChannels(image);
2268 if (LocaleCompare(stream_info->map,
"I") == 0)
2270 p=GetAuthenticPixelQueue(image);
2271 if (p == (
const Quantum *) NULL)
2273 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2275 *q++=ScaleQuantumToLongLong(ClampToQuantum(
2276 GetPixelIntensity(image,p)));
2277 p+=(ptrdiff_t) GetPixelChannels(image);
2281 if (LocaleCompare(stream_info->map,
"RGB") == 0)
2283 p=GetAuthenticPixelQueue(image);
2284 if (p == (
const Quantum *) NULL)
2286 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2288 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
2289 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2290 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2291 p+=(ptrdiff_t) GetPixelChannels(image);
2295 if (LocaleCompare(stream_info->map,
"RGBA") == 0)
2297 p=GetAuthenticPixelQueue(image);
2298 if (p == (
const Quantum *) NULL)
2300 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2302 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
2303 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2304 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2305 *q++=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
2306 p+=(ptrdiff_t) GetPixelChannels(image);
2310 if (LocaleCompare(stream_info->map,
"RGBP") == 0)
2312 p=GetAuthenticPixelQueue(image);
2313 if (p == (
const Quantum *) NULL)
2315 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2317 *q++=ScaleQuantumToLongLong(GetPixelRed(image,p));
2318 *q++=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2319 *q++=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2321 p+=(ptrdiff_t) GetPixelChannels(image);
2325 p=GetAuthenticPixelQueue(image);
2326 if (p == (
const Quantum *) NULL)
2328 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2330 for (i=0; i < (ssize_t) length; i++)
2333 switch (quantum_map[i])
2338 *q=ScaleQuantumToLongLong(GetPixelRed(image,p));
2342 case MagentaQuantum:
2344 *q=ScaleQuantumToLongLong(GetPixelGreen(image,p));
2350 *q=ScaleQuantumToLongLong(GetPixelBlue(image,p));
2355 *q=ScaleQuantumToLongLong(GetPixelAlpha(image,p));
2358 case OpacityQuantum:
2360 *q=ScaleQuantumToLongLong(GetPixelOpacity(image,p));
2365 if (image->colorspace == CMYKColorspace)
2366 *q=ScaleQuantumToLongLong(GetPixelBlack(image,p));
2371 *q=ScaleQuantumToLongLong(ClampToQuantum(
2372 GetPixelIntensity(image,p)));
2380 p+=(ptrdiff_t) GetPixelChannels(image);
2389 q=(Quantum *) stream_info->pixels;
2390 if (LocaleCompare(stream_info->map,
"BGR") == 0)
2392 p=GetAuthenticPixelQueue(image);
2393 if (p == (
const Quantum *) NULL)
2395 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2397 *q++=GetPixelBlue(image,p);
2398 *q++=GetPixelGreen(image,p);
2399 *q++=GetPixelRed(image,p);
2400 p+=(ptrdiff_t) GetPixelChannels(image);
2404 if (LocaleCompare(stream_info->map,
"BGRA") == 0)
2406 p=GetAuthenticPixelQueue(image);
2407 if (p == (
const Quantum *) NULL)
2409 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2411 *q++=GetPixelBlue(image,p);
2412 *q++=GetPixelGreen(image,p);
2413 *q++=GetPixelRed(image,p);
2414 *q++=GetPixelAlpha(image,p);
2415 p+=(ptrdiff_t) GetPixelChannels(image);
2419 if (LocaleCompare(stream_info->map,
"BGRP") == 0)
2421 p=GetAuthenticPixelQueue(image);
2422 if (p == (
const Quantum *) NULL)
2424 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2426 *q++=GetPixelBlue(image,p);
2427 *q++=GetPixelGreen(image,p);
2428 *q++=GetPixelRed(image,p);
2430 p+=(ptrdiff_t) GetPixelChannels(image);
2434 if (LocaleCompare(stream_info->map,
"I") == 0)
2436 p=GetAuthenticPixelQueue(image);
2437 if (p == (
const Quantum *) NULL)
2439 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2441 *q++=ClampToQuantum(GetPixelIntensity(image,p));
2442 p+=(ptrdiff_t) GetPixelChannels(image);
2446 if (LocaleCompare(stream_info->map,
"RGB") == 0)
2448 p=GetAuthenticPixelQueue(image);
2449 if (p == (
const Quantum *) NULL)
2451 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2453 *q++=GetPixelRed(image,p);
2454 *q++=GetPixelGreen(image,p);
2455 *q++=GetPixelBlue(image,p);
2456 p+=(ptrdiff_t) GetPixelChannels(image);
2460 if (LocaleCompare(stream_info->map,
"RGBA") == 0)
2462 p=GetAuthenticPixelQueue(image);
2463 if (p == (
const Quantum *) NULL)
2465 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2467 *q++=GetPixelRed(image,p);
2468 *q++=GetPixelGreen(image,p);
2469 *q++=GetPixelBlue(image,p);
2470 *q++=GetPixelAlpha(image,p);
2471 p+=(ptrdiff_t) GetPixelChannels(image);
2475 if (LocaleCompare(stream_info->map,
"RGBP") == 0)
2477 p=GetAuthenticPixelQueue(image);
2478 if (p == (
const Quantum *) NULL)
2480 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2482 *q++=GetPixelRed(image,p);
2483 *q++=GetPixelGreen(image,p);
2484 *q++=GetPixelBlue(image,p);
2486 p+=(ptrdiff_t) GetPixelChannels(image);
2490 p=GetAuthenticPixelQueue(image);
2491 if (p == (
const Quantum *) NULL)
2493 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2495 for (i=0; i < (ssize_t) length; i++)
2498 switch (quantum_map[i])
2503 *q=GetPixelRed(image,p);
2507 case MagentaQuantum:
2509 *q=GetPixelGreen(image,p);
2515 *q=GetPixelBlue(image,p);
2520 *q=GetPixelAlpha(image,p);
2523 case OpacityQuantum:
2525 *q=GetPixelOpacity(image,p);
2530 if (image->colorspace == CMYKColorspace)
2531 *q=GetPixelBlack(image,p);
2536 *q=ClampToQuantum(GetPixelIntensity(image,p));
2544 p+=(ptrdiff_t) GetPixelChannels(image);
2553 q=(
unsigned short *) stream_info->pixels;
2554 if (LocaleCompare(stream_info->map,
"BGR") == 0)
2556 p=GetAuthenticPixelQueue(image);
2557 if (p == (
const Quantum *) NULL)
2559 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2561 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2562 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2563 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2564 p+=(ptrdiff_t) GetPixelChannels(image);
2568 if (LocaleCompare(stream_info->map,
"BGRA") == 0)
2570 p=GetAuthenticPixelQueue(image);
2571 if (p == (
const Quantum *) NULL)
2573 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2575 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2576 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2577 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2578 *q++=ScaleQuantumToShort(GetPixelAlpha(image,p));
2579 p+=(ptrdiff_t) GetPixelChannels(image);
2583 if (LocaleCompare(stream_info->map,
"BGRP") == 0)
2585 p=GetAuthenticPixelQueue(image);
2586 if (p == (
const Quantum *) NULL)
2588 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2590 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2591 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2592 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2594 p+=(ptrdiff_t) GetPixelChannels(image);
2598 if (LocaleCompare(stream_info->map,
"I") == 0)
2600 p=GetAuthenticPixelQueue(image);
2601 if (p == (
const Quantum *) NULL)
2603 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2605 *q++=ScaleQuantumToShort(ClampToQuantum(
2606 GetPixelIntensity(image,p)));
2607 p+=(ptrdiff_t) GetPixelChannels(image);
2611 if (LocaleCompare(stream_info->map,
"RGB") == 0)
2613 p=GetAuthenticPixelQueue(image);
2614 if (p == (
const Quantum *) NULL)
2616 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2618 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2619 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2620 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2621 p+=(ptrdiff_t) GetPixelChannels(image);
2625 if (LocaleCompare(stream_info->map,
"RGBA") == 0)
2627 p=GetAuthenticPixelQueue(image);
2628 if (p == (
const Quantum *) NULL)
2630 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2632 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2633 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2634 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2635 *q++=ScaleQuantumToShort(GetPixelAlpha(image,p));
2636 p+=(ptrdiff_t) GetPixelChannels(image);
2640 if (LocaleCompare(stream_info->map,
"RGBP") == 0)
2642 p=GetAuthenticPixelQueue(image);
2643 if (p == (
const Quantum *) NULL)
2645 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2647 *q++=ScaleQuantumToShort(GetPixelRed(image,p));
2648 *q++=ScaleQuantumToShort(GetPixelGreen(image,p));
2649 *q++=ScaleQuantumToShort(GetPixelBlue(image,p));
2651 p+=(ptrdiff_t) GetPixelChannels(image);
2655 p=GetAuthenticPixelQueue(image);
2656 if (p == (
const Quantum *) NULL)
2658 for (x=0; x < (ssize_t) GetImageExtent(image); x++)
2660 for (i=0; i < (ssize_t) length; i++)
2663 switch (quantum_map[i])
2668 *q=ScaleQuantumToShort(GetPixelRed(image,p));
2672 case MagentaQuantum:
2674 *q=ScaleQuantumToShort(GetPixelGreen(image,p));
2680 *q=ScaleQuantumToShort(GetPixelBlue(image,p));
2685 *q=ScaleQuantumToShort(GetPixelAlpha(image,p));
2688 case OpacityQuantum:
2690 *q=ScaleQuantumToShort(GetPixelOpacity(image,p));
2695 if (image->colorspace == CMYKColorspace)
2696 *q=ScaleQuantumToShort(GetPixelBlack(image,p));
2701 *q=ScaleQuantumToShort(ClampToQuantum(
2702 GetPixelIntensity(image,p)));
2710 p+=(ptrdiff_t) GetPixelChannels(image);
2716 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2717 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
2718 "UnrecognizedPixelMap",
"`%s'",stream_info->map);
2722 quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
2752static MagickBooleanType SyncAuthenticPixelsStream(
Image *image,
2764 assert(image != (
Image *) NULL);
2765 assert(image->signature == MagickCoreSignature);
2766 if (IsEventLogging() != MagickFalse)
2767 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
2769 assert(cache_info->signature == MagickCoreSignature);
2770 stream_handler=GetBlobStreamHandler(image);
2771 if (stream_handler == (StreamHandler) NULL)
2773 (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
2774 "NoStreamHandlerIsDefined",
"`%s'",image->filename);
2775 return(MagickFalse);
2777 length=stream_handler(image,cache_info->pixels,(
size_t) cache_info->columns);
2778 return(length == cache_info->columns ? MagickTrue : MagickFalse);
2809MagickExport MagickBooleanType WriteStream(
const ImageInfo *image_info,
2818 assert(image_info != (
ImageInfo *) NULL);
2819 assert(image_info->signature == MagickCoreSignature);
2820 if (IsEventLogging() != MagickFalse)
2821 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
2822 image_info->filename);
2823 assert(image != (
Image *) NULL);
2824 assert(image->signature == MagickCoreSignature);
2825 write_info=CloneImageInfo(image_info);
2826 *write_info->magick=
'\0';
2827 write_info->stream=stream;
2828 status=WriteImage(write_info,image,exception);
2829 write_info=DestroyImageInfo(write_info);