Beispiel #1
0
long* imPaletteLinear(void)
{
  long* palette = imPaletteNew(256);
  long* ct = palette;
  int lIndex, lHue;
  unsigned char r, g, b;

  for (lIndex = 0; lIndex < 256; lIndex += 8)
  {
    float intensity = lIndex / 256.0f;

    for (lHue = 0; lHue < 8; lHue++)
    {
      float hue = (lHue * 360.0f) / 8.0f;

      imColorHSI2RGBbyte(hue, 1.0f, intensity, &r, &g, &b);

      *(ct++) = imColorEncode(r, g, b);
    }
  }

#if 0
  for (lIndex = 0; lIndex < 256; lIndex++)
  {
    float norm = (float)lIndex / 256.0f;
    imColorHSI2RGBbyte(norm * 360, 1.0f, norm, &r, &g, &b);

    *(ct++) = imColorEncode(r, g, b);
  }
#endif

  return palette;
}
Beispiel #2
0
long* imPaletteUniform(void)
{
  long* palette = imPaletteNew(256);
  long* ct = palette;

  for (int lRedIndex = 0; lRedIndex < 6; lRedIndex++)
    for (int lGreenIndex = 0; lGreenIndex < 6; lGreenIndex++)
      for (int lBlueIndex = 0; lBlueIndex < 6; lBlueIndex++)
      {
        imbyte red = (imbyte)iSixStepsTable[lRedIndex];
        imbyte green = (imbyte)iSixStepsTable[lGreenIndex];
        imbyte blue = (imbyte)iSixStepsTable[lBlueIndex];

        *(ct++) = imColorEncode(red, green, blue);
      }

  /* We initialized only 216 colors (6x6x6), rest 40 colors.*/
  /* Fill them with a gray scale palette.*/
  for (int lIndex = 6; lIndex < 246; lIndex += 6)
  {
    *(ct++) = imColorEncode((imbyte)lIndex, (imbyte)lIndex, (imbyte)lIndex);
  }

  return palette;
}
Beispiel #3
0
long* imPaletteBlackBody(void)
{
  long* palette = imPaletteNew(256);
  long* ct = palette;
  int lIndex, lSubIndex;

  for (lIndex = 0, lSubIndex = 0; lSubIndex < 85; lSubIndex++, lIndex += 3)
  {
    /* From (0, 0, 0) to (252, 0, 0) */
    /* From   Black   to     ~Red   */
    *(ct++) = imColorEncode((imbyte)lIndex, 0, 0);
  }

  for (lIndex = 0, lSubIndex = 0; lSubIndex < 85; lSubIndex++, lIndex += 3)
  {
    /* From (255, 0, 0) to (255, 252, 0)*/
    /* From      Red    to     ~Yellow */
    *(ct++) = imColorEncode(255, (imbyte)lIndex, 0);
  }

  for (lIndex = 0, lSubIndex = 0; lSubIndex < 86; lSubIndex++, lIndex += 3)
  {
    /* From (255, 255, 0) to (255, 255, 255)*/
    /* From     Yellow    to      White  */
    *(ct++) = imColorEncode(255, 255, (imbyte)lIndex);
  }

  return palette;
}
Beispiel #4
0
long* imPaletteRainbow(void)
{
  long* palette = imPaletteNew(256);
  long* ct = palette;
  int hue;
  unsigned char r, g, b;
  float h, s, i, factor, H;

  s = 1.0f;
  factor = 360.0f / 256.0f;

  for (hue = 0; hue < 256; hue++)
  {
    h = hue * factor;
    h = 300-h;
    if (h < 0) h += 360;
    H = h/57.2957795131f;

    i = imColorHSI_ImaxS(H, cos(H), sin(H));

    imColorHSI2RGBbyte(h, s, i, &r, &g, &b);

    *(ct++) = imColorEncode(r, g, b);;
  }

  return palette;
}
Beispiel #5
0
long* imPaletteHotIron(void)
{
  long* palette = imPaletteNew(256);
  long* ct = palette;
  int lIndex, lSubIndex;

  for (lIndex = 0, lSubIndex = 0; lSubIndex < 128; lSubIndex++, lIndex += 2)
  {
    /* From (0, 0, 0) to (254, 0, 0) */
    /* From   Black   to     ~Red    */
    *(ct++) = imColorEncode((imbyte)lIndex, 0, 0);
  }

  for (lIndex = 0, lSubIndex = 0; lSubIndex < 64; lSubIndex++, lIndex += 2)
  {
    /* From (255, 0, 0) to (255, 126, 0) */
    /* From      Red    to     ~Orange  */
    *(ct++) = imColorEncode(255, (imbyte)lIndex, 0);
  }

  for (lIndex = 0, lSubIndex = 0; lSubIndex < 63; lSubIndex++, lIndex += 2)
  {
    /* From (255, 128, 0) to (255, 252, 252)*/
    /* From     Orange    to     ~White   */
    imbyte red = 255;
    imbyte green = (imbyte)(128 + lIndex);
    imbyte blue = (imbyte)(lIndex * 2 + 4);

    *(ct++) = imColorEncode(red, green, blue);
  }

  *(ct++) = imColorEncode(255, 255, 255);

  return palette;
}
Beispiel #6
0
/*****************************************************************************\
 file:GetPalette()
\*****************************************************************************/
static int imluaFileGetPalette (lua_State *L)
{
  imFile *ifile = imlua_checkfile(L, 1);
  long* palette = imPaletteNew(256);
  int count;
  imFileGetPalette(ifile, palette, &count);
  imlua_pushpalette(L, palette, count);
  return 1;
}
Beispiel #7
0
long* imPaletteBlueIce(void)
{
  long* palette = imPaletteNew(256);
  long* ct = palette;
  
  for (int lIndex = 0; lIndex < 256; lIndex++)
  {
    /* From (0, 0, 255) to (255, 255, 255)*/
    /* From    Blue    to       White     */
    *(ct++) = imColorEncode((imbyte)lIndex, (imbyte)lIndex, 255);
  }

  return palette;
}
Beispiel #8
0
long* imPaletteCian(void)
{
  long* palette = imPaletteNew(256);
  long* ct = palette;
  
  for (int lIndex = 0; lIndex < 256; lIndex++)
  {
    /* From (0, 0, 0) to (0, 255, 255)*/
    /* From   Black   to     Cian    */
    *(ct++) = imColorEncode(0, (imbyte)lIndex, (imbyte)lIndex);
  }

  return palette;
}
Beispiel #9
0
long* imPaletteYellow(void)
{
  long* palette = imPaletteNew(256);
  long* ct = palette;
  
  for (int lIndex = 0; lIndex < 256; lIndex++)
  {
    /* From (0, 0, 0) to (255, 255, 0)*/
    /* From   Black   to      Yellow  */
    *(ct++) = imColorEncode((imbyte)lIndex, (imbyte)lIndex, 0);
  }

  return palette;
}
Beispiel #10
0
/***************************************************************************\
* Creates a palette as a "imPalette" userdata. A palette can be          *
* considered and treated as a color table.                                 *
* im.PaletteCreate(count: number) -> (palette: "imPalette")               *
\***************************************************************************/
static int imluaPaletteCreate(lua_State *L)
{
  long* color;

  int count = luaL_optinteger(L, 1, 256);
  if (count < 1 || count > 256)
    luaL_argerror(L, 1, "palette count should be a positive integer and less then 256");

  color = imPaletteNew(256);
  memset(color, 0, 256*sizeof(long));

  imlua_pushpalette(L, color, count);
  return 1;
}
Beispiel #11
0
long* imPaletteHighContrast(void)
{
  long* palette = imPaletteNew(256);
  long* ct = palette;
  int lIndex;
#define NUM_HC 128

  static struct{ unsigned char r, g, b; } HighContrastColors[NUM_HC] = {
    { 0,0,0 },     

    { 255,0,0 },      { 128,0,0 },      { 64,0,0 },       { 192,0,0 },
    { 0,255,0 },      { 0,128,0 },      { 0,64,0 },       { 0,192,0 },    
    { 0,0,255 },      { 0,0,128 },      { 0,0,64 },       { 0,0,192 },    
    { 255,255,0 },    { 128,128,0 },    { 64,64,0 },      { 192,192,0 },    
    { 255,0,255 },    { 128,0,128 },    { 64,0,64 },      { 192,0,192 },    
    { 0,255,255 },    { 0,128,128 },    { 0,64,64 },      { 0,192,192 },    
    { 255,255,255 },  { 128,128,128 },  { 64,64,64 },     { 192,192,192 },    

    { 255,128,128 },  { 64,255,255 },   { 192,255,255 },   
    { 128,255,128 },  { 255,64,255 },   { 255,192,255 },     
    { 128,128,255 },  { 255,255,64 },   { 255,255,192 },     
    { 255,255,128 },  { 64,64,255 },    { 192,192,255 },     
    { 255,128,255 },  { 64,255,64 },    { 192,255,192 },     
    { 128,255,255 },  { 255,64,64 },    { 255,192,192 },   

    { 128,64,64 },    { 128,192,192 },   
    { 64,128,64 },    { 192,128,192 },   
    { 64,64,128 },    { 192,192,128 },   
    { 128,128,64 },   { 128,128,192 },   
    { 128,64,128 },   { 128,192,128 },   
    { 64,128,128 },   { 192,128,128 },   
    
   { 160,0,0 },      { 32,0,0 },       { 224,0,0 },       { 96,0,0 },    
   { 0,160,0 },      { 0,32,0 },       { 0,224,0 },       { 0,96,0 },    
   { 0,0,160 },      { 0,0,32 },       { 0,0,224 },       { 0,0,96 },    
   { 160,160,0 },    { 32,32,0 },      { 224,224,0 },     { 96,96,0 },   
   { 160,0,160 },    { 32,0,32 },      { 224,0,224 },     { 96,0,96 },   
   { 0,160,160 },    { 0,32,32 },      { 0,224,224 },     { 0,96,96 },   
   { 160,160,160 },  { 32,32,32 },     { 224,224,224 },   { 96,96,96 },  

    { 255,160,160 },  { 32,255,255 },   { 224,255,255 },     { 96,255,255 },  
    { 160,255,160 },  { 255,32,255 },   { 255,224,255 },     { 255,96,255 },   
    { 160,160,255 },  { 255,255,32 },   { 255,255,224 },     { 255,255,96 },   
    { 255,255,160 },  { 32,32,255 },    { 224,224,255 },     { 96,96,255 },   
    { 255,160,255 },  { 32,255,32 },    { 224,255,224 },     { 96,255,96 },   
    { 160,255,255 },  { 255,32,32 },    { 255,224,224 },     { 255,96,96 },  

    { 128,32,32 },    { 64,192,192 },      { 64,224,224 },
    { 32,128,32 },    { 192,64,192 },      { 224,64,224 },
    { 32,32,128 },    { 192,192,64 },      { 224,224,64 },
    { 128,128,32 },   { 64,64,192 },       { 64,64,224 }, 
    { 128,32,128 },   { 64,192,64 },       { 64,224,64 }, 
    { 32,128,128 },   { 192,64,64 },       

 };

  for (lIndex = 0; lIndex < NUM_HC; lIndex++)
  {
    *(ct++) = imColorEncode(HighContrastColors[lIndex].r, 
                            HighContrastColors[lIndex].g, 
                            HighContrastColors[lIndex].b);
  }

  for (; lIndex < 256; lIndex++)
  {
    *(ct++) = imColorEncode(HighContrastColors[lIndex - NUM_HC].r,
                            HighContrastColors[lIndex - NUM_HC].g, 
                            HighContrastColors[lIndex - NUM_HC].b);
  }

  return palette;
}
Beispiel #12
0
long* imPaletteHues(void)
{
  long* palette = imPaletteNew(256);
  long* ct = palette;
  int i;
  float tone, step1 = 255.0f/41.0f, step2 = 255.0f/42.0f;

  /* 1+42+1+41+1+42+1+41+1+42+1+41+1 = 256 */

  /* red */
  *(ct++) = imColorEncode((imbyte)255, 0, 0);

  for (tone = step2, i = 0; i < 42; i++, tone += step2)
  {
    /* From (255, 0, 0) to (255, 255, 0) */
    /* From      Red    to      Yellow   */
    *(ct++) = imColorEncode((imbyte)255, (imbyte)tone, 0);
  }

  /* yellow */
  *(ct++) = imColorEncode((imbyte)255, (imbyte)255, 0);

  for (tone = step1, i = 0; i < 41; i++, tone += step1)
  {
    /* From (255, 255, 0) to (0, 255, 0)  */
    /* From     Yellow    to    Green    */
    *(ct++) = imColorEncode((imbyte)(255.0f-tone), (imbyte)255, 0);
  }

  /* green */
  *(ct++) = imColorEncode(0, (imbyte)255, 0);;

  for (tone = step2, i = 0; i < 42; i++, tone += step2)
  {
    /* From (0, 255, 0) to (0, 255, 255) */
    /* From    Green    to     Cian      */
    *(ct++) = imColorEncode(0, (imbyte)255, (imbyte)tone);
  }

  /* cian */
  *(ct++) = imColorEncode(0, (imbyte)255, (imbyte)255);

  for (tone = step1, i = 0; i < 41; i++, tone += step1)
  {
    /* From (0, 255, 255) to (0, 0, 255) */
    /* From     Cian      to     Blue    */
    *(ct++) = imColorEncode(0, (imbyte)(255.0f-tone), (imbyte)255);
  }

  /* blue */
  *(ct++) = imColorEncode(0, 0, (imbyte)255);

  for (tone = step2, i = 0; i < 42; i++, tone += step2)
  {
    /* From (0, 0, 255) to (255, 0, 255) */
    /* From    Blue     to    Magenta    */
    *(ct++) = imColorEncode((imbyte)tone, 0, (imbyte)255);
  }

  /* magenta */
  *(ct++) = imColorEncode((imbyte)255, 0, (imbyte)255);

  for (tone = step1, i = 0; i < 41; i++, tone += step1)
  {
    /* From (255, 0, 255) to (255, 0, 0) */
    /* From    Magenta    to      Red    */
    *(ct++) = imColorEncode((imbyte)255, 0, (imbyte)(255.0f-tone));
  }

  /* black */
  *(ct++) = imColorEncode(0, 0, 0);;

  return palette;
}