12b0e5d60 Snapshot 202403 a4c9b1981 loop parameters in remove_trailing_spaces e231b01a4 CR3-Qstep table: avoid wrong 64-bit code generation 21368133a 0.21.2 release a6f212a4a tag type => tag size mapping fixed 41506ef73 cubic_spline: better handling of non-integer data 17294b5fd extra metadata check in arq_load_raw 47d9dd8e2 Better incorrect data handling in cubic_spline 3baa51068 skip invalid pattern in xtrans_interpolate eaf63bf5f Check HL recovery coeffs before processing a14574080 limit wavelet denoise minimum size 4e597e4e9 Merge pull request #594 from pinotree/path_max 086dcb9a6 raw-identify: use fallback if PATH_MAX not available 0e105f9f8 additional check against corrupted ljpeg layout 0c8b68e9f Disable color conversion for Canon 16-bit thumbnails cd1abd695 docs/changelog: explained the case when no thumbnail is found in specific file 6fffd414b rename swapXX to libraw_swapXX to avoid name conflict af78ae48a Check against corrupted LJPEG header in Canon sRAW decoder ba780e600 Limit embedded color profile allocation/read size 122bf7c5b Wrong alloc result check for 16-bit bitmap thumbnail e6dd2709e check pana_data/buffer offset before use ae2dc5884 Check P1 quadrant linearization coeff[15] against zero f2998bacc avoid integer overflow in buffer space check 443b7fb51 prevent buffer overrun in buffer_datastream::scanf_one 35a6d3615 ensure correct T.tlength for 16b bitmap thumbnails(2) b69ea8be5 ensure correct T.tlength for 16b bitmap thumbnails 2b6eca897 Do not run sraw decoder on (crafted) bayer files 68808b57f better striped thumbnails handling 9ab70f6dc do not set shrink flag for 3/4 component images 32425dd96 allow more decoders for fuji-rotated RAWs REVERT: 1ef70158d 0.21.2 release REVERT: 62f042366 tag type => tag size mapping fixed REVERT: ee087e3fe cubic_spline: better handling of non-integer data REVERT: af755b991 extra metadata check in arq_load_raw REVERT: 0fadd8819 Better incorrect data handling in cubic_spline REVERT: d7fb66053 skip invalid pattern in xtrans_interpolate REVERT: d059ed280 Check HL recovery coeffs before processing REVERT: 104730519 limit wavelet denoise minimum size REVERT: cae09838e raw-identify: use fallback if PATH_MAX not available REVERT: d6c677608 additional check against corrupted ljpeg layout REVERT: 1001a6ac1 Disable color conversion for Canon 16-bit thumbnails REVERT: a5130b01b docs/changelog: explained the case when no thumbnail is found in specific file REVERT: 600c0c63d rename swapXX to libraw_swapXX to avoid name conflict REVERT: 299c8a11b Check against corrupted LJPEG header in Canon sRAW decoder REVERT: ec8671ad9 Limit embedded color profile allocation/read size REVERT: 5229d5942 Wrong alloc result check for 16-bit bitmap thumbnail REVERT: b278b775f check pana_data/buffer offset before use REVERT: 7f4b8d3af Check P1 quadrant linearization coeff[15] against zero REVERT: e942a7db6 avoid integer overflow in buffer space check REVERT: f6a57cfb8 prevent buffer overrun in buffer_datastream::scanf_one REVERT: 3e62ed304 ensure correct T.tlength for 16b bitmap thumbnails(2) REVERT: 8e52d81cd ensure correct T.tlength for 16b bitmap thumbnails REVERT: 8e1af15e2 Do not run sraw decoder on (crafted) bayer files REVERT: 0ace959c2 better striped thumbnails handling REVERT: 477e0719f do not set shrink flag for 3/4 component images REVERT: c8efae6c5 allow more decoders for fuji-rotated RAWs git-subtree-dir: rtengine/libraw git-subtree-split: 12b0e5d60c57bb795382fda8494fc45f683550b8
149 lines
3.1 KiB
C++
149 lines
3.1 KiB
C++
/* -*- C++ -*-
|
|
* File: libraw_alloc.h
|
|
* Copyright 2008-2024 LibRaw LLC (info@libraw.org)
|
|
* Created: Sat Mar 22, 2008
|
|
*
|
|
* LibRaw C++ interface
|
|
*
|
|
LibRaw is free software; you can redistribute it and/or modify
|
|
it under the terms of the one of two licenses as you choose:
|
|
|
|
1. GNU LESSER GENERAL PUBLIC LICENSE version 2.1
|
|
(See file LICENSE.LGPL provided in LibRaw distribution archive for details).
|
|
|
|
2. COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
|
|
(See file LICENSE.CDDL provided in LibRaw distribution archive for details).
|
|
|
|
*/
|
|
|
|
#ifndef __LIBRAW_ALLOC_H
|
|
#define __LIBRAW_ALLOC_H
|
|
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include "libraw_const.h"
|
|
|
|
#ifdef __cplusplus
|
|
|
|
#define LIBRAW_MSIZE 512
|
|
|
|
class DllDef libraw_memmgr
|
|
{
|
|
public:
|
|
libraw_memmgr(unsigned ee) : extra_bytes(ee)
|
|
{
|
|
size_t alloc_sz = LIBRAW_MSIZE * sizeof(void *);
|
|
mems = (void **)::malloc(alloc_sz);
|
|
memset(mems, 0, alloc_sz);
|
|
}
|
|
~libraw_memmgr()
|
|
{
|
|
cleanup();
|
|
::free(mems);
|
|
}
|
|
void *malloc(size_t sz)
|
|
{
|
|
#ifdef LIBRAW_USE_CALLOC_INSTEAD_OF_MALLOC
|
|
void *ptr = ::calloc(sz + extra_bytes, 1);
|
|
#else
|
|
void *ptr = ::malloc(sz + extra_bytes);
|
|
#endif
|
|
mem_ptr(ptr);
|
|
return ptr;
|
|
}
|
|
void *calloc(size_t n, size_t sz)
|
|
{
|
|
void *ptr = ::calloc(n + (extra_bytes + sz - 1) / (sz ? sz : 1), sz);
|
|
mem_ptr(ptr);
|
|
return ptr;
|
|
}
|
|
void *realloc(void *ptr, size_t newsz)
|
|
{
|
|
void *ret = ::realloc(ptr, newsz + extra_bytes);
|
|
forget_ptr(ptr);
|
|
mem_ptr(ret);
|
|
return ret;
|
|
}
|
|
void free(void *ptr)
|
|
{
|
|
forget_ptr(ptr);
|
|
::free(ptr);
|
|
}
|
|
void cleanup(void)
|
|
{
|
|
for (int i = 0; i < LIBRAW_MSIZE; i++)
|
|
if (mems[i])
|
|
{
|
|
::free(mems[i]);
|
|
mems[i] = NULL;
|
|
}
|
|
}
|
|
|
|
private:
|
|
void **mems;
|
|
unsigned extra_bytes;
|
|
void mem_ptr(void *ptr)
|
|
{
|
|
#if defined(LIBRAW_USE_OPENMP)
|
|
bool ok = false; /* do not return from critical section */
|
|
#endif
|
|
|
|
#if defined(LIBRAW_USE_OPENMP)
|
|
#pragma omp critical
|
|
{
|
|
#endif
|
|
if (ptr)
|
|
{
|
|
for (int i = 0; i < LIBRAW_MSIZE - 1; i++)
|
|
if (!mems[i])
|
|
{
|
|
mems[i] = ptr;
|
|
#if defined(LIBRAW_USE_OPENMP)
|
|
ok = true;
|
|
break;
|
|
#else
|
|
return;
|
|
#endif
|
|
}
|
|
#ifdef LIBRAW_MEMPOOL_CHECK
|
|
#if !defined(LIBRAW_USE_OPENMP)
|
|
/* remember ptr in last mems item to be free'ed at cleanup */
|
|
if (!mems[LIBRAW_MSIZE - 1])
|
|
mems[LIBRAW_MSIZE - 1] = ptr;
|
|
throw LIBRAW_EXCEPTION_MEMPOOL;
|
|
#endif
|
|
#endif
|
|
}
|
|
#if defined(LIBRAW_USE_OPENMP)
|
|
}
|
|
if(!ok)
|
|
{
|
|
if (!mems[LIBRAW_MSIZE - 1])
|
|
mems[LIBRAW_MSIZE - 1] = ptr;
|
|
throw LIBRAW_EXCEPTION_MEMPOOL;
|
|
}
|
|
#endif
|
|
}
|
|
void forget_ptr(void *ptr)
|
|
{
|
|
#if defined(LIBRAW_USE_OPENMP)
|
|
#pragma omp critical
|
|
{
|
|
#endif
|
|
if (ptr)
|
|
for (int i = 0; i < LIBRAW_MSIZE; i++)
|
|
if (mems[i] == ptr)
|
|
{
|
|
mems[i] = NULL;
|
|
break;
|
|
}
|
|
#if defined(LIBRAW_USE_OPENMP)
|
|
}
|
|
#endif
|
|
}
|
|
};
|
|
|
|
#endif /* C++ */
|
|
|
|
#endif
|