From 39930a02337b58a07e01e4b3fc82fe966af25cfd Mon Sep 17 00:00:00 2001 From: dirk Date: Sat, 27 Dec 2014 11:28:17 +0000 Subject: [PATCH] Fix problem with images written in an incorrect format and added test to Magick++ to check this. --- Magick++/tests/readWriteImages.cpp | 176 +++++++++++++++++++---------- MagickCore/constitute.c | 6 +- 2 files changed, 118 insertions(+), 64 deletions(-) diff --git a/Magick++/tests/readWriteImages.cpp b/Magick++/tests/readWriteImages.cpp index 7af711a2a..d59cd276d 100644 --- a/Magick++/tests/readWriteImages.cpp +++ b/Magick++/tests/readWriteImages.cpp @@ -1,8 +1,10 @@ // This may look like C code, but it is really -*- C++ -*- // // Copyright Bob Friesenhahn, 1999, 2000, 2003 +// Copyright Dirk Lemstra 2014 // -// Test STL readImages and writeImages functions +// Test STL readImages and writeImages functions and test +// image format when reading/writing. // #include @@ -15,98 +17,150 @@ using namespace std; using namespace Magick; -int main( int /*argc*/, char ** argv) +int main(int,char ** argv) { + int + failures=0; - // Initialize ImageMagick install location for Windows - InitializeMagick(*argv); + string + srcdir(""); - int failures=0; - try { + // Initialize ImageMagick install location for Windows + InitializeMagick(*argv); - string srcdir(""); - if(getenv("SRCDIR") != 0) - srcdir = getenv("SRCDIR"); + try + { + if (getenv("SRCDIR") != 0) + srcdir=getenv("SRCDIR"); // // Test readImages and writeImages // - list first; - readImages( &first, srcdir + "test_image_anim.miff" ); - - if ( first.size() != 6 ) + readImages(&first,srcdir + "test_image_anim.miff"); + + if (first.size() != 6) { - ++failures; - cout << "Line: " << __LINE__ - << " Read images failed, number of frames is " - << first.size() - << " rather than 6 as expected." << endl; + ++failures; + cout << "Line: " << __LINE__ + << " Read images failed, number of frames is " + << first.size() + << " rather than 6 as expected." << endl; } - - writeImages( first.begin(), first.end(), "testmagick_anim_out.miff" ); - + + writeImages(first.begin(),first.end(),"testmagick_anim_out.miff"); + list second; - readImages( &second, "testmagick_anim_out.miff" ); - + readImages(&second,"testmagick_anim_out.miff"); + list::iterator firstIter = first.begin(); list::iterator secondIter = second.begin(); - while( firstIter != first.end() && secondIter != second.end() ) + while (firstIter != first.end() && secondIter != second.end()) + { + if (firstIter->scene() != secondIter->scene()) + { + ++failures; + cout << "Line: " << __LINE__ + << " Image scene: " << secondIter->scene() + << " is not equal to original " + << firstIter->scene() + << endl; + } + + if (firstIter->rows() != secondIter->rows()) + { + ++failures; + cout << "Line: " << __LINE__ + << " Image rows " << secondIter->rows() + << " are not equal to original " + << firstIter->rows() + << endl; + } + + if (firstIter->columns() != secondIter->columns()) + { + ++failures; + cout << "Line: " << __LINE__ + << " Image columns " << secondIter->columns() + << " are not equal to original " + << firstIter->rows() + << endl; + } + + firstIter++; + secondIter++; + } + + Image third(*first.begin()); + third.write("testmagick_anim_out"); + + Image fourth; + fourth.read("testmagick_anim_out"); + + if (fourth.magick() != "MIFF") { + ++failures; + cout << "Line: " << __LINE__ + << " Image magick: " << fourth.magick() + << " is not equal to MIFF" + << endl; + } + + third.write("testmagick_anim_out.ico"); + fourth.read("testmagick_anim_out.ico"); - if ( firstIter->scene() != secondIter->scene() ) - { - ++failures; - cout << "Line: " << __LINE__ - << " Image scene: " << secondIter->scene() - << " is not equal to original " - << firstIter->scene() - << endl; - } - - if ( firstIter->rows() != secondIter->rows() ) - { - ++failures; - cout << "Line: " << __LINE__ - << " Image rows " << secondIter->rows() - << " are not equal to original " - << firstIter->rows() - << endl; - } - - if ( firstIter->columns() != secondIter->columns() ) - { - ++failures; - cout << "Line: " << __LINE__ - << " Image columns " << secondIter->columns() - << " are not equal to original " - << firstIter->rows() - << endl; - } - - firstIter++; - secondIter++; + if (fourth.magick() != "ICO") + { + ++failures; + cout << "Line: " << __LINE__ + << " Image magick: " << fourth.magick() + << " is not equal to ICO" + << endl; } - } - catch( Exception &error_ ) + third.magick("BMP"); + third.write("testmagick_anim_out.ico"); + fourth.read("testmagick_anim_out.ico"); + + if (fourth.magick() != "BMP") + { + ++failures; + cout << "Line: " << __LINE__ + << " Image magick: " << fourth.magick() + << " is not equal to BMP" + << endl; + } + + third.write("PDB:testmagick_anim_out.ico"); + fourth.read("testmagick_anim_out.ico"); + + if (fourth.magick() != "PDB") + { + ++failures; + cout << "Line: " << __LINE__ + << " Image magick: " << fourth.magick() + << " is not equal to PDB" + << endl; + } + } + catch(Exception &error_) { cout << "Caught exception: " << error_.what() << endl; return 1; } - catch( exception &error_ ) + catch(exception &error_) { cout << "Caught exception: " << error_.what() << endl; return 1; } - if ( failures ) + if (failures) { cout << failures << " failures" << endl; return 1; } - + return 0; } diff --git a/MagickCore/constitute.c b/MagickCore/constitute.c index 5efcf8d86..0114e4108 100644 --- a/MagickCore/constitute.c +++ b/MagickCore/constitute.c @@ -1001,9 +1001,9 @@ MagickExport MagickBooleanType WriteImage(const ImageInfo *image_info, sans_exception=AcquireExceptionInfo(); write_info=CloneImageInfo(image_info); (void) CopyMagickString(write_info->filename,image->filename,MaxTextExtent); + (void) SetImageInfo(write_info,1,sans_exception); if (*write_info->magick == '\0') (void) CopyMagickString(write_info->magick,image->magick,MaxTextExtent); - (void) SetImageInfo(write_info,1,sans_exception); (void) CopyMagickString(filename,image->filename,MaxTextExtent); (void) CopyMagickString(image->filename,write_info->filename,MaxTextExtent); domain=CoderPolicyDomain; @@ -1276,12 +1276,12 @@ MagickExport MagickBooleanType WriteImages(const ImageInfo *image_info, for (p=images; p != (Image *) NULL; p=GetNextImageInList(p)) (void) CopyMagickString(p->filename,filename,MaxTextExtent); (void) CopyMagickString(write_info->filename,images->filename,MaxTextExtent); - if (*write_info->magick == '\0') - (void) CopyMagickString(write_info->magick,images->magick,MaxTextExtent); sans_exception=AcquireExceptionInfo(); (void) SetImageInfo(write_info,(unsigned int) GetImageListLength(images), sans_exception); sans_exception=DestroyExceptionInfo(sans_exception); + if (*write_info->magick == '\0') + (void) CopyMagickString(write_info->magick,images->magick,MaxTextExtent); p=images; for ( ; GetNextImageInList(p) != (Image *) NULL; p=GetNextImageInList(p)) if (p->scene >= GetNextImageInList(p)->scene) -- 2.40.0