Created
May 12, 2013 04:29
-
-
Save Makopo/5562412 to your computer and use it in GitHub Desktop.
Modified /indra/llmath/v3color.h color retrieve function (https://gist.github.com/Makopo/5562402) for standalone use. $ ./rgb_to_float 7F194C
STRING = 7F194C, R = 0.498039, G = 0.098039, B = 0.298039 $ ./float_to_rgb .5 .1 .3
RGB = 7F194C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
int main(int argc, char const *argv[]) | |
{ | |
long red = atof(argv[1])*255.f; // RED | |
long green = atof(argv[2])*255.f; // GREEN | |
long blue = atof(argv[3])*255.f; // BLUE | |
printf("RGB = %02lX%02lX%02lX\n", red, green, blue); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
#include <stdlib.h> | |
int main(int argc, char const *argv[]) | |
{ | |
char tempstr[7]; | |
strncpy(tempstr,argv[1],6); /* Flawfinder: ignore */ | |
tempstr[6] = '\0'; | |
float blue = (float)strtol(&tempstr[4],NULL,16)/255.f; // BLUE | |
tempstr[4] = '\0'; | |
float green = (float)strtol(&tempstr[2],NULL,16)/255.f; // GREEN | |
tempstr[2] = '\0'; | |
float red = (float)strtol(&tempstr[0],NULL,16)/255.f; // RED | |
printf("STRING = %s, R = %f, G = %f, B = %f\n", argv[1], red, green, blue); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment