Skip to content

Commit

Permalink
slight optimization + cosmetic
Browse files Browse the repository at this point in the history
  • Loading branch information
Cristy committed Dec 30, 2022
1 parent a45686d commit f559bbd
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 36 deletions.
4 changes: 2 additions & 2 deletions coders/mat.c
Original file line number Diff line number Diff line change
Expand Up @@ -817,8 +817,8 @@ static Image *ReadMATImageV4(const ImageInfo *image_info,Image *image,
rotated_image->colors = image->colors;
DestroyBlob(rotated_image);
rotated_image->blob=ReferenceBlob(image->blob);
AppendImageToList(&image,rotated_image);
DeleteImageFromList(&image);
ReplaceImageInList(&image,rotated_image);
image=rotated_image;
}
/*
Proceed to next image.
Expand Down
11 changes: 6 additions & 5 deletions coders/pcx.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ static MagickBooleanType IsPCX(const unsigned char *magick,const size_t length)
*/
static Image *ReadPCXImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
#define MaxNumberScenes 1024
#define ThrowPCXException(severity,tag) \
{ \
if (scanline != (unsigned char *) NULL) \
Expand Down Expand Up @@ -298,11 +299,11 @@ static Image *ReadPCXImage(const ImageInfo *image_info,ExceptionInfo *exception)
magic=ReadBlobLSBLong(image);
if (magic != 987654321)
ThrowPCXException(CorruptImageError,"ImproperImageHeader");
page_table=(MagickOffsetType *) AcquireQuantumMemory(1024UL,
page_table=(MagickOffsetType *) AcquireQuantumMemory(MaxNumberScenes,
sizeof(*page_table));
if (page_table == (MagickOffsetType *) NULL)
ThrowPCXException(ResourceLimitError,"MemoryAllocationFailed");
for (id=0; id < 1024; id++)
for (id=0; id < MaxNumberScenes; id++)
{
page_table[id]=(MagickOffsetType) ReadBlobLSBLong(image);
if (page_table[id] == 0)
Expand All @@ -316,7 +317,7 @@ static Image *ReadPCXImage(const ImageInfo *image_info,ExceptionInfo *exception)
ThrowPCXException(CorruptImageError,"ImproperImageHeader");
}
count=ReadBlob(image,1,&pcx_info.identifier);
for (id=1; id < 1024; id++)
for (id=1; id < MaxNumberScenes; id++)
{
int
bits_per_pixel;
Expand Down Expand Up @@ -919,11 +920,11 @@ static MagickBooleanType WritePCXImage(const ImageInfo *image_info,Image *image)
Write the DCX page table.
*/
(void) WriteBlobLSBLong(image,0x3ADE68B1L);
page_table=(MagickOffsetType *) AcquireQuantumMemory(1024UL,
page_table=(MagickOffsetType *) AcquireQuantumMemory(MaxNumberScenes,
sizeof(*page_table));
if (page_table == (MagickOffsetType *) NULL)
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
for (scene=0; scene < 1024; scene++)
for (scene=0; scene < MaxNumberScenes; scene++)
(void) WriteBlobLSBLong(image,0x00000000L);
}
scene=0;
Expand Down
13 changes: 5 additions & 8 deletions magick/color.c
Original file line number Diff line number Diff line change
Expand Up @@ -2651,6 +2651,9 @@ MagickExport MagickBooleanType QueryMagickColorCompliance(const char *name,
const ComplianceType compliance,MagickPixelPacket *color,
ExceptionInfo *exception)
{
const ColorInfo
*p;

double
scale;

Expand All @@ -2660,13 +2663,8 @@ MagickExport MagickBooleanType QueryMagickColorCompliance(const char *name,
MagickStatusType
flags;

const ColorInfo
*p;

ssize_t
i;

ssize_t
i,
type;

/*
Expand All @@ -2692,7 +2690,7 @@ MagickExport MagickBooleanType QueryMagickColorCompliance(const char *name,
c;

LongPixelPacket
pixel;
pixel = { 0 };

QuantumAny
range;
Expand All @@ -2704,7 +2702,6 @@ MagickExport MagickBooleanType QueryMagickColorCompliance(const char *name,
/*
Parse hex color.
*/
(void) memset(&pixel,0,sizeof(pixel));
name++;
for (n=0; isxdigit((int) ((unsigned char) name[n])) != 0; n++) ;
if ((n == 3) || (n == 6) || (n == 9) || (n == 12) || (n == 24) ||
Expand Down
16 changes: 13 additions & 3 deletions magick/image-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,45 @@
#ifndef MAGICKCORE_IMAGE_PRIVATE_H
#define MAGICKCORE_IMAGE_PRIVATE_H

#define MagickMax(x,y) (((x) > (y)) ? (x) : (y))
#define MagickMin(x,y) (((x) < (y)) ? (x) : (y))

#include "magick/quantum-private.h"

#define BackgroundColor "#ffffff" /* white */
#if defined(__cplusplus) || defined(c_plusplus)
extern "C" {
#endif

#define BackgroundColor "#ffffff" /* white */
#define BackgroundColorRGBA QuantumRange,QuantumRange,QuantumRange,OpaqueOpacity
#define BorderColor "#dfdfdf" /* gray */
#define BorderColorRGBA ScaleShortToQuantum(0xdfdf),\
ScaleShortToQuantum(0xdfdf),ScaleShortToQuantum(0xdfdf),OpaqueOpacity
#define DefaultResolution 72.0
#define DefaultTileFrame "15x15+3+3"
#define DefaultTileGeometry "120x120+4+3>"
#define DefaultTileLabel "%f\n%G\n%b"
#define ForegroundColor "#000" /* black */
#define ForegroundColorRGBA 0,0,0,OpaqueOpacity
#define LoadImagesTag "Load/Images"
#define LoadImageTag "Load/Image"
#define Magick2PI 6.28318530717958647692528676655900576839433879875020
#define MagickAbsoluteValue(x) ((x) < 0 ? -(x) : (x))
#define MagickMax(x,y) (((x) > (y)) ? (x) : (y))
#define MagickMin(x,y) (((x) < (y)) ? (x) : (y))
#define MagickPHI 1.61803398874989484820458683436563811772030917980576
#define MagickPI2 1.57079632679489661923132169163975144209858469968755
#define MagickPI 3.14159265358979323846264338327950288419716939937510
#define MagickSQ1_2 0.70710678118654752440084436210484903928483593768847
#define MagickSQ2 1.41421356237309504880168872420969807856967187537695
#define MagickSQ2PI 2.50662827463100024161235523934010416269302368164062
#define MatteColor "#bdbdbd" /* gray */
#define MatteColorRGBA ScaleShortToQuantum(0xbdbd),\
ScaleShortToQuantum(0xbdbd),ScaleShortToQuantum(0xbdbd),OpaqueOpacity
#define PSDensityGeometry "72.0x72.0"
#define PSPageGeometry "612x792"
#define SaveImagesTag "Save/Images"
#define SaveImageTag "Save/Image"
#define TransparentColor "#00000000" /* transparent black */
#define TransparentColorRGBA 0,0,0,TransparentOpacity
#define UndefinedCompressionQuality 0UL
#define UndefinedTicksPerSecond 100L

Expand Down
27 changes: 9 additions & 18 deletions magick/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,17 +171,15 @@ MagickExport Image *AcquireImage(const ImageInfo *image_info)
image->ticks_per_second=UndefinedTicksPerSecond;
image->compose=OverCompositeOp;
image->blur=1.0;
InitializeExceptionInfo(&image->exception);
(void) QueryColorDatabase(BackgroundColor,&image->background_color,
&image->exception);
(void) QueryColorDatabase(BorderColor,&image->border_color,&image->exception);
(void) QueryColorDatabase(MatteColor,&image->matte_color,&image->exception);
(void) QueryColorDatabase(TransparentColor,&image->transparent_color,
&image->exception);
GetPixelPacketRGBA(BackgroundColorRGBA,&image->background_color);
GetPixelPacketRGBA(BorderColorRGBA,&image->border_color);
GetPixelPacketRGBA(MatteColorRGBA,&image->matte_color);
GetPixelPacketRGBA(TransparentColorRGBA,&image->transparent_color);
GetTimerInfo(&image->timer);
image->ping=MagickFalse;
image->cache=AcquirePixelCache(0);
image->blob=CloneBlobInfo((BlobInfo *) NULL);
InitializeExceptionInfo(&image->exception);
image->timestamp=GetMagickTime();
image->debug=(GetLogEventMask() & (ImageEvent | TransformEvent | CoderEvent))
!= 0 ? MagickTrue : MagickFalse;
Expand Down Expand Up @@ -1432,9 +1430,6 @@ MagickExport void GetImageInfo(ImageInfo *image_info)
char
*synchronize;

ExceptionInfo
*exception;

/*
File and image dimension members.
*/
Expand All @@ -1454,14 +1449,10 @@ MagickExport void GetImageInfo(ImageInfo *image_info)
image_info->synchronize=IsStringTrue(synchronize);
synchronize=DestroyString(synchronize);
}
exception=AcquireExceptionInfo();
(void) QueryColorDatabase(BackgroundColor,&image_info->background_color,
exception);
(void) QueryColorDatabase(BorderColor,&image_info->border_color,exception);
(void) QueryColorDatabase(MatteColor,&image_info->matte_color,exception);
(void) QueryColorDatabase(TransparentColor,&image_info->transparent_color,
exception);
exception=DestroyExceptionInfo(exception);
GetPixelPacketRGBA(BackgroundColorRGBA,&image_info->background_color);
GetPixelPacketRGBA(BorderColorRGBA,&image_info->border_color);
GetPixelPacketRGBA(MatteColorRGBA,&image_info->matte_color);
GetPixelPacketRGBA(TransparentColorRGBA,&image_info->transparent_color);
image_info->debug=(GetLogEventMask() & ImageEvent) != 0 ? MagickTrue :
MagickFalse;
image_info->signature=MagickCoreSignature;
Expand Down
9 changes: 9 additions & 0 deletions magick/pixel-accessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,15 @@ static inline MagickRealType GetPixelLuminance(
return(intensity);
}

static inline void GetPixelPacketRGBA(const Quantum red,const Quantum green,
const Quantum blue,const Quantum opacity,PixelPacket *magick_restrict pixel)
{
pixel->red=red;
pixel->green=green;
pixel->blue=blue;
pixel->opacity=opacity;
}

static inline MagickBooleanType IsPixelAtDepth(const Quantum pixel,
const QuantumAny range)
{
Expand Down

0 comments on commit f559bbd

Please sign in to comment.