44 #define GSS(x) (((uchar *)(x))[1] << 8 | ((uchar *)(x))[0])
69 #define TARGA_HEADER_SIZE 18
78 if (putc(p[0],
file) == EOF) {
89 if (putc(p[0],
file) == EOF) {
92 if (putc(p[1],
file) == EOF) {
103 if (putc(p[2],
file) == EOF) {
106 if (putc(p[1],
file) == EOF) {
109 if (putc(p[0],
file) == EOF) {
121 if (putc(p[2],
file) == EOF) {
124 if (putc(p[1],
file) == EOF) {
127 if (putc(p[0],
file) == EOF) {
130 if (putc(p[3],
file) == EOF) {
140 unsigned int *rect, *rectstart, *temp;
143 for (
y = 0;
y < ibuf->
y;
y++) {
145 rectstart = rect = ibuf->
rect + (
y * ibuf->
x);
155 if (
this == rect[-3]) {
160 }
while (--bytes != 0);
162 copy = rect - rectstart;
177 if (fputc(last - 1,
file) == EOF) {
181 if (out(*rect++,
file) == EOF) {
184 }
while (--last != 0);
193 while (*rect++ ==
this) {
199 copy = rect - rectstart;
206 if (fputc(255,
file) == EOF) {
213 if (fputc(0,
file) == EOF) {
217 else if (fputc(127 +
copy,
file) == EOF) {
222 if (out(last,
file) == EOF) {
250 if (putc(*rect,
file) == EOF) {
257 else if (ibuf->
planes <= 16) {
260 if (putc(rect[1],
file) == EOF) {
267 else if (ibuf->
planes <= 24) {
271 if (putc(rect[0],
file) == EOF) {
278 else if (ibuf->
planes <= 32) {
283 if (putc(rect[3],
file) == EOF) {
303 buf[16] = (ibuf->
planes + 0x7) & ~0x7;
320 buf[12] = ibuf->
x & 0xff;
321 buf[13] = ibuf->
x >> 8;
322 buf[14] = ibuf->
y & 0xff;
323 buf[15] = ibuf->
y >> 8;
344 switch ((ibuf->
planes + 7) >> 3) {
401 if (tga->
xsize <= 0) {
404 if (tga->
ysize <= 0) {
425 int size = (ibuf->
x * ibuf->
y) - (rect - ibuf->
rect);
427 printf(
"decodetarga: incomplete file, %.1f%% missing\n",
428 100 * ((
float)
size / (ibuf->
x * ibuf->
y)));
431 memset(rect, 0,
size);
435 printf(
"decodetarga: incomplete file, all pixels written\n");
439 static void decodetarga(
struct ImBuf *ibuf,
const unsigned char *mem,
size_t mem_size,
int psize)
441 const unsigned char *mem_end = mem + mem_size;
556 printf(
"decodetarga: count would overwrite %d pixels\n", -
size);
564 static void ldtarga(
struct ImBuf *ibuf,
const unsigned char *mem,
size_t mem_size,
int psize)
566 const unsigned char *mem_end = mem + mem_size;
636 unsigned int *
rect, *cmap =
NULL , cmap_max = 0;
669 cmap =
MEM_callocN(
sizeof(
unsigned int) * cmap_max,
"targa cmap");
695 cmap[
count] = cp_data;
699 for (
int cmap_index = cmap_max - 1; cmap_index > 0; cmap_index >>= 1) {
728 ldtarga(ibuf, mem, mem_size, 0);
731 ldtarga(ibuf, mem, mem_size, 1);
734 ldtarga(ibuf, mem, mem_size, 2);
737 ldtarga(ibuf, mem, mem_size, 3);
762 int cmap_index = *
rect;
763 if (cmap_index >= 0 && cmap_index < cmap_max) {
764 *
rect = cmap[cmap_index];
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);
792 unsigned int *lrect,
col;
795 lrect = (
unsigned int *)ibuf->
rect;
801 crect[1] = crect[2] = crect[3] =
col;
File and directory operations.
FILE * BLI_fopen(const char *filename, const char *mode) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
_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)
void IMB_convert_rgba_to_abgr(struct ImBuf *ibuf)
void IMB_flipy(struct ImBuf *ibuf)
Contains defines and structs used throughout the imbuf module.
Read Guarded memory(de)allocation.
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
void colorspace_set_default_role(char *colorspace, int size, int role)
void(* MEM_freeN)(void *vmemh)
void *(* MEM_callocN)(size_t len, const char *str)
static void copy(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node)
ImbFormatOptions foptions
static int tga_out2(unsigned int data, FILE *file)
static void decodetarga(struct ImBuf *ibuf, const unsigned char *mem, size_t mem_size, int psize)
static int tga_out3(unsigned int data, FILE *file)
static void ldtarga(struct ImBuf *ibuf, const unsigned char *mem, size_t mem_size, int psize)
static void complete_partial_load(struct ImBuf *ibuf, unsigned int *rect)
static bool makebody_tga(ImBuf *ibuf, FILE *file, int(*out)(unsigned int, FILE *))
static bool dumptarga(struct ImBuf *ibuf, FILE *file)
static int tga_out1(unsigned int data, FILE *file)
bool imb_savetarga(struct ImBuf *ibuf, const char *filepath, int UNUSED(flags))
static int tga_out4(unsigned int data, FILE *file)
#define TARGA_HEADER_SIZE
bool imb_is_a_targa(const unsigned char *buf, size_t size)
ImBuf * imb_loadtarga(const unsigned char *mem, size_t mem_size, int flags, char colorspace[IM_MAX_SPACE])
static bool checktarga(TARGA *tga, const unsigned char *mem, const size_t size)