various kinds of color plane order of RGB raw image
Posted: 2008-11-27T04:30:10-07:00
Could you adopt the attached patch to rgb.c as formal
functionality in the next update, which supports various
kinds of color plane order of RGB raw image?
This work was motivated by a request to have G.B,R order
RGB raw file.
functionality in the next update, which supports various
kinds of color plane order of RGB raw image?
This work was motivated by a request to have G.B,R order
RGB raw file.
Code: Select all
--- ImageMagick-6.4.6/coders/rgb.c.gbr 2008-11-22 11:36:53.000000000 +0900
+++ ImageMagick-6.4.6/coders/rgb.c 2008-11-25 15:04:16.000000000 +0900
@@ -120,11 +120,15 @@
register long
i,
+ j,
x;
register PixelPacket
*q;
+ Quantum
+ qx[3];
+
ssize_t
count;
@@ -134,6 +138,15 @@
unsigned char
*pixels;
+ QuantumType
+ quantum_types[4];
+
+ char
+ sfx[] = {0, 0};
+
+ int
+ channels = 3;
+
/*
Open image file.
*/
@@ -178,11 +191,13 @@
{
quantum_type=RGBAQuantum;
image->matte=MagickTrue;
+ channels=4;
}
if (LocaleCompare(image_info->magick,"RGBO") == 0)
{
quantum_type=RGBOQuantum;
image->matte=MagickTrue;
+ channels=4;
}
if (image_info->number_scenes != 0)
while (image->scene < image_info->scene)
@@ -199,6 +214,17 @@
break;
}
}
+ for (i=0; i < channels; i++)
+ {
+ switch(image_info->magick[i])
+ {
+ case 'R': quantum_types[i]=RedQuantum; break;
+ case 'G': quantum_types[i]=GreenQuantum; break;
+ case 'B': quantum_types[i]=BlueQuantum; break;
+ case 'A': quantum_types[i]=AlphaQuantum; break;
+ case 'O': quantum_types[i]=OpacityQuantum; break;
+ }
+ }
count=0;
length=0;
scene=0;
@@ -247,9 +273,17 @@
break;
for (x=0; x < (long) image->columns; x++)
{
- q->red=p->red;
- q->green=p->green;
- q->blue=p->blue;
+ qx[0]=p->red;
+ qx[1]=p->green;
+ qx[2]=p->blue;
+ for (i=0; i < 3; i++)
+ switch(quantum_types[i])
+ {
+ case RedQuantum: q->red=qx[i]; break;
+ case GreenQuantum: q->green=qx[i]; break;
+ case BlueQuantum: q->blue=qx[i]; break;
+ default: break;
+ }
if (image->matte != MagickFalse)
q->opacity=p->opacity;
p++;
@@ -272,36 +306,26 @@
}
case LineInterlace:
{
- static QuantumType
- quantum_types[4] =
- {
- RedQuantum,
- GreenQuantum,
- BlueQuantum,
- OpacityQuantum
- };
-
/*
Line interlacing: RRR...GGG...BBB...RRR...GGG...BBB...
*/
if (scene == 0)
{
- length=GetQuantumExtent(canvas_image,quantum_info,RedQuantum);
+ length=GetQuantumExtent(canvas_image,quantum_info,quantum_types[0]);
count=ReadBlob(image,length,pixels);
if (count != (ssize_t) length)
break;
}
for (y=0; y < (long) image->extract_info.height; y++)
{
- for (i=0; i < (image->matte != MagickFalse ? 4 : 3); i++)
+ for (i=0; i < channels; i++)
{
- quantum_type=quantum_types[i];
q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
exception);
if (q == (PixelPacket *) NULL)
break;
length=ImportQuantumPixels(canvas_image,(ViewInfo *) NULL,
- quantum_info,quantum_type,pixels,exception);
+ quantum_info,quantum_types[i],pixels,exception);
if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
break;
if (((y-image->extract_info.y) >= 0) &&
@@ -314,19 +338,16 @@
if ((p == (const PixelPacket *) NULL) ||
(q == (PixelPacket *) NULL))
break;
- for (x=0; x < (long) image->columns; x++)
- {
- switch (quantum_type)
+ if (i == (channels - 1))
+ for (x=0; x < (long) image->columns; x++)
{
- case RedQuantum: q->red=p->red; break;
- case GreenQuantum: q->green=p->green; break;
- case BlueQuantum: q->blue=p->blue; break;
- case OpacityQuantum: q->opacity=p->opacity; break;
- default: break;
+ q->red=p->red;
+ q->green=p->green;
+ q->blue=p->blue;
+ q->opacity=p->opacity;
+ p++;
+ q++;
}
- p++;
- q++;
- }
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
}
@@ -350,171 +371,61 @@
*/
if (scene == 0)
{
- length=GetQuantumExtent(canvas_image,quantum_info,RedQuantum);
+ length=GetQuantumExtent(canvas_image,quantum_info,quantum_types[0]);
count=ReadBlob(image,length,pixels);
if (count != (ssize_t) length)
break;
}
- for (y=0; y < (long) image->extract_info.height; y++)
+ for (i=0; i < channels; i++)
{
- q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
- exception);
- if (q == (PixelPacket *) NULL)
- break;
- length=ImportQuantumPixels(canvas_image,(ViewInfo *) NULL,
- quantum_info,RedQuantum,pixels,exception);
- if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
- break;
- if (((y-image->extract_info.y) >= 0) &&
- ((y-image->extract_info.y) < (long) image->rows))
- {
- p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
- canvas_image->columns,1,exception);
- q=GetAuthenticPixels(image,0,y-image->extract_info.y,
- image->columns,1,exception);
- if ((p == (const PixelPacket *) NULL) ||
- (q == (PixelPacket *) NULL))
- break;
- for (x=0; x < (long) image->columns; x++)
- {
- q->red=p->red;
- p++;
- q++;
- }
- if (SyncAuthenticPixels(image,exception) == MagickFalse)
- break;
- }
- count=ReadBlob(image,length,pixels);
- if (count != (ssize_t) length)
- break;
- }
- if (image->previous == (Image *) NULL)
+ for (y=0; y < (long) image->extract_info.height; y++)
{
- status=SetImageProgress(image,LoadImageTag,1,5);
- if (status == MagickFalse)
+ q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
+ exception);
+ if (q == (PixelPacket *) NULL)
break;
- }
- for (y=0; y < (long) image->extract_info.height; y++)
- {
- q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
- exception);
- if (q == (PixelPacket *) NULL)
- break;
- length=ImportQuantumPixels(canvas_image,(ViewInfo *) NULL,
- quantum_info,GreenQuantum,pixels,exception);
- if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
- break;
- if (((y-image->extract_info.y) >= 0) &&
- ((y-image->extract_info.y) < (long) image->rows))
- {
- p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
- canvas_image->columns,1,exception);
- q=GetAuthenticPixels(image,0,y-image->extract_info.y,
- image->columns,1,exception);
- if ((p == (const PixelPacket *) NULL) ||
- (q == (PixelPacket *) NULL))
- break;
- for (x=0; x < (long) image->columns; x++)
- {
- q->green=p->green;
- p++;
- q++;
- }
- if (SyncAuthenticPixels(image,exception) == MagickFalse)
- break;
- }
- count=ReadBlob(image,length,pixels);
- if (count != (ssize_t) length)
- break;
- }
- if (image->previous == (Image *) NULL)
- {
- status=SetImageProgress(image,LoadImageTag,2,5);
- if (status == MagickFalse)
+ length=ImportQuantumPixels(canvas_image,(ViewInfo *) NULL,
+ quantum_info,quantum_types[i],pixels,exception);
+ if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
break;
- }
- for (y=0; y < (long) image->extract_info.height; y++)
- {
- q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
- exception);
- if (q == (PixelPacket *) NULL)
- break;
- length=ImportQuantumPixels(canvas_image,(ViewInfo *) NULL,
- quantum_info,BlueQuantum,pixels,exception);
- if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
- break;
- if (((y-image->extract_info.y) >= 0) &&
- ((y-image->extract_info.y) < (long) image->rows))
- {
- p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
- canvas_image->columns,1,exception);
- q=GetAuthenticPixels(image,0,y-image->extract_info.y,
- image->columns,1,exception);
- if ((p == (const PixelPacket *) NULL) ||
- (q == (PixelPacket *) NULL))
- break;
- for (x=0; x < (long) image->columns; x++)
+ if (((y-image->extract_info.y) >= 0) &&
+ ((y-image->extract_info.y) < (long) image->rows))
{
- q->blue=p->blue;
- p++;
- q++;
- }
- if (SyncAuthenticPixels(image,exception) == MagickFalse)
- break;
- }
- count=ReadBlob(image,length,pixels);
- if (count != (ssize_t) length)
- break;
- }
- if (image->previous == (Image *) NULL)
- {
- status=SetImageProgress(image,LoadImageTag,3,5);
- if (status == MagickFalse)
- break;
- }
- if (image->matte != MagickFalse)
- {
- for (y=0; y < (long) image->extract_info.height; y++)
- {
- q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
- exception);
- if (q == (PixelPacket *) NULL)
- break;
- length=ImportQuantumPixels(canvas_image,(ViewInfo *) NULL,
- quantum_info,AlphaQuantum,pixels,exception);
- if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
- break;
- if (((y-image->extract_info.y) >= 0) &&
- ((y-image->extract_info.y) < (long) image->rows))
+ p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
+ canvas_image->columns,1,exception);
+ q=GetAuthenticPixels(image,0,y-image->extract_info.y,
+ image->columns,1,exception);
+ if ((p == (const PixelPacket *) NULL) ||
+ (q == (PixelPacket *) NULL))
+ break;
+ for (x=0; x < (long) image->columns; x++)
{
- p=GetVirtualPixels(canvas_image,
- canvas_image->extract_info.x,0,canvas_image->columns,1,
- exception);
- q=GetAuthenticPixels(image,0,y-image->extract_info.y,
- image->columns,1,exception);
- if ((p == (const PixelPacket *) NULL) ||
- (q == (PixelPacket *) NULL))
- break;
- for (x=0; x < (long) image->columns; x++)
+ switch(quantum_types[i])
{
- q->opacity=p->opacity;
- p++;
- q++;
+ case RedQuantum: q->red=p->red; break;
+ case GreenQuantum: q->green=p->green; break;
+ case BlueQuantum: q->blue=p->blue; break;
+ case OpacityQuantum:
+ case AlphaQuantum: q->opacity=p->opacity; break;
+ default: break;
}
- if (SyncAuthenticPixels(image,exception) == MagickFalse)
- break;
+ p++;
+ q++;
}
- count=ReadBlob(image,length,pixels);
- if (count != (ssize_t) length)
- break;
- }
- if (image->previous == (Image *) NULL)
- {
- status=SetImageProgress(image,LoadImageTag,4,5);
- if (status == MagickFalse)
+ if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
}
+ count=ReadBlob(image,length,pixels);
+ if (count != (ssize_t) length)
+ break;
}
+ if (image->previous == (Image *) NULL)
+ {
+ status=SetImageProgress(image,LoadImageTag,(i+1),5);
+ if (status == MagickFalse)
+ break;
+ }
+ }
if (image->previous == (Image *) NULL)
{
status=SetImageProgress(image,LoadImageTag,5,5);
@@ -528,256 +439,87 @@
/*
Partition interlacing: RRRRRR..., GGGGGG..., BBBBBB...
*/
- AppendImageFormat("R",image->filename);
- status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
- if (status == MagickFalse)
- {
- canvas_image=DestroyImageList(canvas_image);
- image=DestroyImageList(image);
- return((Image *) NULL);
- }
- for (i=0; i < image->offset; i++)
- if (ReadBlobByte(image) == EOF)
- {
- ThrowFileException(exception,CorruptImageError,
- "UnexpectedEndOfFile",image->filename);
- break;
- }
- length=GetQuantumExtent(canvas_image,quantum_info,RedQuantum);
- for (i=0; i < (long) scene; i++)
- for (y=0; y < (long) image->extract_info.height; y++)
- if (ReadBlob(image,length,pixels) != (ssize_t) length)
- {
- ThrowFileException(exception,CorruptImageError,
- "UnexpectedEndOfFile",image->filename);
- break;
- }
- count=ReadBlob(image,length,pixels);
- if (count != (ssize_t) length)
- break;
- for (y=0; y < (long) image->extract_info.height; y++)
- {
- q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
- exception);
- if (q == (PixelPacket *) NULL)
- break;
- length=ImportQuantumPixels(canvas_image,(ViewInfo *) NULL,
- quantum_info,RedQuantum,pixels,exception);
- if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
- break;
- if (((y-image->extract_info.y) >= 0) &&
- ((y-image->extract_info.y) < (long) image->rows))
- {
- p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
- canvas_image->columns,1,exception);
- q=GetAuthenticPixels(image,0,y-image->extract_info.y,
- image->columns,1,exception);
- if ((p == (const PixelPacket *) NULL) ||
- (q == (PixelPacket *) NULL))
- break;
- for (x=0; x < (long) image->columns; x++)
- {
- q->red=p->red;
- p++;
- q++;
- }
- if (SyncAuthenticPixels(image,exception) == MagickFalse)
- break;
- }
- count=ReadBlob(image,length,pixels);
- if (count != (ssize_t) length)
- break;
- }
- if (image->previous == (Image *) NULL)
- {
- status=SetImageProgress(image,LoadImageTag,1,5);
- if (status == MagickFalse)
- break;
- }
- (void) CloseBlob(image);
- AppendImageFormat("G",image->filename);
- status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
- if (status == MagickFalse)
- {
- canvas_image=DestroyImageList(canvas_image);
- image=DestroyImageList(image);
- return((Image *) NULL);
- }
- length=GetQuantumExtent(canvas_image,quantum_info,GreenQuantum);
- for (i=0; i < (long) scene; i++)
- for (y=0; y < (long) image->extract_info.height; y++)
- if (ReadBlob(image,length,pixels) != (ssize_t) length)
- {
- ThrowFileException(exception,CorruptImageError,
- "UnexpectedEndOfFile",image->filename);
- break;
- }
- count=ReadBlob(image,length,pixels);
- if (count != (ssize_t) length)
- break;
- for (y=0; y < (long) image->extract_info.height; y++)
+ for(i=0; i < channels; i++)
{
- q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
- exception);
- if (q == (PixelPacket *) NULL)
- break;
- length=ImportQuantumPixels(canvas_image,(ViewInfo *) NULL,
- quantum_info,GreenQuantum,pixels,exception);
- if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
- break;
- if (((y-image->extract_info.y) >= 0) &&
- ((y-image->extract_info.y) < (long) image->rows))
- {
- p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
- canvas_image->columns,1,exception);
- q=GetAuthenticPixels(image,0,y-image->extract_info.y,
- image->columns,1,exception);
- if ((p == (const PixelPacket *) NULL) ||
- (q == (PixelPacket *) NULL))
- break;
- for (x=0; x < (long) image->columns; x++)
- {
- q->green=p->green;
- p++;
- q++;
- }
- if (SyncAuthenticPixels(image,exception) == MagickFalse)
- break;
- }
- count=ReadBlob(image,length,pixels);
- if (count != (ssize_t) length)
- break;
- }
- if (image->previous == (Image *) NULL)
- {
- status=SetImageProgress(image,LoadImageTag,2,5);
- if (status == MagickFalse)
- break;
- }
- (void) CloseBlob(image);
- AppendImageFormat("B",image->filename);
- status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
- if (status == MagickFalse)
- {
- canvas_image=DestroyImageList(canvas_image);
- image=DestroyImageList(image);
- return((Image *) NULL);
- }
- length=GetQuantumExtent(canvas_image,quantum_info,BlueQuantum);
- for (i=0; i < (long) scene; i++)
- for (y=0; y < (long) image->extract_info.height; y++)
- if (ReadBlob(image,length,pixels) != (ssize_t) length)
- {
- ThrowFileException(exception,CorruptImageError,
- "UnexpectedEndOfFile",image->filename);
- break;
- }
- count=ReadBlob(image,length,pixels);
- if (count != (ssize_t) length)
- break;
- for (y=0; y < (long) image->extract_info.height; y++)
- {
- q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
- exception);
- if (q == (PixelPacket *) NULL)
- break;
- length=ImportQuantumPixels(canvas_image,(ViewInfo *) NULL,
- quantum_info,BlueQuantum,pixels,exception);
- if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
- break;
- if (((y-image->extract_info.y) >= 0) &&
- ((y-image->extract_info.y) < (long) image->rows))
- {
- p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
- canvas_image->columns,1,exception);
- q=GetAuthenticPixels(image,0,y-image->extract_info.y,
- image->columns,1,exception);
- if ((p == (const PixelPacket *) NULL) ||
- (q == (PixelPacket *) NULL))
- break;
- for (x=0; x < (long) image->columns; x++)
- {
- q->blue=p->blue;
- p++;
- q++;
- }
- if (SyncAuthenticPixels(image,exception) == MagickFalse)
- break;
- }
+ sfx[0]=image_info->magick[i];
+ AppendImageFormat(sfx,image->filename);
+ status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
+ if (status == MagickFalse)
+ {
+ canvas_image=DestroyImageList(canvas_image);
+ image=DestroyImageList(image);
+ return((Image *) NULL);
+ }
+ if (i == 0)
+ for (j=0; j < image->offset; j++)
+ if (ReadBlobByte(image) == EOF)
+ {
+ ThrowFileException(exception,CorruptImageError,
+ "UnexpectedEndOfFile",image->filename);
+ break;
+ }
+ length=GetQuantumExtent(canvas_image,quantum_info,quantum_types[i]);
+ for (j=0; j < (long) scene; j++)
+ for (y=0; y < (long) image->extract_info.height; y++)
+ if (ReadBlob(image,length,pixels) != (ssize_t) length)
+ {
+ ThrowFileException(exception,CorruptImageError,
+ "UnexpectedEndOfFile",image->filename);
+ break;
+ }
count=ReadBlob(image,length,pixels);
if (count != (ssize_t) length)
break;
- }
- if (image->previous == (Image *) NULL)
+ for (y=0; y < (long) image->extract_info.height; y++)
{
- status=SetImageProgress(image,LoadImageTag,3,5);
- if (status == MagickFalse)
+ q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
+ exception);
+ if (q == (PixelPacket *) NULL)
break;
- }
- if (image->matte != MagickFalse)
- {
- (void) CloseBlob(image);
- AppendImageFormat("A",image->filename);
- status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
- if (status == MagickFalse)
+ length=ImportQuantumPixels(canvas_image,(ViewInfo *) NULL,
+ quantum_info,quantum_types[i],pixels,exception);
+ if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
+ break;
+ if (((y-image->extract_info.y) >= 0) &&
+ ((y-image->extract_info.y) < (long) image->rows))
{
- canvas_image=DestroyImageList(canvas_image);
- image=DestroyImageList(image);
- return((Image *) NULL);
- }
- length=GetQuantumExtent(canvas_image,quantum_info,AlphaQuantum);
- for (i=0; i < (long) scene; i++)
- for (y=0; y < (long) image->extract_info.height; y++)
- if (ReadBlob(image,length,pixels) != (ssize_t) length)
+ p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
+ canvas_image->columns,1,exception);
+ q=GetAuthenticPixels(image,0,y-image->extract_info.y,
+ image->columns,1,exception);
+ if ((p == (const PixelPacket *) NULL) ||
+ (q == (PixelPacket *) NULL))
+ break;
+ for (x=0; x < (long) image->columns; x++)
+ {
+ switch(quantum_types[i])
{
- ThrowFileException(exception,CorruptImageError,
- "UnexpectedEndOfFile",image->filename);
- break;
+ case RedQuantum: q->red=p->red; break;
+ case GreenQuantum: q->green=p->green; break;
+ case BlueQuantum: q->blue=p->blue; break;
+ case OpacityQuantum:
+ case AlphaQuantum: q->opacity=p->opacity; break;
+ default: break;
}
+ p++;
+ q++;
+ }
+ if (SyncAuthenticPixels(image,exception) == MagickFalse)
+ break;
+ }
count=ReadBlob(image,length,pixels);
if (count != (ssize_t) length)
break;
- for (y=0; y < (long) image->extract_info.height; y++)
+ }
+ if (image->previous == (Image *) NULL)
{
- q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
- exception);
- if (q == (PixelPacket *) NULL)
- break;
- length=ImportQuantumPixels(canvas_image,(ViewInfo *) NULL,
- quantum_info,BlueQuantum,pixels,exception);
- if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
- break;
- if (((y-image->extract_info.y) >= 0) &&
- ((y-image->extract_info.y) < (long) image->rows))
- {
- p=GetVirtualPixels(canvas_image,
- canvas_image->extract_info.x,0,canvas_image->columns,1,
- exception);
- q=GetAuthenticPixels(image,0,y-image->extract_info.y,
- image->columns,1,exception);
- if ((p == (const PixelPacket *) NULL) ||
- (q == (PixelPacket *) NULL))
- break;
- for (x=0; x < (long) image->columns; x++)
- {
- q->opacity=p->opacity;
- p++;
- q++;
- }
- if (SyncAuthenticPixels(image,exception) == MagickFalse)
- break;
- }
- count=ReadBlob(image,length,pixels);
- if (count != (ssize_t) length)
+ status=SetImageProgress(image,LoadImageTag,(i+1),5);
+ if (status == MagickFalse)
break;
}
- if (image->previous == (Image *) NULL)
- {
- status=SetImageProgress(image,LoadImageTag,4,5);
- if (status == MagickFalse)
- break;
- }
- }
+ if(i != (channels-1))
+ (void) CloseBlob(image);
+ }
if (image->previous == (Image *) NULL)
{
status=SetImageProgress(image,LoadImageTag,5,5);
@@ -857,6 +599,51 @@
entry->description=ConstantString("Raw red, green, and blue samples");
entry->module=ConstantString("RGB");
(void) RegisterMagickInfo(entry);
+ entry=SetMagickInfo("RBG");
+ entry->decoder=(DecodeImageHandler *) ReadRGBImage;
+ entry->encoder=(EncodeImageHandler *) WriteRGBImage;
+ entry->raw=MagickTrue;
+ entry->endian_support=MagickTrue;
+ entry->format_type=ExplicitFormatType;
+ entry->description=ConstantString("Raw red, blue, and green samples");
+ entry->module=ConstantString("RGB");
+ (void) RegisterMagickInfo(entry);
+ entry=SetMagickInfo("GRB");
+ entry->decoder=(DecodeImageHandler *) ReadRGBImage;
+ entry->encoder=(EncodeImageHandler *) WriteRGBImage;
+ entry->raw=MagickTrue;
+ entry->endian_support=MagickTrue;
+ entry->format_type=ExplicitFormatType;
+ entry->description=ConstantString("Raw green, red, and blue samples");
+ entry->module=ConstantString("RGB");
+ (void) RegisterMagickInfo(entry);
+ entry=SetMagickInfo("GBR");
+ entry->decoder=(DecodeImageHandler *) ReadRGBImage;
+ entry->encoder=(EncodeImageHandler *) WriteRGBImage;
+ entry->raw=MagickTrue;
+ entry->endian_support=MagickTrue;
+ entry->format_type=ExplicitFormatType;
+ entry->description=ConstantString("Raw green, blue, and red samples");
+ entry->module=ConstantString("RGB");
+ (void) RegisterMagickInfo(entry);
+ entry=SetMagickInfo("BRG");
+ entry->decoder=(DecodeImageHandler *) ReadRGBImage;
+ entry->encoder=(EncodeImageHandler *) WriteRGBImage;
+ entry->raw=MagickTrue;
+ entry->endian_support=MagickTrue;
+ entry->format_type=ExplicitFormatType;
+ entry->description=ConstantString("Raw blue, red, and green samples");
+ entry->module=ConstantString("RGB");
+ (void) RegisterMagickInfo(entry);
+ entry=SetMagickInfo("BGR");
+ entry->decoder=(DecodeImageHandler *) ReadRGBImage;
+ entry->encoder=(EncodeImageHandler *) WriteRGBImage;
+ entry->raw=MagickTrue;
+ entry->endian_support=MagickTrue;
+ entry->format_type=ExplicitFormatType;
+ entry->description=ConstantString("Raw blue, green, and red samples");
+ entry->module=ConstantString("RGB");
+ (void) RegisterMagickInfo(entry);
entry=SetMagickInfo("RGBA");
entry->decoder=(DecodeImageHandler *) ReadRGBImage;
entry->encoder=(EncodeImageHandler *) WriteRGBImage;
@@ -902,6 +689,11 @@
{
(void) UnregisterMagickInfo("RGBO");
(void) UnregisterMagickInfo("RGBA");
+ (void) UnregisterMagickInfo("BGR");
+ (void) UnregisterMagickInfo("BRG");
+ (void) UnregisterMagickInfo("GBR");
+ (void) UnregisterMagickInfo("GRB");
+ (void) UnregisterMagickInfo("RBG");
(void) UnregisterMagickInfo("RGB");
}
@@ -950,6 +742,13 @@
register const PixelPacket
*p;
+ register long
+ i,
+ x;
+
+ register PixelPacket
+ *q;
+
ssize_t
count;
@@ -959,6 +758,21 @@
unsigned char
*pixels;
+ QuantumType
+ quantum_types[4];
+
+ Quantum
+ *qx[3];
+
+ char
+ sfx[] = {0, 0};
+
+ int
+ channels = 3;
+
+ ExceptionInfo
+ exception;
+
/*
Allocate memory for pixels.
*/
@@ -982,12 +796,25 @@
{
quantum_type=RGBAQuantum;
image->matte=MagickTrue;
+ channels=4;
}
if (LocaleCompare(image_info->magick,"RGBO") == 0)
{
quantum_type=RGBOQuantum;
image->matte=MagickTrue;
+ channels=4;
+ }
+ for (i=0; i < channels; i++)
+ {
+ switch(image_info->magick[i])
+ {
+ case 'R': quantum_types[i]=RedQuantum; break;
+ case 'G': quantum_types[i]=GreenQuantum; break;
+ case 'B': quantum_types[i]=BlueQuantum; break;
+ case 'A': quantum_types[i]=AlphaQuantum; break;
+ case 'O': quantum_types[i]=OpacityQuantum; break;
}
+ }
scene=0;
do
{
@@ -1001,7 +828,7 @@
(void) SetImageAlphaChannel(image,ResetAlphaChannel);
quantum_info=AcquireQuantumInfo(image_info,image);
if (quantum_info == (QuantumInfo *) NULL)
- ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
+ ThrowWriterExeption(ResourceLimitError,"MemoryAllocationFailed");
pixels=GetQuantumPixels(quantum_info);
switch (image_info->interlace)
{
@@ -1011,11 +838,32 @@
/*
No interlacing: RGBRGBRGBRGBRGBRGB...
*/
+ register PixelPacket
+ px;
+
for (y=0; y < (long) image->rows; y++)
{
p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
- if (p == (const PixelPacket *) NULL)
- break;
+ q=QueueAuthenticPixels(image,0,y,image->columns,1,&exception);
+ if ((p == (const PixelPacket *) NULL) ||
+ (q == (PixelPacket *) NULL))
+ break;
+ for (x=0; x < (long)image->columns; x++)
+ {
+ px=*q;
+ qx[0]=&(q->red);
+ qx[1]=&(q->green);
+ qx[2]=&(q->blue);
+ for(i=0; i < 3; i++)
+ switch(quantum_types[i])
+ {
+ case RedQuantum: *qx[i]=px.red; break;
+ case GreenQuantum: *qx[i]=px.green; break;
+ case BlueQuantum: *qx[i]=px.blue; break;
+ default: break;
+ }
+ q++;
+ }
length=ExportQuantumPixels(image,(const ViewInfo *) NULL,quantum_info,
quantum_type,pixels,&image->exception);
count=WriteBlob(image,length,pixels);
@@ -1040,37 +888,14 @@
p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
if (p == (const PixelPacket *) NULL)
break;
- length=ExportQuantumPixels(image,(const ViewInfo *) NULL,quantum_info,
- RedQuantum,pixels,&image->exception);
- count=WriteBlob(image,length,pixels);
- if (count != (ssize_t) length)
- break;
- length=ExportQuantumPixels(image,(const ViewInfo *) NULL,quantum_info,
- GreenQuantum,pixels,&image->exception);
- count=WriteBlob(image,length,pixels);
- if (count != (ssize_t) length)
- break;
- length=ExportQuantumPixels(image,(const ViewInfo *) NULL,quantum_info,
- BlueQuantum,pixels,&image->exception);
- count=WriteBlob(image,length,pixels);
- if (count != (ssize_t) length)
- break;
- if (quantum_type == RGBAQuantum)
- {
- length=ExportQuantumPixels(image,(const ViewInfo *) NULL,
- quantum_info,AlphaQuantum,pixels,&image->exception);
- count=WriteBlob(image,length,pixels);
- if (count != (ssize_t) length)
- break;
- }
- if (quantum_type == RGBOQuantum)
- {
- length=ExportQuantumPixels(image,(const ViewInfo *) NULL,
- quantum_info,OpacityQuantum,pixels,&image->exception);
- count=WriteBlob(image,length,pixels);
- if (count != (ssize_t) length)
- break;
- }
+ for (i=0; i < channels; i++)
+ {
+ length=ExportQuantumPixels(image,(const ViewInfo *) NULL,quantum_info,
+ quantum_types[i],pixels,&image->exception);
+ count=WriteBlob(image,length,pixels);
+ if (count != (ssize_t) length)
+ break;
+ }
if (image->previous == (Image *) NULL)
{
status=SetImageProgress(image,SaveImageTag,y,image->rows);
@@ -1085,96 +910,26 @@
/*
Plane interlacing: RRRRRR...GGGGGG...BBBBBB...
*/
- for (y=0; y < (long) image->rows; y++)
- {
- p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
- if (p == (const PixelPacket *) NULL)
- break;
- length=ExportQuantumPixels(image,(const ViewInfo *) NULL,quantum_info,
- RedQuantum,pixels,&image->exception);
- count=WriteBlob(image,length,pixels);
- if (count != (ssize_t) length)
- break;
- }
- if (image->previous == (Image *) NULL)
- {
- status=SetImageProgress(image,SaveImageTag,1,5);
- if (status == MagickFalse)
- break;
- }
- for (y=0; y < (long) image->rows; y++)
- {
- p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
- if (p == (const PixelPacket *) NULL)
- break;
- length=ExportQuantumPixels(image,(const ViewInfo *) NULL,quantum_info,
- GreenQuantum,pixels,&image->exception);
- count=WriteBlob(image,length,pixels);
- if (count != (ssize_t) length)
- break;
- }
- if (image->previous == (Image *) NULL)
- {
- status=SetImageProgress(image,SaveImageTag,2,5);
- if (status == MagickFalse)
- break;
- }
- for (y=0; y < (long) image->rows; y++)
+ for (i=0; i < channels; i++)
{
- p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
- if (p == (const PixelPacket *) NULL)
- break;
- length=ExportQuantumPixels(image,(const ViewInfo *) NULL,quantum_info,
- BlueQuantum,pixels,&image->exception);
- count=WriteBlob(image,length,pixels);
- if (count != (ssize_t) length)
- break;
- }
- if (image->previous == (Image *) NULL)
+ for (y=0; y < (long) image->rows; y++)
{
- status=SetImageProgress(image,SaveImageTag,3,5);
- if (status == MagickFalse)
+ p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
+ if (p == (const PixelPacket *) NULL)
break;
- }
- if (quantum_type == RGBAQuantum)
- {
- for (y=0; y < (long) image->rows; y++)
- {
- p=GetVirtualPixels(image,0,y,image->columns,1,
- &image->exception);
- if (p == (const PixelPacket *) NULL)
- break;
- length=ExportQuantumPixels(image,(const ViewInfo *) NULL,
- quantum_info,AlphaQuantum,pixels,&image->exception);
- count=WriteBlob(image,length,pixels);
- if (count != (ssize_t) length)
+ length=ExportQuantumPixels(image,(const ViewInfo *) NULL,quantum_info,
+ quantum_types[i],pixels,&image->exception);
+ count=WriteBlob(image,length,pixels);
+ if (count != (ssize_t) length)
break;
- }
}
- if (quantum_type == RGBOQuantum)
- {
- if (image->previous == (Image *) NULL)
- {
- status=SetImageProgress(image,SaveImageTag,4,5);
- if (status == MagickFalse)
- break;
- }
- for (y=0; y < (long) image->rows; y++)
+ if (image->previous == (Image *) NULL)
{
- p=GetVirtualPixels(image,0,y,image->columns,1,
- &image->exception);
- if (p == (const PixelPacket *) NULL)
+ status=SetImageProgress(image,SaveImageTag,(i+1),5);
+ if (status == MagickFalse)
break;
- length=ExportQuantumPixels(image,(const ViewInfo *) NULL,
- quantum_info,OpacityQuantum,pixels,&image->exception);
- count=WriteBlob(image,length,pixels);
- if (count != (ssize_t) length)
- break;
}
- }
- if (image_info->interlace == PartitionInterlace)
- (void) CopyMagickString(image->filename,image_info->filename,
- MaxTextExtent);
+ }
if (image->previous == (Image *) NULL)
{
status=SetImageProgress(image,SaveImageTag,5,5);
@@ -1188,135 +943,33 @@
/*
Partition interlacing: RRRRRR..., GGGGGG..., BBBBBB...
*/
- AppendImageFormat("R",image->filename);
- status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode :
- AppendBinaryBlobMode,&image->exception);
- if (status == MagickFalse)
- return(status);
- for (y=0; y < (long) image->rows; y++)
- {
- p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
- if (p == (const PixelPacket *) NULL)
- break;
- length=ExportQuantumPixels(image,(const ViewInfo *) NULL,quantum_info,
- RedQuantum,pixels,&image->exception);
- count=WriteBlob(image,length,pixels);
- if (count != (ssize_t) length)
- break;
- }
- if (image->previous == (Image *) NULL)
- {
- status=SetImageProgress(image,SaveImageTag,1,5);
- if (status == MagickFalse)
- break;
- }
- (void) CloseBlob(image);
- AppendImageFormat("G",image->filename);
- status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode :
- AppendBinaryBlobMode,&image->exception);
- if (status == MagickFalse)
- return(status);
- for (y=0; y < (long) image->rows; y++)
- {
- p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
- if (p == (const PixelPacket *) NULL)
- break;
- length=ExportQuantumPixels(image,(const ViewInfo *) NULL,quantum_info,
- GreenQuantum,pixels,&image->exception);
- count=WriteBlob(image,length,pixels);
- if (count != (ssize_t) length)
- break;
- }
- if (image->previous == (Image *) NULL)
- {
- status=SetImageProgress(image,SaveImageTag,2,5);
- if (status == MagickFalse)
- break;
- }
- (void) CloseBlob(image);
- AppendImageFormat("B",image->filename);
- status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode :
- AppendBinaryBlobMode,&image->exception);
- if (status == MagickFalse)
- return(status);
- for (y=0; y < (long) image->rows; y++)
+ for (i=0; i < channels; i++)
{
- p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
- if (p == (const PixelPacket *) NULL)
- break;
- length=ExportQuantumPixels(image,(const ViewInfo *) NULL,quantum_info,
- BlueQuantum,pixels,&image->exception);
- count=WriteBlob(image,length,pixels);
- if (count != (ssize_t) length)
- break;
- }
- if (image->previous == (Image *) NULL)
- {
- status=SetImageProgress(image,SaveImageTag,3,5);
- if (status == MagickFalse)
+ sfx[0]=image_info->magick[i];
+ AppendImageFormat(sfx,image->filename);
+ status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode :
+ AppendBinaryBlobMode,&image->exception);
+ if (status == MagickFalse)
+ return(status);
+ for (y=0; y < (long) image->rows; y++)
+ {
+ p=GetVirtualPixels(image,0,y,image->columns,1,&image->exception);
+ if (p == (const PixelPacket *) NULL)
+ break;
+ length=ExportQuantumPixels(image,(const ViewInfo *) NULL,quantum_info,
+ quantum_types[i],pixels,&image->exception);
+ count=WriteBlob(image,length,pixels);
+ if (count != (ssize_t) length)
break;
}
- if (quantum_type == RGBAQuantum)
- {
- (void) CloseBlob(image);
- AppendImageFormat("A",image->filename);
- status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode :
- AppendBinaryBlobMode,&image->exception);
- if (status == MagickFalse)
- return(status);
- for (y=0; y < (long) image->rows; y++)
- {
- p=GetVirtualPixels(image,0,y,image->columns,1,
- &image->exception);
- if (p == (const PixelPacket *) NULL)
- break;
- length=ExportQuantumPixels(image,(const ViewInfo *) NULL,
- quantum_info,AlphaQuantum,pixels,&image->exception);
- count=WriteBlob(image,length,pixels);
- if (count != (ssize_t) length)
- break;
- }
- if (image->previous == (Image *) NULL)
- {
- status=SetImageProgress(image,SaveImageTag,4,5);
- if (status == MagickFalse)
- break;
- }
- }
- if (quantum_type == RGBOQuantum)
- {
- if (image->previous == (Image *) NULL)
- {
- status=SetImageProgress(image,SaveImageTag,4,5);
- if (status == MagickFalse)
- break;
- }
- (void) CloseBlob(image);
- AppendImageFormat("O",image->filename);
- status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode :
- AppendBinaryBlobMode,&image->exception);
- if (status == MagickFalse)
- return(status);
- for (y=0; y < (long) image->rows; y++)
+ if (image->previous == (Image *) NULL)
{
- p=GetVirtualPixels(image,0,y,image->columns,1,
- &image->exception);
- if (p == (const PixelPacket *) NULL)
- break;
- length=ExportQuantumPixels(image,(const ViewInfo *) NULL,
- quantum_info,OpacityQuantum,pixels,&image->exception);
- count=WriteBlob(image,length,pixels);
- if (count != (ssize_t) length)
+ status=SetImageProgress(image,SaveImageTag,(i+1),5);
+ if (status == MagickFalse)
break;
}
- if (image->previous == (Image *) NULL)
- {
- status=SetImageProgress(image,SaveImageTag,4,5);
- if (status == MagickFalse)
- break;
- }
- }
- (void) CloseBlob(image);
+ (void) CloseBlob(image);
+ }
(void) CopyMagickString(image->filename,image_info->filename,
MaxTextExtent);
if (image->previous == (Image *) NULL)
--- ImageMagick-6.4.6/config/coder.xml.gbr 2008-10-04 22:17:10.000000000 +0900
+++ ImageMagick-6.4.6/config/coder.xml 2008-11-20 19:27:53.000000000 +0900
@@ -19,6 +19,8 @@
<coder magick="BMP3" name="BMP"/>
<coder magick="B" name="RAW"/>
<coder magick="BRF" name="BRAILLE"/>
+ <coder magick="BGR" name="RGB"/>
+ <coder magick="BRG" name="RGB"/>
<coder magick="CMYKA" name="CMYK"/>
<coder magick="C" name="RAW"/>
<coder magick="CR2" name="DNG"/>
@@ -44,6 +46,8 @@
<coder magick="G3" name="FAX"/>
<coder magick="GIF87" name="GIF"/>
<coder magick="G" name="RAW"/>
+ <coder magick="GBR" name="RGB"/>
+ <coder magick="GRB" name="RGB"/>
<coder magick="GRANITE" name="MAGICK"/>
<coder magick="H" name="MAGICK"/>
<coder magick="HTM" name="HTML"/>
@@ -103,6 +107,7 @@
<coder magick="RADIAL-GRADIENT" name="GRADIENT"/>
<coder magick="RAF" name="DNG"/>
<coder magick="RAS" name="SUN"/>
+ <coder magick="RBG" name="RGB"/>
<coder magick="RGBA" name="RGB"/>
<coder magick="RGBO" name="RGB"/>
<coder magick="R" name="RAW"/>