Can anyone tell me what format this colour value is in: 0x000066FF.
I believe its a 16 bit hex with an Alpha Channel?
You are right - looks like an ARGB value.
ARGB values are typically expressed using 8 hexadecimal digits, with each pair of the hexadecimal digits representing the sample values of the Alpha, Red, Green and Blue channel, respectively. For example, 0x80FFFF00 represents 50.2% opaque (non-premultiplied) yellow. The "0x" prefix is used to identify a number as hexadecimal in C notation. 0x80 represents a 50.2% alpha value, because it is 50.2% of 0xFF (in decimal 128 is 50.2% of 255), the first 0xFF represents the maximum value a red sample can have; the second 0xFF is like the previous but for green; 0x00 represents the minimum value a blue sample can have (effectively – no blue). Consequently red + green yields yellow.
Related
I have a column "HEX" and three columns "R", "G", and "B".
How can I convert a HEX to RGB, e.g. ff0000 to R=255, G=0, and B=0?
I know that the first 2 characters ff belongs to "R", the next 2 00 belongs to "G", and the final 2 00 belongs to "B". So I will have to use =LEFT(A1, 2) for "R", =RIGHT(LEFT(A1, 4), 2), and =RIGHT(A1, 2) for the last.
But how can I convert ff to 255 and 00 to 0, etc.? I guess I will have to do something to parse from hexadecimal (base 16) to decimal (base 10)?
I would like to do it without VBA.
You can try with the =Hex2Dec(A1) indeed, but you should split its input into 3 parts:
One for R, one for G and one for B, considering that you would always get them in a format like this ff0000.
=HEX2DEC(LEFT(B1,2))&"-"&HEX2DEC(MID(B1,3,2))&"-"&HEX2DEC(RIGHT(B1,2))
This is the result from the formula:
You can convert from hex to decimal using the HEX2DEC() function. For instance:
=HEX2DEC(A1)
Where cell A1 contains the string FF, this will return 255.
More details here.
I have managed to create a excel spreadsheet that converts Hex to RGB in three columns; Red, Green and Blue. Below is the code for it:
Red: =HEX2DEC(LEFT([Cell],2))
Green: =HEX2DEC(MID([Cell],3,2))
Blue: =HEX2DEC(RIGHT([Cell],2))
So far, I have not found any restrictions to this code.
I also made code for RGB to hex:
=DEC2HEX(([Red]*65536)+([Green]*256)+[Blue],6)
I hope this answers your question.
Some pages make that (w3SCHOOL PICKER), but in excel you can make this
vba rgb to hex and inverse
If you try without vba, you'll only can use 56 colors.
(in case use the colors from a cell)
Right at the beginning of this page The OpenType Font File you'll find this table, with examples of the F2DOT14 format for a 16-bit signed fixed number with the low 14 bits of a fraction.
I couldn't obtain the hex value 0xffff for the decimal -0.000061. By the way the mantissa -1 seems to be wrong and the value for the fraction should be 1/16384, instead of 16383/16384, unless I'm missing something related to the two's complement notation used to express a negative value in code.
The mantissa and fraction values listed are entirely correct: the F2DOT14 field encodes numbers as the arithmetic computation mantissa + fraction, not as "signed mantissa with unsigned concatenated fraction remainder".
As such, if you want -0.000061, you have to start with the signed integer -1 in the first two bits (11) and then add the positive value 16383/16384 in the last 14 bits (11111111111111), such that mantissa + fraction = -1 + 16383/16384 = -1/16384, which in turn is encoded using the 16 bit code 0xFFFF
I stumbled over this blogpost by Brian Suda and quickly applied the "Dopplr’s coloring algorithm" to some examples, and that this works is not in question. What is, is why?
The process is as follows:
$hex_color = sub-string(md5($original_string), 0, 6)
Input some string (e.g. city names as with dopplr's original usage), make a md5-hash of this, and use the first 6 digits from the hash. Prepend this with a "#" and a string is transformed into a color fit for use in CSS-documents etc.
How is it that the six first digits of a md5-hash always matches a color in the hexadecimal representation?
MD5 always outputs hex. Colors can be represented as a 6-character hex string in css. So, the MD5 hash is just producing a semi-random hex string.
And any hex string (that is 6 characters long and begins with a #) is valid to define a color.
With 8 bit color depth there are 256 colors. With 24 bit color depth there are 16,777,216 colors. Is there a direct mapping between every color in the 8 bit space to a color in the 24 bit space? I would think the answer to this question is yes, but the comments to this answer suggest the mapping is only an approximation.
What I would like to do is create a palette of 8 bit colors in the 24 bit color space by specifying a 24 bit RGB value. I figured I could do this using this (obviously broken) logic:
3 bits for red == 8 unique values of red, 0-7
3 bits for green == 8 unique values of green, 0-7
2 bits for blue == 4 unique values of blue, 0-3
255/8 = 32 for red and green increment value
255/4 = 64 for blue increment value
{
"Red": [0,31,63,95,127,159,191,223,255],
"Green": [0,31,63,95,127,159,191,223,255],
"Blue": [0,63,127,191, 255]
}
So with 9 values of red, 9 values of green, and 5 values of blue I get 405 colors which is wrong. I know I need 8 values of red and green and 4 values of blue so I just adjusted things a bit:
255/87 = 36.57142857142857 for red and green increment value
255/43 = 85 for blue increment value
So this works for blue, but now my red and green increment value is not a whole number.
Once I got the mapping figured out I was going to loop through it like this:
for(r in rgbData.get("Red")) {
for(g in rgbData.get("Green")) {
for(b in rgbData.get("Blue")) {
colors.add("rgb ${r} ${g} ${b}")
}
}
}
This may be a totally incorrect approach to do what I want, just wanted to show I have tried something :)
UPDATE:
I tried the approach #Marc B suggested but it doesn't seem right. For instance, there is no white in the map I generated (which is 255, 255, 255 using 24 bit RGB). Using his approach this makes sense to me because the highest RGB value is 224, 224, 192 as can be seen:
full red == 111
111 >> 5 == 11100000
full green == 111
111 >> 5 == 11100000
full blue == 11
11 >> 6 == 11000000
11100000 11100000 11000000 == 224, 224, 192
224, 224, 192 != white
Here is the map generated using his approach:
{
"Red": [0,32,64,96,128,160,196,224],
"Green": [0,32,64,96,128,160,196,224],
"Blue": [0,64,128,192]
}
And the palette it generates:
UPDATE 2:
After doing some more research I have realized that when "X colors" (X being some number like 256, 16,777,216, etc.) are referred to that those colors can be just about anything. There is not a predefined set of 256 colors that are "the" 256 colors, though there are (as several have already mentioned) predefined sets of 256 colors that are "the" 256 colors for a specific implementation. I was also able to find a GIMP .gpl palette file on my organizations wiki that specified the 256 colors I am concerned with, so I can just copy the values out of there.
The practical answer is probably yes. Having said that, it's really a hardware dependant thing. #Marc B is close to correct (probably close enough for most people) but the real answer is it depends, it depends on the hardware, and it wont be exact from (hardware)implementation to implementation, but it will likely be exact enough for most people.
The way to convert is to multiply each channel by the highest level you want output and divide by the highest level of input.
{
"Red": [0,36,72,109,145,182,218,255],
"Green": [0,36,72,109,145,182,218,255],
"Blue": [0,85,170,255]
}
With this method you don't need to devote an even number of bits to each channel, you can use an arbitrary number of levels for each. You can get a more even distribution, but you don't get to use all 256 colors. One common arrangement is 6/7/6 for 252 colors:
{
"Red": [0,51,102,153,204,255],
"Green": [0,42,85,127,170,212,255],
"Blue": [0,51,102,153,204,255]
}
I know this answer is probably a bit late, but it might be useful for others. If someone knows what the algorithm outlined below is called, please let me know in a comment.
I'm currently working with different display hardware and I've run into the problem of converting a channel with m bits to one with n bits, where m < n; for example: convert a 5 bit channel to an 8 bits channel. White (b11111) should map to white (b11111111) and black should map to black.
To map, for example, 5-bits b10111 to 8 bits, I pad the missing bits with the MSBs from the original data:
b10111
^^^--- we need these three MSB again later, as 8-5 = 3 missing bits
shift left 3 bits:
b10111000
and pad with MSBs:
b10111101
^^^--- the MSBs
That maps quite well (you might want to apply rounding for values that are not all 1s) and round-trips (you can convert less than 8 bits to 8 bits, convert back and the result is the same as the original value).
If the narrower channel is less than 4 bits wide (like 3), the whole value will repeat completely:
b101 -> b10110110
Basically, I have a context where I can't programatically tint an image, though I can change it's alpha value. With some experimentation, I've found that I can layer a red, blue, and green version of the image, with specific alpha values, to produce a wide range of colors. However, I am wondering if it's possible to achieve a true RGB representation through this method? If so, what is the formula for converting an RGB value into different alpha values for the red, blue, and green layers.
The basic "equation" of alpha combination is:
alpha * (R1,G1,B1) + (1-alpha) * (R2,G2,B2)
When you have three layers with alpha you are actually combining 4 layers (the 4th one is black) so the final color is:
alpha1 * (R1,G1,B1) + (1-alpha1) * (
alpha2 * (R2,G2,B2) + (1-alpha2) * (
alpha3 * (R3,G3,B3) + (1-alpha2) * (0,0,0) ) )
Provided you have the same image on each layer and layer1 is the red channel (G1=B1=0) and layer2 is green and layer3 is blue you get:
(alpha1 * R, (1-alpha1)*alpha2 * G, (1-alpha1)*(1-alpha2)*alpha3 * B)
For a white pixel you can do any possible color. For a black pixel you cannot do anything but black. For any other pixel, you are restricted by the values of R, G and B.
Say you wanted to achieve (Rd, Gd, Bd) at a pixel where the current color is (R, G, B) then you would have to choose:
alpha1 = Rd/R
alpha2 = Gd/(G*(1-alpha1))
alpha3 = Bd/(B*(1-alpha1)*(1-alpha2))
The problem is that alpha can typically only be between 0 and 1. So, for example, if Rd > R there is nothing you can do.
You can do better if you can control the blending function (for example, in Photoshop).
I don't think that's possible, if I understand you correctly.
If, for a certain pixel, your image's red value is, say, 0.5, you can combine that with an alpha in the (typical) range [0,1] to form any value up to and including 0.5, but you can't go above, to get e.g. 0.6 or so as the output value.
If you're looking to create 3 layers that blended together add up to the original image, it's quite possible. Here's a link to a Python script that calls functions in Paint Shop Pro to do the hard parts.
http://pixelnook.home.comcast.net/~pixelnook/SplitToRGB.htm
If you need more detail than that, leave a comment and I'll try to fill it in later.