From: Dirk Lemstra Date: Sun, 7 May 2017 09:54:08 +0000 (+0200) Subject: Code cleanup. X-Git-Tag: 7.0.5-6~18 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4feca79a8337d71a01214a5cfb5910ee9609c95a;p=imagemagick Code cleanup. --- diff --git a/coders/mat.c b/coders/mat.c index 13f03849d..04af93d4f 100644 --- a/coders/mat.c +++ b/coders/mat.c @@ -1436,25 +1436,20 @@ ModuleExport void UnregisterMATImage(void) static MagickBooleanType WriteMATImage(const ImageInfo *image_info,Image *image, ExceptionInfo *exception) { - ssize_t y; - unsigned z; - register const Quantum *p; + char + MATLAB_HDR[0x80]; - unsigned int status; - int logging; - size_t DataSize; - char padding; - char MATLAB_HDR[0x80]; - time_t current_time; - struct tm local_time; - unsigned char *pixels; - int is_gray; + MagickBooleanType + status; MagickOffsetType scene; - QuantumInfo - *quantum_info; + struct tm + local_time; + + time_t + current_time; /* Open output image file. @@ -1463,8 +1458,7 @@ static MagickBooleanType WriteMATImage(const ImageInfo *image_info,Image *image, assert(image_info->signature == MagickCoreSignature); assert(image != (Image *) NULL); assert(image->signature == MagickCoreSignature); - logging=LogMagickEvent(CoderEvent,GetMagickModule(),"enter MAT"); - (void) logging; + (void) LogMagickEvent(CoderEvent,GetMagickModule(),"enter MAT"); assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickCoreSignature); status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception); @@ -1492,37 +1486,57 @@ static MagickBooleanType WriteMATImage(const ImageInfo *image_info,Image *image, scene=0; do { + char + padding; + + MagickBooleanType + is_gray; + + QuantumInfo + *quantum_info; + + size_t + data_size; + + unsigned char + *pixels; + + unsigned int + z; + (void) TransformImageColorspace(image,sRGBColorspace,exception); - is_gray = SetImageGray(image,exception); - z = is_gray ? 0 : 3; + is_gray=SetImageGray(image,exception); + z=(is_gray != MagickFalse) ? 0 : 3; /* Store MAT header. */ - DataSize = image->rows /*Y*/ * image->columns /*X*/; - if(!is_gray) DataSize *= 3 /*Z*/; - padding=((unsigned char)(DataSize-1) & 0x7) ^ 0x7; - - (void) WriteBlobLSBLong(image, miMATRIX); - (void) WriteBlobLSBLong(image, (unsigned int) DataSize+padding+(is_gray ? 48 : 56)); - (void) WriteBlobLSBLong(image, 0x6); /* 0x88 */ - (void) WriteBlobLSBLong(image, 0x8); /* 0x8C */ - (void) WriteBlobLSBLong(image, 0x6); /* 0x90 */ - (void) WriteBlobLSBLong(image, 0); - (void) WriteBlobLSBLong(image, 0x5); /* 0x98 */ - (void) WriteBlobLSBLong(image, is_gray ? 0x8 : 0xC); /* 0x9C - DimFlag */ - (void) WriteBlobLSBLong(image, (unsigned int) image->rows); /* x: 0xA0 */ - (void) WriteBlobLSBLong(image, (unsigned int) image->columns); /* y: 0xA4 */ - if(!is_gray) - { - (void) WriteBlobLSBLong(image, 3); /* z: 0xA8 */ - (void) WriteBlobLSBLong(image, 0); - } - (void) WriteBlobLSBShort(image, 1); /* 0xB0 */ - (void) WriteBlobLSBShort(image, 1); /* 0xB2 */ - (void) WriteBlobLSBLong(image, 'M'); /* 0xB4 */ - (void) WriteBlobLSBLong(image, 0x2); /* 0xB8 */ - (void) WriteBlobLSBLong(image, (unsigned int) DataSize); /* 0xBC */ + data_size = image->rows * image->columns; + if (is_gray == MagickFalse) + data_size*=3; + padding=((unsigned char)(data_size-1) & 0x7) ^ 0x7; + + (void) WriteBlobLSBLong(image,miMATRIX); + (void) WriteBlobLSBLong(image,(unsigned int) data_size+padding+ + ((is_gray != MagickFalse) ? 48 : 56)); + (void) WriteBlobLSBLong(image,0x6); /* 0x88 */ + (void) WriteBlobLSBLong(image,0x8); /* 0x8C */ + (void) WriteBlobLSBLong(image,0x6); /* 0x90 */ + (void) WriteBlobLSBLong(image,0); + (void) WriteBlobLSBLong(image,0x5); /* 0x98 */ + (void) WriteBlobLSBLong(image,(is_gray != MagickFalse) ? 0x8 : 0xC); /* 0x9C - DimFlag */ + (void) WriteBlobLSBLong(image,(unsigned int) image->rows); /* x: 0xA0 */ + (void) WriteBlobLSBLong(image,(unsigned int) image->columns); /* y: 0xA4 */ + if (is_gray == MagickFalse) + { + (void) WriteBlobLSBLong(image,3); /* z: 0xA8 */ + (void) WriteBlobLSBLong(image,0); + } + (void) WriteBlobLSBShort(image,1); /* 0xB0 */ + (void) WriteBlobLSBShort(image,1); /* 0xB2 */ + (void) WriteBlobLSBLong(image,'M'); /* 0xB4 */ + (void) WriteBlobLSBLong(image,0x2); /* 0xB8 */ + (void) WriteBlobLSBLong(image,(unsigned int) data_size); /* 0xBC */ /* Store image data. @@ -1533,6 +1547,12 @@ static MagickBooleanType WriteMATImage(const ImageInfo *image_info,Image *image, pixels=(unsigned char *) GetQuantumPixels(quantum_info); do { + const Quantum + *p; + + ssize_t + y; + for (y=0; y < (ssize_t)image->columns; y++) { p=GetVirtualPixels(image,y,0,1,image->rows,exception); @@ -1544,8 +1564,9 @@ static MagickBooleanType WriteMATImage(const ImageInfo *image_info,Image *image, } if (SyncAuthenticPixels(image,exception) == MagickFalse) break; - } while(z-- >= 2); - while(padding-->0) (void) WriteBlobByte(image,0); + } while (z-- >= 2); + while (padding-- > 0) + (void) WriteBlobByte(image,0); quantum_info=DestroyQuantumInfo(quantum_info); if (GetNextImageInList(image) == (Image *) NULL) break; @@ -1556,5 +1577,5 @@ static MagickBooleanType WriteMATImage(const ImageInfo *image_info,Image *image, break; } while (image_info->adjoin != MagickFalse); (void) CloseBlob(image); - return(MagickTrue); + return(status); }