Drawings SDK Developer Guide > Working with .dwg Files > Working with Colors > Color Functionality as an ACI-value
Color Functionality as an ACI-value

An ACI-value is an integer value that is named a color index defining the number of the color in a color palette. A color palette is an array containing 256 items that define RGB-values of available colors. Each item is a three-element array of 8-bit integer values that define the red, green, and blue components for each color of the palette. Each element defines the intensity of its own color component in the range 0 to 255. The palette can be the default or can be redefined by the rendering device. The packed color integer value stores the color index from 0 to 7 bits. A color index has the range from 1 to 255. Indices 0, 7, 256, 257 have special purposes. The byACI and byDGNIndex color methods use the index to define its own colors.

Color indices with 1 to 7 have predefined names: 1 – Red, 2 – Yellow, 3 – Green, 4 – Cyan, 5 – Blue, 6 – Magenta, 7 – White. The following special indices switch the color method: index 256 sets the byLayer color method (value 0xC0000000), index 0 sets the byBlock color method (value 0xC1000000), index 7 sets the Foreground color method (value 0xC3000007), index 257 sets the None color method (value 0xC8000000). The byDGNIndex color method uses a specific color palette to define DGN colors. The ACIcolorMethod enumeration defines the admissible names of predefined indices.

The database color object and entity color object use ACI-values. The color objects are declared by the following lines:


OdCmEntityColor eColor;
OdCmColor nColor;

To get the color index, use the colorIndex() method that returns the color index as an integer value in the range 1 to 255. For example:


odPrintConsoleString(L"\nEntity color index = %d", eColor.colorIndex());
odPrintConsoleString(L"\nDatabase color index = %d", nColor.colorIndex());

To set the color index, use the setColorIndex() method which requires an integer value in the range 0 to 257 and modifies the color index or color method for the color object. The setColorIndex() method sets the color method to kByACI when the index in range 1 to 255. For example:


int idx;

odPrintConsoleString(L"\nEntry a color index [1...255]:>");
scanf("%d", &idx);

if(idx >= 1 && idx <= 255)
{
  eColor.setColorIndex(idx);
  nColor.setColorIndex(idx);
  
  odPrintConsoleString(L"\nEntity color value = %x", eColor.color());
  odPrintConsoleString(L"\nDatabase color value = %x", nColor.color());
}
else odPrintConsoleString(L"Color index is outside the scope 1...255\n");

To switch the color method to byBlock, specify the value kACIbyBlock (=0) for the setColorIndex() method:


eColor.setColorIndex(OdCmEntityColor::kACIbyBlock);
nColor.setColorIndex(0);

odPrintConsoleString(L"\nColor methods: %x , %x", eColor.colorMethod(), nColor.colorMethod());

To switch the color method to byLayer, specify the value kACIbyLayer (=256) for the setColorIndex() method:


eColor.setColorIndex(OdCmEntityColor::kACIbyLayer);
nColor.setColorIndex(256);

odPrintConsoleString(L"\nColor methods: %x , %x", eColor.colorMethod(), nColor.colorMethod());

To switch the color method to None, specify the value kACInone (=257) for the setColorIndex() method:


eColor.setColorIndex(OdCmEntityColor::kACInone);
nColor.setColorIndex(257);

odPrintConsoleString(L"\nColor methods: %x , %x", eColor.colorMethod(), nColor.colorMethod());

The value kACIforeground (=7) indicates the Foreground color method, but the colorIndex() method will return the byACI color method. The isByACI() and isForeground() methods return True together. For example:


eColor.setColorIndex(OdCmEntityColor::kACIforeground);
nColor.setColorIndex(7);

odPrintConsoleString(L"\nColor methods: %x , %x", eColor.colorMethod(), nColor.colorMethod());

The OdCmEntityColor class has the lookUpRGB() method for converting a color index to an RGB-value and the lookUpACI() method for converting an RGB-value to a color index. Both methods use the mLUT static constant array defined in the OdCmEntityColor class to search an index.

To convert a color index to an RGB-value, use the lookUpRGB() method that requires an index as an integer value in the range 1 to 255 and that returns the RGB-value corresponding to the specified index using the default color palette defined by the mLUT member. The RGB-value is a packed integer value of the OdUInt32 type that stores the color component values: scope 0 to 7 bits is blue, scope 8 to 15 bits is green, scope 16 to 23 bits is red. For example:


int idx;

odPrintConsoleString(L"\nEntry a color index [1...255]:>");
scanf("%d", &idx);

if(idx >= 1 && idx <= 255)
{
  OdUInt32 rgb = eColor.lookUpRGB(idx);

  odPrintConsoleString(L"\nRGB-value = %x , Red = %d , Green = %d , Blue = %d",  
                       rgb, ODGETRED(rgb), ODGETGREEN(rgb), ODGETBLUE(rgb));
}

To convert an RGB-value to the color index, use the lookUpACI() method that requires the red component value as a first argument of the OdUInt8 type, green component value as a second argument of the OdUInt8 type, blue component value as a third argument of the OdUInt8 type, and that returns the color index corresponding to the specified components using the default color palette defined by the mLUT member. For example:


int red_value, green_value, blue_value;

odPrintConsoleString(L"\nEntry a red value [0...255]:>");
scanf("%d", &red_value);

if(red_value >= 0 && red_value <= 255)
{
  odPrintConsoleString(L"\nEntry a green value [0...255]:>");
  scanf("%d", &green_value);

  if(green_value >= 0 && green_value <= 255)
  {
    odPrintConsoleString(L"\nEntry a blue value [0...255]:>");
    scanf("%d", &blue_value);

    if(blue_value >= 0 && blue_value <= 255 )
    {
      odPrintConsoleString(L"\nColor index = %d", eColor.lookUpACI(red_value, green_value, blue_value));
    }
    else odPrintConsoleString(L"Blue value is outside the scope 0...255\n");
  }
  else odPrintConsoleString(L"Green value is outside the scope 0...255\n");
}
else odPrintConsoleString(L"Red value is outside the scope 0...255\n");

The mLUT member is the static constant array that contains 256 colors defined by the red, green, blue components. Each color of the array is defined by three integer values for the corresponding color components. The mLUT array is the default palette that is used when the rendering device is absent.

See Also

Working with Colors and Transparencies

Methods of the Color Definition

Example of Working with the Entity Color

Example of Working with the Database Color

Copyright © 2002 – 2020. Open Design Alliance. All rights reserved.