38#define HEADER_SIZE 512
46#define ILUM(r, g, b) (int(RINTLUM * (r) + GINTLUM * (g) + BINTLUM * (b)) >> 8)
53#define CHANOFFSET(z) (3 - (z))
58#define ITYPE_RLE 0x0100
59#define ISRLE(type) (((type) & 0xff00) == ITYPE_RLE)
61#define BPP(type) ((type) & BPPMASK)
62#define RLE(bpp) (ITYPE_RLE | (bpp))
73#define MFILE_DATA(inf) ((void)0, ((inf)->_file_data + (inf)->_file_offset))
74#define MFILE_STEP(inf, step) \
76 (inf)->_file_offset += step; \
79#define MFILE_SEEK(inf, pos) \
81 (inf)->_file_offset = pos; \
86#define DIRTY_FLAG_EOF (1 << 0)
87#define DIRTY_FLAG_ENCODING (1 << 1)
103 float *optr,
const float *optr_end,
const uchar *iptr,
const uchar *iptr_end,
int z);
130 return (
uint(buf[0]) << 24) + (
uint(buf[1]) << 16) + (
uint(buf[2]) << 8) + (
uint(buf[3]) << 0);
139 fwrite(buf, 2, 1, outf);
146 buf[0] = (val >> 24);
147 buf[1] = (val >> 16);
150 return fwrite(buf, 4, 1, outf);
155 memset(image, 0,
sizeof(
IMAGE));
168 fwrite(&t,
sizeof(
IMAGE), 1, outf);
169 fseek(outf, 0, SEEK_SET);
179 return fwrite(
"no name", 8, 1, outf);
202#define GS(x) (((uchar *)(x))[0] << 8 | ((uchar *)(x))[1])
205#define GSS(x) (((uchar *)(x))[1] << 8 | ((uchar *)(x))[0])
217 uint *base, *lptr =
nullptr;
218 float *fbase, *fptr =
nullptr;
221 MFileOffset _inf_data = {mem, 0}, *inf = &_inf_data;
223 int bpp, rle, cur, badorder;
224 ImBuf *ibuf =
nullptr;
225 uchar dirty_flag = 0;
241 if (image.imagic !=
IMAGIC) {
242 fprintf(stderr,
"longimagedata: bad magic number in image file\n");
246 rle =
ISRLE(image.type);
247 bpp =
BPP(image.type);
248 if (!
ELEM(bpp, 1, 2)) {
249 fprintf(stderr,
"longimagedata: image must have 1 or 2 byte per pix chan\n");
252 if (
uint(image.zsize) > 8) {
253 fprintf(stderr,
"longimagedata: channels over 8 not supported\n");
257 const int xsize = image.xsize;
258 const int ysize = image.ysize;
260 const int zsize_file = image.zsize;
261 const int zsize_read =
min_ii(image.zsize, 4);
264 ibuf =
IMB_allocImBuf(image.xsize, image.ysize, 8 * image.zsize, 0);
272 size_t tablen = size_t(ysize) * size_t(zsize_file) *
sizeof(
int);
278#define MFILE_CAPACITY_AT_PTR_OK_OR_FAIL(p) \
279 if (UNLIKELY((p) > mem_end)) { \
280 dirty_flag |= DIRTY_FLAG_EOF; \
287 readtab(inf, starttab, tablen);
288 readtab(inf, lengthtab, tablen);
293 for (
size_t y = 0; y < ysize; y++) {
294 for (
size_t z = 0;
z < zsize_file;
z++) {
295 if (starttab[y +
z * ysize] < cur) {
299 cur = starttab[y +
z * ysize];
318 for (
size_t z = 0;
z < zsize_read;
z++) {
320 for (
size_t y = 0; y < ysize; y++) {
325 uint *lptr_next = lptr + xsize;
334 for (
size_t y = 0; y < ysize; y++) {
336 uint *lptr_next = lptr + xsize;
338 for (
size_t z = 0;
z < zsize_read;
z++) {
346 (
uchar *)lptr, (
uchar *)lptr_next, rledat, rledat_next, 3 -
z);
366 for (
size_t z = 0;
z < zsize_read;
z++) {
368 for (
size_t y = 0; y < ysize; y++) {
374 float *fptr_next = fptr + (xsize * 4);
375 dirty_flag |=
expandrow2(fptr, fptr_next, rledat, rledat_next, 3 -
z);
382 float *fptr_next = fptr + (xsize * 4);
384 for (
size_t y = 0; y < ysize; y++) {
386 for (
size_t z = 0;
z < zsize_read;
z++) {
392 dirty_flag |=
expandrow2(fptr, fptr_next, rledat, rledat_next, 3 -
z);
398#undef MFILE_CAPACITY_AT_PTR_OK_OR_FAIL
409#define MFILE_CAPACITY_AT_PTR_OK_OR_FAIL(p) \
410 if (UNLIKELY((p) > mem_end)) { \
411 dirty_flag |= DIRTY_FLAG_EOF; \
412 goto fail_uncompressed; \
420 goto fail_uncompressed;
431 for (
size_t z = 0;
z < zsize_read;
z++) {
440 for (
size_t y = 0; y < ysize; y++) {
441 const uchar *rledat_next = rledat + xsize;
442 const int z_ofs = 3 -
z;
445 rledat = rledat_next;
454 goto fail_uncompressed;
462 for (
size_t z = 0;
z < zsize_read;
z++) {
466 for (
size_t y = 0; y < ysize; y++) {
467 const uchar *rledat_next = rledat + xsize * 2;
468 const int z_ofs = 3 -
z;
471 rledat = rledat_next;
476#undef MFILE_CAPACITY_AT_PTR_OK_OR_FAIL
486 if (image.zsize == 1) {
488 for (
size_t x =
size_t(ibuf->
x) *
size_t(ibuf->
y); x > 0; x--) {
490 rect[1] = rect[2] = rect[3];
494 else if (image.zsize == 2) {
497 for (
size_t x =
size_t(ibuf->
x) * size_t(ibuf->
y); x > 0; x--) {
499 rect[1] = rect[2] = rect[3];
503 else if (image.zsize == 3) {
506 for (
size_t x =
size_t(ibuf->
x) * size_t(ibuf->
y); x > 0; x--) {
514 if (image.zsize == 1) {
516 for (
size_t x =
size_t(ibuf->
x) * size_t(ibuf->
y); x > 0; x--) {
518 fbase[1] = fbase[2] = fbase[3];
522 else if (image.zsize == 2) {
525 for (
size_t x =
size_t(ibuf->
x) * size_t(ibuf->
y); x > 0; x--) {
527 fbase[1] = fbase[2] = fbase[3];
531 else if (image.zsize == 3) {
534 for (
size_t x =
size_t(ibuf->
x) * size_t(ibuf->
y); x > 0; x--) {
546 fprintf(stderr,
"longimagedata: corrupt file content (%d)\n", dirty_flag);
572 *lptr = ((cptr[0] << 8) | (cptr[1] << 0)) /
float(0xFFFF);
579 float *optr,
const float *optr_end,
const uchar *iptr,
const uchar *iptr_end,
int z)
584#define EXPAND_CAPACITY_AT_INPUT_OK_OR_FAIL(iptr_next) \
585 if (UNLIKELY(iptr_next > iptr_end)) { \
590#define EXPAND_CAPACITY_AT_OUTPUT_OK_OR_FAIL(optr_next) \
591 if (UNLIKELY(optr_next > optr_end)) { \
599 const uchar *iptr_next = iptr + 2;
601 pixel = (iptr[0] << 8) | (iptr[1] << 0);
604 if (!(
count = (pixel & 0x7f))) {
607 const float *optr_next = optr +
count;
610 iptr_next = iptr + (
count * 2);
613 optr[0 * 4] = ((iptr[0] << 8) | (iptr[1] << 0)) /
float(0xFFFF);
614 optr[1 * 4] = ((iptr[2] << 8) | (iptr[3] << 0)) /
float(0xFFFF);
615 optr[2 * 4] = ((iptr[4] << 8) | (iptr[5] << 0)) /
float(0xFFFF);
616 optr[3 * 4] = ((iptr[6] << 8) | (iptr[7] << 0)) /
float(0xFFFF);
617 optr[4 * 4] = ((iptr[8] << 8) | (iptr[9] << 0)) /
float(0xFFFF);
618 optr[5 * 4] = ((iptr[10] << 8) | (iptr[11] << 0)) /
float(0xFFFF);
619 optr[6 * 4] = ((iptr[12] << 8) | (iptr[13] << 0)) /
float(0xFFFF);
620 optr[7 * 4] = ((iptr[14] << 8) | (iptr[15] << 0)) /
float(0xFFFF);
626 *optr = ((iptr[0] << 8) | (iptr[1] << 0)) /
float(0xFFFF);
633 iptr_next = iptr + 2;
635 pixel_f = ((iptr[0] << 8) | (iptr[1] << 0)) /
float(0xFFFF);
639 optr[0 * 4] = pixel_f;
640 optr[1 * 4] = pixel_f;
641 optr[2 * 4] = pixel_f;
642 optr[3 * 4] = pixel_f;
643 optr[4 * 4] = pixel_f;
644 optr[5 * 4] = pixel_f;
645 optr[6 * 4] = pixel_f;
646 optr[7 * 4] = pixel_f;
660#undef EXPAND_CAPACITY_AT_INPUT_OK_OR_FAIL
661#undef EXPAND_CAPACITY_AT_OUTPUT_OK_OR_FAIL
671#define EXPAND_CAPACITY_AT_INPUT_OK_OR_FAIL(iptr_next) \
672 if (UNLIKELY(iptr_next > iptr_end)) { \
677#define EXPAND_CAPACITY_AT_OUTPUT_OK_OR_FAIL(optr_next) \
678 if (UNLIKELY(optr_next > optr_end)) { \
686 const uchar *iptr_next = iptr + 1;
690 if (!(
count = (pixel & 0x7f))) {
697 iptr_next = iptr +
count;
700 optr[0 * 4] = iptr[0];
701 optr[1 * 4] = iptr[1];
702 optr[2 * 4] = iptr[2];
703 optr[3 * 4] = iptr[3];
704 optr[4 * 4] = iptr[4];
705 optr[5 * 4] = iptr[5];
706 optr[6 * 4] = iptr[6];
707 optr[7 * 4] = iptr[7];
719 iptr_next = iptr + 1;
745#undef EXPAND_CAPACITY_AT_INPUT_OK_OR_FAIL
746#undef EXPAND_CAPACITY_AT_OUTPUT_OK_OR_FAIL
774 uint *starttab, *lengthtab;
777 int rlebuflen, goodwrite;
785 tablen = ysize * zsize *
sizeof(
int);
790 rlebuflen = 1.05 * xsize + 10;
794 memset(image, 0,
sizeof(
IMAGE));
796 image->type =
RLE(1);
803 image->xsize = xsize;
804 image->ysize = ysize;
805 image->zsize = zsize;
812 for (y = 0; y < ysize; y++) {
813 for (
z = 0;
z < zsize;
z++) {
823 else if (
z < 8 && zptr) {
828 BLI_assert_msg(
len <= rlebuflen,
"The length calculated for 'rlebuflen' was too small!");
830 goodwrite *= fwrite(rlebuf,
len, 1, outf);
831 starttab[y +
z * ysize] =
pos;
832 lengthtab[y +
z * ysize] =
len;
842 goodwrite *=
writetab(outf, starttab, tablen);
843 goodwrite *=
writetab(outf, lengthtab, tablen);
854 fprintf(stderr,
"output_iris: not enough space for image!!\n");
872 const uchar *iptr, *ibufend, *sptr;
879 ibufend = iptr + row_len * 4;
882 while (iptr < ibufend) {
885 while ((iptr < ibufend) && ((iptr[-8] != iptr[-4]) || (iptr[-4] != iptr[0]))) {
889 count = (iptr - sptr) / 4;
893 *optr++ = 0x80 | todo;
895 optr[0] = sptr[0 * 4];
896 optr[1] = sptr[1 * 4];
897 optr[2] = sptr[2 * 4];
898 optr[3] = sptr[3 * 4];
899 optr[4] = sptr[4 * 4];
900 optr[5] = sptr[5 * 4];
901 optr[6] = sptr[6 * 4];
902 optr[7] = sptr[7 * 4];
916 while ((iptr < ibufend) && (*iptr == cc)) {
919 count = (iptr - sptr) / 4;
928 return optr - (
uchar *)rlebuf;
933 const short zsize = (ibuf->
planes + 7) >> 3;
#define BLI_STATIC_ASSERT(a, msg)
#define BLI_assert_msg(a, msg)
File and directory operations.
FILE * BLI_fopen(const char *filepath, const char *mode) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
MINLINE int min_ii(int a, int b)
@ COLOR_ROLE_DEFAULT_BYTE
void IMB_rect_from_float(ImBuf *ibuf)
void IMB_convert_rgba_to_abgr(ImBuf *ibuf)
Contains defines and structs used throughout the imbuf module.
Read Guarded memory(de)allocation.
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
void colorspace_set_default_role(char *colorspace, int size, int role)
input_tx image(0, GPU_RGBA16F, Qualifier::WRITE, ImageType::FLOAT_2D, "preview_img") .compute_source("compositor_compute_preview.glsl") .do_static_compilation(true)
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
struct ImBuf * IMB_allocImBuf(unsigned int, unsigned int, unsigned char, unsigned int)
static bool output_iris(const char *filepath, const uint *lptr, const int *zptr, const int xsize, const int ysize, const int zsize)
#define DIRTY_FLAG_ENCODING
bool imb_saveiris(ImBuf *ibuf, const char *filepath, int)
static void interleaverow(uchar *lptr, const uchar *cptr, int z, int n)
ImBuf * imb_loadiris(const uchar *mem, size_t size, int flags, char colorspace[IM_MAX_SPACE])
bool imb_is_a_iris(const uchar *mem, size_t size)
static int expandrow2(float *optr, const float *optr_end, const uchar *iptr, const uchar *iptr_end, int z)
static void putshort(FILE *outf, ushort val)
static int writeheader(FILE *outf, const IMAGE *image)
static uint getlong(MFileOffset *mofs)
#define EXPAND_CAPACITY_AT_OUTPUT_OK_OR_FAIL(optr_next)
static void lumrow(const uchar *rgbptr, uchar *lumptr, int n)
static int expandrow(uchar *optr, const uchar *optr_end, const uchar *iptr, const uchar *iptr_end, int z)
static ushort getshort(MFileOffset *inf)
static int compressrow(const uchar *lbuf, uchar *rlebuf, int z, int row_len)
#define MFILE_STEP(inf, step)
static void readtab(MFileOffset *inf, uint *tab, int len)
static void interleaverow2(float *lptr, const uchar *cptr, int z, int n)
static int writetab(FILE *outf, const uint *tab, int len)
#define MFILE_CAPACITY_AT_PTR_OK_OR_FAIL(p)
static int putlong(FILE *outf, uint val)
#define EXPAND_CAPACITY_AT_INPUT_OK_OR_FAIL(iptr_next)
#define MFILE_SEEK(inf, pos)
static void readheader(MFileOffset *inf, IMAGE *image)
void *(* MEM_mallocN)(size_t len, const char *str)
void MEM_freeN(void *vmemh)
ImBufFloatBuffer float_buffer
ImBufByteBuffer byte_buffer