Alien-FreeImage
view release on metacpan or search on metacpan
src/Source/FreeImage/MultiPage.cpp view on Meta::CPAN
}
}
// close the files
FreeImage_Close(header->node, header->io, header->handle, data_read);
FreeImage_Close(node, io, handle, data);
return success;
}
}
return FALSE;
}
BOOL DLL_CALLCONV
FreeImage_CloseMultiBitmap(FIMULTIBITMAP *bitmap, int flags) {
if (bitmap) {
BOOL success = TRUE;
if (bitmap->data) {
MULTIBITMAPHEADER *header = FreeImage_GetMultiBitmapHeader(bitmap);
// saves changes only of images loaded directly from a file
if (header->changed && header->m_filename) {
try {
// open a temp file
std::string spool_name;
ReplaceExtension(spool_name, header->m_filename, "fispool");
// open the spool file and the source file
FILE *f = fopen(spool_name.c_str(), "w+b");
// saves changes
if (f == NULL) {
FreeImage_OutputMessageProc(header->fif, "Failed to open %s, %s", spool_name.c_str(), strerror(errno));
success = FALSE;
} else {
success = FreeImage_SaveMultiBitmapToHandle(header->fif, bitmap, header->io, (fi_handle)f, flags);
// close the files
if (fclose(f) != 0) {
success = FALSE;
FreeImage_OutputMessageProc(header->fif, "Failed to close %s, %s", spool_name.c_str(), strerror(errno));
}
}
if (header->handle) {
fclose((FILE *)header->handle);
}
// applies changes to the destination file
if (success) {
remove(header->m_filename);
success = (rename(spool_name.c_str(), header->m_filename) == 0) ? TRUE:FALSE;
if(!success) {
FreeImage_OutputMessageProc(header->fif, "Failed to rename %s to %s", spool_name.c_str(), header->m_filename);
}
} else {
remove(spool_name.c_str());
}
} catch (std::bad_alloc &) {
success = FALSE;
}
} else {
if (header->handle && header->m_filename) {
fclose((FILE *)header->handle);
}
}
// clear the blocks list
for (BlockListIterator i = header->m_blocks.begin(); i != header->m_blocks.end(); ++i) {
delete *i;
}
// flush and dispose the cache
if (header->m_cachefile) {
header->m_cachefile->close();
delete header->m_cachefile;
}
// delete the last open bitmaps
while (!header->locked_pages.empty()) {
FreeImage_Unload(header->locked_pages.begin()->first);
header->locked_pages.erase(header->locked_pages.begin()->first);
}
// get rid of the IO structure
delete header->io;
// delete the filename
if(header->m_filename) {
delete[] header->m_filename;
}
// delete the FIMULTIBITMAPHEADER
delete header;
}
delete bitmap;
return success;
}
return FALSE;
}
int DLL_CALLCONV
FreeImage_GetPageCount(FIMULTIBITMAP *bitmap) {
( run in 0.960 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )