Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2012-05-16 11:38:23 +0400
committerCampbell Barton <ideasman42@gmail.com>2012-05-16 11:38:23 +0400
commitd64fd168c96a1a5bee3aa5ffb847d7612059c993 (patch)
tree0fb6c0b46a18e9521bd2693b466b2d6a82ba4daa /source/blender/imbuf/intern/targa.c
parente6ddad51463ad4634e6c2bd89b7733637572b629 (diff)
style cleanup: imbuf
Diffstat (limited to 'source/blender/imbuf/intern/targa.c')
-rw-r--r--source/blender/imbuf/intern/targa.c196
1 files changed, 97 insertions, 99 deletions
diff --git a/source/blender/imbuf/intern/targa.c b/source/blender/imbuf/intern/targa.c
index 1a05dd93229..c690995d28a 100644
--- a/source/blender/imbuf/intern/targa.c
+++ b/source/blender/imbuf/intern/targa.c
@@ -50,8 +50,7 @@
/***/
-typedef struct TARGA
-{
+typedef struct TARGA {
unsigned char numid;
unsigned char maptyp;
unsigned char imgtyp;
@@ -72,27 +71,27 @@ static int tga_out1(unsigned int data, FILE *file)
{
uchar *p;
- p = (uchar *) & data;
+ p = (uchar *) &data;
if (putc(p[0], file) == EOF) return(EOF);
return (~EOF);
}
-static int tga_out2(unsigned int data, FILE * file)
+static int tga_out2(unsigned int data, FILE *file)
{
uchar *p;
- p = (uchar *) & data;
+ p = (uchar *) &data;
if (putc(p[0], file) == EOF) return(EOF);
if (putc(p[1], file) == EOF) return(EOF);
return (~EOF);
}
-static int tga_out3(unsigned int data, FILE * file)
+static int tga_out3(unsigned int data, FILE *file)
{
uchar *p;
- p = (uchar *) & data;
+ p = (uchar *) &data;
if (putc(p[2], file) == EOF) return(EOF);
if (putc(p[1], file) == EOF) return(EOF);
if (putc(p[0], file) == EOF) return(EOF);
@@ -100,11 +99,11 @@ static int tga_out3(unsigned int data, FILE * file)
}
-static int tga_out4(unsigned int data, FILE * file)
+static int tga_out4(unsigned int data, FILE *file)
{
uchar *p;
- p = (uchar *) & data;
+ p = (uchar *) &data;
/* order = bgra */
if (putc(p[2], file) == EOF) return(EOF);
if (putc(p[1], file) == EOF) return(EOF);
@@ -113,7 +112,7 @@ static int tga_out4(unsigned int data, FILE * file)
return (~EOF);
}
-static short makebody_tga(ImBuf * ibuf, FILE * file, int (*out)(unsigned int, FILE*))
+static short makebody_tga(ImBuf *ibuf, FILE *file, int (*out)(unsigned int, FILE *))
{
register int last, this;
register int copy, bytes;
@@ -125,22 +124,22 @@ static short makebody_tga(ImBuf * ibuf, FILE * file, int (*out)(unsigned int, FI
rectstart = rect = ibuf->rect + (y * ibuf->x);
last = *rect++;
this = *rect++;
- copy = last^this;
+ copy = last ^ this;
while (bytes > 0) {
if (copy) {
do {
last = this;
this = *rect++;
if (last == this) {
- if (this == rect[-3]) { /* three the same? */
- bytes --; /* set bytes */
+ if (this == rect[-3]) { /* three the same? */
+ bytes--; /* set bytes */
break;
}
}
} while (--bytes != 0);
- copy = rect-rectstart;
- copy --;
+ copy = rect - rectstart;
+ copy--;
if (bytes) copy -= 2;
temp = rect;
@@ -148,9 +147,9 @@ static short makebody_tga(ImBuf * ibuf, FILE * file, int (*out)(unsigned int, FI
while (copy) {
last = copy;
- if (copy>=128) last = 128;
+ if (copy >= 128) last = 128;
copy -= last;
- if (fputc(last-1, file) == EOF) return(0);
+ if (fputc(last - 1, file) == EOF) return(0);
do {
if (out(*rect++, file) == EOF) return(0);
} while (--last != 0);
@@ -162,17 +161,17 @@ static short makebody_tga(ImBuf * ibuf, FILE * file, int (*out)(unsigned int, FI
copy = FALSE;
}
else {
- while (*rect++ == this) { /* seek for first different byte */
- if (--bytes == 0) break; /* oor end of line */
+ while (*rect++ == this) { /* seek for first different byte */
+ if (--bytes == 0) break; /* oor end of line */
}
- rect --;
- copy = rect-rectstart;
+ rect--;
+ copy = rect - rectstart;
rectstart = rect;
- bytes --;
+ bytes--;
this = *rect++;
while (copy) {
- if (copy>128) {
+ if (copy > 128) {
if (fputc(255, file) == EOF) return(0);
copy -= 128;
}
@@ -185,14 +184,14 @@ static short makebody_tga(ImBuf * ibuf, FILE * file, int (*out)(unsigned int, FI
}
if (out(last, file) == EOF) return(0);
}
- copy=TRUE;
+ copy = TRUE;
}
}
}
return (1);
}
-static int dumptarga(struct ImBuf * ibuf, FILE * file)
+static int dumptarga(struct ImBuf *ibuf, FILE *file)
{
int size;
uchar *rect;
@@ -243,16 +242,16 @@ static int dumptarga(struct ImBuf * ibuf, FILE * file)
}
-int imb_savetarga(struct ImBuf * ibuf, const char *name, int flags)
+int imb_savetarga(struct ImBuf *ibuf, const char *name, int flags)
{
- char buf[20]= {0};
+ char buf[20] = {0};
FILE *fildes;
short ok = 0;
(void)flags; /* unused */
- buf[16] = (ibuf->planes + 0x7 ) & ~0x7;
- if (ibuf->planes > 8 ) {
+ buf[16] = (ibuf->planes + 0x7) & ~0x7;
+ if (ibuf->planes > 8) {
buf[2] = 10;
}
else {
@@ -273,11 +272,11 @@ int imb_savetarga(struct ImBuf * ibuf, const char *name, int flags)
/* Don't forget to indicate that your 32 bit
* targa uses 8 bits for the alpha channel! */
- if (ibuf->planes==32) {
+ if (ibuf->planes == 32) {
buf[17] |= 0x08;
}
fildes = BLI_fopen(name, "wb");
- if (!fildes) return 0;
+ if (!fildes) return 0;
if (fwrite(buf, 1, 18, fildes) != 18) {
fclose(fildes);
@@ -289,18 +288,18 @@ int imb_savetarga(struct ImBuf * ibuf, const char *name, int flags)
}
else {
switch ((ibuf->planes + 7) >> 3) {
- case 1:
- ok = makebody_tga(ibuf, fildes, tga_out1);
- break;
- case 2:
- ok = makebody_tga(ibuf, fildes, tga_out2);
- break;
- case 3:
- ok = makebody_tga(ibuf, fildes, tga_out3);
- break;
- case 4:
- ok = makebody_tga(ibuf, fildes, tga_out4);
- break;
+ case 1:
+ ok = makebody_tga(ibuf, fildes, tga_out1);
+ break;
+ case 2:
+ ok = makebody_tga(ibuf, fildes, tga_out2);
+ break;
+ case 3:
+ ok = makebody_tga(ibuf, fildes, tga_out3);
+ break;
+ case 4:
+ ok = makebody_tga(ibuf, fildes, tga_out4);
+ break;
}
}
@@ -315,27 +314,27 @@ static int checktarga(TARGA *tga, unsigned char *mem)
tga->maptyp = mem[1];
tga->imgtyp = mem[2];
- tga->maporig = GSS(mem+3);
- tga->mapsize = GSS(mem+5);
+ tga->maporig = GSS(mem + 3);
+ tga->mapsize = GSS(mem + 5);
tga->mapbits = mem[7];
- tga->xorig = GSS(mem+8);
- tga->yorig = GSS(mem+10);
- tga->xsize = GSS(mem+12);
- tga->ysize = GSS(mem+14);
+ tga->xorig = GSS(mem + 8);
+ tga->yorig = GSS(mem + 10);
+ tga->xsize = GSS(mem + 12);
+ tga->ysize = GSS(mem + 14);
tga->pixsize = mem[16];
tga->imgdes = mem[17];
if (tga->maptyp > 1) return(0);
switch (tga->imgtyp) {
- case 1: /* raw cmap */
- case 2: /* raw rgb */
- case 3: /* raw b&w */
- case 9: /* cmap */
- case 10: /* rgb */
- case 11: /* b&w */
- break;
- default:
- return(0);
+ case 1: /* raw cmap */
+ case 2: /* raw rgb */
+ case 3: /* raw b&w */
+ case 9: /* cmap */
+ case 10: /* rgb */
+ case 11: /* b&w */
+ break;
+ default:
+ return(0);
}
if (tga->mapsize && tga->mapbits > 32) return(0);
if (tga->xsize <= 0 || tga->xsize >= 8192) return(0);
@@ -356,7 +355,7 @@ static void complete_partial_load(struct ImBuf *ibuf, unsigned int *rect)
{
int size = (ibuf->x * ibuf->y) - (rect - ibuf->rect);
if (size) {
- printf("decodetarga: incomplete file, %.1f%% missing\n", 100*((float)size / (ibuf->x * ibuf->y)));
+ printf("decodetarga: incomplete file, %.1f%% missing\n", 100 * ((float)size / (ibuf->x * ibuf->y)));
/* not essential but makes displaying partially rendered TGA's less ugly */
memset(rect, 0, size);
@@ -369,10 +368,10 @@ static void complete_partial_load(struct ImBuf *ibuf, unsigned int *rect)
static void decodetarga(struct ImBuf *ibuf, unsigned char *mem, size_t mem_size, int psize)
{
- unsigned char *mem_end = mem+mem_size;
+ unsigned char *mem_end = mem + mem_size;
int count, col, size;
unsigned int *rect;
- uchar * cp = (uchar *) &col;
+ uchar *cp = (uchar *) &col;
if (ibuf == NULL) return;
if (ibuf->rect == NULL) return;
@@ -387,7 +386,7 @@ static void decodetarga(struct ImBuf *ibuf, unsigned char *mem, size_t mem_size,
while (size > 0) {
count = *mem++;
- if (mem>mem_end)
+ if (mem > mem_end)
goto partial_load;
if (count >= 128) {
@@ -432,7 +431,7 @@ static void decodetarga(struct ImBuf *ibuf, unsigned char *mem, size_t mem_size,
}
}
else {
- count ++;
+ count++;
size -= count;
if (size >= 0) {
while (count > 0) {
@@ -465,13 +464,13 @@ static void decodetarga(struct ImBuf *ibuf, unsigned char *mem, size_t mem_size,
}
}
*rect++ = col;
- count --;
+ count--;
- if (mem>mem_end)
+ if (mem > mem_end)
goto partial_load;
}
- if (mem>mem_end)
+ if (mem > mem_end)
goto partial_load;
}
}
@@ -485,12 +484,12 @@ partial_load:
complete_partial_load(ibuf, rect);
}
-static void ldtarga(struct ImBuf * ibuf, unsigned char * mem, size_t mem_size, int psize)
+static void ldtarga(struct ImBuf *ibuf, unsigned char *mem, size_t mem_size, int psize)
{
- unsigned char *mem_end = mem+mem_size;
+ unsigned char *mem_end = mem + mem_size;
int col, size;
unsigned int *rect;
- uchar * cp = (uchar *) &col;
+ uchar *cp = (uchar *) &col;
if (ibuf == NULL) return;
if (ibuf->rect == NULL) return;
@@ -503,7 +502,7 @@ static void ldtarga(struct ImBuf * ibuf, unsigned char * mem, size_t mem_size, i
cp[1] = cp[2] = 0;
while (size > 0) {
- if (mem>mem_end)
+ if (mem > mem_end)
goto partial_load;
if (psize & 2) {
@@ -545,13 +544,12 @@ partial_load:
}
-struct ImBuf *imb_loadtarga(unsigned char *mem, size_t mem_size, int flags)
-{
+struct ImBuf *imb_loadtarga(unsigned char *mem, size_t mem_size, int flags){
TARGA tga;
- struct ImBuf * ibuf;
+ struct ImBuf *ibuf;
int col, count, size;
- unsigned int *rect, *cmap= NULL /*, mincol= 0*/, maxcol= 0;
- uchar * cp = (uchar *) &col;
+ unsigned int *rect, *cmap = NULL /*, mincol= 0*/, maxcol = 0;
+ uchar *cp = (uchar *) &col;
if (checktarga(&tga, mem) == 0) return(NULL);
@@ -570,9 +568,9 @@ struct ImBuf *imb_loadtarga(unsigned char *mem, size_t mem_size, int flags)
/* load color map */
/*mincol = tga.maporig;*/ /*UNUSED*/
maxcol = tga.mapsize;
- cmap = MEM_callocN(sizeof(unsigned int)*maxcol, "targa cmap");
+ cmap = MEM_callocN(sizeof(unsigned int) * maxcol, "targa cmap");
- for (count = 0 ; count < maxcol ; count ++) {
+ for (count = 0; count < maxcol; count++) {
switch (tga.mapbits >> 3) {
case 4:
cp[0] = mem[3];
@@ -603,7 +601,7 @@ struct ImBuf *imb_loadtarga(unsigned char *mem, size_t mem_size, int flags)
for (col = maxcol - 1; col > 0; col >>= 1) size++;
ibuf->planes = size;
- if (tga.mapbits != 32) { /* set alpha bits */
+ if (tga.mapbits != 32) { /* set alpha bits */
cmap[0] &= BIG_LONG(0x00ffffffl);
}
}
@@ -613,33 +611,33 @@ struct ImBuf *imb_loadtarga(unsigned char *mem, size_t mem_size, int flags)
if (tga.imgtyp != 1 && tga.imgtyp != 9) { /* happens sometimes (beuh) */
if (cmap) {
MEM_freeN(cmap);
- cmap= NULL;
+ cmap = NULL;
}
}
switch (tga.imgtyp) {
- case 1:
- case 2:
- case 3:
- if (tga.pixsize <= 8) ldtarga(ibuf, mem, mem_size, 0);
- else if (tga.pixsize <= 16) ldtarga(ibuf, mem, mem_size, 1);
- else if (tga.pixsize <= 24) ldtarga(ibuf, mem, mem_size, 2);
- else if (tga.pixsize <= 32) ldtarga(ibuf, mem, mem_size, 3);
- break;
- case 9:
- case 10:
- case 11:
- if (tga.pixsize <= 8) decodetarga(ibuf, mem, mem_size, 0);
- else if (tga.pixsize <= 16) decodetarga(ibuf, mem, mem_size, 1);
- else if (tga.pixsize <= 24) decodetarga(ibuf, mem, mem_size, 2);
- else if (tga.pixsize <= 32) decodetarga(ibuf, mem, mem_size, 3);
- break;
+ case 1:
+ case 2:
+ case 3:
+ if (tga.pixsize <= 8) ldtarga(ibuf, mem, mem_size, 0);
+ else if (tga.pixsize <= 16) ldtarga(ibuf, mem, mem_size, 1);
+ else if (tga.pixsize <= 24) ldtarga(ibuf, mem, mem_size, 2);
+ else if (tga.pixsize <= 32) ldtarga(ibuf, mem, mem_size, 3);
+ break;
+ case 9:
+ case 10:
+ case 11:
+ if (tga.pixsize <= 8) decodetarga(ibuf, mem, mem_size, 0);
+ else if (tga.pixsize <= 16) decodetarga(ibuf, mem, mem_size, 1);
+ else if (tga.pixsize <= 24) decodetarga(ibuf, mem, mem_size, 2);
+ else if (tga.pixsize <= 32) decodetarga(ibuf, mem, mem_size, 3);
+ break;
}
if (cmap) {
/* apply color map */
rect = ibuf->rect;
- for (size = ibuf->x * ibuf->y; size>0; --size, ++rect) {
+ for (size = ibuf->x * ibuf->y; size > 0; --size, ++rect) {
col = *rect;
if (col >= 0 && col < maxcol) *rect = cmap[col];
}
@@ -651,8 +649,8 @@ struct ImBuf *imb_loadtarga(unsigned char *mem, size_t mem_size, int flags)
rect = ibuf->rect;
for (size = ibuf->x * ibuf->y; size > 0; --size, ++rect) {
col = *rect;
- cp = (uchar*)rect;
- mem = (uchar*)&col;
+ cp = (uchar *)rect;
+ mem = (uchar *)&col;
cp[3] = ((mem[1] << 1) & 0xf8);
cp[2] = ((mem[0] & 0xe0) >> 2) + ((mem[1] & 0x03) << 6);
@@ -672,7 +670,7 @@ struct ImBuf *imb_loadtarga(unsigned char *mem, size_t mem_size, int flags)
crect = (uchar *) ibuf->rect;
lrect = (unsigned int *) ibuf->rect;
- for (size = ibuf->x * ibuf->y; size > 0; size --) {
+ for (size = ibuf->x * ibuf->y; size > 0; size--) {
col = *lrect++;
crect[0] = 255;