Skip to content

Commit

Permalink
generalize multispectral support
Browse files Browse the repository at this point in the history
  • Loading branch information
Cristy committed Apr 3, 2022
1 parent 4576d73 commit 101e955
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 157 deletions.
27 changes: 19 additions & 8 deletions MagickCore/identify.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
#include "MagickCore/montage.h"
#include "MagickCore/option.h"
#include "MagickCore/pixel-accessor.h"
#include "MagickCore/pixel-private.h"
#include "MagickCore/prepress.h"
#include "MagickCore/profile.h"
#include "MagickCore/property.h"
Expand Down Expand Up @@ -594,7 +595,7 @@ MagickExport MagickBooleanType IdentifyImage(Image *image,FILE *file,
default:
{
for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
(void) PrintChannelLocations(file,image,(PixelChannel) i,"Gray",
(void) PrintChannelLocations(file,image,(PixelChannel) i,"Channel",
statistic_type,max_locations,channel_statistics);
break;
}
Expand Down Expand Up @@ -816,9 +817,6 @@ MagickExport MagickBooleanType IdentifyImage(Image *image,FILE *file,
if (image->alpha_trait != UndefinedPixelTrait)
(void) FormatLocaleFile(file," Alpha: %.20g-bit\n",(double)
channel_statistics[AlphaPixelChannel].depth);
if (image->number_meta_channels != 0)
(void) FormatLocaleFile(file," Meta: %.20g-bit\n",(double)
channel_statistics[MetaPixelChannel].depth);
if ((image->channels & ReadMaskChannel) != 0)
(void) FormatLocaleFile(file," Read mask: %.20g-bit\n",(double)
channel_statistics[ReadMaskPixelChannel].depth);
Expand All @@ -828,6 +826,10 @@ MagickExport MagickBooleanType IdentifyImage(Image *image,FILE *file,
if ((image->channels & CompositeMaskChannel) != 0)
(void) FormatLocaleFile(file," Composite mask: %.20g-bit\n",(double)
channel_statistics[CompositeMaskPixelChannel].depth);
if (image->number_meta_channels != 0)
for (i=0; i < (ssize_t) image->number_meta_channels; i++)
(void) FormatLocaleFile(file," Meta channel[%.20g]: %.20g-bit\n",
(double) i,(double) channel_statistics[StartMetaPixelChannel+i].depth);
scale=1.0;
if (image->depth <= MAGICKCORE_QUANTUM_DEPTH)
scale=(double) (QuantumRange/((size_t) QuantumRange >> ((size_t)
Expand Down Expand Up @@ -885,9 +887,6 @@ MagickExport MagickBooleanType IdentifyImage(Image *image,FILE *file,
if (image->alpha_trait != UndefinedPixelTrait)
(void) PrintChannelStatistics(file,AlphaPixelChannel,"Alpha",1.0/scale,
channel_statistics);
if (image->number_meta_channels != 0)
(void) PrintChannelStatistics(file,MetaPixelChannel,"Meta",1.0/scale,
channel_statistics);
if ((image->channels & ReadMaskChannel) != 0)
(void) PrintChannelStatistics(file,ReadMaskPixelChannel,"Read mask",
1.0/scale,channel_statistics);
Expand All @@ -897,7 +896,19 @@ MagickExport MagickBooleanType IdentifyImage(Image *image,FILE *file,
if ((image->channels & CompositeMaskChannel) != 0)
(void) PrintChannelStatistics(file,WriteMaskPixelChannel,
"Composite mask",1.0/scale,channel_statistics);
if ((colorspace != LinearGRAYColorspace) && (colorspace != GRAYColorspace))
if (image->number_meta_channels != 0)
for (i=0; i < (ssize_t) image->number_meta_channels; i++)
{
char
label[MagickPathExtent];

(void) FormatLocaleString(label,MagickPathExtent,
"Meta channel[%.20g]",(double) i);
(void) PrintChannelStatistics(file,StartMetaPixelChannel+i,label,
1.0/scale,channel_statistics);
}
if ((colorspace != LinearGRAYColorspace) &&
(colorspace != GRAYColorspace))
{
(void) FormatLocaleFile(file," Image statistics:\n");
(void) PrintChannelStatistics(file,CompositePixelChannel,"Overall",
Expand Down
1 change: 0 additions & 1 deletion MagickCore/pixel.c
Original file line number Diff line number Diff line change
Expand Up @@ -4382,7 +4382,6 @@ MagickExport void InitializePixelChannelMap(Image *image)
i;

meta_channel=StartMetaPixelChannel;
SetPixelChannelAttributes(image,MetaPixelChannel,UpdatePixelTrait,n++);
for (i=0; i < (ssize_t) image->number_meta_channels; i++)
{
assert(meta_channel < MaxPixelChannels);
Expand Down
143 changes: 0 additions & 143 deletions MagickCore/quantum-import.c
Original file line number Diff line number Diff line change
Expand Up @@ -3492,143 +3492,6 @@ static void ImportIndexAlphaQuantum(const Image *image,
"InvalidColormapIndex","`%s'",image->filename);
}

static void ImportMetaQuantum(const Image *image,QuantumInfo *quantum_info,
const MagickSizeType number_pixels,const unsigned char *magick_restrict p,
Quantum *magick_restrict q)
{
QuantumAny
range;

ssize_t
x;

assert(image != (Image *) NULL);
assert(image->signature == MagickCoreSignature);
switch (quantum_info->depth)
{
case 8:
{
unsigned char
pixel;

for (x=0; x < (ssize_t) number_pixels; x++)
{
p=PushCharPixel(p,&pixel);
SetPixelMeta(image,ScaleCharToQuantum(pixel),q);
p+=quantum_info->pad;
q+=GetPixelChannels(image);
}
break;
}
case 16:
{
unsigned short
pixel;

if (quantum_info->format == FloatingPointQuantumFormat)
{
for (x=0; x < (ssize_t) number_pixels; x++)
{
p=PushShortPixel(quantum_info->endian,p,&pixel);
SetPixelMeta(image,ClampToQuantum(QuantumRange*
HalfToSinglePrecision(pixel)),q);
p+=quantum_info->pad;
q+=GetPixelChannels(image);
}
break;
}
for (x=0; x < (ssize_t) number_pixels; x++)
{
p=PushShortPixel(quantum_info->endian,p,&pixel);
SetPixelMeta(image,ScaleShortToQuantum(pixel),q);
p+=quantum_info->pad;
q+=GetPixelChannels(image);
}
break;
}
case 24:
{
if (quantum_info->format == FloatingPointQuantumFormat)
{
float
pixel;

for (x=0; x < (ssize_t) number_pixels; x++)
{
p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
SetPixelMeta(image,ClampToQuantum(pixel),q);
p+=quantum_info->pad;
q+=GetPixelChannels(image);
}
break;
}
}
case 32:
{
if (quantum_info->format == FloatingPointQuantumFormat)
{
float
pixel;

for (x=0; x < (ssize_t) number_pixels; x++)
{
p=PushQuantumFloatPixel(quantum_info,p,&pixel);
SetPixelMeta(image,ClampToQuantum(pixel),q);
p+=quantum_info->pad;
q+=GetPixelChannels(image);
}
break;
}
else
{
unsigned int
pixel;

for (x=0; x < (ssize_t) number_pixels; x++)
{
p=PushLongPixel(quantum_info->endian,p,&pixel);
SetPixelMeta(image,ScaleLongToQuantum(pixel),q);
p+=quantum_info->pad;
q+=GetPixelChannels(image);
}
break;
}
}
case 64:
{
if (quantum_info->format == FloatingPointQuantumFormat)
{
double
pixel;

for (x=0; x < (ssize_t) number_pixels; x++)
{
p=PushDoublePixel(quantum_info,p,&pixel);
SetPixelMeta(image,ClampToQuantum(pixel),q);
p+=quantum_info->pad;
q+=GetPixelChannels(image);
}
break;
}
}
default:
{
unsigned int
pixel;

range=GetQuantumRange(quantum_info->depth);
for (x=0; x < (ssize_t) number_pixels; x++)
{
p=PushQuantumPixel(quantum_info,p,&pixel);
SetPixelMeta(image,ScaleAnyToQuantum(pixel,range),q);
p+=quantum_info->pad;
q+=GetPixelChannels(image);
}
break;
}
}
}

static void ImportMultispectralQuantum(const Image *image,
QuantumInfo *quantum_info,const MagickSizeType number_pixels,
const unsigned char *magick_restrict p,Quantum *magick_restrict q,
Expand Down Expand Up @@ -3781,7 +3644,6 @@ static void ImportMultispectralQuantum(const Image *image,
p=PushQuantumPixel(quantum_info,p,&pixel);
q[i]=ScaleAnyToQuantum(pixel,range);
}
SetPixelMeta(image,ScaleAnyToQuantum(pixel,range),q);
q+=GetPixelChannels(image);
}
break;
Expand Down Expand Up @@ -5059,11 +4921,6 @@ MagickExport size_t ImportQuantumPixels(const Image *image,
ImportIndexAlphaQuantum(image,quantum_info,number_pixels,p,q,exception);
break;
}
case MetaQuantum:
{
ImportMetaQuantum(image,quantum_info,number_pixels,p,q);
break;
}
case OpacityQuantum:
{
ImportOpacityQuantum(image,quantum_info,number_pixels,p,q);
Expand Down
1 change: 0 additions & 1 deletion MagickCore/quantum.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ typedef enum
RGBPadQuantum,
RGBQuantum,
YellowQuantum,
MetaQuantum,
MultispectralQuantum
} QuantumType;

Expand Down
18 changes: 14 additions & 4 deletions coders/tiff.c
Original file line number Diff line number Diff line change
Expand Up @@ -1823,7 +1823,10 @@ static Image *ReadTIFFImage(const ImageInfo *image_info,
}
}
if (image->number_meta_channels != 0)
quantum_type=MultispectralQuantum;
{
quantum_type=MultispectralQuantum;
quantum_info->pad=0;
}
switch (method)
{
case ReadYCCKMethod:
Expand Down Expand Up @@ -1927,7 +1930,8 @@ static Image *ReadTIFFImage(const ImageInfo *image_info,
break;
}
case 4: quantum_type=AlphaQuantum; break;
default: quantum_type=MetaQuantum; break;
default:
break;
}
rows_remaining=0;
for (y=0; y < (ssize_t) image->rows; y++)
Expand Down Expand Up @@ -3973,7 +3977,10 @@ static MagickBooleanType WriteTIFFImage(const ImageInfo *image_info,
if (image->alpha_trait != UndefinedPixelTrait)
quantum_type=RGBAQuantum;
if (image->number_meta_channels != 0)
quantum_type=MultispectralQuantum;
{
quantum_type=MultispectralQuantum;
quantum_info->pad=0;
}
for (y=0; y < (ssize_t) image->rows; y++)
{
const Quantum
Expand Down Expand Up @@ -4099,7 +4106,10 @@ static MagickBooleanType WriteTIFFImage(const ImageInfo *image_info,
if (image->alpha_trait != UndefinedPixelTrait)
quantum_type=CMYKAQuantum;
if (image->number_meta_channels != 0)
quantum_type=MultispectralQuantum;
{
quantum_type=MultispectralQuantum;
quantum_info->pad=0;
}
if (image->colorspace != CMYKColorspace)
(void) TransformImageColorspace(image,CMYKColorspace,exception);
for (y=0; y < (ssize_t) image->rows; y++)
Expand Down

0 comments on commit 101e955

Please sign in to comment.