Blender  V3.3
iris.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2001-2002 NaN Holding BV. All rights reserved. */
3 
8 #include <string.h>
9 
10 #include "BLI_fileops.h"
11 #include "BLI_utildefines.h"
12 
13 #include "MEM_guardedalloc.h"
14 
15 #include "IMB_filetype.h"
16 #include "IMB_imbuf.h"
17 #include "IMB_imbuf_types.h"
18 #include "imbuf.h"
19 
20 #include "IMB_colormanagement.h"
22 
23 #define IMAGIC 0732
24 
25 typedef struct {
26  ushort imagic; /* Stuff saved on disk. */
34  uchar _pad1[4];
35  char name[80];
37  uchar _pad2[404];
38 } IMAGE;
39 
40 #define HEADER_SIZE 512
41 
42 BLI_STATIC_ASSERT(sizeof(IMAGE) == HEADER_SIZE, "Invalid header size");
43 
44 #define RINTLUM (79)
45 #define GINTLUM (156)
46 #define BINTLUM (21)
47 
48 #define ILUM(r, g, b) ((int)(RINTLUM * (r) + GINTLUM * (g) + BINTLUM * (b)) >> 8)
49 
50 #define OFFSET_R 0 /* this is byte order dependent */
51 #define OFFSET_G 1
52 #define OFFSET_B 2
53 // #define OFFSET_A 3
54 
55 #define CHANOFFSET(z) (3 - (z)) /* this is byte order dependent */
56 
57 // #define TYPEMASK 0xff00
58 #define BPPMASK 0x00ff
59 // #define ITYPE_VERBATIM 0x0000 /* UNUSED */
60 #define ITYPE_RLE 0x0100
61 #define ISRLE(type) (((type)&0xff00) == ITYPE_RLE)
62 // #define ISVERBATIM(type) (((type) & 0xff00) == ITYPE_VERBATIM)
63 #define BPP(type) ((type)&BPPMASK)
64 #define RLE(bpp) (ITYPE_RLE | (bpp))
65 // #define VERBATIM(bpp) (ITYPE_VERBATIM | (bpp)) /* UNUSED */
66 // #define IBUFSIZE(pixels) ((pixels + (pixels >> 6)) << 2) /* UNUSED */
67 // #define RLE_NOP 0x00
68 
69 /* local struct for mem access */
70 typedef struct MFileOffset {
71  const uchar *_file_data;
74 
75 #define MFILE_DATA(inf) ((void)0, ((inf)->_file_data + (inf)->_file_offset))
76 #define MFILE_STEP(inf, step) \
77  { \
78  (inf)->_file_offset += step; \
79  } \
80  ((void)0)
81 #define MFILE_SEEK(inf, pos) \
82  { \
83  (inf)->_file_offset = pos; \
84  } \
85  ((void)0)
86 
87 /* error flags */
88 #define DIRTY_FLAG_EOF (1 << 0)
89 #define DIRTY_FLAG_ENCODING (1 << 1)
90 
91 /* funcs */
92 static void readheader(MFileOffset *inf, IMAGE *image);
93 static int writeheader(FILE *outf, IMAGE *image);
94 
95 static ushort getshort(MFileOffset *inf);
96 static uint getlong(MFileOffset *mofs);
97 static void putshort(FILE *outf, ushort val);
98 static int putlong(FILE *outf, uint val);
99 static int writetab(FILE *outf, uint *tab, int len);
100 static void readtab(MFileOffset *inf, uint *tab, int len);
101 
102 static int expandrow(
103  uchar *optr, const uchar *optr_end, const uchar *iptr, const uchar *iptr_end, int z);
104 static int expandrow2(
105  float *optr, const float *optr_end, const uchar *iptr, const uchar *iptr_end, int z);
106 static void interleaverow(uchar *lptr, const uchar *cptr, int z, int n);
107 static void interleaverow2(float *lptr, const uchar *cptr, int z, int n);
108 static int compressrow(const uchar *lbuf, uchar *rlebuf, int z, int row_len);
109 static void lumrow(const uchar *rgbptr, uchar *lumptr, int n);
110 
111 /*
112  * byte order independent read/write of shorts and ints.
113  */
114 
116 {
117  const uchar *buf;
118 
119  buf = MFILE_DATA(inf);
120  MFILE_STEP(inf, 2);
121 
122  return ((ushort)buf[0] << 8) + ((ushort)buf[1] << 0);
123 }
124 
125 static uint getlong(MFileOffset *mofs)
126 {
127  const uchar *buf;
128 
129  buf = MFILE_DATA(mofs);
130  MFILE_STEP(mofs, 4);
131 
132  return ((uint)buf[0] << 24) + ((uint)buf[1] << 16) + ((uint)buf[2] << 8) + ((uint)buf[3] << 0);
133 }
134 
135 static void putshort(FILE *outf, ushort val)
136 {
137  uchar buf[2];
138 
139  buf[0] = (val >> 8);
140  buf[1] = (val >> 0);
141  fwrite(buf, 2, 1, outf);
142 }
143 
144 static int putlong(FILE *outf, uint val)
145 {
146  uchar buf[4];
147 
148  buf[0] = (val >> 24);
149  buf[1] = (val >> 16);
150  buf[2] = (val >> 8);
151  buf[3] = (val >> 0);
152  return fwrite(buf, 4, 1, outf);
153 }
154 
155 static void readheader(MFileOffset *inf, IMAGE *image)
156 {
157  memset(image, 0, sizeof(IMAGE));
158  image->imagic = getshort(inf);
159  image->type = getshort(inf);
160  image->dim = getshort(inf);
161  image->xsize = getshort(inf);
162  image->ysize = getshort(inf);
163  image->zsize = getshort(inf);
164 }
165 
166 static int writeheader(FILE *outf, IMAGE *image)
167 {
168  IMAGE t = {0};
169 
170  fwrite(&t, sizeof(IMAGE), 1, outf);
171  fseek(outf, 0, SEEK_SET);
172  putshort(outf, image->imagic);
173  putshort(outf, image->type);
174  putshort(outf, image->dim);
175  putshort(outf, image->xsize);
176  putshort(outf, image->ysize);
177  putshort(outf, image->zsize);
178  putlong(outf, image->min);
179  putlong(outf, image->max);
180  putlong(outf, 0);
181  return fwrite("no name", 8, 1, outf);
182 }
183 
184 static int writetab(FILE *outf, uint *tab, int len)
185 {
186  int r = 0;
187 
188  while (len) {
189  r = putlong(outf, *tab++);
190  len -= 4;
191  }
192  return r;
193 }
194 
195 static void readtab(MFileOffset *inf, uint *tab, int len)
196 {
197  while (len) {
198  *tab++ = getlong(inf);
199  len -= 4;
200  }
201 }
202 
203 static void test_endian_zbuf(struct ImBuf *ibuf)
204 {
205  int len;
206  int *zval;
207 
208  if (BIG_LONG(1) == 1) {
209  return;
210  }
211  if (ibuf->zbuf == NULL) {
212  return;
213  }
214 
215  len = ibuf->x * ibuf->y;
216  zval = ibuf->zbuf;
217 
218  while (len--) {
219  zval[0] = BIG_LONG(zval[0]);
220  zval++;
221  }
222 }
223 
224 /* From misc_util: flip the bytes from x. */
225 #define GS(x) (((uchar *)(x))[0] << 8 | ((uchar *)(x))[1])
226 
227 /* This one is only def-ed once, strangely... */
228 #define GSS(x) (((uchar *)(x))[1] << 8 | ((uchar *)(x))[0])
229 
230 bool imb_is_a_iris(const uchar *mem, size_t size)
231 {
232  if (size < 2) {
233  return false;
234  }
235  return ((GS(mem) == IMAGIC) || (GSS(mem) == IMAGIC));
236 }
237 
238 struct ImBuf *imb_loadiris(const uchar *mem, size_t size, int flags, char colorspace[IM_MAX_SPACE])
239 {
240  uint *base, *lptr = NULL;
241  float *fbase, *fptr = NULL;
242  uint *zbase, *zptr;
243  const uchar *rledat;
244  const uchar *mem_end = mem + size;
245  MFileOffset _inf_data = {mem, 0}, *inf = &_inf_data;
246  IMAGE image;
247  int bpp, rle, cur, badorder;
248  ImBuf *ibuf = NULL;
249  uchar dirty_flag = 0;
250 
251  if (!imb_is_a_iris(mem, size)) {
252  return NULL;
253  }
254 
255  /* Could be part of the magic check above,
256  * by convention this check only requests the size needed to read it's magic though. */
257  if (size < HEADER_SIZE) {
258  return NULL;
259  }
260 
261  /* OCIO_TODO: only tested with 1 byte per pixel, not sure how to test with other settings */
263 
264  readheader(inf, &image);
265  if (image.imagic != IMAGIC) {
266  fprintf(stderr, "longimagedata: bad magic number in image file\n");
267  return NULL;
268  }
269 
270  rle = ISRLE(image.type);
271  bpp = BPP(image.type);
272  if (!ELEM(bpp, 1, 2)) {
273  fprintf(stderr, "longimagedata: image must have 1 or 2 byte per pix chan\n");
274  return NULL;
275  }
276  if ((uint)image.zsize > 8) {
277  fprintf(stderr, "longimagedata: channels over 8 not supported\n");
278  return NULL;
279  }
280 
281  const int xsize = image.xsize;
282  const int ysize = image.ysize;
283  const int zsize = image.zsize;
284 
285  if (flags & IB_test) {
286  ibuf = IMB_allocImBuf(image.xsize, image.ysize, 8 * image.zsize, 0);
287  if (ibuf) {
288  ibuf->ftype = IMB_FTYPE_IMAGIC;
289  }
290  return ibuf;
291  }
292 
293  if (rle) {
294  size_t tablen = (size_t)ysize * (size_t)zsize * sizeof(int);
295  MFILE_SEEK(inf, HEADER_SIZE);
296 
297  uint *starttab = MEM_mallocN(tablen, "iris starttab");
298  uint *lengthtab = MEM_mallocN(tablen, "iris endtab");
299 
300 #define MFILE_CAPACITY_AT_PTR_OK_OR_FAIL(p) \
301  if (UNLIKELY((p) > mem_end)) { \
302  dirty_flag |= DIRTY_FLAG_EOF; \
303  goto fail_rle; \
304  } \
305  ((void)0)
306 
307  MFILE_CAPACITY_AT_PTR_OK_OR_FAIL(MFILE_DATA(inf) + ((4 * 2) * tablen));
308 
309  readtab(inf, starttab, tablen);
310  readtab(inf, lengthtab, tablen);
311 
312  /* check data order */
313  cur = 0;
314  badorder = 0;
315  for (size_t y = 0; y < ysize; y++) {
316  for (size_t z = 0; z < zsize; z++) {
317  if (starttab[y + z * ysize] < cur) {
318  badorder = 1;
319  break;
320  }
321  cur = starttab[y + z * ysize];
322  }
323  if (badorder) {
324  break;
325  }
326  }
327 
328  if (bpp == 1) {
329 
330  ibuf = IMB_allocImBuf(xsize, ysize, 8 * zsize, IB_rect);
331  if (!ibuf) {
332  goto fail_rle;
333  }
334  if (ibuf->planes > 32) {
335  ibuf->planes = 32;
336  }
337  base = ibuf->rect;
338  zbase = (uint *)ibuf->zbuf;
339 
340  if (badorder) {
341  for (size_t z = 0; z < zsize; z++) {
342  lptr = base;
343  for (size_t y = 0; y < ysize; y++) {
344  MFILE_SEEK(inf, starttab[y + z * ysize]);
345  rledat = MFILE_DATA(inf);
346  MFILE_STEP(inf, lengthtab[y + z * ysize]);
347  const uchar *rledat_next = MFILE_DATA(inf);
348  uint *lptr_next = lptr + xsize;
350  dirty_flag |= expandrow((uchar *)lptr, (uchar *)lptr_next, rledat, rledat_next, 3 - z);
351  lptr = lptr_next;
352  }
353  }
354  }
355  else {
356  lptr = base;
357  zptr = zbase;
358  for (size_t y = 0; y < ysize; y++) {
359 
360  uint *lptr_next = lptr + xsize;
361  uint *zptr_next = zptr + xsize;
362 
363  for (size_t z = 0; z < zsize; z++) {
364  MFILE_SEEK(inf, starttab[y + z * ysize]);
365  rledat = MFILE_DATA(inf);
366  MFILE_STEP(inf, lengthtab[y + z * ysize]);
367  const uchar *rledat_next = MFILE_DATA(inf);
369  if (z < 4) {
370  dirty_flag |= expandrow(
371  (uchar *)lptr, (uchar *)lptr_next, rledat, rledat_next, 3 - z);
372  }
373  else if (z < 8) {
374  dirty_flag |= expandrow(
375  (uchar *)zptr, (uchar *)zptr_next, rledat, rledat_next, 7 - z);
376  }
377  }
378  lptr = lptr_next;
379  zptr = zptr_next;
380  }
381  }
382  }
383  else { /* bpp == 2 */
384 
385  ibuf = IMB_allocImBuf(xsize, ysize, 32, (flags & IB_rect) | IB_rectfloat);
386  if (!ibuf) {
387  goto fail_rle;
388  }
389 
390  fbase = ibuf->rect_float;
391 
392  if (badorder) {
393  for (size_t z = 0; z < zsize; z++) {
394  fptr = fbase;
395  for (size_t y = 0; y < ysize; y++) {
396  MFILE_SEEK(inf, starttab[y + z * ysize]);
397  rledat = MFILE_DATA(inf);
398  MFILE_STEP(inf, lengthtab[y + z * ysize]);
399  const uchar *rledat_next = MFILE_DATA(inf);
401  float *fptr_next = fptr + (xsize * 4);
402  dirty_flag |= expandrow2(fptr, fptr_next, rledat, rledat_next, 3 - z);
403  fptr = fptr_next;
404  }
405  }
406  }
407  else {
408  fptr = fbase;
409  float *fptr_next = fptr + (xsize * 4);
410 
411  for (size_t y = 0; y < ysize; y++) {
412 
413  for (size_t z = 0; z < zsize; z++) {
414  MFILE_SEEK(inf, starttab[y + z * ysize]);
415  rledat = MFILE_DATA(inf);
416  MFILE_STEP(inf, lengthtab[y + z * ysize]);
417  const uchar *rledat_next = MFILE_DATA(inf);
419  dirty_flag |= expandrow2(fptr, fptr_next, rledat, rledat_next, 3 - z);
420  }
421  fptr = fptr_next;
422  }
423  }
424  }
425 #undef MFILE_CAPACITY_AT_PTR_OK_OR_FAIL
426  fail_rle:
427  MEM_freeN(starttab);
428  MEM_freeN(lengthtab);
429 
430  if (!ibuf) {
431  return NULL;
432  }
433  }
434  else {
435 
436 #define MFILE_CAPACITY_AT_PTR_OK_OR_FAIL(p) \
437  if (UNLIKELY((p) > mem_end)) { \
438  dirty_flag |= DIRTY_FLAG_EOF; \
439  goto fail_uncompressed; \
440  } \
441  ((void)0)
442 
443  if (bpp == 1) {
444 
445  ibuf = IMB_allocImBuf(xsize, ysize, 8 * zsize, IB_rect);
446  if (!ibuf) {
447  goto fail_uncompressed;
448  }
449  if (ibuf->planes > 32) {
450  ibuf->planes = 32;
451  }
452 
453  base = ibuf->rect;
454  zbase = (uint *)ibuf->zbuf;
455 
456  MFILE_SEEK(inf, HEADER_SIZE);
457  rledat = MFILE_DATA(inf);
458 
459  for (size_t z = 0; z < zsize; z++) {
460 
461  if (z < 4) {
462  lptr = base;
463  }
464  else if (z < 8) {
465  lptr = zbase;
466  }
467 
468  for (size_t y = 0; y < ysize; y++) {
469  const uchar *rledat_next = rledat + xsize;
470  const int z_ofs = 3 - z;
471  MFILE_CAPACITY_AT_PTR_OK_OR_FAIL(rledat_next + z_ofs);
472  interleaverow((uchar *)lptr, rledat, z_ofs, xsize);
473  rledat = rledat_next;
474  lptr += xsize;
475  }
476  }
477  }
478  else { /* bpp == 2 */
479 
480  ibuf = IMB_allocImBuf(xsize, ysize, 32, (flags & IB_rect) | IB_rectfloat);
481  if (!ibuf) {
482  goto fail_uncompressed;
483  }
484 
485  fbase = ibuf->rect_float;
486 
487  MFILE_SEEK(inf, HEADER_SIZE);
488  rledat = MFILE_DATA(inf);
489 
490  for (size_t z = 0; z < zsize; z++) {
491 
492  fptr = fbase;
493 
494  for (size_t y = 0; y < ysize; y++) {
495  const uchar *rledat_next = rledat + xsize * 2;
496  const int z_ofs = 3 - z;
497  MFILE_CAPACITY_AT_PTR_OK_OR_FAIL(rledat_next + z_ofs);
498  interleaverow2(fptr, rledat, z_ofs, xsize);
499  rledat = rledat_next;
500  fptr += xsize * 4;
501  }
502  }
503  }
504 #undef MFILE_CAPACITY_AT_PTR_OK_OR_FAIL
505  fail_uncompressed:
506  if (!ibuf) {
507  return NULL;
508  }
509  }
510 
511  if (bpp == 1) {
512  uchar *rect;
513 
514  if (image.zsize == 1) {
515  rect = (uchar *)ibuf->rect;
516  for (size_t x = (size_t)ibuf->x * (size_t)ibuf->y; x > 0; x--) {
517  rect[0] = 255;
518  rect[1] = rect[2] = rect[3];
519  rect += 4;
520  }
521  }
522  else if (image.zsize == 2) {
523  /* Gray-scale with alpha. */
524  rect = (uchar *)ibuf->rect;
525  for (size_t x = (size_t)ibuf->x * (size_t)ibuf->y; x > 0; x--) {
526  rect[0] = rect[2];
527  rect[1] = rect[2] = rect[3];
528  rect += 4;
529  }
530  }
531  else if (image.zsize == 3) {
532  /* add alpha */
533  rect = (uchar *)ibuf->rect;
534  for (size_t x = (size_t)ibuf->x * (size_t)ibuf->y; x > 0; x--) {
535  rect[0] = 255;
536  rect += 4;
537  }
538  }
539  }
540  else { /* bpp == 2 */
541 
542  if (image.zsize == 1) {
543  fbase = ibuf->rect_float;
544  for (size_t x = (size_t)ibuf->x * (size_t)ibuf->y; x > 0; x--) {
545  fbase[0] = 1;
546  fbase[1] = fbase[2] = fbase[3];
547  fbase += 4;
548  }
549  }
550  else if (image.zsize == 2) {
551  /* Gray-scale with alpha. */
552  fbase = ibuf->rect_float;
553  for (size_t x = (size_t)ibuf->x * (size_t)ibuf->y; x > 0; x--) {
554  fbase[0] = fbase[2];
555  fbase[1] = fbase[2] = fbase[3];
556  fbase += 4;
557  }
558  }
559  else if (image.zsize == 3) {
560  /* add alpha */
561  fbase = ibuf->rect_float;
562  for (size_t x = (size_t)ibuf->x * (size_t)ibuf->y; x > 0; x--) {
563  fbase[0] = 1;
564  fbase += 4;
565  }
566  }
567 
568  if (flags & IB_rect) {
569  IMB_rect_from_float(ibuf);
570  }
571  }
572 
573  if (dirty_flag) {
574  fprintf(stderr, "longimagedata: corrupt file content (%d)\n", dirty_flag);
575  }
576  ibuf->ftype = IMB_FTYPE_IMAGIC;
577 
578  test_endian_zbuf(ibuf);
579 
580  if (ibuf->rect) {
582  }
583 
584  return ibuf;
585 }
586 
587 /* static utility functions for longimagedata */
588 
589 static void interleaverow(uchar *lptr, const uchar *cptr, int z, int n)
590 {
591  lptr += z;
592  while (n--) {
593  *lptr = *cptr++;
594  lptr += 4;
595  }
596 }
597 
598 static void interleaverow2(float *lptr, const uchar *cptr, int z, int n)
599 {
600  lptr += z;
601  while (n--) {
602  *lptr = ((cptr[0] << 8) | (cptr[1] << 0)) / (float)0xFFFF;
603  cptr += 2;
604  lptr += 4;
605  }
606 }
607 
608 static int expandrow2(
609  float *optr, const float *optr_end, const uchar *iptr, const uchar *iptr_end, int z)
610 {
611  ushort pixel, count;
612  float pixel_f;
613 
614 #define EXPAND_CAPACITY_AT_INPUT_OK_OR_FAIL(iptr_next) \
615  if (UNLIKELY(iptr_next > iptr_end)) { \
616  goto fail; \
617  } \
618  ((void)0)
619 
620 #define EXPAND_CAPACITY_AT_OUTPUT_OK_OR_FAIL(optr_next) \
621  if (UNLIKELY(optr_next > optr_end)) { \
622  goto fail; \
623  } \
624  ((void)0)
625 
626  optr += z;
627  optr_end += z;
628  while (1) {
629  const uchar *iptr_next = iptr + 2;
631  pixel = (iptr[0] << 8) | (iptr[1] << 0);
632  iptr = iptr_next;
633 
634  if (!(count = (pixel & 0x7f))) {
635  return false;
636  }
637  const float *optr_next = optr + count;
639  if (pixel & 0x80) {
640  iptr_next = iptr + (count * 2);
642  while (count >= 8) {
643  optr[0 * 4] = ((iptr[0] << 8) | (iptr[1] << 0)) / (float)0xFFFF;
644  optr[1 * 4] = ((iptr[2] << 8) | (iptr[3] << 0)) / (float)0xFFFF;
645  optr[2 * 4] = ((iptr[4] << 8) | (iptr[5] << 0)) / (float)0xFFFF;
646  optr[3 * 4] = ((iptr[6] << 8) | (iptr[7] << 0)) / (float)0xFFFF;
647  optr[4 * 4] = ((iptr[8] << 8) | (iptr[9] << 0)) / (float)0xFFFF;
648  optr[5 * 4] = ((iptr[10] << 8) | (iptr[11] << 0)) / (float)0xFFFF;
649  optr[6 * 4] = ((iptr[12] << 8) | (iptr[13] << 0)) / (float)0xFFFF;
650  optr[7 * 4] = ((iptr[14] << 8) | (iptr[15] << 0)) / (float)0xFFFF;
651  optr += 8 * 4;
652  iptr += 8 * 2;
653  count -= 8;
654  }
655  while (count--) {
656  *optr = ((iptr[0] << 8) | (iptr[1] << 0)) / (float)0xFFFF;
657  iptr += 2;
658  optr += 4;
659  }
660  BLI_assert(iptr == iptr_next);
661  }
662  else {
663  iptr_next = iptr + 2;
665  pixel_f = ((iptr[0] << 8) | (iptr[1] << 0)) / (float)0xFFFF;
666  iptr = iptr_next;
667 
668  while (count >= 8) {
669  optr[0 * 4] = pixel_f;
670  optr[1 * 4] = pixel_f;
671  optr[2 * 4] = pixel_f;
672  optr[3 * 4] = pixel_f;
673  optr[4 * 4] = pixel_f;
674  optr[5 * 4] = pixel_f;
675  optr[6 * 4] = pixel_f;
676  optr[7 * 4] = pixel_f;
677  optr += 8 * 4;
678  count -= 8;
679  }
680  while (count--) {
681  *optr = pixel_f;
682  optr += 4;
683  }
684  BLI_assert(iptr == iptr_next);
685  }
686  BLI_assert(optr == optr_next);
687  }
688  return false;
689 
690 #undef EXPAND_CAPACITY_AT_INPUT_OK_OR_FAIL
691 #undef EXPAND_CAPACITY_AT_OUTPUT_OK_OR_FAIL
692 fail:
693  return DIRTY_FLAG_ENCODING;
694 }
695 
696 static int expandrow(
697  uchar *optr, const uchar *optr_end, const uchar *iptr, const uchar *iptr_end, int z)
698 {
699  uchar pixel, count;
700 
701 #define EXPAND_CAPACITY_AT_INPUT_OK_OR_FAIL(iptr_next) \
702  if (UNLIKELY(iptr_next > iptr_end)) { \
703  goto fail; \
704  } \
705  ((void)0)
706 
707 #define EXPAND_CAPACITY_AT_OUTPUT_OK_OR_FAIL(optr_next) \
708  if (UNLIKELY(optr_next > optr_end)) { \
709  goto fail; \
710  } \
711  ((void)0)
712 
713  optr += z;
714  optr_end += z;
715  while (1) {
716  const uchar *iptr_next = iptr + 1;
718  pixel = *iptr;
719  iptr = iptr_next;
720  if (!(count = (pixel & 0x7f))) {
721  return false;
722  }
723  const uchar *optr_next = optr + ((int)count * 4);
725 
726  if (pixel & 0x80) {
727  iptr_next = iptr + count;
729  while (count >= 8) {
730  optr[0 * 4] = iptr[0];
731  optr[1 * 4] = iptr[1];
732  optr[2 * 4] = iptr[2];
733  optr[3 * 4] = iptr[3];
734  optr[4 * 4] = iptr[4];
735  optr[5 * 4] = iptr[5];
736  optr[6 * 4] = iptr[6];
737  optr[7 * 4] = iptr[7];
738  optr += 8 * 4;
739  iptr += 8;
740  count -= 8;
741  }
742  while (count--) {
743  *optr = *iptr++;
744  optr += 4;
745  }
746  BLI_assert(iptr == iptr_next);
747  }
748  else {
749  iptr_next = iptr + 1;
751  pixel = *iptr++;
752  while (count >= 8) {
753  optr[0 * 4] = pixel;
754  optr[1 * 4] = pixel;
755  optr[2 * 4] = pixel;
756  optr[3 * 4] = pixel;
757  optr[4 * 4] = pixel;
758  optr[5 * 4] = pixel;
759  optr[6 * 4] = pixel;
760  optr[7 * 4] = pixel;
761  optr += 8 * 4;
762  count -= 8;
763  }
764  while (count--) {
765  *optr = pixel;
766  optr += 4;
767  }
768  BLI_assert(iptr == iptr_next);
769  }
770  BLI_assert(optr == optr_next);
771  }
772 
773  return false;
774 
775 #undef EXPAND_CAPACITY_AT_INPUT_OK_OR_FAIL
776 #undef EXPAND_CAPACITY_AT_OUTPUT_OK_OR_FAIL
777 fail:
778  return DIRTY_FLAG_ENCODING;
779 }
780 
794 static bool output_iris(const char *filepath,
795  const uint *lptr,
796  const int *zptr,
797  const int xsize,
798  const int ysize,
799  const int zsize)
800 {
801  FILE *outf;
802  IMAGE *image;
803  int tablen, y, z, pos, len = 0;
804  uint *starttab, *lengthtab;
805  uchar *rlebuf;
806  uint *lumbuf;
807  int rlebuflen, goodwrite;
808 
809  goodwrite = 1;
810  outf = BLI_fopen(filepath, "wb");
811  if (!outf) {
812  return 0;
813  }
814 
815  tablen = ysize * zsize * sizeof(int);
816 
817  image = (IMAGE *)MEM_mallocN(sizeof(IMAGE), "iris image");
818  starttab = (uint *)MEM_mallocN(tablen, "iris starttab");
819  lengthtab = (uint *)MEM_mallocN(tablen, "iris lengthtab");
820  rlebuflen = 1.05 * xsize + 10;
821  rlebuf = (uchar *)MEM_mallocN(rlebuflen, "iris rlebuf");
822  lumbuf = (uint *)MEM_mallocN(xsize * sizeof(int), "iris lumbuf");
823 
824  memset(image, 0, sizeof(IMAGE));
825  image->imagic = IMAGIC;
826  image->type = RLE(1);
827  if (zsize > 1) {
828  image->dim = 3;
829  }
830  else {
831  image->dim = 2;
832  }
833  image->xsize = xsize;
834  image->ysize = ysize;
835  image->zsize = zsize;
836  image->min = 0;
837  image->max = 255;
838  goodwrite *= writeheader(outf, image);
839  fseek(outf, HEADER_SIZE + (2 * tablen), SEEK_SET);
840  pos = HEADER_SIZE + (2 * tablen);
841 
842  for (y = 0; y < ysize; y++) {
843  for (z = 0; z < zsize; z++) {
844 
845  if (zsize == 1) {
846  lumrow((const uchar *)lptr, (uchar *)lumbuf, xsize);
847  len = compressrow((const uchar *)lumbuf, rlebuf, CHANOFFSET(z), xsize);
848  }
849  else {
850  if (z < 4) {
851  len = compressrow((const uchar *)lptr, rlebuf, CHANOFFSET(z), xsize);
852  }
853  else if (z < 8 && zptr) {
854  len = compressrow((const uchar *)zptr, rlebuf, CHANOFFSET(z - 4), xsize);
855  }
856  }
857 
858  BLI_assert_msg(len <= rlebuflen, "The length calculated for 'rlebuflen' was too small!");
859 
860  goodwrite *= fwrite(rlebuf, len, 1, outf);
861  starttab[y + z * ysize] = pos;
862  lengthtab[y + z * ysize] = len;
863  pos += len;
864  }
865  lptr += xsize;
866  if (zptr) {
867  zptr += xsize;
868  }
869  }
870 
871  fseek(outf, HEADER_SIZE, SEEK_SET);
872  goodwrite *= writetab(outf, starttab, tablen);
873  goodwrite *= writetab(outf, lengthtab, tablen);
874  MEM_freeN(image);
875  MEM_freeN(starttab);
876  MEM_freeN(lengthtab);
877  MEM_freeN(rlebuf);
878  MEM_freeN(lumbuf);
879  fclose(outf);
880  if (goodwrite) {
881  return 1;
882  }
883 
884  fprintf(stderr, "output_iris: not enough space for image!!\n");
885  return 0;
886 }
887 
888 /* static utility functions for output_iris */
889 
890 static void lumrow(const uchar *rgbptr, uchar *lumptr, int n)
891 {
892  lumptr += CHANOFFSET(0);
893  while (n--) {
894  *lumptr = ILUM(rgbptr[OFFSET_R], rgbptr[OFFSET_G], rgbptr[OFFSET_B]);
895  lumptr += 4;
896  rgbptr += 4;
897  }
898 }
899 
900 static int compressrow(const uchar *lbuf, uchar *rlebuf, const int z, const int row_len)
901 {
902  const uchar *iptr, *ibufend, *sptr;
903  uchar *optr;
904  short todo, cc;
905  int count;
906 
907  lbuf += z;
908  iptr = lbuf;
909  ibufend = iptr + row_len * 4;
910  optr = rlebuf;
911 
912  while (iptr < ibufend) {
913  sptr = iptr;
914  iptr += 8;
915  while ((iptr < ibufend) && ((iptr[-8] != iptr[-4]) || (iptr[-4] != iptr[0]))) {
916  iptr += 4;
917  }
918  iptr -= 8;
919  count = (iptr - sptr) / 4;
920  while (count) {
921  todo = count > 126 ? 126 : count;
922  count -= todo;
923  *optr++ = 0x80 | todo;
924  while (todo > 8) {
925  optr[0] = sptr[0 * 4];
926  optr[1] = sptr[1 * 4];
927  optr[2] = sptr[2 * 4];
928  optr[3] = sptr[3 * 4];
929  optr[4] = sptr[4 * 4];
930  optr[5] = sptr[5 * 4];
931  optr[6] = sptr[6 * 4];
932  optr[7] = sptr[7 * 4];
933 
934  optr += 8;
935  sptr += 8 * 4;
936  todo -= 8;
937  }
938  while (todo--) {
939  *optr++ = *sptr;
940  sptr += 4;
941  }
942  }
943  sptr = iptr;
944  cc = *iptr;
945  iptr += 4;
946  while ((iptr < ibufend) && (*iptr == cc)) {
947  iptr += 4;
948  }
949  count = (iptr - sptr) / 4;
950  while (count) {
951  todo = count > 126 ? 126 : count;
952  count -= todo;
953  *optr++ = todo;
954  *optr++ = cc;
955  }
956  }
957  *optr++ = 0;
958  return optr - (uchar *)rlebuf;
959 }
960 
961 bool imb_saveiris(struct ImBuf *ibuf, const char *filepath, int flags)
962 {
963  short zsize;
964 
965  zsize = (ibuf->planes + 7) >> 3;
966  if (flags & IB_zbuf && ibuf->zbuf != NULL) {
967  zsize = 8;
968  }
969 
971  test_endian_zbuf(ibuf);
972 
973  const bool ok = output_iris(filepath, ibuf->rect, ibuf->zbuf, ibuf->x, ibuf->y, zsize);
974 
975  /* restore! Quite clumsy, 2 times a switch... maybe better a malloc ? */
977  test_endian_zbuf(ibuf);
978 
979  return ok;
980 }
#define BLI_assert(a)
Definition: BLI_assert.h:46
#define BLI_assert_msg(a, msg)
Definition: BLI_assert.h:53
File and directory operations.
FILE * BLI_fopen(const char *filepath, const char *mode) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition: fileops.c:906
unsigned char uchar
Definition: BLI_sys_types.h:70
unsigned int uint
Definition: BLI_sys_types.h:67
unsigned short ushort
Definition: BLI_sys_types.h:68
#define ELEM(...)
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble z
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble GLdouble r _GL_VOID_RET _GL_VOID GLfloat GLfloat r _GL_VOID_RET _GL_VOID GLint GLint r _GL_VOID_RET _GL_VOID GLshort GLshort r _GL_VOID_RET _GL_VOID GLdouble GLdouble r
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble t
@ COLOR_ROLE_DEFAULT_BYTE
struct ImBuf * IMB_allocImBuf(unsigned int x, unsigned int y, unsigned char planes, unsigned int flags)
Definition: allocimbuf.c:500
void IMB_rect_from_float(struct ImBuf *ibuf)
Definition: divers.c:696
#define IM_MAX_SPACE
Definition: IMB_imbuf.h:49
void IMB_convert_rgba_to_abgr(struct ImBuf *ibuf)
Definition: imageprocess.c:26
Contains defines and structs used throughout the imbuf module.
@ IB_zbuf
@ IB_rectfloat
@ IB_test
@ IB_rect
Read Guarded memory(de)allocation.
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
void colorspace_set_default_role(char *colorspace, int size, int role)
int len
Definition: draw_manager.c:108
depth_tx normal_tx diffuse_light_tx specular_light_tx volume_light_tx environment_tx ambient_occlusion_tx aov_value_tx in_weight_img image(1, GPU_R32F, Qualifier::WRITE, ImageType::FLOAT_2D_ARRAY, "out_weight_img") .image(3
uint pos
@ IMB_FTYPE_IMAGIC
#define BIG_LONG
Definition: imbuf.h:43
int count
static bool output_iris(const char *filepath, const uint *lptr, const int *zptr, const int xsize, const int ysize, const int zsize)
Definition: iris.c:794
#define ILUM(r, g, b)
Definition: iris.c:48
#define OFFSET_R
Definition: iris.c:50
static int writetab(FILE *outf, uint *tab, int len)
Definition: iris.c:184
#define DIRTY_FLAG_ENCODING
Definition: iris.c:89
struct ImBuf * imb_loadiris(const uchar *mem, size_t size, int flags, char colorspace[IM_MAX_SPACE])
Definition: iris.c:238
bool imb_saveiris(struct ImBuf *ibuf, const char *filepath, int flags)
Definition: iris.c:961
static void interleaverow(uchar *lptr, const uchar *cptr, int z, int n)
Definition: iris.c:589
struct MFileOffset MFileOffset
bool imb_is_a_iris(const uchar *mem, size_t size)
Definition: iris.c:230
#define BPP(type)
Definition: iris.c:63
static int expandrow2(float *optr, const float *optr_end, const uchar *iptr, const uchar *iptr_end, int z)
Definition: iris.c:608
static void putshort(FILE *outf, ushort val)
Definition: iris.c:135
static uint getlong(MFileOffset *mofs)
Definition: iris.c:125
#define EXPAND_CAPACITY_AT_OUTPUT_OK_OR_FAIL(optr_next)
#define HEADER_SIZE
Definition: iris.c:40
static void lumrow(const uchar *rgbptr, uchar *lumptr, int n)
Definition: iris.c:890
#define ISRLE(type)
Definition: iris.c:61
static int writeheader(FILE *outf, IMAGE *image)
Definition: iris.c:166
static int expandrow(uchar *optr, const uchar *optr_end, const uchar *iptr, const uchar *iptr_end, int z)
Definition: iris.c:696
#define OFFSET_B
Definition: iris.c:52
#define GSS(x)
Definition: iris.c:228
#define CHANOFFSET(z)
Definition: iris.c:55
#define OFFSET_G
Definition: iris.c:51
static ushort getshort(MFileOffset *inf)
Definition: iris.c:115
static int compressrow(const uchar *lbuf, uchar *rlebuf, int z, int row_len)
Definition: iris.c:900
#define MFILE_STEP(inf, step)
Definition: iris.c:76
static void test_endian_zbuf(struct ImBuf *ibuf)
Definition: iris.c:203
static void readtab(MFileOffset *inf, uint *tab, int len)
Definition: iris.c:195
static void interleaverow2(float *lptr, const uchar *cptr, int z, int n)
Definition: iris.c:598
#define GS(x)
Definition: iris.c:225
BLI_STATIC_ASSERT(sizeof(IMAGE)==HEADER_SIZE, "Invalid header size")
#define MFILE_DATA(inf)
Definition: iris.c:75
#define MFILE_CAPACITY_AT_PTR_OK_OR_FAIL(p)
static int putlong(FILE *outf, uint val)
Definition: iris.c:144
#define EXPAND_CAPACITY_AT_INPUT_OK_OR_FAIL(iptr_next)
#define IMAGIC
Definition: iris.c:23
#define MFILE_SEEK(inf, pos)
Definition: iris.c:81
#define RLE(bpp)
Definition: iris.c:64
static void readheader(MFileOffset *inf, IMAGE *image)
Definition: iris.c:155
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:27
void *(* MEM_mallocN)(size_t len, const char *str)
Definition: mallocn.c:33
Definition: iris.c:25
uint colormap
Definition: iris.c:36
ushort ysize
Definition: iris.c:30
ushort xsize
Definition: iris.c:29
uint max
Definition: iris.c:33
ushort imagic
Definition: iris.c:26
ushort type
Definition: iris.c:27
uint min
Definition: iris.c:32
ushort dim
Definition: iris.c:28
ushort zsize
Definition: iris.c:31
unsigned char planes
enum eImbFileType ftype
unsigned int * rect
float * rect_float
int * zbuf
uint _file_offset
Definition: iris.c:72
const uchar * _file_data
Definition: iris.c:71