#include "HxImageRep.h"
Go to the source code of this file.
Functions | |
bool L_HXIMAGEREP | HxWriteFile (HxImageRep im, HxString fileName) |
Write image to file using HxImgFileIo. More... |
|
Write image to file using HxImgFileIo.
00019 { 00020 HxString fname("HxWriteFile"); 00021 00022 if (im.isNull()) 00023 { 00024 HxGlobalError::instance()->reportError(fname, im.name(), "null image", HxGlobalError::HX_GE_INVALID); 00025 return false; 00026 } 00027 00028 HxString extName = HxSystem::instance().extName(fileName); 00029 00030 if ((extName == "jpg") || (extName == "JPG") || (extName == "jpeg") || 00031 (extName == "JPEG") || (extName == "jfif") || (extName == "JFIF")) 00032 { 00033 if ((im.signature().pixelType() == INT_VALUE) && 00034 (im.signature().pixelPrecision() != 8)) 00035 { 00036 HxGlobalError::instance()->reportError(fname, "jpeg format supported only for byte precision", HxGlobalError::HX_GE_INVALID); 00037 return false; 00038 } 00039 if ((im.signature().pixelType() == INT_VALUE) && 00040 (im.pixelDimensionality() != 1) && (im.pixelDimensionality() != 3)) 00041 { 00042 HxGlobalError::instance()->reportError(fname, "jpeg format supported only 1D and 3D pixels", HxGlobalError::HX_GE_INVALID); 00043 return false; 00044 } 00045 if (im.signature().pixelType() != INT_VALUE) 00046 { 00047 HxGlobalError::instance()->reportError(fname, "jpeg format supported only for integer values, byte precision", HxGlobalError::HX_GE_INVALID); 00048 return false; 00049 } 00050 } 00051 if ((extName == "png") || (extName == "PNG") || (extName == "ping") || 00052 (extName == "PING")) 00053 { 00054 if ((im.signature().pixelType() == INT_VALUE) && 00055 (im.pixelDimensionality() != 1) && (im.pixelDimensionality() != 3)) 00056 { 00057 HxGlobalError::instance()->reportError(fname, "PNG format supported only 1D and 3D pixels", HxGlobalError::HX_GE_INVALID); 00058 return false; 00059 } 00060 } 00061 00062 HxImgFileReader* reader = HxImgFileIoTable::instance().getReader(extName); 00063 00064 if (!reader) 00065 { 00066 HxString errstr = HxString("Illegal file type '") + extName + HxString("'"); 00067 HxGlobalError::instance()->reportError(fname, im.name(), errstr, HxGlobalError::HX_GE_INVALID); 00068 return false; 00069 } 00070 00071 HxTagList tags; 00072 return HxImageFactory::instance().writeFile(im, fileName, tags); 00073 } |