Blender  V2.93
targa.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
17  * All rights reserved.
18  */
19 
24 #ifdef WIN32
25 # include <io.h>
26 #endif
27 
28 #include "BLI_fileops.h"
29 #include "BLI_utildefines.h"
30 
31 #include "MEM_guardedalloc.h"
32 
33 #include "imbuf.h"
34 
35 #include "IMB_imbuf.h"
36 #include "IMB_imbuf_types.h"
37 
38 #include "IMB_filetype.h"
39 
40 #include "IMB_colormanagement.h"
42 
43 /* this one is only def-ed once, strangely... related to GS? */
44 #define GSS(x) (((uchar *)(x))[1] << 8 | ((uchar *)(x))[0])
45 
46 /***/
47 
48 typedef struct TARGA {
49  unsigned char numid;
50  unsigned char maptyp;
51  unsigned char imgtyp;
52  short maporig;
53  short mapsize;
54  unsigned char mapbits;
55  short xorig;
56  short yorig;
57  short xsize;
58  short ysize;
59  unsigned char pixsize;
60  unsigned char imgdes;
62 
69 #define TARGA_HEADER_SIZE 18
70 
71 /***/
72 
73 static int tga_out1(unsigned int data, FILE *file)
74 {
75  uchar *p;
76 
77  p = (uchar *)&data;
78  if (putc(p[0], file) == EOF) {
79  return EOF;
80  }
81  return ~EOF;
82 }
83 
84 static int tga_out2(unsigned int data, FILE *file)
85 {
86  uchar *p;
87 
88  p = (uchar *)&data;
89  if (putc(p[0], file) == EOF) {
90  return EOF;
91  }
92  if (putc(p[1], file) == EOF) {
93  return EOF;
94  }
95  return ~EOF;
96 }
97 
98 static int tga_out3(unsigned int data, FILE *file)
99 {
100  uchar *p;
101 
102  p = (uchar *)&data;
103  if (putc(p[2], file) == EOF) {
104  return EOF;
105  }
106  if (putc(p[1], file) == EOF) {
107  return EOF;
108  }
109  if (putc(p[0], file) == EOF) {
110  return EOF;
111  }
112  return ~EOF;
113 }
114 
115 static int tga_out4(unsigned int data, FILE *file)
116 {
117  uchar *p;
118 
119  p = (uchar *)&data;
120  /* order = bgra */
121  if (putc(p[2], file) == EOF) {
122  return EOF;
123  }
124  if (putc(p[1], file) == EOF) {
125  return EOF;
126  }
127  if (putc(p[0], file) == EOF) {
128  return EOF;
129  }
130  if (putc(p[3], file) == EOF) {
131  return EOF;
132  }
133  return ~EOF;
134 }
135 
136 static bool makebody_tga(ImBuf *ibuf, FILE *file, int (*out)(unsigned int, FILE *))
137 {
138  int last, this;
139  int copy, bytes;
140  unsigned int *rect, *rectstart, *temp;
141  int y;
142 
143  for (y = 0; y < ibuf->y; y++) {
144  bytes = ibuf->x - 1;
145  rectstart = rect = ibuf->rect + (y * ibuf->x);
146  last = *rect++;
147  this = *rect++;
148  copy = last ^ this;
149  while (bytes > 0) {
150  if (copy) {
151  do {
152  last = this;
153  this = *rect++;
154  if (last == this) {
155  if (this == rect[-3]) { /* three the same? */
156  bytes--; /* set bytes */
157  break;
158  }
159  }
160  } while (--bytes != 0);
161 
162  copy = rect - rectstart;
163  copy--;
164  if (bytes) {
165  copy -= 2;
166  }
167 
168  temp = rect;
169  rect = rectstart;
170 
171  while (copy) {
172  last = copy;
173  if (copy >= 128) {
174  last = 128;
175  }
176  copy -= last;
177  if (fputc(last - 1, file) == EOF) {
178  return 0;
179  }
180  do {
181  if (out(*rect++, file) == EOF) {
182  return 0;
183  }
184  } while (--last != 0);
185  }
186  rectstart = rect;
187  rect = temp;
188  last = this;
189 
190  copy = 0;
191  }
192  else {
193  while (*rect++ == this) { /* seek for first different byte */
194  if (--bytes == 0) {
195  break; /* oor end of line */
196  }
197  }
198  rect--;
199  copy = rect - rectstart;
200  rectstart = rect;
201  bytes--;
202  this = *rect++;
203 
204  while (copy) {
205  if (copy > 128) {
206  if (fputc(255, file) == EOF) {
207  return 0;
208  }
209  copy -= 128;
210  }
211  else {
212  if (copy == 1) {
213  if (fputc(0, file) == EOF) {
214  return 0;
215  }
216  }
217  else if (fputc(127 + copy, file) == EOF) {
218  return 0;
219  }
220  copy = 0;
221  }
222  if (out(last, file) == EOF) {
223  return 0;
224  }
225  }
226  copy = 1;
227  }
228  }
229  }
230  return 1;
231 }
232 
233 static bool dumptarga(struct ImBuf *ibuf, FILE *file)
234 {
235  int size;
236  uchar *rect;
237 
238  if (ibuf == NULL) {
239  return 0;
240  }
241  if (ibuf->rect == NULL) {
242  return 0;
243  }
244 
245  size = ibuf->x * ibuf->y;
246  rect = (uchar *)ibuf->rect;
247 
248  if (ibuf->planes <= 8) {
249  while (size > 0) {
250  if (putc(*rect, file) == EOF) {
251  return 0;
252  }
253  size--;
254  rect += 4;
255  }
256  }
257  else if (ibuf->planes <= 16) {
258  while (size > 0) {
259  putc(rect[0], file);
260  if (putc(rect[1], file) == EOF) {
261  return 0;
262  }
263  size--;
264  rect += 4;
265  }
266  }
267  else if (ibuf->planes <= 24) {
268  while (size > 0) {
269  putc(rect[2], file);
270  putc(rect[1], file);
271  if (putc(rect[0], file) == EOF) {
272  return 0;
273  }
274  size--;
275  rect += 4;
276  }
277  }
278  else if (ibuf->planes <= 32) {
279  while (size > 0) {
280  putc(rect[2], file);
281  putc(rect[1], file);
282  putc(rect[0], file);
283  if (putc(rect[3], file) == EOF) {
284  return 0;
285  }
286  size--;
287  rect += 4;
288  }
289  }
290  else {
291  return 0;
292  }
293 
294  return 1;
295 }
296 
297 bool imb_savetarga(struct ImBuf *ibuf, const char *filepath, int UNUSED(flags))
298 {
299  char buf[TARGA_HEADER_SIZE] = {0};
300  FILE *fildes;
301  bool ok = false;
302 
303  buf[16] = (ibuf->planes + 0x7) & ~0x7;
304  if (ibuf->planes > 8) {
305  buf[2] = 10;
306  }
307  else {
308  buf[2] = 11;
309  }
310 
311  if (ibuf->foptions.flag & RAWTGA) {
312  buf[2] &= ~8;
313  }
314 
315  buf[8] = 0;
316  buf[9] = 0;
317  buf[10] = 0;
318  buf[11] = 0;
319 
320  buf[12] = ibuf->x & 0xff;
321  buf[13] = ibuf->x >> 8;
322  buf[14] = ibuf->y & 0xff;
323  buf[15] = ibuf->y >> 8;
324 
325  /* Don't forget to indicate that your 32 bit
326  * targa uses 8 bits for the alpha channel! */
327  if (ibuf->planes == 32) {
328  buf[17] |= 0x08;
329  }
330  fildes = BLI_fopen(filepath, "wb");
331  if (!fildes) {
332  return 0;
333  }
334 
335  if (fwrite(buf, 1, TARGA_HEADER_SIZE, fildes) != TARGA_HEADER_SIZE) {
336  fclose(fildes);
337  return 0;
338  }
339 
340  if (ibuf->foptions.flag & RAWTGA) {
341  ok = dumptarga(ibuf, fildes);
342  }
343  else {
344  switch ((ibuf->planes + 7) >> 3) {
345  case 1:
346  ok = makebody_tga(ibuf, fildes, tga_out1);
347  break;
348  case 2:
349  ok = makebody_tga(ibuf, fildes, tga_out2);
350  break;
351  case 3:
352  ok = makebody_tga(ibuf, fildes, tga_out3);
353  break;
354  case 4:
355  ok = makebody_tga(ibuf, fildes, tga_out4);
356  break;
357  }
358  }
359 
360  fclose(fildes);
361  return ok;
362 }
363 
364 static bool checktarga(TARGA *tga, const unsigned char *mem, const size_t size)
365 {
366  if (size < TARGA_HEADER_SIZE) {
367  return false;
368  }
369 
370  tga->numid = mem[0];
371  tga->maptyp = mem[1];
372  tga->imgtyp = mem[2];
373 
374  tga->maporig = GSS(mem + 3);
375  tga->mapsize = GSS(mem + 5);
376  tga->mapbits = mem[7];
377  tga->xorig = GSS(mem + 8);
378  tga->yorig = GSS(mem + 10);
379  tga->xsize = GSS(mem + 12);
380  tga->ysize = GSS(mem + 14);
381  tga->pixsize = mem[16];
382  tga->imgdes = mem[17];
383 
384  if (tga->maptyp > 1) {
385  return false;
386  }
387  switch (tga->imgtyp) {
388  case 1: /* raw cmap */
389  case 2: /* raw rgb */
390  case 3: /* raw b&w */
391  case 9: /* cmap */
392  case 10: /* rgb */
393  case 11: /* b&w */
394  break;
395  default:
396  return false;
397  }
398  if (tga->mapsize && tga->mapbits > 32) {
399  return false;
400  }
401  if (tga->xsize <= 0) {
402  return false;
403  }
404  if (tga->ysize <= 0) {
405  return false;
406  }
407  if (tga->pixsize > 32) {
408  return false;
409  }
410  if (tga->pixsize == 0) {
411  return false;
412  }
413  return true;
414 }
415 
416 bool imb_is_a_targa(const unsigned char *buf, size_t size)
417 {
418  TARGA tga;
419 
420  return checktarga(&tga, buf, size);
421 }
422 
423 static void complete_partial_load(struct ImBuf *ibuf, unsigned int *rect)
424 {
425  int size = (ibuf->x * ibuf->y) - (rect - ibuf->rect);
426  if (size) {
427  printf("decodetarga: incomplete file, %.1f%% missing\n",
428  100 * ((float)size / (ibuf->x * ibuf->y)));
429 
430  /* not essential but makes displaying partially rendered TGA's less ugly */
431  memset(rect, 0, size);
432  }
433  else {
434  /* shouldn't happen */
435  printf("decodetarga: incomplete file, all pixels written\n");
436  }
437 }
438 
439 static void decodetarga(struct ImBuf *ibuf, const unsigned char *mem, size_t mem_size, int psize)
440 {
441  const unsigned char *mem_end = mem + mem_size;
442  int count, col, size;
443  unsigned int *rect;
444  uchar *cp = (uchar *)&col;
445 
446  if (ibuf == NULL) {
447  return;
448  }
449  if (ibuf->rect == NULL) {
450  return;
451  }
452 
453  size = ibuf->x * ibuf->y;
454  rect = ibuf->rect;
455 
456  /* set alpha */
457  cp[0] = 0xff;
458  cp[1] = cp[2] = 0;
459 
460  while (size > 0) {
461  count = *mem++;
462 
463  if (mem > mem_end) {
464  goto partial_load;
465  }
466 
467  if (count >= 128) {
468  /*if (count == 128) printf("TARGA: 128 in file !\n");*/
469  count -= 127;
470 
471  if (psize & 2) {
472  if (psize & 1) {
473  /* order = bgra */
474  cp[0] = mem[3];
475  cp[1] = mem[0];
476  cp[2] = mem[1];
477  cp[3] = mem[2];
478  /*col = (mem[3] << 24) + (mem[0] << 16) + (mem[1] << 8) + mem[2];*/
479  mem += 4;
480  }
481  else {
482  cp[1] = mem[0];
483  cp[2] = mem[1];
484  cp[3] = mem[2];
485  /*col = 0xff000000 + (mem[0] << 16) + (mem[1] << 8) + mem[2];*/
486  mem += 3;
487  }
488  }
489  else {
490  if (psize & 1) {
491  cp[0] = mem[0];
492  cp[1] = mem[1];
493  mem += 2;
494  }
495  else {
496  col = *mem++;
497  }
498  }
499 
500  size -= count;
501  if (size >= 0) {
502  while (count > 0) {
503  *rect++ = col;
504  count--;
505  }
506  }
507  }
508  else {
509  count++;
510  size -= count;
511  if (size >= 0) {
512  while (count > 0) {
513  if (psize & 2) {
514  if (psize & 1) {
515  /* order = bgra */
516  cp[0] = mem[3];
517  cp[1] = mem[0];
518  cp[2] = mem[1];
519  cp[3] = mem[2];
520  /*col = (mem[3] << 24) + (mem[0] << 16) + (mem[1] << 8) + mem[2];*/
521  mem += 4;
522  }
523  else {
524  cp[1] = mem[0];
525  cp[2] = mem[1];
526  cp[3] = mem[2];
527  /*col = 0xff000000 + (mem[0] << 16) + (mem[1] << 8) + mem[2];*/
528  mem += 3;
529  }
530  }
531  else {
532  if (psize & 1) {
533  cp[0] = mem[0];
534  cp[1] = mem[1];
535  mem += 2;
536  }
537  else {
538  col = *mem++;
539  }
540  }
541  *rect++ = col;
542  count--;
543 
544  if (mem > mem_end) {
545  goto partial_load;
546  }
547  }
548 
549  if (mem > mem_end) {
550  goto partial_load;
551  }
552  }
553  }
554  }
555  if (size) {
556  printf("decodetarga: count would overwrite %d pixels\n", -size);
557  }
558  return;
559 
560 partial_load:
561  complete_partial_load(ibuf, rect);
562 }
563 
564 static void ldtarga(struct ImBuf *ibuf, const unsigned char *mem, size_t mem_size, int psize)
565 {
566  const unsigned char *mem_end = mem + mem_size;
567  int col, size;
568  unsigned int *rect;
569  uchar *cp = (uchar *)&col;
570 
571  if (ibuf == NULL) {
572  return;
573  }
574  if (ibuf->rect == NULL) {
575  return;
576  }
577 
578  size = ibuf->x * ibuf->y;
579  rect = ibuf->rect;
580 
581  /* set alpha */
582  cp[0] = 0xff;
583  cp[1] = cp[2] = 0;
584 
585  while (size > 0) {
586  if (mem > mem_end) {
587  goto partial_load;
588  }
589 
590  if (psize & 2) {
591  if (psize & 1) {
592  /* order = bgra */
593  cp[0] = mem[3];
594  cp[1] = mem[0];
595  cp[2] = mem[1];
596  cp[3] = mem[2];
597  /*col = (mem[3] << 24) + (mem[0] << 16) + (mem[1] << 8) + mem[2];*/
598  mem += 4;
599  }
600  else {
601  /* set alpha for 24 bits colors */
602  cp[1] = mem[0];
603  cp[2] = mem[1];
604  cp[3] = mem[2];
605  /*col = 0xff000000 + (mem[0] << 16) + (mem[1] << 8) + mem[2];*/
606  mem += 3;
607  }
608  }
609  else {
610  if (psize & 1) {
611  cp[0] = mem[0];
612  cp[1] = mem[1];
613  mem += 2;
614  }
615  else {
616  col = *mem++;
617  }
618  }
619  *rect++ = col;
620  size--;
621  }
622  return;
623 
624 partial_load:
625  complete_partial_load(ibuf, rect);
626 }
627 
628 ImBuf *imb_loadtarga(const unsigned char *mem,
629  size_t mem_size,
630  int flags,
631  char colorspace[IM_MAX_SPACE])
632 {
633  TARGA tga;
634  struct ImBuf *ibuf;
635  int count, size;
636  unsigned int *rect, *cmap = NULL /*, mincol = 0*/, cmap_max = 0;
637  int32_t cp_data;
638  uchar *cp = (uchar *)&cp_data;
639 
640  if (checktarga(&tga, mem, mem_size) == 0) {
641  return NULL;
642  }
643 
645 
646  if (flags & IB_test) {
647  ibuf = IMB_allocImBuf(tga.xsize, tga.ysize, tga.pixsize, 0);
648  }
649  else {
650  ibuf = IMB_allocImBuf(tga.xsize, tga.ysize, (tga.pixsize + 0x7) & ~0x7, IB_rect);
651  }
652 
653  if (ibuf == NULL) {
654  return NULL;
655  }
656  ibuf->ftype = IMB_FTYPE_TGA;
657  if (tga.imgtyp < 4) {
658  ibuf->foptions.flag |= RAWTGA;
659  }
660  mem = mem + TARGA_HEADER_SIZE + tga.numid;
661 
662  cp[0] = 0xff;
663  cp[1] = cp[2] = 0;
664 
665  if (tga.mapsize) {
666  /* load color map */
667  /*mincol = tga.maporig;*/ /*UNUSED*/
668  cmap_max = tga.mapsize;
669  cmap = MEM_callocN(sizeof(unsigned int) * cmap_max, "targa cmap");
670 
671  for (count = 0; count < cmap_max; count++) {
672  switch (tga.mapbits >> 3) {
673  case 4:
674  cp[0] = mem[3];
675  cp[1] = mem[0];
676  cp[2] = mem[1];
677  cp[3] = mem[2];
678  mem += 4;
679  break;
680  case 3:
681  cp[1] = mem[0];
682  cp[2] = mem[1];
683  cp[3] = mem[2];
684  mem += 3;
685  break;
686  case 2:
687  cp[1] = mem[1];
688  cp[0] = mem[0];
689  mem += 2;
690  break;
691  case 1:
692  cp_data = *mem++;
693  break;
694  }
695  cmap[count] = cp_data;
696  }
697 
698  size = 0;
699  for (int cmap_index = cmap_max - 1; cmap_index > 0; cmap_index >>= 1) {
700  size++;
701  }
702  ibuf->planes = size;
703 
704  if (tga.mapbits != 32) { /* set alpha bits */
705  cmap[0] &= BIG_LONG(0x00ffffffl);
706  }
707  }
708 
709  if (flags & IB_test) {
710  if (cmap) {
711  MEM_freeN(cmap);
712  }
713  return ibuf;
714  }
715 
716  if (!ELEM(tga.imgtyp, 1, 9)) { /* happens sometimes (ugh) */
717  if (cmap) {
718  MEM_freeN(cmap);
719  cmap = NULL;
720  }
721  }
722 
723  switch (tga.imgtyp) {
724  case 1:
725  case 2:
726  case 3:
727  if (tga.pixsize <= 8) {
728  ldtarga(ibuf, mem, mem_size, 0);
729  }
730  else if (tga.pixsize <= 16) {
731  ldtarga(ibuf, mem, mem_size, 1);
732  }
733  else if (tga.pixsize <= 24) {
734  ldtarga(ibuf, mem, mem_size, 2);
735  }
736  else if (tga.pixsize <= 32) {
737  ldtarga(ibuf, mem, mem_size, 3);
738  }
739  break;
740  case 9:
741  case 10:
742  case 11:
743  if (tga.pixsize <= 8) {
744  decodetarga(ibuf, mem, mem_size, 0);
745  }
746  else if (tga.pixsize <= 16) {
747  decodetarga(ibuf, mem, mem_size, 1);
748  }
749  else if (tga.pixsize <= 24) {
750  decodetarga(ibuf, mem, mem_size, 2);
751  }
752  else if (tga.pixsize <= 32) {
753  decodetarga(ibuf, mem, mem_size, 3);
754  }
755  break;
756  }
757 
758  if (cmap) {
759  /* apply color map */
760  rect = ibuf->rect;
761  for (size = ibuf->x * ibuf->y; size > 0; size--, rect++) {
762  int cmap_index = *rect;
763  if (cmap_index >= 0 && cmap_index < cmap_max) {
764  *rect = cmap[cmap_index];
765  }
766  }
767 
768  MEM_freeN(cmap);
769  }
770 
771  if (tga.pixsize == 16) {
772  unsigned int col;
773  rect = ibuf->rect;
774  for (size = ibuf->x * ibuf->y; size > 0; size--, rect++) {
775  col = *rect;
776  cp = (uchar *)rect;
777  mem = (uchar *)&col;
778 
779  cp[3] = ((mem[1] << 1) & 0xf8);
780  cp[2] = ((mem[0] & 0xe0) >> 2) + ((mem[1] & 0x03) << 6);
781  cp[1] = ((mem[0] << 3) & 0xf8);
782  cp[1] += cp[1] >> 5;
783  cp[2] += cp[2] >> 5;
784  cp[3] += cp[3] >> 5;
785  cp[0] = 0xff;
786  }
787  ibuf->planes = 24;
788  }
789 
790  if (ELEM(tga.imgtyp, 3, 11)) {
791  uchar *crect;
792  unsigned int *lrect, col;
793 
794  crect = (uchar *)ibuf->rect;
795  lrect = (unsigned int *)ibuf->rect;
796 
797  for (size = ibuf->x * ibuf->y; size > 0; size--) {
798  col = *lrect++;
799 
800  crect[0] = 255;
801  crect[1] = crect[2] = crect[3] = col;
802  crect += 4;
803  }
804  }
805 
806  if (tga.imgdes & 0x20) {
807  IMB_flipy(ibuf);
808  }
809 
810  if (ibuf->rect) {
812  }
813 
814  return ibuf;
815 }
File and directory operations.
FILE * BLI_fopen(const char *filename, const char *mode) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition: fileops.c:1003
unsigned char uchar
Definition: BLI_sys_types.h:86
#define UNUSED(x)
#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 y
@ COLOR_ROLE_DEFAULT_BYTE
struct ImBuf * IMB_allocImBuf(unsigned int x, unsigned int y, unsigned char planes, unsigned int flags)
Definition: allocimbuf.c:478
#define IM_MAX_SPACE
Definition: IMB_imbuf.h:65
void IMB_convert_rgba_to_abgr(struct ImBuf *ibuf)
Definition: imageprocess.c:45
void IMB_flipy(struct ImBuf *ibuf)
Definition: rotate.c:33
Contains defines and structs used throughout the imbuf module.
#define RAWTGA
@ 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)
FILE * file
uint col
@ IMB_FTYPE_TGA
#define BIG_LONG
Definition: imbuf.h:59
int count
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:41
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:45
static void copy(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node)
signed int int32_t
Definition: stdint.h:80
ImbFormatOptions foptions
unsigned char planes
enum eImbFileType ftype
unsigned int * rect
Definition: targa.c:48
short mapsize
Definition: targa.c:53
unsigned char numid
Definition: targa.c:49
short xorig
Definition: targa.c:55
short yorig
Definition: targa.c:56
unsigned char maptyp
Definition: targa.c:50
unsigned char imgdes
Definition: targa.c:60
short xsize
Definition: targa.c:57
short maporig
Definition: targa.c:52
short ysize
Definition: targa.c:58
unsigned char pixsize
Definition: targa.c:59
unsigned char imgtyp
Definition: targa.c:51
unsigned char mapbits
Definition: targa.c:54
static int tga_out2(unsigned int data, FILE *file)
Definition: targa.c:84
static void decodetarga(struct ImBuf *ibuf, const unsigned char *mem, size_t mem_size, int psize)
Definition: targa.c:439
static int tga_out3(unsigned int data, FILE *file)
Definition: targa.c:98
static void ldtarga(struct ImBuf *ibuf, const unsigned char *mem, size_t mem_size, int psize)
Definition: targa.c:564
struct TARGA TARGA
static void complete_partial_load(struct ImBuf *ibuf, unsigned int *rect)
Definition: targa.c:423
static bool makebody_tga(ImBuf *ibuf, FILE *file, int(*out)(unsigned int, FILE *))
Definition: targa.c:136
static bool dumptarga(struct ImBuf *ibuf, FILE *file)
Definition: targa.c:233
static int tga_out1(unsigned int data, FILE *file)
Definition: targa.c:73
#define GSS(x)
Definition: targa.c:44
bool imb_savetarga(struct ImBuf *ibuf, const char *filepath, int UNUSED(flags))
Definition: targa.c:297
static int tga_out4(unsigned int data, FILE *file)
Definition: targa.c:115
#define TARGA_HEADER_SIZE
Definition: targa.c:69
bool imb_is_a_targa(const unsigned char *buf, size_t size)
Definition: targa.c:416
ImBuf * imb_loadtarga(const unsigned char *mem, size_t mem_size, int flags, char colorspace[IM_MAX_SPACE])
Definition: targa.c:628
static bool checktarga(TARGA *tga, const unsigned char *mem, const size_t size)
Definition: targa.c:364