Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions Source/FreeImage/CacheFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,10 @@ CacheFile::unlockBlock(int nr) {
FIBOOL
CacheFile::deleteBlock(int nr) {
if (!m_current_block) {
PageMapIt it = m_page_map.find(nr);

// remove block from cache

if (it != m_page_map.end()) {
m_page_map.erase(nr);
if (PageMapIt it = m_page_map.find(nr); it != m_page_map.end()) {
m_page_map.erase(it);
}

// add block to free page list
Expand Down
37 changes: 12 additions & 25 deletions Source/FreeImage/MultiPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ FreeImage_OpenMultiBitmapU(FREE_IMAGE_FORMAT fif, const wchar_t* filename, FIBOO
FIMULTIBITMAP * DLL_CALLCONV
FreeImage_OpenMultiBitmapFromHandle(FREE_IMAGE_FORMAT fif, FreeImageIO *io, fi_handle handle, int flags) {
try {
bool read_only = false; // modifications (if any) will be stored into the memory cache
const bool read_only = false; // modifications (if any) will be stored into the memory cache

if (io && handle) {

Expand Down Expand Up @@ -432,28 +432,20 @@ bool SaveMultiBitmapToHandleImpl(FREE_IMAGE_FORMAT fif, FIMULTIBITMAP* bitmap, F
{
// read the compressed data

auto *compressed_data = (uint8_t*)malloc(i->getSize() * sizeof(uint8_t));
auto compressed_data = std::make_unique<uint8_t[]>(i->getSize());

header->m_cachefile.readFile((uint8_t *)compressed_data, i->getReference(), i->getSize());
header->m_cachefile.readFile(compressed_data.get(), i->getReference(), i->getSize());

// uncompress the data

FIMEMORY *hmem = FreeImage_OpenMemory(compressed_data, i->getSize());
FIBITMAP *dib = FreeImage_LoadFromMemory(header->cache_fif, hmem, 0);
FreeImage_CloseMemory(hmem);

// get rid of the buffer
free(compressed_data);
std::unique_ptr<FIMEMORY, decltype(&FreeImage_CloseMemory)> hmem(FreeImage_OpenMemory(compressed_data.get(), i->getSize()), &FreeImage_CloseMemory);
std::unique_ptr<FIBITMAP, decltype(&FreeImage_Unload)> dib(FreeImage_LoadFromMemory(header->cache_fif, hmem.get(), 0), &FreeImage_Unload);

// save the data

success = dst_node->Save(dib, dst_io, dst_handle, count, flags, dst_data);
success = dst_node->Save(dib.get(), dst_io, dst_handle, count, flags, dst_data);
count++;

// unload the dib

FreeImage_Unload(dib);

break;
}
}
Expand Down Expand Up @@ -605,25 +597,21 @@ FreeImage_SavePageToBlock(MULTIBITMAPHEADER *header, FIBITMAP *data) {
// compress the bitmap data

// open a memory handle
FIMEMORY *hmem = FreeImage_OpenMemory();
std::unique_ptr<FIMEMORY, decltype(&FreeImage_CloseMemory)> hmem(FreeImage_OpenMemory(), &FreeImage_CloseMemory);
if (!hmem) {
return res;
}
// save the file to memory
if (!FreeImage_SaveToMemory(header->cache_fif, data, hmem, 0)) {
FreeImage_CloseMemory(hmem);
if (!FreeImage_SaveToMemory(header->cache_fif, data, hmem.get(), 0)) {
return res;
}
// get the buffer from the memory stream
if (!FreeImage_AcquireMemory(hmem, &compressed_data, &compressed_size)) {
FreeImage_CloseMemory(hmem);
if (!FreeImage_AcquireMemory(hmem.get(), &compressed_data, &compressed_size)) {
return res;
}

// write the compressed data to the cache
int ref = header->m_cachefile.writeFile(compressed_data, compressed_size);
// get rid of the compressed data
FreeImage_CloseMemory(hmem);

res = PageBlock(BLOCK_REFERENCE, ref, compressed_size);

Expand Down Expand Up @@ -785,7 +773,7 @@ FreeImage_UnlockPage(FIMULTIBITMAP *bitmap, FIBITMAP *page, FIBOOL changed) {
int iPage = header->m_cachefile.writeFile(compressed_data, compressed_size);

*i = PageBlock(BLOCK_REFERENCE, iPage, compressed_size);

// get rid of the compressed data

FreeImage_CloseMemory(hmem);
Expand All @@ -810,8 +798,7 @@ FreeImage_MovePage(FIMULTIBITMAP *bitmap, int target, int source) {
BlockListIterator block_source = FreeImage_FindBlock(bitmap, target);
BlockListIterator block_target = FreeImage_FindBlock(bitmap, source);

header->m_blocks.insert(block_target, *block_source);
header->m_blocks.erase(block_source);
header->m_blocks.splice(block_target, header->m_blocks, block_source);

header->changed = true;

Expand Down Expand Up @@ -860,7 +847,7 @@ FreeImage_LoadMultiBitmapFromMemory(FREE_IMAGE_FORMAT fif, FIMEMORY *stream, int
return nullptr;
}

bool read_only = false; // modifications (if any) will be stored into the memory cache
const bool read_only = false; // modifications (if any) will be stored into the memory cache

// retrieve the plugin list to find the node belonging to this plugin

Expand Down
26 changes: 13 additions & 13 deletions Source/Plugins/PluginHDR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,40 +271,40 @@ rgbe_ReadHeader(FreeImageIO *io, fi_handle handle, unsigned *width, unsigned *he
*/
static FIBOOL
rgbe_WriteHeader(FreeImageIO *io, fi_handle handle, unsigned width, unsigned height, rgbeHeaderInfo *info) {
char buffer[HDR_MAXLINE];
char buffer[HDR_MAXLINE + 1];

const char *programtype = "RADIANCE";

if (info && (info->valid & RGBE_VALID_PROGRAMTYPE)) {
programtype = info->programtype;
}
// The #? is to identify file type, the programtype is optional
snprintf(buffer, std::size(buffer), "#?%s\n", programtype);
if (io->write_proc(buffer, 1, (unsigned int)strlen(buffer), handle) < 1) {
unsigned int len = snprintf(buffer, std::size(buffer), "#?%s\n", programtype);
if (io->write_proc(buffer, 1, len, handle) < 1) {
return rgbe_Error(rgbe_write_error, nullptr);
}
snprintf(buffer, std::size(buffer), "%s\n", info->comment);
if (io->write_proc(buffer, 1, (unsigned int)strlen(buffer), handle) < 1) {
len = snprintf(buffer, std::size(buffer), "%s\n", info->comment);
if (io->write_proc(buffer, 1, len, handle) < 1) {
return rgbe_Error(rgbe_write_error, nullptr);
}
snprintf(buffer, std::size(buffer), "FORMAT=32-bit_rle_rgbe\n");
if (io->write_proc(buffer, 1, (unsigned int)strlen(buffer), handle) < 1) {
len = snprintf(buffer, std::size(buffer), "FORMAT=32-bit_rle_rgbe\n");
if (io->write_proc(buffer, 1, len, handle) < 1) {
return rgbe_Error(rgbe_write_error, nullptr);
}
if (info && (info->valid & RGBE_VALID_GAMMA)) {
snprintf(buffer, std::size(buffer), "GAMMA=%g\n", info->gamma);
if (io->write_proc(buffer, 1, (unsigned int)strlen(buffer), handle) < 1) {
len = snprintf(buffer, std::size(buffer), "GAMMA=%g\n", info->gamma);
if (io->write_proc(buffer, 1, len, handle) < 1) {
return rgbe_Error(rgbe_write_error, nullptr);
}
}
if (info && (info->valid & RGBE_VALID_EXPOSURE)) {
snprintf(buffer,std::size(buffer), "EXPOSURE=%g\n", info->exposure);
if (io->write_proc(buffer, 1, (unsigned int)strlen(buffer), handle) < 1) {
len = snprintf(buffer,std::size(buffer), "EXPOSURE=%g\n", info->exposure);
if (io->write_proc(buffer, 1, len, handle) < 1) {
return rgbe_Error(rgbe_write_error, nullptr);
}
}
snprintf(buffer, std::size(buffer), "\n-Y %d +X %d\n", height, width);
if (io->write_proc(buffer, 1, (unsigned int)strlen(buffer), handle) < 1) {
len = snprintf(buffer, std::size(buffer), "\n-Y %d +X %d\n", height, width);
if (io->write_proc(buffer, 1, len, handle) < 1) {
return rgbe_Error(rgbe_write_error, nullptr);
}

Expand Down