diff options
Diffstat (limited to 'source/blender/imbuf/intern/iris.c')
-rw-r--r-- | source/blender/imbuf/intern/iris.c | 362 |
1 files changed, 181 insertions, 181 deletions
diff --git a/source/blender/imbuf/intern/iris.c b/source/blender/imbuf/intern/iris.c index 430361dbb53..10c6a0fd012 100644 --- a/source/blender/imbuf/intern/iris.c +++ b/source/blender/imbuf/intern/iris.c @@ -42,58 +42,58 @@ #include "IMB_filetype.h" typedef struct { - unsigned short imagic; /* stuff saved on disk . . */ - unsigned short type; - unsigned short dim; - unsigned short xsize; - unsigned short ysize; - unsigned short zsize; - unsigned int min; - unsigned int max; - unsigned int wastebytes; - char name[80]; - unsigned int colormap; - - int file; /* stuff used in core only */ - unsigned short flags; - short dorev; - short x; - short y; - short z; - short cnt; - unsigned short *ptr; - unsigned short *base; - unsigned short *tmpbuf; - unsigned int offset; - unsigned int rleend; /* for rle images */ - unsigned int *rowstart; /* for rle images */ - int *rowsize; /* for rle images */ + unsigned short imagic; /* stuff saved on disk . . */ + unsigned short type; + unsigned short dim; + unsigned short xsize; + unsigned short ysize; + unsigned short zsize; + unsigned int min; + unsigned int max; + unsigned int wastebytes; + char name[80]; + unsigned int colormap; + + int file; /* stuff used in core only */ + unsigned short flags; + short dorev; + short x; + short y; + short z; + short cnt; + unsigned short *ptr; + unsigned short *base; + unsigned short *tmpbuf; + unsigned int offset; + unsigned int rleend; /* for rle images */ + unsigned int *rowstart; /* for rle images */ + int *rowsize; /* for rle images */ } IMAGE; #define RINTLUM (79) #define GINTLUM (156) #define BINTLUM (21) -#define ILUM(r, g, b) ((int)(RINTLUM * (r) + GINTLUM * (g) + BINTLUM * (b)) >> 8) +#define ILUM(r, g, b) ((int)(RINTLUM * (r) + GINTLUM * (g) + BINTLUM * (b)) >> 8) -#define OFFSET_R 0 /* this is byte order dependent */ -#define OFFSET_G 1 -#define OFFSET_B 2 -#define OFFSET_A 3 +#define OFFSET_R 0 /* this is byte order dependent */ +#define OFFSET_G 1 +#define OFFSET_B 2 +#define OFFSET_A 3 -#define CHANOFFSET(z) (3-(z)) /* this is byte order dependent */ +#define CHANOFFSET(z) (3 - (z)) /* this is byte order dependent */ -#define TYPEMASK 0xff00 -#define BPPMASK 0x00ff -#define ITYPE_VERBATIM 0x0000 -#define ITYPE_RLE 0x0100 -#define ISRLE(type) (((type) & 0xff00) == ITYPE_RLE) -#define ISVERBATIM(type) (((type) & 0xff00) == ITYPE_VERBATIM) -#define BPP(type) ((type) & BPPMASK) -#define RLE(bpp) (ITYPE_RLE | (bpp)) -#define VERBATIM(bpp) (ITYPE_VERBATIM | (bpp)) -#define IBUFSIZE(pixels) ((pixels+(pixels>>6))<<2) -#define RLE_NOP 0x00 +#define TYPEMASK 0xff00 +#define BPPMASK 0x00ff +#define ITYPE_VERBATIM 0x0000 +#define ITYPE_RLE 0x0100 +#define ISRLE(type) (((type) & 0xff00) == ITYPE_RLE) +#define ISVERBATIM(type) (((type) & 0xff00) == ITYPE_VERBATIM) +#define BPP(type) ((type) & BPPMASK) +#define RLE(bpp) (ITYPE_RLE | (bpp)) +#define VERBATIM(bpp) (ITYPE_VERBATIM | (bpp)) +#define IBUFSIZE(pixels) ((pixels + (pixels >> 6)) << 2) +#define RLE_NOP 0x00 /* funcs */ static void readheader(FILE *inf, IMAGE *image); @@ -118,37 +118,37 @@ static void lumrow(unsigned char *rgbptr, unsigned char *lumptr, int n); * */ -static uchar * file_data; +static uchar *file_data; static int file_offset; static unsigned short getshort(FILE *inf) { - unsigned char * buf; + unsigned char *buf; (void)inf; /* unused */ buf = file_data + file_offset; file_offset += 2; - return (buf[0]<<8)+(buf[1]<<0); + return (buf[0] << 8) + (buf[1] << 0); } static unsigned int getlong(FILE *inf) { - unsigned char * buf; + unsigned char *buf; (void)inf; /* unused */ buf = file_data + file_offset; file_offset += 4; - return (buf[0]<<24)+(buf[1]<<16)+(buf[2]<<8)+(buf[3]<<0); + return (buf[0] << 24) + (buf[1] << 16) + (buf[2] << 8) + (buf[3] << 0); } static void putshort(FILE *outf, unsigned short val) { unsigned char buf[2]; - buf[0] = (val>>8); - buf[1] = (val>>0); + buf[0] = (val >> 8); + buf[1] = (val >> 0); fwrite(buf, 2, 1, outf); } @@ -156,10 +156,10 @@ static int putlong(FILE *outf, unsigned int val) { unsigned char buf[4]; - buf[0] = (val>>24); - buf[1] = (val>>16); - buf[2] = (val>>8); - buf[3] = (val>>0); + buf[0] = (val >> 24); + buf[1] = (val >> 16); + buf[2] = (val >> 8); + buf[3] = (val >> 0); return fwrite(buf, 4, 1, outf); } @@ -176,7 +176,7 @@ static void readheader(FILE *inf, IMAGE *image) static int writeheader(FILE *outf, IMAGE *image) { - IMAGE t= {0}; + IMAGE t = {0}; fwrite(&t, sizeof(IMAGE), 1, outf); fseek(outf, 0, SEEK_SET); @@ -216,14 +216,14 @@ static void test_endian_zbuf(struct ImBuf *ibuf) int len; int *zval; - if ( BIG_LONG(1) == 1 ) return; + if (BIG_LONG(1) == 1) return; if (ibuf->zbuf == NULL) return; - len= ibuf->x*ibuf->y; - zval= ibuf->zbuf; + len = ibuf->x * ibuf->y; + zval = ibuf->zbuf; while (len--) { - zval[0]= BIG_LONG(zval[0]); + zval[0] = BIG_LONG(zval[0]); zval++; } } @@ -258,7 +258,7 @@ struct ImBuf *imb_loadiris(unsigned char *mem, size_t size, int flags) int x, y, z, tablen; int xsize, ysize, zsize; int bpp, rle, cur, badorder; - ImBuf * ibuf; + ImBuf *ibuf; (void)size; /* unused */ @@ -294,7 +294,7 @@ struct ImBuf *imb_loadiris(unsigned char *mem, size_t size, int flags) if (rle) { - tablen = ysize*zsize*sizeof(int); + tablen = ysize * zsize * sizeof(int); starttab = (unsigned int *)MEM_mallocN(tablen, "iris starttab"); lengthtab = (unsigned int *)MEM_mallocN(tablen, "iris endtab"); file_offset = 512; @@ -305,13 +305,13 @@ struct ImBuf *imb_loadiris(unsigned char *mem, size_t size, int flags) /* check data order */ cur = 0; badorder = 0; - for (y = 0; y<ysize; y++) { - for (z = 0; z<zsize; z++) { - if (starttab[y+z*ysize]<cur) { + for (y = 0; y < ysize; y++) { + for (z = 0; z < zsize; z++) { + if (starttab[y + z * ysize] < cur) { badorder = 1; break; } - cur = starttab[y+z*ysize]; + cur = starttab[y + z * ysize]; } if (badorder) break; @@ -325,15 +325,15 @@ struct ImBuf *imb_loadiris(unsigned char *mem, size_t size, int flags) zbase = (unsigned int *)ibuf->zbuf; if (badorder) { - for (z=0; z<zsize; z++) { + for (z = 0; z < zsize; z++) { lptr = base; - for (y=0; y<ysize; y++) { - file_offset = starttab[y+z*ysize]; + for (y = 0; y < ysize; y++) { + file_offset = starttab[y + z * ysize]; rledat = file_data + file_offset; - file_offset += lengthtab[y+z*ysize]; + file_offset += lengthtab[y + z * ysize]; - expandrow((uchar *)lptr, rledat, 3-z); + expandrow((uchar *)lptr, rledat, 3 - z); lptr += xsize; } } @@ -341,17 +341,17 @@ struct ImBuf *imb_loadiris(unsigned char *mem, size_t size, int flags) else { lptr = base; zptr = zbase; - for (y=0; y<ysize; y++) { + for (y = 0; y < ysize; y++) { - for (z=0; z<zsize; z++) { + for (z = 0; z < zsize; z++) { - file_offset = starttab[y+z*ysize]; + file_offset = starttab[y + z * ysize]; rledat = file_data + file_offset; - file_offset += lengthtab[y+z*ysize]; + file_offset += lengthtab[y + z * ysize]; - if (z<4) expandrow((uchar *)lptr, rledat, 3-z); - else if (z<8) expandrow((uchar *)zptr, rledat, 7-z); + if (z < 4) expandrow((uchar *)lptr, rledat, 3 - z); + else if (z < 8) expandrow((uchar *)zptr, rledat, 7 - z); } lptr += xsize; zptr += xsize; @@ -360,22 +360,22 @@ struct ImBuf *imb_loadiris(unsigned char *mem, size_t size, int flags) } - else { /* bpp == 2 */ + else { /* bpp == 2 */ - ibuf = IMB_allocImBuf(xsize, ysize, 32, (flags & IB_rect)|IB_rectfloat); + ibuf = IMB_allocImBuf(xsize, ysize, 32, (flags & IB_rect) | IB_rectfloat); fbase = ibuf->rect_float; if (badorder) { - for (z=0; z<zsize; z++) { + for (z = 0; z < zsize; z++) { fptr = fbase; - for (y=0; y<ysize; y++) { - file_offset = starttab[y+z*ysize]; + for (y = 0; y < ysize; y++) { + file_offset = starttab[y + z * ysize]; rledat = file_data + file_offset; - file_offset += lengthtab[y+z*ysize]; + file_offset += lengthtab[y + z * ysize]; - expandrow2(fptr, rledat, 3-z); + expandrow2(fptr, rledat, 3 - z); fptr += xsize * 4; } } @@ -383,16 +383,16 @@ struct ImBuf *imb_loadiris(unsigned char *mem, size_t size, int flags) else { fptr = fbase; - for (y=0; y<ysize; y++) { + for (y = 0; y < ysize; y++) { - for (z=0; z<zsize; z++) { + for (z = 0; z < zsize; z++) { - file_offset = starttab[y+z*ysize]; + file_offset = starttab[y + z * ysize]; rledat = file_data + file_offset; - file_offset += lengthtab[y+z*ysize]; + file_offset += lengthtab[y + z * ysize]; - expandrow2(fptr, rledat, 3-z); + expandrow2(fptr, rledat, 3 - z); } fptr += xsize * 4; @@ -418,12 +418,12 @@ struct ImBuf *imb_loadiris(unsigned char *mem, size_t size, int flags) for (z = 0; z < zsize; z++) { - if (z<4) lptr = base; - else if (z<8) lptr= zbase; + if (z < 4) lptr = base; + else if (z < 8) lptr = zbase; for (y = 0; y < ysize; y++) { - interleaverow((uchar *)lptr, rledat, 3-z, xsize); + interleaverow((uchar *)lptr, rledat, 3 - z, xsize); rledat += xsize; lptr += xsize; @@ -431,9 +431,9 @@ struct ImBuf *imb_loadiris(unsigned char *mem, size_t size, int flags) } } - else { /* bpp == 2 */ + else { /* bpp == 2 */ - ibuf = IMB_allocImBuf(xsize, ysize, 32, (flags & IB_rect)|IB_rectfloat); + ibuf = IMB_allocImBuf(xsize, ysize, 32, (flags & IB_rect) | IB_rectfloat); fbase = ibuf->rect_float; @@ -446,7 +446,7 @@ struct ImBuf *imb_loadiris(unsigned char *mem, size_t size, int flags) for (y = 0; y < ysize; y++) { - interleaverow2(fptr, rledat, 3-z, xsize); + interleaverow2(fptr, rledat, 3 - z, xsize); rledat += xsize * 2; fptr += xsize * 4; @@ -458,7 +458,7 @@ struct ImBuf *imb_loadiris(unsigned char *mem, size_t size, int flags) if (bpp == 1) { - uchar * rect; + uchar *rect; if (image.zsize == 1) { rect = (uchar *) ibuf->rect; @@ -487,7 +487,7 @@ struct ImBuf *imb_loadiris(unsigned char *mem, size_t size, int flags) } } - else { /* bpp == 2 */ + else { /* bpp == 2 */ if (image.zsize == 1) { fbase = ibuf->rect_float; @@ -550,7 +550,7 @@ static void interleaverow2(float *lptr, unsigned char *cptr, int z, int n) { lptr += z; while (n--) { - *lptr = ((cptr[0]<<8) | (cptr[1]<<0)) / (float)0xFFFF; + *lptr = ((cptr[0] << 8) | (cptr[1] << 0)) / (float)0xFFFF; cptr += 2; lptr += 4; } @@ -563,50 +563,50 @@ static void expandrow2(float *optr, unsigned char *iptr, int z) optr += z; while (1) { - pixel = (iptr[0]<<8) | (iptr[1]<<0); + pixel = (iptr[0] << 8) | (iptr[1] << 0); iptr += 2; - if ( !(count = (pixel & 0x7f)) ) + if (!(count = (pixel & 0x7f)) ) return; if (pixel & 0x80) { - while (count>=8) { - optr[0*4] = ((iptr[0]<<8) | (iptr[1]<<0))/(float)0xFFFF; - optr[1*4] = ((iptr[2]<<8) | (iptr[3]<<0))/(float)0xFFFF; - optr[2*4] = ((iptr[4]<<8) | (iptr[5]<<0))/(float)0xFFFF; - optr[3*4] = ((iptr[6]<<8) | (iptr[7]<<0))/(float)0xFFFF; - optr[4*4] = ((iptr[8]<<8) | (iptr[9]<<0))/(float)0xFFFF; - optr[5*4] = ((iptr[10]<<8) | (iptr[11]<<0))/(float)0xFFFF; - optr[6*4] = ((iptr[12]<<8) | (iptr[13]<<0))/(float)0xFFFF; - optr[7*4] = ((iptr[14]<<8) | (iptr[15]<<0))/(float)0xFFFF; - optr += 8*4; - iptr += 8*2; + while (count >= 8) { + optr[0 * 4] = ((iptr[0] << 8) | (iptr[1] << 0)) / (float)0xFFFF; + optr[1 * 4] = ((iptr[2] << 8) | (iptr[3] << 0)) / (float)0xFFFF; + optr[2 * 4] = ((iptr[4] << 8) | (iptr[5] << 0)) / (float)0xFFFF; + optr[3 * 4] = ((iptr[6] << 8) | (iptr[7] << 0)) / (float)0xFFFF; + optr[4 * 4] = ((iptr[8] << 8) | (iptr[9] << 0)) / (float)0xFFFF; + optr[5 * 4] = ((iptr[10] << 8) | (iptr[11] << 0)) / (float)0xFFFF; + optr[6 * 4] = ((iptr[12] << 8) | (iptr[13] << 0)) / (float)0xFFFF; + optr[7 * 4] = ((iptr[14] << 8) | (iptr[15] << 0)) / (float)0xFFFF; + optr += 8 * 4; + iptr += 8 * 2; count -= 8; } while (count--) { - *optr = ((iptr[0]<<8) | (iptr[1]<<0))/(float)0xFFFF; - iptr+=2; - optr+=4; + *optr = ((iptr[0] << 8) | (iptr[1] << 0)) / (float)0xFFFF; + iptr += 2; + optr += 4; } } else { - pixel_f = ((iptr[0]<<8) | (iptr[1]<<0))/(float)0xFFFF; + pixel_f = ((iptr[0] << 8) | (iptr[1] << 0)) / (float)0xFFFF; iptr += 2; - while (count>=8) { - optr[0*4] = pixel_f; - optr[1*4] = pixel_f; - optr[2*4] = pixel_f; - optr[3*4] = pixel_f; - optr[4*4] = pixel_f; - optr[5*4] = pixel_f; - optr[6*4] = pixel_f; - optr[7*4] = pixel_f; - optr += 8*4; + while (count >= 8) { + optr[0 * 4] = pixel_f; + optr[1 * 4] = pixel_f; + optr[2 * 4] = pixel_f; + optr[3 * 4] = pixel_f; + optr[4 * 4] = pixel_f; + optr[5 * 4] = pixel_f; + optr[6 * 4] = pixel_f; + optr[7 * 4] = pixel_f; + optr += 8 * 4; count -= 8; } while (count--) { *optr = pixel_f; - optr+=4; + optr += 4; } } } @@ -619,44 +619,44 @@ static void expandrow(unsigned char *optr, unsigned char *iptr, int z) optr += z; while (1) { pixel = *iptr++; - if ( !(count = (pixel & 0x7f)) ) + if (!(count = (pixel & 0x7f)) ) return; if (pixel & 0x80) { - while (count>=8) { - optr[0*4] = iptr[0]; - optr[1*4] = iptr[1]; - optr[2*4] = iptr[2]; - optr[3*4] = iptr[3]; - optr[4*4] = iptr[4]; - optr[5*4] = iptr[5]; - optr[6*4] = iptr[6]; - optr[7*4] = iptr[7]; - optr += 8*4; + while (count >= 8) { + optr[0 * 4] = iptr[0]; + optr[1 * 4] = iptr[1]; + optr[2 * 4] = iptr[2]; + optr[3 * 4] = iptr[3]; + optr[4 * 4] = iptr[4]; + optr[5 * 4] = iptr[5]; + optr[6 * 4] = iptr[6]; + optr[7 * 4] = iptr[7]; + optr += 8 * 4; iptr += 8; count -= 8; } while (count--) { *optr = *iptr++; - optr+=4; + optr += 4; } } else { pixel = *iptr++; - while (count>=8) { - optr[0*4] = pixel; - optr[1*4] = pixel; - optr[2*4] = pixel; - optr[3*4] = pixel; - optr[4*4] = pixel; - optr[5*4] = pixel; - optr[6*4] = pixel; - optr[7*4] = pixel; - optr += 8*4; + while (count >= 8) { + optr[0 * 4] = pixel; + optr[1 * 4] = pixel; + optr[2 * 4] = pixel; + optr[3 * 4] = pixel; + optr[4 * 4] = pixel; + optr[5 * 4] = pixel; + optr[6 * 4] = pixel; + optr[7 * 4] = pixel; + optr += 8 * 4; count -= 8; } while (count--) { *optr = pixel; - optr+=4; + optr += 4; } } } @@ -689,19 +689,19 @@ static int output_iris(unsigned int *lptr, int xsize, int ysize, int zsize, cons outf = BLI_fopen(name, "wb"); if (!outf) return 0; - tablen = ysize*zsize*sizeof(int); + tablen = ysize * zsize * sizeof(int); image = (IMAGE *)MEM_mallocN(sizeof(IMAGE), "iris image"); starttab = (unsigned int *)MEM_mallocN(tablen, "iris starttab"); lengthtab = (unsigned int *)MEM_mallocN(tablen, "iris lengthtab"); - rlebuflen = 1.05*xsize+10; + rlebuflen = 1.05 * xsize + 10; rlebuf = (unsigned char *)MEM_mallocN(rlebuflen, "iris rlebuf"); - lumbuf = (unsigned int *)MEM_mallocN(xsize*sizeof(int), "iris lumbuf"); + lumbuf = (unsigned int *)MEM_mallocN(xsize * sizeof(int), "iris lumbuf"); memset(image, 0, sizeof(IMAGE)); image->imagic = IMAGIC; image->type = RLE(1); - if (zsize>1) + if (zsize > 1) image->dim = 3; else image->dim = 2; @@ -711,8 +711,8 @@ static int output_iris(unsigned int *lptr, int xsize, int ysize, int zsize, cons image->min = 0; image->max = 255; goodwrite *= writeheader(outf, image); - fseek(outf, 512+2*tablen, SEEK_SET); - pos = 512+2*tablen; + fseek(outf, 512 + 2 * tablen, SEEK_SET); + pos = 512 + 2 * tablen; for (y = 0; y < ysize; y++) { for (z = 0; z < zsize; z++) { @@ -722,20 +722,20 @@ static int output_iris(unsigned int *lptr, int xsize, int ysize, int zsize, cons len = compressrow((uchar *)lumbuf, rlebuf, CHANOFFSET(z), xsize); } else { - if (z<4) { + if (z < 4) { len = compressrow((uchar *)lptr, rlebuf, CHANOFFSET(z), xsize); } - else if (z<8 && zptr) { - len = compressrow((uchar *)zptr, rlebuf, CHANOFFSET(z-4), xsize); + else if (z < 8 && zptr) { + len = compressrow((uchar *)zptr, rlebuf, CHANOFFSET(z - 4), xsize); } } - if (len>rlebuflen) { + if (len > rlebuflen) { fprintf(stderr, "output_iris: rlebuf is too small - bad poop\n"); exit(1); } goodwrite *= fwrite(rlebuf, len, 1, outf); - starttab[y+z*ysize] = pos; - lengthtab[y+z*ysize] = len; + starttab[y + z * ysize] = pos; + lengthtab[y + z * ysize] = len; pos += len; } lptr += xsize; @@ -779,32 +779,32 @@ static int compressrow(unsigned char *lbuf, unsigned char *rlebuf, int z, int cn lbuf += z; iptr = lbuf; - ibufend = iptr+cnt*4; + ibufend = iptr + cnt * 4; optr = rlebuf; - while (iptr<ibufend) { + while (iptr < ibufend) { sptr = iptr; iptr += 8; - while ((iptr<ibufend)&& ((iptr[-8]!=iptr[-4])||(iptr[-4]!=iptr[0]))) - iptr+=4; + while ((iptr < ibufend) && ((iptr[-8] != iptr[-4]) || (iptr[-4] != iptr[0]))) + iptr += 4; iptr -= 8; - count = (iptr-sptr)/4; + count = (iptr - sptr) / 4; while (count) { - todo = count>126 ? 126:count; + todo = count > 126 ? 126 : count; count -= todo; - *optr++ = 0x80|todo; - while (todo>8) { - optr[0] = sptr[0*4]; - optr[1] = sptr[1*4]; - optr[2] = sptr[2*4]; - optr[3] = sptr[3*4]; - optr[4] = sptr[4*4]; - optr[5] = sptr[5*4]; - optr[6] = sptr[6*4]; - optr[7] = sptr[7*4]; + *optr++ = 0x80 | todo; + while (todo > 8) { + optr[0] = sptr[0 * 4]; + optr[1] = sptr[1 * 4]; + optr[2] = sptr[2 * 4]; + optr[3] = sptr[3 * 4]; + optr[4] = sptr[4 * 4]; + optr[5] = sptr[5 * 4]; + optr[6] = sptr[6 * 4]; + optr[7] = sptr[7 * 4]; optr += 8; - sptr += 8*4; + sptr += 8 * 4; todo -= 8; } while (todo--) { @@ -815,11 +815,11 @@ static int compressrow(unsigned char *lbuf, unsigned char *rlebuf, int z, int cn sptr = iptr; cc = *iptr; iptr += 4; - while ( (iptr<ibufend) && (*iptr == cc) ) + while ( (iptr < ibufend) && (*iptr == cc) ) iptr += 4; - count = (iptr-sptr)/4; + count = (iptr - sptr) / 4; while (count) { - todo = count>126 ? 126:count; + todo = count > 126 ? 126 : count; count -= todo; *optr++ = todo; *optr++ = cc; @@ -829,7 +829,7 @@ static int compressrow(unsigned char *lbuf, unsigned char *rlebuf, int z, int cn return optr - (unsigned char *)rlebuf; } -int imb_saveiris(struct ImBuf * ibuf, const char *name, int flags) +int imb_saveiris(struct ImBuf *ibuf, const char *name, int flags) { short zsize; int ret; |