Example #1
0
static int checktarga(TARGA *tga, unsigned char *mem)
{
	tga->numid = mem[0];
	tga->maptyp = mem[1];
	tga->imgtyp = mem[2];

	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->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);
	}
	if (tga->mapsize && tga->mapbits > 32) return(0);
	if (tga->xsize <= 0 || tga->xsize >= 8192) return(0);
	if (tga->ysize <= 0 || tga->ysize >= 8192) return(0);
	if (tga->pixsize > 32) return(0);
	if (tga->pixsize == 0) return(0);
	return(1);
}
Example #2
0
struct ImBuf *IMB_loadiffmem(int *mem, int flags) {
    int len,maxlen;
    struct ImBuf *ibuf;

    // IMB_loadiffmem shouldn't be used anymore in new development
    // it's still here to be backwards compatible...

    maxlen= (GET_BIG_LONG(mem+1) + 1) & ~1;

    if (GET_ID(mem) == CAT) {
        mem += 3;
        maxlen -= 4;
        while(maxlen > 0) {
            if (GET_ID(mem) == FORM) {
                len = ((GET_BIG_LONG(mem+1) + 1) & ~1) + 8;
                if ((GET_ID(mem+2) == ILBM) || (GET_ID(mem+2) == ANIM)) break;
                mem = (int *)((uchar *)mem +len);
                maxlen -= len;
            } else return(0);
        }
    }

    if (maxlen > 0) {
        if (GET_ID(mem) == FORM) {
            if (GET_ID(mem+2) == ILBM) {
                return (imb_loadamiga(mem, flags));
            } else if (GET_ID(mem+5) == ILBM) {			/* animaties */
                return (imb_loadamiga(mem+3, flags));
            } else if (GET_ID(mem+2) == ANIM) {
                return (imb_loadanim(mem, flags));
            }
        } else if ((GS(mem) == IMAGIC) || (GSS(mem) == IMAGIC)) {
            return (imb_loadiris((uchar *) mem,flags));
        } else if ((BIG_LONG(mem[0]) & 0xfffffff0) == 0xffd8ffe0) {
            return (0);
        }
    }

    ibuf = imb_loadtarga((uchar *) mem,maxlen,flags);
    if (ibuf) return(ibuf);

    if (IB_verbose) fprintf(stderr,"Unknown fileformat\n");
    return (0);
}
Example #3
0
ImBuf *IMB_ibImageFromMemory(int *mem, int size, int flags) {
    int len;
    struct ImBuf *ibuf;

    if (mem == NULL) {
        printf("Error in ibImageFromMemory: NULL pointer\n");
    } else {
        if ((GS(mem) == IMAGIC) || (GSS(mem) == IMAGIC)) {
            return (imb_loadiris((uchar *) mem, flags));
        } else if (imb_is_a_jpeg((uchar *)mem)) {
            return (imb_ibJpegImageFromMemory((uchar *)mem, size, flags));
        }

        if (GET_ID(mem) == CAT) {
            mem += 3;
            size -= 4;
            while (size > 0) {
                if (GET_ID(mem) == FORM) {
                    len = ((GET_BIG_LONG(mem+1) + 1) & ~1) + 8;
                    if ((GET_ID(mem+2) == ILBM) || (GET_ID(mem+2) == ANIM)) break;
                    mem = (int *)((uchar *)mem +len);
                    size -= len;
                } else return(0);
            }
        }

        if (size > 0) {
            if (GET_ID(mem) == FORM) {
                if (GET_ID(mem+2) == ILBM) {
                    return (imb_loadamiga(mem, flags));
                } else if (GET_ID(mem+5) == ILBM) {			/* animaties */
                    return (imb_loadamiga(mem+3, flags));
                } else if (GET_ID(mem+2) == ANIM) {
                    return (imb_loadanim(mem, flags));
                }
            }
        }

        ibuf = imb_loadpng((uchar *)mem, size, flags);
        if (ibuf) return(ibuf);

        ibuf = imb_bmp_decode((uchar *)mem, size, flags);
        if (ibuf) return(ibuf);

        ibuf = imb_loadtarga((uchar *)mem, size, flags);
        if (ibuf) return(ibuf);

        ibuf = imb_loaddpx((uchar *)mem, size, flags);
        if (ibuf) return(ibuf);

        ibuf = imb_loadcineon((uchar *)mem, size, flags);
        if (ibuf) return(ibuf);

        if (G.have_libtiff) {
            ibuf = imb_loadtiff((uchar *)mem, size, flags);
            if (ibuf) return(ibuf);
        }

        ibuf = imb_loadhdr((uchar*)mem, size, flags);
        if (ibuf) return (ibuf);

#ifdef WITH_OPENEXR
        ibuf = imb_load_openexr((uchar *)mem, size, flags);
        if (ibuf) return (ibuf);
#endif

#ifdef WITH_OPENJPEG
        ibuf = imb_jp2_decode((uchar *)mem, size, flags);
        if (ibuf) return (ibuf);
#endif

#ifdef WITH_DDS
        ibuf = imb_load_dds((uchar *)mem, size, flags);
        if (ibuf) return (ibuf);
#endif

#ifdef WITH_QUICKTIME
#if defined(_WIN32) || defined (__APPLE__)
        if(G.have_quicktime) {
            ibuf = imb_quicktime_decode((uchar *)mem, size, flags);
            if (ibuf) return(ibuf);
        }
#endif
#endif

        if (IB_verbose) fprintf(stderr, "Unknown fileformat\n");
    }

    return (0);
}