Exemple #1
0
int imb_is_a_targa(unsigned char *buf)
{
	TARGA tga;
	
	return checktarga(&tga, buf);
}
Exemple #2
0
ImBuf *imb_loadtarga(unsigned char *mem, size_t mem_size, int flags, char colorspace[IM_MAX_SPACE])
{
	TARGA tga;
	struct ImBuf *ibuf;
	int col, count, size;
	unsigned int *rect, *cmap = NULL /*, mincol = 0*/, maxcol = 0;
	uchar *cp = (uchar *) &col;

	if (checktarga(&tga, mem) == 0) return(NULL);

	colorspace_set_default_role(colorspace, IM_MAX_SPACE, COLOR_ROLE_DEFAULT_BYTE);

	if (flags & IB_test) ibuf = IMB_allocImBuf(tga.xsize, tga.ysize, tga.pixsize, 0);
	else ibuf = IMB_allocImBuf(tga.xsize, tga.ysize, (tga.pixsize + 0x7) & ~0x7, IB_rect);

	if (ibuf == NULL) return(NULL);
	ibuf->ftype = TGA;
	mem = mem + 18 + tga.numid;
	
	cp[0] = 0xff;
	cp[1] = cp[2] = 0;
	
	if (tga.mapsize) {
		/* load color map */
		/*mincol = tga.maporig;*/ /*UNUSED*/
		maxcol = tga.mapsize;
		cmap = MEM_callocN(sizeof(unsigned int) * maxcol, "targa cmap");

		for (count = 0; count < maxcol; count++) {
			switch (tga.mapbits >> 3) {
				case 4:
					cp[0] = mem[3];
					cp[1] = mem[0];
					cp[2] = mem[1];
					cp[3] = mem[2];
					mem += 4;
					break;
				case 3:
					cp[1] = mem[0];
					cp[2] = mem[1];
					cp[3] = mem[2];
					mem += 3;
					break;
				case 2:
					cp[1] = mem[1];
					cp[0] = mem[0];
					mem += 2;
					break;
				case 1:
					col = *mem++;
					break;
			}
			cmap[count] = col;
		}
		
		size = 0;
		for (col = maxcol - 1; col > 0; col >>= 1) size++;
		ibuf->planes = size;

		if (tga.mapbits != 32) {    /* set alpha bits  */
			cmap[0] &= BIG_LONG(0x00ffffffl);
		}
	}
Exemple #3
0
ImBuf *imb_loadtarga(const unsigned char *mem,
                     size_t mem_size,
                     int flags,
                     char colorspace[IM_MAX_SPACE])
{
  TARGA tga;
  struct ImBuf *ibuf;
  int count, size;
  unsigned int *rect, *cmap = NULL /*, mincol = 0*/, cmap_max = 0;
  int32_t cp_data;
  uchar *cp = (uchar *)&cp_data;

  if (checktarga(&tga, mem) == 0) {
    return NULL;
  }

  colorspace_set_default_role(colorspace, IM_MAX_SPACE, COLOR_ROLE_DEFAULT_BYTE);

  if (flags & IB_test) {
    ibuf = IMB_allocImBuf(tga.xsize, tga.ysize, tga.pixsize, 0);
  }
  else {
    ibuf = IMB_allocImBuf(tga.xsize, tga.ysize, (tga.pixsize + 0x7) & ~0x7, IB_rect);
  }

  if (ibuf == NULL) {
    return NULL;
  }
  ibuf->ftype = IMB_FTYPE_TGA;
  if (tga.imgtyp < 4) {
    ibuf->foptions.flag |= RAWTGA;
  }
  mem = mem + 18 + tga.numid;

  cp[0] = 0xff;
  cp[1] = cp[2] = 0;

  if (tga.mapsize) {
    /* load color map */
    /*mincol = tga.maporig;*/ /*UNUSED*/
    cmap_max = tga.mapsize;
    cmap = MEM_callocN(sizeof(unsigned int) * cmap_max, "targa cmap");

    for (count = 0; count < cmap_max; count++) {
      switch (tga.mapbits >> 3) {
        case 4:
          cp[0] = mem[3];
          cp[1] = mem[0];
          cp[2] = mem[1];
          cp[3] = mem[2];
          mem += 4;
          break;
        case 3:
          cp[1] = mem[0];
          cp[2] = mem[1];
          cp[3] = mem[2];
          mem += 3;
          break;
        case 2:
          cp[1] = mem[1];
          cp[0] = mem[0];
          mem += 2;
          break;
        case 1:
          cp_data = *mem++;
          break;
      }
      cmap[count] = cp_data;
    }

    size = 0;
    for (int cmap_index = cmap_max - 1; cmap_index > 0; cmap_index >>= 1) {
      size++;
    }
    ibuf->planes = size;

    if (tga.mapbits != 32) { /* set alpha bits  */
      cmap[0] &= BIG_LONG(0x00ffffffl);
    }
  }