Converting colors to RGB

Anonymous

Converting colors to RGB

Anonymous
Not applicable
Does anyone know of a formula to convert AutoCAD ACI color codes
to RGB ?

Thanks,
Brian D.
0 Likes
Reply
1,222 Views
6 Replies
Replies (6)

Anonymous
Not applicable
Tony Tanzillo has it in his acadx.arx which I think is free for personal
use.
www.caddzone.com or
http://members.bellatlantic.net/~vze2vjds/

--
Rodney McManamy - President
MACSolids - Maximizing AutoCAD Solids
website: www.macsolids.com
"Brian D" wrote in message
news:7EAEAD8BB86ADC0E4554EBA2320E39A0@in.WebX.maYIadrTaRb...
> Does anyone know of a formula to convert AutoCAD ACI color codes
> to RGB ?
>
> Thanks,
> Brian D.
>
>
>
0 Likes

Anonymous
Not applicable
Crude but works.

Public Function AcadToRGB&(ByVal Col&)
Dim r&, g&, b&
Select Case Col
Case 1: AcadToRGB = 255: Exit Function
Case 2: AcadToRGB = 65535: Exit Function
Case 3: AcadToRGB = 65280: Exit Function
Case 4: AcadToRGB = 16776960: Exit Function
Case 5: AcadToRGB = 16711680: Exit Function
Case 6: AcadToRGB = 16711935: Exit Function
Case 7: AcadToRGB = 16777215: Exit Function
Case 8: AcadToRGB = 8355711: Exit Function
Case 9: AcadToRGB = 12566463: Exit Function
Case 10: AcadToRGB = 255: Exit Function
Case 11: AcadToRGB = 8355839: Exit Function
Case 12: AcadToRGB = 207: Exit Function
Case 13: AcadToRGB = 6316239: Exit Function
Case 14: AcadToRGB = 144: Exit Function
Case 15: AcadToRGB = 5197712: Exit Function
Case 16: AcadToRGB = 127: Exit Function
Case 90, 92, 94, 96, 98, 100, 102, 104, 106, 108, 110, 112, 114, 116, 118,
120, 122, 124, 126, 128, 130, 132, 134, 136, 138, 140, 142, 144, 146, 148,
150, 152, 154, 156, 158, 160, 162, 164, 166, 168, 170, 172, 174, 176, 178: r
= 0
Case 88, 188: r = 15
Case 86, 186: r = 31
Case 78, 84, 99, 109, 119, 129, 139, 149, 159, 169, 179, 184, 198: r = 32
Case 82, 89, 182, 189, 250: r = 47
Case 68, 79, 199, 208: r = 48
Case 69, 76, 80, 97, 107, 117, 127, 137, 147, 157, 167, 177, 180, 196, 209:
r = 63
Case 18, 19, 28, 29, 38, 39, 48, 49, 58, 59, 74, 87, 95, 105, 115, 125, 135,
145, 155, 165, 175, 187, 194, 218, 219, 228, 229, 238, 239, 248, 249: r = 79
Case 66, 77, 185, 197, 206: r = 95
Case 72, 85, 93, 103, 113, 123, 133, 143, 153, 163, 173, 192: r = 96
Case 64, 67, 75, 195, 204, 207: r = 111
Case 17, 26, 27, 36, 37, 46, 47, 56, 57, 70, 83, 91, 101, 111, 121, 131,
141, 151, 161, 171, 183, 190, 216, 217, 226, 227, 236, 237, 246, 247: r =
127
Case 65, 205, 252: r = 128
Case 24, 25, 34, 35, 44, 45, 54, 55, 62, 73, 193, 202, 214, 215, 224, 225,
234, 235, 244, 245: r = 144
Case 81, 181: r = 159
Case 63, 203, 253: r = 175
Case 60, 71, 191, 200: r = 191
Case 22, 23, 32, 33, 42, 43, 52, 53, 212, 213, 222, 223, 232, 233, 242, 243:
r = 207
Case 61, 201: r = 223
Case 20, 21, 30, 31, 40, 41, 50, 51, 210, 211, 220, 221, 230, 231, 240, 241,
255: r = 255
Case 251: r = 80: g = 80: b = 80
Case 254: r = 208: g = 208: b = 208
End Select

Select Case Col
Case 18, 170, 172, 174, 176, 178, 180, 182, 184, 186, 188, 190, 192, 194,
196, 198, 200, 202, 204, 206, 208, 210, 212, 214, 216, 218, 220, 222, 224,
226, 228, 230, 232, 234, 236, 238, 240, 242, 244, 246, 248: g = 0
Case 28, 168: g = 15
Case 26, 166: g = 31
Case 19, 24, 38, 158, 164, 179, 189, 199, 209, 219, 229, 239, 249: g = 32
Case 22, 29, 162, 169, 250: g = 47
Case 39, 48, 148, 159: g = 48
Case 17, 20, 36, 49, 149, 156, 160, 177, 187, 197, 207, 217, 227, 237, 247:
g = 63
Case 18, 27, 34, 58, 59, 68, 69, 78, 79, 88, 89, 98, 99, 108, 109, 118, 119,
128, 129, 138, 139, 154, 167, 175, 185, 195, 205, 215, 225, 235, 245: g = 79
Case 152: g = 86
Case 25, 37, 46, 146, 157, 165: g = 95
Case 32, 173, 183, 193, 203, 213, 223, 233, 243: g = 96
Case 35, 44, 47, 144, 147, 155: g = 111
Case 23, 30, 56, 57, 66, 67, 76, 77, 86, 87, 96, 97, 106, 107, 116, 117,
126, 127, 136, 137, 150, 163, 171, 181, 191, 201, 211, 221, 231, 241: g =
127
Case 45, 145, 252: g = 128
Case 33, 42, 54, 55, 64, 65, 74, 75, 84, 85, 94, 95, 104, 105, 114, 115,
124, 125, 134, 135, 142, 153: g = 144
Case 21, 161: g = 159
Case 43, 143, 253: g = 175
Case 31, 40, 140, 151: g = 191
Case 52, 53, 62, 63, 72, 73, 82, 83, 92, 93, 102, 103, 112, 113, 122, 123,
132, 133: g = 207
Case 41, 141: g = 223
Case 50, 51, 60, 61, 70, 71, 80, 81, 90, 91, 100, 101, 110, 111, 120, 121,
130, 131, 255: g = 255
End Select

Select Case Col
Case 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52,
54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90,
92, 94, 96, 98: b = 0
Case 108, 248: b = 15
Case 106, 246: b = 31
Case 19, 29, 39, 49, 59, 69, 79, 89, 99, 104, 118, 238, 244: b = 32
Case 102, 109, 242, 249, 250: b = 47
Case 119, 128, 228, 239: b = 48
Case 17, 27, 37, 47, 57, 67, 77, 87, 97, 100, 116, 129, 229, 236, 240: b =
63
Case 25, 35, 45, 55, 65, 75, 85, 95, 107, 114, 138, 139, 148, 149, 158, 159,
168, 169, 178, 179, 188, 189, 198, 199, 208, 209, 218, 219, 234, 247: b = 79
Case 105, 117, 126, 226, 237, 245: b = 95
Case 23, 33, 43, 53, 63, 73, 83, 93, 112, 232: b = 96
Case 115, 124, 127, 224, 227, 235: b = 111
Case 21, 31, 41, 51, 61, 71, 81, 91, 103, 110, 136, 137, 146, 147, 156, 157,
166, 167, 176, 177, 186, 187, 196, 197, 206, 207, 216, 217, 230, 243: b =
127
Case 125, 225, 252: b = 128
Case 113, 122, 134, 135, 144, 145, 154, 155, 164, 165, 174, 175, 184, 185,
194, 195, 204, 205, 214, 215, 222, 233: b = 144
Case 101, 241: b = 159
Case 123, 223, 253: g = 175
Case 111, 120, 220, 231: b = 191
Case 132, 133, 142, 143, 152, 153, 162, 163, 172, 173, 182, 183, 192, 193,
202, 203, 212, 213: b = 207
Case 121: b = 223
Case 130, 131, 140, 141, 150, 151, 160, 161, 170, 171, 180, 181, 190, 191,
200, 201, 210, 211, 221, 255: b = 255
End Select

AcadToRGB = RGB(r, g, b)
End Function
0 Likes

Anonymous
Not applicable
Crude... allright, but can you tell me where you got this, I spent
uncalculable hours to get colors from other aplications to match those of
AutoCAD.


"broadbent" a écrit dans le message de news:
3F49DCC0CB469F254A2BD731B6D9F9E3@in.WebX.maYIadrTaRb...
> Crude but works.
>
> Public Function AcadToRGB&(ByVal Col&)
> Dim r&, g&, b&
> Select Case Col
> Case 1: AcadToRGB = 255: Exit Function
> Case 2: AcadToRGB = 65535: Exit Function
> Case 3: AcadToRGB = 65280: Exit Function
> Case 4: AcadToRGB = 16776960: Exit Function
> Case 5: AcadToRGB = 16711680: Exit Function
> Case 6: AcadToRGB = 16711935: Exit Function
> Case 7: AcadToRGB = 16777215: Exit Function
> Case 8: AcadToRGB = 8355711: Exit Function
> Case 9: AcadToRGB = 12566463: Exit Function
> Case 10: AcadToRGB = 255: Exit Function
> Case 11: AcadToRGB = 8355839: Exit Function
> Case 12: AcadToRGB = 207: Exit Function
> Case 13: AcadToRGB = 6316239: Exit Function
> Case 14: AcadToRGB = 144: Exit Function
> Case 15: AcadToRGB = 5197712: Exit Function
> Case 16: AcadToRGB = 127: Exit Function
> Case 90, 92, 94, 96, 98, 100, 102, 104, 106, 108, 110, 112, 114, 116, 118,
> 120, 122, 124, 126, 128, 130, 132, 134, 136, 138, 140, 142, 144, 146, 148,
> 150, 152, 154, 156, 158, 160, 162, 164, 166, 168, 170, 172, 174, 176, 178:
r
> = 0
> Case 88, 188: r = 15
> Case 86, 186: r = 31
> Case 78, 84, 99, 109, 119, 129, 139, 149, 159, 169, 179, 184, 198: r = 32
> Case 82, 89, 182, 189, 250: r = 47
> Case 68, 79, 199, 208: r = 48
> Case 69, 76, 80, 97, 107, 117, 127, 137, 147, 157, 167, 177, 180, 196,
209:
> r = 63
> Case 18, 19, 28, 29, 38, 39, 48, 49, 58, 59, 74, 87, 95, 105, 115, 125,
135,
> 145, 155, 165, 175, 187, 194, 218, 219, 228, 229, 238, 239, 248, 249: r =
79
> Case 66, 77, 185, 197, 206: r = 95
> Case 72, 85, 93, 103, 113, 123, 133, 143, 153, 163, 173, 192: r = 96
> Case 64, 67, 75, 195, 204, 207: r = 111
> Case 17, 26, 27, 36, 37, 46, 47, 56, 57, 70, 83, 91, 101, 111, 121, 131,
> 141, 151, 161, 171, 183, 190, 216, 217, 226, 227, 236, 237, 246, 247: r =
> 127
> Case 65, 205, 252: r = 128
> Case 24, 25, 34, 35, 44, 45, 54, 55, 62, 73, 193, 202, 214, 215, 224, 225,
> 234, 235, 244, 245: r = 144
> Case 81, 181: r = 159
> Case 63, 203, 253: r = 175
> Case 60, 71, 191, 200: r = 191
> Case 22, 23, 32, 33, 42, 43, 52, 53, 212, 213, 222, 223, 232, 233, 242,
243:
> r = 207
> Case 61, 201: r = 223
> Case 20, 21, 30, 31, 40, 41, 50, 51, 210, 211, 220, 221, 230, 231, 240,
241,
> 255: r = 255
> Case 251: r = 80: g = 80: b = 80
> Case 254: r = 208: g = 208: b = 208
> End Select
>
> Select Case Col
> Case 18, 170, 172, 174, 176, 178, 180, 182, 184, 186, 188, 190, 192, 194,
> 196, 198, 200, 202, 204, 206, 208, 210, 212, 214, 216, 218, 220, 222, 224,
> 226, 228, 230, 232, 234, 236, 238, 240, 242, 244, 246, 248: g = 0
> Case 28, 168: g = 15
> Case 26, 166: g = 31
> Case 19, 24, 38, 158, 164, 179, 189, 199, 209, 219, 229, 239, 249: g = 32
> Case 22, 29, 162, 169, 250: g = 47
> Case 39, 48, 148, 159: g = 48
> Case 17, 20, 36, 49, 149, 156, 160, 177, 187, 197, 207, 217, 227, 237,
247:
> g = 63
> Case 18, 27, 34, 58, 59, 68, 69, 78, 79, 88, 89, 98, 99, 108, 109, 118,
119,
> 128, 129, 138, 139, 154, 167, 175, 185, 195, 205, 215, 225, 235, 245: g =
79
> Case 152: g = 86
> Case 25, 37, 46, 146, 157, 165: g = 95
> Case 32, 173, 183, 193, 203, 213, 223, 233, 243: g = 96
> Case 35, 44, 47, 144, 147, 155: g = 111
> Case 23, 30, 56, 57, 66, 67, 76, 77, 86, 87, 96, 97, 106, 107, 116, 117,
> 126, 127, 136, 137, 150, 163, 171, 181, 191, 201, 211, 221, 231, 241: g =
> 127
> Case 45, 145, 252: g = 128
> Case 33, 42, 54, 55, 64, 65, 74, 75, 84, 85, 94, 95, 104, 105, 114, 115,
> 124, 125, 134, 135, 142, 153: g = 144
> Case 21, 161: g = 159
> Case 43, 143, 253: g = 175
> Case 31, 40, 140, 151: g = 191
> Case 52, 53, 62, 63, 72, 73, 82, 83, 92, 93, 102, 103, 112, 113, 122, 123,
> 132, 133: g = 207
> Case 41, 141: g = 223
> Case 50, 51, 60, 61, 70, 71, 80, 81, 90, 91, 100, 101, 110, 111, 120, 121,
> 130, 131, 255: g = 255
> End Select
>
> Select Case Col
> Case 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50,
52,
> 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88,
90,
> 92, 94, 96, 98: b = 0
> Case 108, 248: b = 15
> Case 106, 246: b = 31
> Case 19, 29, 39, 49, 59, 69, 79, 89, 99, 104, 118, 238, 244: b = 32
> Case 102, 109, 242, 249, 250: b = 47
> Case 119, 128, 228, 239: b = 48
> Case 17, 27, 37, 47, 57, 67, 77, 87, 97, 100, 116, 129, 229, 236, 240: b =
> 63
> Case 25, 35, 45, 55, 65, 75, 85, 95, 107, 114, 138, 139, 148, 149, 158,
159,
> 168, 169, 178, 179, 188, 189, 198, 199, 208, 209, 218, 219, 234, 247: b =
79
> Case 105, 117, 126, 226, 237, 245: b = 95
> Case 23, 33, 43, 53, 63, 73, 83, 93, 112, 232: b = 96
> Case 115, 124, 127, 224, 227, 235: b = 111
> Case 21, 31, 41, 51, 61, 71, 81, 91, 103, 110, 136, 137, 146, 147, 156,
157,
> 166, 167, 176, 177, 186, 187, 196, 197, 206, 207, 216, 217, 230, 243: b =
> 127
> Case 125, 225, 252: b = 128
> Case 113, 122, 134, 135, 144, 145, 154, 155, 164, 165, 174, 175, 184, 185,
> 194, 195, 204, 205, 214, 215, 222, 233: b = 144
> Case 101, 241: b = 159
> Case 123, 223, 253: g = 175
> Case 111, 120, 220, 231: b = 191
> Case 132, 133, 142, 143, 152, 153, 162, 163, 172, 173, 182, 183, 192, 193,
> 202, 203, 212, 213: b = 207
> Case 121: b = 223
> Case 130, 131, 140, 141, 150, 151, 160, 161, 170, 171, 180, 181, 190, 191,
> 200, 201, 210, 211, 221, 255: b = 255
> End Select
>
> AcadToRGB = RGB(r, g, b)
> End Function
>
>
>
0 Likes

Anonymous
Not applicable
trial and error
0 Likes

Anonymous
Not applicable
"Yves Allaire" wrote in message
news:7328AD64EAFB6182E81EF88E9626A01B@in.WebX.maYIadrTaRb...
> Crude... allright, but can you tell me where you got this, I spent
> uncalculable hours to get colors from other aplications to match those of
> AutoCAD.
>

Here is some Delphi code that uses the values taken
from DRV\acad.ctb (from R14). If I recall correctly,
the colors are not totally accurate.

unit AcColor;

interface

Uses Windows, Graphics;

Function ACIToColor(ACI: Integer): TColor;

const acrgb : Array[0..255, 0..2] of Byte = (

(0, 0, 0),
(255, 0, 0),
(255, 255, 0),
(0, 255, 0),
(0, 255, 255),
(0, 0, 255),
(255, 0, 255),
(255, 255, 255),
(162, 162, 162),
(239, 239, 239),
(255, 0, 0),
(255, 191, 191),
(237, 0, 0),
(237, 161, 161),
(216, 0, 0),
(216, 130, 130),
(193, 0, 0),
(193, 98, 98),
(164, 0, 0),
(164, 82, 82),
(255, 63, 0),
(255, 207, 191),
(237, 59, 0),
(237, 180, 161),
(216, 54, 0),
(216, 151, 130),
(193, 48, 0),
(193, 121, 98),
(164, 41, 0),
(164, 102, 82),
(255, 127, 0),
(255, 223, 191),
(237, 118, 0),
(237, 199, 161),
(216, 108, 0),
(216, 173, 130),
(193, 96, 0),
(193, 145, 98),
(164, 82, 0),
(164, 123, 82),
(255, 191, 0),
(255, 239, 191),
(237, 177, 0),
(237, 218, 161),
(216, 162, 0),
(216, 195, 130),
(193, 144, 0),
(193, 169, 98),
(164, 123, 0),
(164, 143, 82),
(255, 255, 0),
(255, 255, 191),
(237, 237, 0),
(237, 237, 161),
(216, 216, 0),
(216, 216, 130),
(193, 193, 0),
(193, 193, 98),
(164, 164, 0),
(164, 164, 82),
(191, 255, 0),
(239, 255, 191),
(177, 237, 0),
(218, 237, 161),
(162, 216, 0),
(195, 216, 130),
(144, 193, 0),
(169, 193, 98),
(123, 164, 0),
(143, 164, 82),
(127, 255, 0),
(223, 255, 191),
(118, 237, 0),
(199, 237, 161),
(108, 216, 0),
(173, 216, 130),
(96, 193, 0),
(145, 193, 98),
(82, 164, 0),
(123, 164, 82),
(63, 255, 0),
(207, 255, 191),
(59, 237, 0),
(180, 237, 161),
(54, 216, 0),
(151, 216, 130),
(48, 193, 0),
(121, 193, 98),
(41, 164, 0),
(102, 164, 82),
(0, 255, 0),
(191, 255, 191),
(0, 237, 0),
(161, 237, 161),
(0, 216, 0),
(130, 216, 130),
(0, 193, 0),
(98, 193, 98),
(0, 164, 0),
(82, 164, 82),
(0, 255, 63),
(191, 255, 207),
(0, 237, 59),
(161, 237, 180),
(0, 216, 54),
(130, 216, 151),
(0, 193, 48),
(98, 193, 121),
(0, 164, 41),
(82, 164, 102),
(0, 255, 127),
(191, 255, 223),
(0, 237, 118),
(161, 237, 199),
(0, 216, 108),
(130, 216, 173),
(0, 193, 96),
(98, 193, 145),
(0, 164, 82),
(82, 164, 123),
(0, 255, 191),
(191, 255, 239),
(0, 237, 177),
(161, 237, 218),
(0, 216, 162),
(130, 216, 195),
(0, 193, 144),
(98, 193, 169),
(0, 164, 123),
(82, 164, 143),
(0, 255, 255),
(191, 255, 255),
(0, 237, 237),
(161, 237, 237),
(0, 216, 216),
(130, 216, 216),
(0, 193, 193),
(98, 193, 193),
(0, 164, 164),
(82, 164, 164),
(0, 191, 255),
(191, 239, 255),
(0, 177, 237),
(161, 218, 237),
(0, 162, 216),
(130, 195, 216),
(0, 144, 193),
(98, 169, 193),
(0, 123, 164),
(82, 143, 164),
(0, 127, 255),
(191, 223, 255),
(0, 118, 237),
(161, 199, 237),
(0, 108, 216),
(130, 173, 216),
(0, 96, 193),
(98, 145, 193),
(0, 82, 164),
(82, 123, 164),
(0, 63, 255),
(191, 207, 255),
(0, 59, 237),
(161, 180, 237),
(0, 54, 216),
(130, 151, 216),
(0, 48, 193),
(98, 121, 193),
(0, 41, 164),
(82, 102, 164),
(0, 0, 255),
(191, 191, 255),
(0, 0, 237),
(161, 161, 237),
(0, 0, 216),
(130, 130, 216),
(0, 0, 193),
(98, 98, 193),
(0, 0, 164),
(82, 82, 164),
(63, 0, 255),
(207, 191, 255),
(59, 0, 237),
(180, 161, 237),
(54, 0, 216),
(151, 130, 216),
(48, 0, 193),
(121, 98, 193),
(41, 0, 164),
(102, 82, 164),
(127, 0, 255),
(223, 191, 255),
(118, 0, 237),
(199, 161, 237),
(108, 0, 216),
(173, 130, 216),
(96, 0, 193),
(145, 98, 193),
(82, 0, 164),
(123, 82, 164),
(191, 0, 255),
(239, 191, 255),
(177, 0, 237),
(218, 161, 237),
(162, 0, 216),
(195, 130, 216),
(144, 0, 193),
(169, 98, 193),
(123, 0, 164),
(143, 82, 164),
(255, 0, 255),
(255, 191, 255),
(237, 0, 237),
(237, 161, 237),
(216, 0, 216),
(216, 130, 216),
(193, 0, 193),
(193, 98, 193),
(164, 0, 164),
(164, 82, 164),
(255, 0, 191),
(255, 191, 239),
(237, 0, 177),
(237, 161, 218),
(216, 0, 162),
(216, 130, 195),
(193, 0, 144),
(193, 98, 169),
(164, 0, 123),
(164, 82, 143),
(255, 0, 127),
(255, 191, 223),
(237, 0, 118),
(237, 161, 199),
(216, 0, 108),
(216, 130, 173),
(193, 0, 96),
(193, 98, 145),
(164, 0, 82),
(164, 82, 123),
(255, 0, 63),
(255, 191, 207),
(237, 0, 59),
(237, 161, 180),
(216, 0, 54),
(216, 130, 151),
(193, 0, 48),
(193, 98, 121),
(164, 0, 41),
(164, 82, 102),
(93, 93, 93),
(162, 162, 162),
(210, 210, 210),
(239, 239, 239),
(252, 252, 252),
(255, 255, 255)

);

var
AcColors : Array [0..255] of TColor;
i : integer;

implementation

Function ACIToColor(ACI: Integer): TColor;
begin
If ACI < 256 then
Result := AcColors[ACI]
else
Result := clNone;
end;

// Set to white for dark background or black for light background

Procedure SetColor7(r, g, b: byte);
begin
AcColors[7] := TColor(Rgb(r, g, b));
end;

Procedure SetLightBackground;
begin
AcColors[7] := clBlack;
end;

Procedure SetDarkBackground;
begin
AcColors[7] := clWhite;
end;

initialization
begin
For i := 0 to 255 do
AcColors := TColor(rgb(acrgb[i, 0], acrgb[i,1], acrgb[i,2]));
end;

end.
0 Likes

Anonymous
Not applicable
I have compared all of the posted suggestions, along with some formulas
found on
the web. None of them seem to produce reliable values. Can anyone shed any
light on this ?

Brian D.


"Brian D" wrote in message
news:7EAEAD8BB86ADC0E4554EBA2320E39A0@in.WebX.maYIadrTaRb...
> Does anyone know of a formula to convert AutoCAD ACI color codes
> to RGB ?
>
> Thanks,
> Brian D.
>
>
>
0 Likes