Esempio n. 1
0
void BurnMain::make_palette(int color_model)
{
	int i, r, g, b;

	for(i = 0; i < MAXCOLOR; i++)
	{
		HSItoRGB(4.6 - 1.5 * i / MAXCOLOR, 
			(double)i / MAXCOLOR, 
			(double)i / MAXCOLOR,  
			&r, 
			&g, 
			&b, 
			color_model);
		palette[0][i] = r;
		palette[1][i] = g;
		palette[2][i] = b;
//printf("BurnMain::make_palette %d %d %d %d\n", i, palette[0][i], palette[1][i], palette[2][i]);
	}


	for(i = MAXCOLOR; i < 256; i++)
	{
		if(r < 255) r++;
		if(r < 255) r++;
		if(r < 255) r++;
		if(g < 255) g++;
		if(g < 255) g++;
		if(b < 255) b++;
		if(b < 255) b++;
		palette[0][i] = r;
		palette[1][i] = g;
		palette[2][i] = b;
//printf("BurnMain::make_palette %d %d %d %d\n", i, palette[0][i], palette[1][i], palette[2][i]);
	}
}
Esempio n. 2
0
void VolumeTexture::generateIndexTexture() {
  // nice small texture that will work everywhere
  size[0] = size[1] = size[2] = 32; 
  int x, y, z;
  int addr, addr2, addr3, index;
  int num = size[0]*size[1]*size[2];
  unsigned char coltable[3 * 4096];

  if (!allocateTextureMap(num)) return;

  // build a fast color lookup table
  for (index=0; index<4096; index++) {
    addr = index * 3;
    HSItoRGB(8.0f * index / 4096.0f, 0.75, 1.0,
             coltable+addr, coltable+addr+1, coltable+addr+2);
  }

  for (z=0; z<size[2]; z++) {
    for (y=0; y<size[1]; y++) {
      addr = z * size[0] * size[1] + y * size[0];
      for (x=0; x<size[0]; x++) {
        index = addr + x;
        addr2 = index * 3;
        addr3 = ((int) ((index / (float) num) * 4095)) * 3;
        texmap[addr2    ] = coltable[addr3    ];
        texmap[addr2 + 1] = coltable[addr3 + 1];
        texmap[addr2 + 2] = coltable[addr3 + 2];
      }
    }
  }
}
Esempio n. 3
0
void VolumeTexture::generateHSVTexture(float vmin, float vmax) {
  int x, y, z;
  int index, addr, addr2, addr3;
  int daddr;
  float vscale, vrange;
  unsigned char coltable[3 * 4096];

  size[0] = v->xsize;
  size[1] = v->ysize;
  size[2] = v->zsize;
  for (int i=0; i<3; i++) {
    size[i] = nextpower2(size[i]);
  }
  int num = size[0]*size[1]*size[2];
  if (!allocateTextureMap(num)) return;

  // build a fast color lookup table
  for (index=0; index<4096; index++) {
    addr = index * 3;
    HSItoRGB(4.0f * index / 4096.0f, 0.75, 1.0,
             coltable+addr, coltable+addr+1, coltable+addr+2);
  }

  // calculate scaling factors
  vrange = vmax - vmin;
  if (fabs(vrange) < 0.00001)
    vscale = 0.0f;
  else
    vscale = 1.00001f / vrange;

  // map volume data scalars to colors
  for (z=0; z<v->zsize; z++) {
    for (y=0; y<v->ysize; y++) {
       addr = z * size[0] * size[1] + y * size[0];
      daddr = z * v->xsize * v->ysize + y * v->xsize;
      for (x=0; x<v->xsize; x++) {
        addr2 = (addr + x) * 3;
        float level;

        // map data to range 0->1        
        level = (v->data[daddr + x] - vmin) * vscale; 
        level = level < 0 ? 0 :
                level > 1 ? 1 : level;

        // map values to an HSV color map
        addr3 = ((int) (level * 4095)) * 3;
        texmap[addr2    ] = coltable[addr3    ];
        texmap[addr2 + 1] = coltable[addr3 + 1];
        texmap[addr2 + 2] = coltable[addr3 + 2];
      }
    }
  }
}
Esempio n. 4
0
static void makePalette(void)
{
	int i, r, g, b;
	uint8_t *p = (uint8_t*) palette;

	for(i=0; i<MaxColor; i++) {
		HSItoRGB(4.6-1.5*i/MaxColor, (double)i/MaxColor, (double)i/MaxColor, &r, &g, &b);
		*p++ = r & 0xfe;
		*p++ = g & 0xfe;
		*p++ = b & 0xfe;
		p++;
	}
	for(i=MaxColor; i<256; i++) {
		if(r<255)r++;if(r<255)r++;if(r<255)r++;
		if(g<255)g++;
		if(g<255)g++;
		if(b<255)b++;
		if(b<255)b++;
		*p++ = r & 0xfe;
		*p++ = g & 0xfe;
		*p++ = b & 0xfe;
		p++;
	}
}