Refactor: Improve image buffer save/load function names and arguments
This commit is contained in:
@@ -3420,7 +3420,7 @@ void dynamicPaint_outputSurfaceImage(DynamicPaintSurface *surface,
|
||||
}
|
||||
|
||||
/* Save image */
|
||||
IMB_saveiff(ibuf, output_file, IB_float_data);
|
||||
IMB_save_image(ibuf, output_file, IB_float_data);
|
||||
IMB_freeImBuf(ibuf);
|
||||
}
|
||||
|
||||
|
||||
@@ -1016,7 +1016,8 @@ static void image_init_color_management(Image *ima)
|
||||
BKE_image_user_file_path(nullptr, ima, filepath);
|
||||
|
||||
/* Will set input color space to image format default's. */
|
||||
ibuf = IMB_loadiffname(filepath, IB_test | IB_alphamode_detect, ima->colorspace_settings.name);
|
||||
ibuf = IMB_load_image_from_filepath(
|
||||
filepath, IB_test | IB_alphamode_detect, ima->colorspace_settings.name);
|
||||
|
||||
if (ibuf) {
|
||||
if (ibuf->flags & IB_alphamode_premul) {
|
||||
@@ -1412,7 +1413,7 @@ static bool image_memorypack_imbuf(
|
||||
{
|
||||
ibuf->ftype = (ibuf->float_buffer.data) ? IMB_FTYPE_OPENEXR : IMB_FTYPE_PNG;
|
||||
|
||||
IMB_saveiff(ibuf, filepath, IB_byte_data | IB_mem);
|
||||
IMB_save_image(ibuf, filepath, IB_byte_data | IB_mem);
|
||||
|
||||
if (ibuf->encoded_buffer.data == nullptr) {
|
||||
CLOG_STR_ERROR(&LOG, "memory save for pack error");
|
||||
@@ -2671,7 +2672,7 @@ bool BKE_imbuf_write(ImBuf *ibuf, const char *filepath, const ImageFormatData *i
|
||||
|
||||
BLI_file_ensure_parent_dir_exists(filepath);
|
||||
|
||||
const bool ok = IMB_saveiff(ibuf, filepath, IB_byte_data);
|
||||
const bool ok = IMB_save_image(ibuf, filepath, IB_byte_data);
|
||||
if (ok == 0) {
|
||||
perror(filepath);
|
||||
}
|
||||
@@ -4287,11 +4288,12 @@ static ImBuf *load_image_single(Image *ima,
|
||||
LISTBASE_FOREACH (ImagePackedFile *, imapf, &ima->packedfiles) {
|
||||
if (imapf->view == view_id && imapf->tile_number == tile_number) {
|
||||
if (imapf->packedfile) {
|
||||
ibuf = IMB_ibImageFromMemory((uchar *)imapf->packedfile->data,
|
||||
imapf->packedfile->size,
|
||||
flag,
|
||||
ima->colorspace_settings.name,
|
||||
"<packed data>");
|
||||
ibuf = IMB_load_image_from_memory((uchar *)imapf->packedfile->data,
|
||||
imapf->packedfile->size,
|
||||
flag,
|
||||
"<packed data>",
|
||||
nullptr,
|
||||
ima->colorspace_settings.name);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -4321,7 +4323,7 @@ static ImBuf *load_image_single(Image *ima,
|
||||
BKE_image_user_file_path(&iuser_t, ima, filepath);
|
||||
|
||||
/* read ibuf */
|
||||
ibuf = IMB_loadiffname(filepath, flag, ima->colorspace_settings.name);
|
||||
ibuf = IMB_load_image_from_filepath(filepath, flag, ima->colorspace_settings.name);
|
||||
}
|
||||
|
||||
if (ibuf) {
|
||||
|
||||
@@ -572,7 +572,7 @@ static ImBuf *movieclip_load_sequence_file(MovieClip *clip,
|
||||
loadflag = IB_byte_data | IB_multilayer | IB_alphamode_detect | IB_metadata;
|
||||
|
||||
/* read ibuf */
|
||||
ibuf = IMB_loadiffname(filepath, loadflag, colorspace);
|
||||
ibuf = IMB_load_image_from_filepath(filepath, loadflag, colorspace);
|
||||
BKE_movieclip_convert_multilayer_ibuf(ibuf);
|
||||
|
||||
return ibuf;
|
||||
@@ -936,7 +936,7 @@ static void detect_clip_source(Main *bmain, MovieClip *clip)
|
||||
STRNCPY(filepath, clip->filepath);
|
||||
BLI_path_abs(filepath, BKE_main_blendfile_path(bmain));
|
||||
|
||||
ibuf = IMB_testiffname(filepath, IB_byte_data | IB_multilayer);
|
||||
ibuf = IMB_load_image_from_filepath(filepath, IB_byte_data | IB_multilayer | IB_test);
|
||||
if (ibuf) {
|
||||
clip->source = MCLIP_SRC_SEQUENCE;
|
||||
IMB_freeImBuf(ibuf);
|
||||
@@ -1793,7 +1793,7 @@ static void movieclip_build_proxy_ibuf(const MovieClip *clip,
|
||||
BLI_thread_lock(LOCK_MOVIECLIP);
|
||||
|
||||
BLI_file_ensure_parent_dir_exists(filepath);
|
||||
if (IMB_saveiff(scaleibuf, filepath, IB_byte_data) == 0) {
|
||||
if (IMB_save_image(scaleibuf, filepath, IB_byte_data) == 0) {
|
||||
perror(filepath);
|
||||
}
|
||||
|
||||
|
||||
@@ -1357,19 +1357,19 @@ void BKE_ocean_simulate_cache(OceanCache *och, int frame)
|
||||
* files were saved with default settings too. */
|
||||
|
||||
cache_filepath(filepath, och->bakepath, och->relbase, frame, CACHE_TYPE_DISPLACE);
|
||||
och->ibufs_disp[f] = IMB_loadiffname(filepath, 0, nullptr);
|
||||
och->ibufs_disp[f] = IMB_load_image_from_filepath(filepath, 0);
|
||||
|
||||
cache_filepath(filepath, och->bakepath, och->relbase, frame, CACHE_TYPE_FOAM);
|
||||
och->ibufs_foam[f] = IMB_loadiffname(filepath, 0, nullptr);
|
||||
och->ibufs_foam[f] = IMB_load_image_from_filepath(filepath, 0);
|
||||
|
||||
cache_filepath(filepath, och->bakepath, och->relbase, frame, CACHE_TYPE_SPRAY);
|
||||
och->ibufs_spray[f] = IMB_loadiffname(filepath, 0, nullptr);
|
||||
och->ibufs_spray[f] = IMB_load_image_from_filepath(filepath, 0);
|
||||
|
||||
cache_filepath(filepath, och->bakepath, och->relbase, frame, CACHE_TYPE_SPRAY_INVERSE);
|
||||
och->ibufs_spray_inverse[f] = IMB_loadiffname(filepath, 0, nullptr);
|
||||
och->ibufs_spray_inverse[f] = IMB_load_image_from_filepath(filepath, 0);
|
||||
|
||||
cache_filepath(filepath, och->bakepath, och->relbase, frame, CACHE_TYPE_NORMAL);
|
||||
och->ibufs_norm[f] = IMB_loadiffname(filepath, 0, nullptr);
|
||||
och->ibufs_norm[f] = IMB_load_image_from_filepath(filepath, 0);
|
||||
}
|
||||
|
||||
void BKE_ocean_bake(Ocean *o,
|
||||
|
||||
@@ -567,7 +567,7 @@ static void unpack_generate_paths(const char *filepath,
|
||||
if (imapf != nullptr && imapf->packedfile != nullptr) {
|
||||
const PackedFile *pf = imapf->packedfile;
|
||||
enum eImbFileType ftype = eImbFileType(
|
||||
IMB_ispic_type_from_memory((const uchar *)pf->data, pf->size));
|
||||
IMB_test_image_type_from_memory((const uchar *)pf->data, pf->size));
|
||||
if (ima->source == IMA_SRC_TILED) {
|
||||
char tile_number[6];
|
||||
SNPRINTF(tile_number, ".%d", imapf->tile_number);
|
||||
|
||||
@@ -346,7 +346,7 @@ static void studiolight_multilayer_addpass(void *base,
|
||||
static void studiolight_load_equirect_image(StudioLight *sl)
|
||||
{
|
||||
if (sl->flag & STUDIOLIGHT_EXTERNAL_FILE) {
|
||||
ImBuf *ibuf = IMB_loadiffname(sl->filepath, IB_multilayer | IB_alphamode_ignore, nullptr);
|
||||
ImBuf *ibuf = IMB_load_image_from_filepath(sl->filepath, IB_multilayer | IB_alphamode_ignore);
|
||||
ImBuf *specular_ibuf = nullptr;
|
||||
ImBuf *diffuse_ibuf = nullptr;
|
||||
const bool failed = (ibuf == nullptr);
|
||||
|
||||
@@ -916,8 +916,8 @@ static void icon_verify_datatoc(IconImage *iimg)
|
||||
}
|
||||
|
||||
if (iimg->datatoc_rect) {
|
||||
ImBuf *bbuf = IMB_ibImageFromMemory(
|
||||
iimg->datatoc_rect, iimg->datatoc_size, IB_byte_data, nullptr, "<matcap icon>");
|
||||
ImBuf *bbuf = IMB_load_image_from_memory(
|
||||
iimg->datatoc_rect, iimg->datatoc_size, IB_byte_data, "<matcap icon>");
|
||||
/* w and h were set on initialize */
|
||||
if (bbuf->x != iimg->h && bbuf->y != iimg->w) {
|
||||
IMB_scale(bbuf, iimg->w, iimg->h, IMBScaleFilter::Box, false);
|
||||
@@ -1369,11 +1369,10 @@ PreviewImage *UI_icon_to_preview(int icon_id)
|
||||
else if (di->data.buffer.image) {
|
||||
ImBuf *bbuf;
|
||||
|
||||
bbuf = IMB_ibImageFromMemory(di->data.buffer.image->datatoc_rect,
|
||||
di->data.buffer.image->datatoc_size,
|
||||
IB_byte_data,
|
||||
nullptr,
|
||||
__func__);
|
||||
bbuf = IMB_load_image_from_memory(di->data.buffer.image->datatoc_rect,
|
||||
di->data.buffer.image->datatoc_size,
|
||||
IB_byte_data,
|
||||
__func__);
|
||||
if (bbuf) {
|
||||
PreviewImage *prv = BKE_previewimg_create();
|
||||
|
||||
|
||||
@@ -1351,7 +1351,7 @@ static ImBuf *icon_preview_imbuf_from_brush(Brush *brush)
|
||||
BLI_path_abs(filepath, ID_BLEND_PATH_FROM_GLOBAL(&brush->id));
|
||||
|
||||
/* Use default color-spaces for brushes. */
|
||||
brush->icon_imbuf = IMB_loadiffname(filepath, flags, nullptr);
|
||||
brush->icon_imbuf = IMB_load_image_from_filepath(filepath, flags);
|
||||
|
||||
if (brush->icon_imbuf) {
|
||||
BKE_icon_changed(BKE_icon_id_ensure(&brush->id));
|
||||
|
||||
@@ -862,7 +862,7 @@ static void prefetch_task_func(TaskPool *__restrict pool, void *task_data)
|
||||
colorspace_name = clip->colorspace_settings.name;
|
||||
}
|
||||
|
||||
ibuf = IMB_ibImageFromMemory(mem, size, flag, colorspace_name, "prefetch frame");
|
||||
ibuf = IMB_load_image_from_memory(mem, size, flag, "prefetch frame", nullptr, colorspace_name);
|
||||
if (ibuf == nullptr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1368,11 +1368,12 @@ static void proxy_task_func(TaskPool *__restrict pool, void *task_data)
|
||||
while ((mem = proxy_thread_next_frame(queue, data->clip, &size, &cfra))) {
|
||||
ImBuf *ibuf;
|
||||
|
||||
ibuf = IMB_ibImageFromMemory(mem,
|
||||
size,
|
||||
IB_byte_data | IB_multilayer | IB_alphamode_detect,
|
||||
data->clip->colorspace_settings.name,
|
||||
"proxy frame");
|
||||
ibuf = IMB_load_image_from_memory(mem,
|
||||
size,
|
||||
IB_byte_data | IB_multilayer | IB_alphamode_detect,
|
||||
"proxy frame",
|
||||
nullptr,
|
||||
data->clip->colorspace_settings.name);
|
||||
|
||||
BKE_movieclip_build_proxy_frame_for_ibuf(
|
||||
data->clip, ibuf, nullptr, cfra, data->build_sizes, data->build_count, false);
|
||||
|
||||
@@ -2307,7 +2307,7 @@ static wmOperatorStatus image_save_sequence_exec(bContext *C, wmOperator *op)
|
||||
ibuf = IMB_moviecacheIter_getImBuf(iter);
|
||||
|
||||
if (ibuf != nullptr && ibuf->userflags & IB_BITMAPDIRTY) {
|
||||
if (0 == IMB_saveiff(ibuf, ibuf->filepath, IB_byte_data)) {
|
||||
if (0 == IMB_save_image(ibuf, ibuf->filepath, IB_byte_data)) {
|
||||
BKE_reportf(op->reports, RPT_ERROR, "Could not write image: %s", strerror(errno));
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -338,7 +338,7 @@ void Canvas::loadMap(const char *iFileName, const char *iMapName, uint iNbLevels
|
||||
qimg = &newMap;
|
||||
#endif
|
||||
/* OCIO_TODO: support different input color space */
|
||||
ImBuf *qimg = IMB_loadiffname(filePath.c_str(), 0, nullptr);
|
||||
ImBuf *qimg = IMB_load_image_from_filepath(filePath.c_str(), 0);
|
||||
if (qimg == nullptr) {
|
||||
cerr << "Could not load image file " << filePath << endl;
|
||||
return;
|
||||
@@ -430,7 +430,7 @@ void Canvas::loadMap(const char *iFileName, const char *iMapName, uint iNbLevels
|
||||
filepath << base;
|
||||
filepath << i << ".bmp";
|
||||
qtmp->ftype = IMB_FTYPE_BMP;
|
||||
IMB_saveiff(qtmp, const_cast<char *>(filepath.str().c_str()), 0);
|
||||
IMB_save_image(qtmp, const_cast<char *>(filepath.str().c_str()), 0);
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
||||
@@ -266,7 +266,7 @@ void SteerableViewMap::saveSteerableViewMap() const
|
||||
filepath << base;
|
||||
filepath << i << "-" << j << ".png";
|
||||
ibuf->ftype = IMB_FTYPE_PNG;
|
||||
IMB_saveiff(ibuf, const_cast<char *>(filepath.str().c_str()), 0);
|
||||
IMB_save_image(ibuf, const_cast<char *>(filepath.str().c_str()), 0);
|
||||
}
|
||||
#if 0
|
||||
QString base("SteerableViewMap");
|
||||
|
||||
@@ -26,20 +26,47 @@ struct GSet;
|
||||
struct ImageFormatData;
|
||||
struct Stereo3dFormat;
|
||||
|
||||
/**
|
||||
* Module init/exit.
|
||||
*/
|
||||
void IMB_init();
|
||||
void IMB_exit();
|
||||
|
||||
ImBuf *IMB_ibImageFromMemory(const unsigned char *mem,
|
||||
size_t size,
|
||||
int flags,
|
||||
char colorspace[IM_MAX_SPACE],
|
||||
const char *descr,
|
||||
const char *filepath = nullptr);
|
||||
/**
|
||||
* Load image.
|
||||
*/
|
||||
ImBuf *IMB_load_image_from_memory(const unsigned char *mem,
|
||||
const size_t size,
|
||||
const int flags,
|
||||
const char *descr,
|
||||
const char *filepath = nullptr,
|
||||
char r_colorspace[IM_MAX_SPACE] = nullptr);
|
||||
|
||||
ImBuf *IMB_testiffname(const char *filepath, int flags);
|
||||
ImBuf *IMB_load_image_from_file_descriptor(const int file,
|
||||
const int flags,
|
||||
const char *filepath = nullptr,
|
||||
char r_colorspace[IM_MAX_SPACE] = nullptr);
|
||||
|
||||
ImBuf *IMB_loadiffname(const char *filepath, int flags, char colorspace[IM_MAX_SPACE]);
|
||||
ImBuf *IMB_load_image_from_filepath(const char *filepath,
|
||||
const int flags,
|
||||
char r_colorspace[IM_MAX_SPACE] = nullptr);
|
||||
|
||||
/**
|
||||
* Save image.
|
||||
*/
|
||||
bool IMB_save_image(ImBuf *ibuf, const char *filepath, const int flags);
|
||||
|
||||
/*
|
||||
* Test image file.
|
||||
*/
|
||||
bool IMB_test_image(const char *filepath);
|
||||
bool IMB_test_image_type_matches(const char *filepath, int filetype);
|
||||
int IMB_test_image_type_from_memory(const unsigned char *buf, size_t buf_size);
|
||||
int IMB_test_image_type(const char *filepath);
|
||||
|
||||
/*
|
||||
* Load thumbnail image.
|
||||
*/
|
||||
enum class IMBThumbLoadFlags {
|
||||
Zero = 0,
|
||||
/** Normally files larger than 100MB are not loaded for thumbnails, except when this flag is set.
|
||||
@@ -51,11 +78,13 @@ ENUM_OPERATORS(IMBThumbLoadFlags, IMBThumbLoadFlags::LoadLargeFiles);
|
||||
ImBuf *IMB_thumb_load_image(const char *filepath,
|
||||
const size_t max_thumb_size,
|
||||
char colorspace[IM_MAX_SPACE],
|
||||
IMBThumbLoadFlags load_flags = IMBThumbLoadFlags::Zero);
|
||||
|
||||
void IMB_freeImBuf(ImBuf *ibuf);
|
||||
const IMBThumbLoadFlags load_flags = IMBThumbLoadFlags::Zero);
|
||||
|
||||
/*
|
||||
* Allocate and free image buffer.
|
||||
*/
|
||||
ImBuf *IMB_allocImBuf(unsigned int x, unsigned int y, unsigned char planes, unsigned int flags);
|
||||
void IMB_freeImBuf(ImBuf *ibuf);
|
||||
|
||||
/**
|
||||
* Initialize given ImBuf.
|
||||
@@ -322,13 +351,6 @@ ImBuf *IMB_scale_into_new(const ImBuf *ibuf,
|
||||
IMBScaleFilter filter,
|
||||
bool threaded = true);
|
||||
|
||||
bool IMB_saveiff(ImBuf *ibuf, const char *filepath, int flags);
|
||||
|
||||
bool IMB_ispic(const char *filepath);
|
||||
bool IMB_ispic_type_matches(const char *filepath, int filetype);
|
||||
int IMB_ispic_type_from_memory(const unsigned char *buf, size_t buf_size);
|
||||
int IMB_ispic_type(const char *filepath);
|
||||
|
||||
/**
|
||||
* Test if color-space conversions of pixels in buffer need to take into account alpha.
|
||||
*/
|
||||
@@ -446,8 +468,6 @@ void IMB_convert_rgba_to_abgr(ImBuf *ibuf);
|
||||
void IMB_alpha_under_color_float(float *rect_float, int x, int y, float backcol[3]);
|
||||
void IMB_alpha_under_color_byte(unsigned char *rect, int x, int y, const float backcol[3]);
|
||||
|
||||
ImBuf *IMB_loadifffile(int file, int flags, char colorspace[IM_MAX_SPACE], const char *filepath);
|
||||
|
||||
ImBuf *IMB_half_x(ImBuf *ibuf1);
|
||||
ImBuf *IMB_half_y(ImBuf *ibuf1);
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ struct ImFileType {
|
||||
/**
|
||||
* Check if the data matches this file types 'magic',
|
||||
* \note that this may only read in a small part of the files header,
|
||||
* see: #IMB_ispic_type for details.
|
||||
* see: #IMB_test_image_type for details.
|
||||
*/
|
||||
bool (*is_a)(const unsigned char *buf, size_t size);
|
||||
|
||||
|
||||
@@ -111,12 +111,12 @@ static void imb_handle_colorspace_and_alpha(ImBuf *ibuf,
|
||||
colormanage_imbuf_make_linear(ibuf, new_colorspace);
|
||||
}
|
||||
|
||||
ImBuf *IMB_ibImageFromMemory(const uchar *mem,
|
||||
size_t size,
|
||||
int flags,
|
||||
char colorspace[IM_MAX_SPACE],
|
||||
const char *descr,
|
||||
const char *filepath)
|
||||
ImBuf *IMB_load_image_from_memory(const uchar *mem,
|
||||
const size_t size,
|
||||
const int flags,
|
||||
const char *descr,
|
||||
const char *filepath,
|
||||
char r_colorspace[IM_MAX_SPACE])
|
||||
{
|
||||
ImBuf *ibuf;
|
||||
const ImFileType *type;
|
||||
@@ -132,7 +132,7 @@ ImBuf *IMB_ibImageFromMemory(const uchar *mem,
|
||||
if (type->load) {
|
||||
ibuf = type->load(mem, size, flags, file_colorspace);
|
||||
if (ibuf) {
|
||||
imb_handle_colorspace_and_alpha(ibuf, flags, filepath, file_colorspace, colorspace);
|
||||
imb_handle_colorspace_and_alpha(ibuf, flags, filepath, file_colorspace, r_colorspace);
|
||||
return ibuf;
|
||||
}
|
||||
}
|
||||
@@ -145,7 +145,10 @@ ImBuf *IMB_ibImageFromMemory(const uchar *mem,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ImBuf *IMB_loadifffile(int file, int flags, char colorspace[IM_MAX_SPACE], const char *filepath)
|
||||
ImBuf *IMB_load_image_from_file_descriptor(const int file,
|
||||
const int flags,
|
||||
const char *filepath,
|
||||
char r_colorspace[IM_MAX_SPACE])
|
||||
{
|
||||
ImBuf *ibuf;
|
||||
|
||||
@@ -164,7 +167,7 @@ ImBuf *IMB_loadifffile(int file, int flags, char colorspace[IM_MAX_SPACE], const
|
||||
const uchar *mem = static_cast<const uchar *>(BLI_mmap_get_pointer(mmap_file));
|
||||
const size_t size = BLI_mmap_get_length(mmap_file);
|
||||
|
||||
ibuf = IMB_ibImageFromMemory(mem, size, flags, colorspace, filepath, filepath);
|
||||
ibuf = IMB_load_image_from_memory(mem, size, flags, filepath, filepath, r_colorspace);
|
||||
|
||||
imb_mmap_lock();
|
||||
BLI_mmap_free(mmap_file);
|
||||
@@ -173,7 +176,9 @@ ImBuf *IMB_loadifffile(int file, int flags, char colorspace[IM_MAX_SPACE], const
|
||||
return ibuf;
|
||||
}
|
||||
|
||||
ImBuf *IMB_loadiffname(const char *filepath, int flags, char colorspace[IM_MAX_SPACE])
|
||||
ImBuf *IMB_load_image_from_filepath(const char *filepath,
|
||||
const int flags,
|
||||
char r_colorspace[IM_MAX_SPACE])
|
||||
{
|
||||
ImBuf *ibuf;
|
||||
int file;
|
||||
@@ -185,7 +190,7 @@ ImBuf *IMB_loadiffname(const char *filepath, int flags, char colorspace[IM_MAX_S
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ibuf = IMB_loadifffile(file, flags, colorspace, filepath);
|
||||
ibuf = IMB_load_image_from_file_descriptor(file, flags, filepath, r_colorspace);
|
||||
|
||||
if (ibuf) {
|
||||
STRNCPY(ibuf->filepath, filepath);
|
||||
@@ -197,11 +202,11 @@ ImBuf *IMB_loadiffname(const char *filepath, int flags, char colorspace[IM_MAX_S
|
||||
}
|
||||
|
||||
ImBuf *IMB_thumb_load_image(const char *filepath,
|
||||
size_t max_thumb_size,
|
||||
char colorspace[IM_MAX_SPACE],
|
||||
IMBThumbLoadFlags load_flags)
|
||||
const size_t max_thumb_size,
|
||||
char r_colorspace[IM_MAX_SPACE],
|
||||
const IMBThumbLoadFlags load_flags)
|
||||
{
|
||||
const ImFileType *type = IMB_file_type_from_ftype(IMB_ispic_type(filepath));
|
||||
const ImFileType *type = IMB_file_type_from_ftype(IMB_test_image_type(filepath));
|
||||
if (type == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
@@ -217,7 +222,7 @@ ImBuf *IMB_thumb_load_image(const char *filepath,
|
||||
ibuf = type->load_filepath_thumbnail(
|
||||
filepath, flags, max_thumb_size, file_colorspace, &width, &height);
|
||||
if (ibuf) {
|
||||
imb_handle_colorspace_and_alpha(ibuf, flags, filepath, file_colorspace, colorspace);
|
||||
imb_handle_colorspace_and_alpha(ibuf, flags, filepath, file_colorspace, r_colorspace);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -228,7 +233,7 @@ ImBuf *IMB_thumb_load_image(const char *filepath,
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
ibuf = IMB_loadiffname(filepath, flags, colorspace);
|
||||
ibuf = IMB_load_image_from_filepath(filepath, flags, r_colorspace);
|
||||
if (ibuf) {
|
||||
width = ibuf->x;
|
||||
height = ibuf->y;
|
||||
@@ -250,27 +255,3 @@ ImBuf *IMB_thumb_load_image(const char *filepath,
|
||||
|
||||
return ibuf;
|
||||
}
|
||||
|
||||
ImBuf *IMB_testiffname(const char *filepath, int flags)
|
||||
{
|
||||
ImBuf *ibuf;
|
||||
int file;
|
||||
char colorspace[IM_MAX_SPACE] = "\0";
|
||||
|
||||
BLI_assert(!BLI_path_is_rel(filepath));
|
||||
|
||||
file = BLI_open(filepath, O_BINARY | O_RDONLY, 0);
|
||||
if (file == -1) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ibuf = IMB_loadifffile(file, flags | IB_test | IB_multilayer, colorspace, filepath);
|
||||
|
||||
if (ibuf) {
|
||||
STRNCPY(ibuf->filepath, filepath);
|
||||
}
|
||||
|
||||
close(file);
|
||||
|
||||
return ibuf;
|
||||
}
|
||||
|
||||
@@ -444,7 +444,7 @@ static ImBuf *thumb_create_ex(const char *file_path,
|
||||
IMB_byte_from_float(img);
|
||||
IMB_free_float_pixels(img);
|
||||
|
||||
if (IMB_saveiff(img, temp, IB_byte_data | IB_metadata)) {
|
||||
if (IMB_save_image(img, temp, IB_byte_data | IB_metadata)) {
|
||||
#ifndef WIN32
|
||||
chmod(temp, S_IRUSR | S_IWUSR);
|
||||
#endif
|
||||
@@ -507,7 +507,7 @@ ImBuf *IMB_thumb_read(const char *file_or_lib_path, ThumbSize size)
|
||||
return nullptr;
|
||||
}
|
||||
if (thumbpath_from_uri(uri, thumb, sizeof(thumb), size)) {
|
||||
img = IMB_loadiffname(thumb, IB_byte_data | IB_metadata, nullptr);
|
||||
img = IMB_load_image_from_filepath(thumb, IB_byte_data | IB_metadata);
|
||||
}
|
||||
|
||||
return img;
|
||||
@@ -565,7 +565,7 @@ ImBuf *IMB_thumb_manage(const char *file_or_lib_path, ThumbSize size, ThumbSourc
|
||||
if (file_attributes & FILE_ATTR_OFFLINE) {
|
||||
char thumb_path[FILE_MAX];
|
||||
if (thumbpath_from_uri(uri, thumb_path, sizeof(thumb_path), size)) {
|
||||
return IMB_loadiffname(thumb_path, IB_byte_data | IB_metadata, nullptr);
|
||||
return IMB_load_image_from_filepath(thumb_path, IB_byte_data | IB_metadata);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
@@ -592,10 +592,10 @@ ImBuf *IMB_thumb_manage(const char *file_or_lib_path, ThumbSize size, ThumbSourc
|
||||
/* The requested path points to a generated thumbnail already (path into the thumbnail cache
|
||||
* directory). Attempt to load that, there's nothing we can recreate. */
|
||||
if (BLI_path_ncmp(file_or_lib_path, thumb_path, sizeof(thumb_path)) == 0) {
|
||||
img = IMB_loadiffname(file_or_lib_path, IB_byte_data, nullptr);
|
||||
img = IMB_load_image_from_filepath(file_or_lib_path, IB_byte_data);
|
||||
}
|
||||
else {
|
||||
img = IMB_loadiffname(thumb_path, IB_byte_data | IB_metadata, nullptr);
|
||||
img = IMB_load_image_from_filepath(thumb_path, IB_byte_data | IB_metadata);
|
||||
if (img) {
|
||||
bool regenerate = false;
|
||||
|
||||
|
||||
@@ -74,7 +74,8 @@ const char *imb_ext_audio[] = {
|
||||
/* OIIO will validate the entire header of some files and DPX requires 2048 */
|
||||
#define HEADER_SIZE 2048
|
||||
|
||||
static int64_t imb_ispic_read_header_from_filepath(const char *filepath, uchar buf[HEADER_SIZE])
|
||||
static int64_t imb_test_image_read_header_from_filepath(const char *filepath,
|
||||
uchar buf[HEADER_SIZE])
|
||||
{
|
||||
BLI_stat_t st;
|
||||
int fp;
|
||||
@@ -102,7 +103,7 @@ static int64_t imb_ispic_read_header_from_filepath(const char *filepath, uchar b
|
||||
return size;
|
||||
}
|
||||
|
||||
int IMB_ispic_type_from_memory(const uchar *buf, const size_t buf_size)
|
||||
int IMB_test_image_type_from_memory(const uchar *buf, const size_t buf_size)
|
||||
{
|
||||
for (const ImFileType *type = IMB_FILE_TYPES; type < IMB_FILE_TYPES_LAST; type++) {
|
||||
if (type->is_a != nullptr) {
|
||||
@@ -115,20 +116,20 @@ int IMB_ispic_type_from_memory(const uchar *buf, const size_t buf_size)
|
||||
return IMB_FTYPE_NONE;
|
||||
}
|
||||
|
||||
int IMB_ispic_type(const char *filepath)
|
||||
int IMB_test_image_type(const char *filepath)
|
||||
{
|
||||
uchar buf[HEADER_SIZE];
|
||||
const int64_t buf_size = imb_ispic_read_header_from_filepath(filepath, buf);
|
||||
const int64_t buf_size = imb_test_image_read_header_from_filepath(filepath, buf);
|
||||
if (buf_size <= 0) {
|
||||
return IMB_FTYPE_NONE;
|
||||
}
|
||||
return IMB_ispic_type_from_memory(buf, size_t(buf_size));
|
||||
return IMB_test_image_type_from_memory(buf, size_t(buf_size));
|
||||
}
|
||||
|
||||
bool IMB_ispic_type_matches(const char *filepath, int filetype)
|
||||
bool IMB_test_image_type_matches(const char *filepath, int filetype)
|
||||
{
|
||||
uchar buf[HEADER_SIZE];
|
||||
const int64_t buf_size = imb_ispic_read_header_from_filepath(filepath, buf);
|
||||
const int64_t buf_size = imb_test_image_read_header_from_filepath(filepath, buf);
|
||||
if (buf_size <= 0) {
|
||||
return false;
|
||||
}
|
||||
@@ -147,7 +148,7 @@ bool IMB_ispic_type_matches(const char *filepath, int filetype)
|
||||
|
||||
#undef HEADER_SIZE
|
||||
|
||||
bool IMB_ispic(const char *filepath)
|
||||
bool IMB_test_image(const char *filepath)
|
||||
{
|
||||
return (IMB_ispic_type(filepath) != IMB_FTYPE_NONE);
|
||||
return (IMB_test_image_type(filepath) != IMB_FTYPE_NONE);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#include "IMB_imbuf.hh"
|
||||
#include "IMB_imbuf_types.hh"
|
||||
|
||||
bool IMB_saveiff(ImBuf *ibuf, const char *filepath, int flags)
|
||||
bool IMB_save_image(ImBuf *ibuf, const char *filepath, const int flags)
|
||||
{
|
||||
errno = 0;
|
||||
|
||||
|
||||
@@ -374,7 +374,7 @@ std::string cache_image_color(const float color[4])
|
||||
IMB_rectfill(ibuf, color);
|
||||
ibuf->ftype = IMB_FTYPE_RADHDR;
|
||||
|
||||
if (IMB_saveiff(ibuf, file_path.c_str(), IB_float_data)) {
|
||||
if (IMB_save_image(ibuf, file_path.c_str(), IB_float_data)) {
|
||||
CLOG_INFO(&LOG, 1, "%s", file_path.c_str());
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -859,7 +859,7 @@ static void export_packed_texture(Image *ima,
|
||||
* a file extension based on the file magic. */
|
||||
|
||||
enum eImbFileType ftype = eImbFileType(
|
||||
IMB_ispic_type_from_memory(static_cast<const uchar *>(pf->data), pf->size));
|
||||
IMB_test_image_type_from_memory(static_cast<const uchar *>(pf->data), pf->size));
|
||||
if (ima->source == IMA_SRC_TILED) {
|
||||
char tile_number[6];
|
||||
SNPRINTF(tile_number, ".%d", imapf->tile_number);
|
||||
|
||||
@@ -512,7 +512,7 @@ static PyObject *imbuf_load_impl(const char *filepath)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ImBuf *ibuf = IMB_loadifffile(file, IB_byte_data, nullptr, filepath);
|
||||
ImBuf *ibuf = IMB_load_image_from_file_descriptor(file, IB_byte_data, filepath);
|
||||
|
||||
close(file);
|
||||
|
||||
@@ -563,7 +563,7 @@ static PyObject *M_imbuf_load(PyObject * /*self*/, PyObject *args, PyObject *kw)
|
||||
|
||||
static PyObject *imbuf_write_impl(ImBuf *ibuf, const char *filepath)
|
||||
{
|
||||
const bool ok = IMB_saveiff(ibuf, filepath, IB_byte_data);
|
||||
const bool ok = IMB_save_image(ibuf, filepath, IB_byte_data);
|
||||
if (ok == false) {
|
||||
PyErr_Format(
|
||||
PyExc_IOError, "write: Unable to write image file (%s) '%s'", strerror(errno), filepath);
|
||||
|
||||
@@ -2752,7 +2752,7 @@ void RE_layer_load_from_file(
|
||||
}
|
||||
|
||||
/* OCIO_TODO: assume layer was saved in default color space */
|
||||
ImBuf *ibuf = IMB_loadiffname(filepath, IB_byte_data, nullptr);
|
||||
ImBuf *ibuf = IMB_load_image_from_filepath(filepath, IB_byte_data);
|
||||
RenderPass *rpass = nullptr;
|
||||
|
||||
/* multi-view: since the API takes no 'view', we use the first combined pass found */
|
||||
|
||||
@@ -244,7 +244,7 @@ ImBuf *seq_proxy_fetch(const RenderData *context, Strip *strip, int timeline_fra
|
||||
}
|
||||
|
||||
if (BLI_exists(filepath)) {
|
||||
ImBuf *ibuf = IMB_loadiffname(filepath, IB_byte_data | IB_metadata, nullptr);
|
||||
ImBuf *ibuf = IMB_load_image_from_filepath(filepath, IB_byte_data | IB_metadata);
|
||||
|
||||
if (ibuf) {
|
||||
seq_imbuf_assign_spaces(context->scene, ibuf);
|
||||
@@ -311,7 +311,7 @@ static void seq_proxy_build_frame(const RenderData *context,
|
||||
}
|
||||
BLI_file_ensure_parent_dir_exists(filepath);
|
||||
|
||||
const bool ok = IMB_saveiff(ibuf, filepath, save_float ? IB_float_data : IB_byte_data);
|
||||
const bool ok = IMB_save_image(ibuf, filepath, save_float ? IB_float_data : IB_byte_data);
|
||||
if (ok == false) {
|
||||
perror(filepath);
|
||||
}
|
||||
|
||||
@@ -864,13 +864,14 @@ static ImBuf *seq_render_image_strip_view(const RenderData *context,
|
||||
}
|
||||
|
||||
if (prefix[0] == '\0') {
|
||||
ibuf = IMB_loadiffname(filepath, flag, strip->data->colorspace_settings.name);
|
||||
ibuf = IMB_load_image_from_filepath(filepath, flag, strip->data->colorspace_settings.name);
|
||||
}
|
||||
else {
|
||||
char filepath_view[FILE_MAX];
|
||||
BKE_scene_multiview_view_prefix_get(context->scene, filepath, prefix, &ext);
|
||||
seq_multiview_name(context->scene, view_id, prefix, ext, filepath_view, FILE_MAX);
|
||||
ibuf = IMB_loadiffname(filepath_view, flag, strip->data->colorspace_settings.name);
|
||||
ibuf = IMB_load_image_from_filepath(
|
||||
filepath_view, flag, strip->data->colorspace_settings.name);
|
||||
}
|
||||
|
||||
if (ibuf == nullptr) {
|
||||
|
||||
@@ -213,9 +213,9 @@ void add_image_init_alpha_mode(Strip *strip)
|
||||
|
||||
/* Initialize input color space. */
|
||||
if (strip->type == STRIP_TYPE_IMAGE) {
|
||||
ibuf = IMB_loadiffname(filepath,
|
||||
IB_test | IB_multilayer | IB_alphamode_detect,
|
||||
strip->data->colorspace_settings.name);
|
||||
ibuf = IMB_load_image_from_filepath(filepath,
|
||||
IB_test | IB_multilayer | IB_alphamode_detect,
|
||||
strip->data->colorspace_settings.name);
|
||||
|
||||
/* Byte images are default to straight alpha, however sequencer
|
||||
* works in premul space, so mark strip to be premultiplied first.
|
||||
@@ -257,7 +257,7 @@ Strip *add_image_strip(Main *bmain, Scene *scene, ListBase *seqbase, LoadData *l
|
||||
char file_path[FILE_MAX];
|
||||
STRNCPY(file_path, load_data->path);
|
||||
BLI_path_abs(file_path, BKE_main_blendfile_path(bmain));
|
||||
ImBuf *ibuf = IMB_loadiffname(
|
||||
ImBuf *ibuf = IMB_load_image_from_filepath(
|
||||
file_path, IB_byte_data | IB_multilayer, strip->data->colorspace_settings.name);
|
||||
if (ibuf != nullptr) {
|
||||
/* Set image resolution. Assume that all images in sequence are same size. This fields are only
|
||||
|
||||
@@ -465,12 +465,12 @@ static ImBuf *ibuf_from_picture(PlayAnimPict *pic)
|
||||
}
|
||||
else if (pic->mem) {
|
||||
/* Use correct color-space here. */
|
||||
ibuf = IMB_ibImageFromMemory(
|
||||
pic->mem, pic->size, pic->IB_flags, nullptr, pic->filepath, pic->filepath);
|
||||
ibuf = IMB_load_image_from_memory(
|
||||
pic->mem, pic->size, pic->IB_flags, pic->filepath, pic->filepath);
|
||||
}
|
||||
else {
|
||||
/* Use correct color-space here. */
|
||||
ibuf = IMB_loadiffname(pic->filepath, pic->IB_flags, nullptr);
|
||||
ibuf = IMB_load_image_from_filepath(pic->filepath, pic->IB_flags);
|
||||
}
|
||||
|
||||
return ibuf;
|
||||
@@ -916,7 +916,7 @@ static void build_pict_list_from_image_sequence(ListBase &picsbase,
|
||||
g_playanim.total_time = 1.0;
|
||||
|
||||
for (int pic = 0; pic < totframes; pic++) {
|
||||
if (!IMB_ispic(filepath)) {
|
||||
if (!IMB_test_image(filepath)) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1821,14 +1821,14 @@ static bool wm_main_playanim_intern(int argc, const char **argv, PlayArgs *args_
|
||||
anim = nullptr;
|
||||
}
|
||||
}
|
||||
else if (!IMB_ispic(filepath)) {
|
||||
else if (!IMB_test_image(filepath)) {
|
||||
printf("%s: '%s' not an image file\n", __func__, filepath);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (ibuf == nullptr) {
|
||||
/* OCIO_TODO: support different input color space. */
|
||||
ibuf = IMB_loadiffname(filepath, IB_byte_data, nullptr);
|
||||
ibuf = IMB_load_image_from_filepath(filepath, IB_byte_data);
|
||||
}
|
||||
|
||||
if (ibuf == nullptr) {
|
||||
|
||||
@@ -144,22 +144,22 @@ static ImBuf *wm_block_splash_image(int width, int *r_height)
|
||||
U.app_template, template_directory, sizeof(template_directory)))
|
||||
{
|
||||
BLI_path_join(splash_filepath, sizeof(splash_filepath), template_directory, "splash.png");
|
||||
ibuf = IMB_loadiffname(splash_filepath, IB_byte_data, nullptr);
|
||||
ibuf = IMB_load_image_from_filepath(splash_filepath, IB_byte_data);
|
||||
}
|
||||
}
|
||||
|
||||
if (ibuf == nullptr) {
|
||||
const char *custom_splash_path = BLI_getenv("BLENDER_CUSTOM_SPLASH");
|
||||
if (custom_splash_path) {
|
||||
ibuf = IMB_loadiffname(custom_splash_path, IB_byte_data, nullptr);
|
||||
ibuf = IMB_load_image_from_filepath(custom_splash_path, IB_byte_data);
|
||||
}
|
||||
}
|
||||
|
||||
if (ibuf == nullptr) {
|
||||
const uchar *splash_data = (const uchar *)datatoc_splash_png;
|
||||
size_t splash_data_size = datatoc_splash_png_size;
|
||||
ibuf = IMB_ibImageFromMemory(
|
||||
splash_data, splash_data_size, IB_byte_data, nullptr, "<splash screen>");
|
||||
ibuf = IMB_load_image_from_memory(
|
||||
splash_data, splash_data_size, IB_byte_data, "<splash screen>");
|
||||
}
|
||||
|
||||
if (ibuf) {
|
||||
@@ -192,7 +192,7 @@ static ImBuf *wm_block_splash_banner_image(int *r_width,
|
||||
|
||||
const char *custom_splash_path = BLI_getenv("BLENDER_CUSTOM_SPLASH_BANNER");
|
||||
if (custom_splash_path) {
|
||||
ibuf = IMB_loadiffname(custom_splash_path, IB_byte_data, nullptr);
|
||||
ibuf = IMB_load_image_from_filepath(custom_splash_path, IB_byte_data);
|
||||
}
|
||||
|
||||
if (!ibuf) {
|
||||
|
||||
Reference in New Issue
Block a user