void colorizeHilbert(void) { unsigned long i; double hue=0.0, current=0; for (i=0; i<hilbertSize; i++) { hilbertPointList[i].a=1.0f; if (i<sampleSize) { current = randList[i]; hue = current / maxAll; hsv2rgb(hue, 0.8, 1.0, &(hilbertPointList[i].r), &(hilbertPointList[i].g), &(hilbertPointList[i].b)); } else { hsv2rgb(0.0, 0.1, 0.1, &(hilbertPointList[i].r), &(hilbertPointList[i].g), &(hilbertPointList[i].b)); } } }
void mix_color(struct color_t *c, struct color_t *c1, struct color_t *c2, int64_t v1, int64_t v2) { double r1, r2; struct hsvcolor_t hc, hc1, hc2; r1 = v1 / (double) (v1 + v2); r2 = v2 / (double) (v1 + v2); rgb2hsv(&hc1, c1); rgb2hsv(&hc2, c2); if (hc1.s == 0 || hc2.s == 0 || hc1.h - hc2.h == 1800 || hc2.h - hc1.h == 1800) { c->r = c1->r * r1 + c2->r * r2; c->g = c1->g * r1 + c2->g * r2; c->b = c1->b * r1 + c2->b * r2; } else { if (hc1.h - hc2.h > 1800) hc2.h += 3600; else if (hc2.h - hc1.h > 1800) hc1.h += 3600; hc.h = hc1.h * r1 + hc2.h * r2; if (hc.h >= 3600) hc.h -= 3600; hc.s = hc1.s * r1 + hc2.s * r2; hc.v = hc1.v * r1 + hc2.v * r2; hsv2rgb(c, &hc); } c->a = c1->a * r1 + c2->a * r2; }
void interpolate_cmap(flam3_palette cmap, double blend, int index0, double hue0, int index1, double hue1) { flam3_palette p0,p1; int i, j; flam3_get_palette(index0, p0, hue0); flam3_get_palette(index1, p1, hue1); for (i = 0; i < 256; i++) { double t[5], s[5]; rgb2hsv(p0[i].color, s); rgb2hsv(p1[i].color, t); s[3] = p0[i].color[3]; t[3] = p1[i].color[3]; s[4] = p0[i].index; t[4] = p1[i].index; for (j = 0; j < 5; j++) t[j] = ((1.0-blend) * s[j]) + (blend * t[j]); hsv2rgb(t, cmap[i].color); cmap[i].color[3] = t[3]; cmap[i].index = t[4]; } }
void colorizeFFT(void) { unsigned long i=0; double hue=0.0, max=0.0; for (i=0; i<fftN; i++) { max = fmax(max, fftPointList[i].y); } for (i=0; i<fftN*2; i+=2) { //hue = (double)i / (double)fftN; hue = fftPointList[i].y / max; hsv2rgb(hue, 0.8, 1.0, &(fftPointList[i].r), &(fftPointList[i].g), &(fftPointList[i].b)); fftPointList[i].a = 1.0; hsv2rgb(0.01, 0.8, 1.0, &(fftPointList[i+1].r), &(fftPointList[i+1].g), &(fftPointList[i+1].b)); fftPointList[i+1].a = 1.0; } }
void make_hsv_wheel_texture() { glGenTextures(1, &hsv_wheel_num); static unsigned char hsv_pix[HSV_WHEEL_SIZE * HSV_WHEEL_SIZE * 4]; for (int y = 0; y < HSV_WHEEL_SIZE; ++y) { for (int x = 0; x < HSV_WHEEL_SIZE; ++x) { float yf = 2.0f * y / (float)(HSV_WHEEL_SIZE) - 1.0f; float xf = 2.0f * x / (float)(HSV_WHEEL_SIZE) - 1.0f; float rad = hypot(xf, yf); float theta = atan2(yf, xf); float r, g, b; hsv2rgb(theta, rad, 1.0f, &r, &g, &b); hsv_pix[(y * HSV_WHEEL_SIZE + x) * 4 + 0] = lrintf(r * 255.0f); hsv_pix[(y * HSV_WHEEL_SIZE + x) * 4 + 1] = lrintf(g * 255.0f); hsv_pix[(y * HSV_WHEEL_SIZE + x) * 4 + 2] = lrintf(b * 255.0f); if (rad > 1.0f) { hsv_pix[(y * HSV_WHEEL_SIZE + x) * 4 + 3] = 0; } else { hsv_pix[(y * HSV_WHEEL_SIZE + x) * 4 + 3] = 255; } } } glBindTexture(GL_TEXTURE_2D, hsv_wheel_num); check_error(); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); check_error(); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, HSV_WHEEL_SIZE, HSV_WHEEL_SIZE, 0, GL_RGBA, GL_UNSIGNED_BYTE, hsv_pix); check_error(); }
unsigned long ColorUtils::hsv2bgr(double h, double s, double v) { int r, g, b; hsv2rgb(h, s, v, r, g, b); return (b << 16) | (g << 8) | r; }
QImage Dialog::addShine(int value) { rgb structRgb; hsv structHsv; for(int i=0; i<m_Image.byteCount();i+=4) { //structRgb.b = m_listImageIn[i]; //structRgb.g = m_listImageIn[i+1]; //structRgb.r = m_listImageIn[i+2]; structRgb.b = m_listImageOut[i]; structRgb.g = m_listImageOut[i+1]; structRgb.r = m_listImageOut[i+2]; structHsv = rgb2hsv(structRgb); structHsv.v=structHsv.v*value/100.0; if(structHsv.v>1) structHsv.v = 1; structRgb = hsv2rgb(structHsv); m_listImageOut[i] = structRgb.b; m_listImageOut[i+1] = structRgb.g; m_listImageOut[i+2] = structRgb.r; m_listImageOut[i+3] = m_listImageIn[i+3]; } return QImage((unsigned char *)m_listImageOut,m_Image.width(),m_Image.height(),m_Image.format()); }
void setRainbow(uint8_t ledsBrBuf[], uint8_t ledsCount, uint8_t range, uint16_t iCurrent, uint8_t direction){ uint16_t i; uint16_t hh; uint16_t ss; uint16_t vv; uint16_t rr; uint16_t gg; uint16_t bb; uint16_t ii; for (i = 0; i < 16; i++){ if (direction){ ii = iCurrent; }else{ ii = 360 - iCurrent; } hh = ((i*360/(range) + ii)) % 360; ss = 255; vv = 255; hsv2rgb(hh, ss, vv, &rr, &gg, &bb, 255); //printf("%d, %d, %d, %d, %d, %d, %d, %d\n\r", i, ii, hh, ss, vv, rr, gg, bb); if (direction){ ii = i*3; }else{ ii = (15-i)*3; } ledsBrBuf[ii] = bb; ledsBrBuf[ii+1] = rr; ledsBrBuf[ii+2] = gg; } }
void image_normalize(const img_header_t* head, const int slice_size, uint8_t* data, int min, int max, int newMin, int newMax) { int i; int displ = DISPLACEMENT(head); int channels = head->channels; #pragma omp parallel for private(i) for(i = 0; i < slice_size; i+=displ) { if(channels == 1) data[i] = (data[i] - min) * (newMax - newMin) / (max - min) + newMin; else { rgb_point_t rgb; hsv_point_t hsv; rgb.r = data[i]; rgb.g = data[i+1]; rgb.b = data[i+2]; hsv = rgb2hsv(&rgb); hsv.v = (hsv.v - min) * (newMax - newMin) / (max - min) + newMin; rgb = hsv2rgb(&hsv); data[i] = rgb.r; data[i+1] = rgb.g; data[i+2] = rgb.b; } } }
static void br_cairo_draw_section(duc_graph *g, double a1, double a2, double r1, double r2, double H, double S, double V, double line) { struct cairo_backend_data *bd = g->backend_data; cairo_t *cr = bd->cr; double R, G, B; hsv2rgb(H, S, V, &R, &G, &B); cairo_new_path(cr); cairo_arc(cr, g->cx, g->cy, r1, ang(a1), ang(a2)); cairo_arc_negative(cr, g->cx, g->cy, r2, ang(a2), ang(a1)); cairo_close_path(cr); if(R != 1.0 || G != 1.0 || B != 1.0) { cairo_pattern_t *pat; pat = cairo_pattern_create_radial(g->cx, g->cy, 0, g->cx, g->cy, g->cx-50); double off1 = r2 / g->cx; double off2 = r1 / g->cx; cairo_pattern_add_color_stop_rgb(pat, off1, R, G, B); cairo_pattern_add_color_stop_rgb(pat, off2, R * 0.6, G * 0.6, B * 0.6); cairo_set_source(cr, pat); cairo_fill_preserve(cr); cairo_pattern_destroy(pat); } if(line) { cairo_set_line_width(cr, 0.5); cairo_set_source_rgba(cr, 0, 0, 0, 0.9); cairo_stroke(cr); } }
void initWorm( uint16_t worm_number, uint16_t number_of_worms, uint16_t worm_length, WORM_T *worm, IMAGE_T *image) { hsv2rgb((3600 * worm_number) / number_of_worms, 1000, 1000, &(worm->colour)); worm->colour.alpha = 255; worm->direction = (rand() * 360.0) / RAND_MAX; worm->head = worm_length - 1; worm->size = worm_length; worm->body = malloc(worm->size * sizeof(COORD_T)); if (worm->body == NULL) { fprintf(stderr, "worms: memory exhausted\n"); exit(EXIT_FAILURE); } double x = (double)rand() * image->width / RAND_MAX; double y = (double)rand() * image->height / RAND_MAX; uint16_t i = 0; for (i = 0 ; i < worm->size ; i++) { worm->body[i].x = x; worm->body[i].y = y; } }
void rgbLedRainbow(int numRGBLeds, int delayVal, int numCycles, int maxBrightnessRainbow, int rainbowWidth, bool fade){ // Displays a rainbow spread over all LED's, which shifts in hue. int hue, sat, val; unsigned char red, green, blue, temp_maxBrightness=maxBrightness, fadeInDone=0; // if(fade) // ShiftPWM.FadeOut(); ShiftPWM.SetAll(0); for(int cycle=0;cycle<numCycles;cycle++){ // shift the raibom numCycles times for(int colorshift=0;colorshift<360;colorshift++){ // Shift over full color range (like the hue slider in photoshop) for(int led=0;led<numRGBLeds;led++){ // loop over all LED's hue = ((led)*360/(rainbowWidth-1)+colorshift)%360; // Set hue from 0 to 360 from first to last led and shift the hue sat = 255; val = 255; hsv2rgb(hue, sat, val, &red, &green, &blue, maxBrightnessRainbow); // convert hsv to rgb values ShiftPWM.SetGroupOf3(led, red, green, blue); // write rgb values } // if((!fadeInDone)&&(fade)) { // //ShiftPWM.FadeIn(); // } delay(delayVal); } } // if(fade) // ShiftPWM.FadeOut(); }
int color2rgb(char *str, double rgb[3]) { static hsbcolor_t *last; char *p,canon[SMALLBUF],buf[BUFSIZ]; hsbcolor_t fake; double hsv[3]; if ((last == NULL)||(last->name[0] != str[0])||(strcmp(last->name,str))) { fake.name = canoncolor(str,canon); last = (hsbcolor_t*) bsearch((void*)&fake,(void*)color_lib,sizeof(color_lib)/sizeof(hsbcolor_t),sizeof(fake),(bsearch_cmpf)colorcmpf); } if (last == NULL) { if (isdigit(canon[0]) == FALSE) return 0; else { for (p = buf; (*p = *str++); p++) if (*p == ',') *p = ' '; sscanf(buf,"%lf%lf%lf",&hsv[0],&hsv[1],&hsv[2]); } } else { hsv[0] = ((double)last->h)/255; hsv[1] = ((double)last->s)/255; hsv[2] = ((double)last->b)/255; } hsv2rgb(&rgb[0],&rgb[1],&rgb[2],hsv[0],hsv[1],hsv[2]); return 1; }
int process(const tendrils& inputs, const tendrils& outputs, boost::shared_ptr<const ::pcl::PointCloud<Point> >& input) { // initialize outputs and filter typename ::pcl::PointCloud<Point>::Ptr output(new typename ::pcl::PointCloud<Point>); ::pcl::ExtractIndices<Point> filter; filter.setInputCloud(input); output->header = input->header; // Extract location of rgb (similar to pcl::PackedRGBComparison<T>) #if PCL_VERSION_COMPARE(<,1,7,0) std::vector<sensor_msgs::PointField> fields; #else typedef ::pcl::PCLPointField PCLPointField; std::vector<PCLPointField> fields; #endif ::pcl::getFields(*input, fields); size_t idx; for (idx = 0; idx < fields.size(); idx++) { if ( fields[idx].name == "rgb" || fields[idx].name == "rgba" ) break; } if (idx == fields.size()) { throw std::runtime_error("[ColorizeClouds] requires an rgb or rgba field."); return -1; } for (size_t i = 0; i < clusters_->size(); i++) { ::pcl::PointCloud<Point> cloud; // extract indices into a cloud filter.setIndices( ::pcl::PointIndicesPtr( new ::pcl::PointIndices ((*clusters_)[i])) ); filter.filter(cloud); float hue = (360.0 / clusters_->size()) * i; float r, g, b; hsv2rgb(hue, *saturation_, *value_, r, g, b); // colorize cloud for (size_t j = 0; j < cloud.points.size(); j++) { Point &p = cloud.points[j]; unsigned char* pt_rgb = (unsigned char*) &p; pt_rgb += fields[idx].offset; (*pt_rgb) = (unsigned char) (r * 255); (*(pt_rgb+1)) = (unsigned char) (g * 255); (*(pt_rgb+2)) = (unsigned char) (b * 255); } // append cloud.header = input->header; *output += cloud; } *output_ = xyz_cloud_variant_t(output); return OK; }
//------------------------------------------------------------------------------ // setHSV() -- Sets the hsv vector //------------------------------------------------------------------------------ bool Hsv::setHSV(const osg::Vec3& vec) { hsv[0] = vec[0]; hsv[1] = vec[1]; hsv[2] = vec[2]; hsv2rgb(color,hsv); return true; }
rgb operator()() { // use golden ratio rand += golden_ratio_conjugate; rand = std::fmod(rand,1); return (hsv2rgb(hsv(rand*360.0, 0.5, 0.95))); }
int board_write_hsv(const board_t* board, const hsv_t* hsv) { rgb_t col; hsv2rgb(hsv, &col); return board_write_rgb(board, &col); }
void ColorUtils::hsv2rgb(double h, double s, double v, int& r, int& g, int& b) { double rd, gd, bd; hsv2rgb(h, s, v, rd, gd, bd); r = rd * 255; g = gd * 255; b = bd * 255; }
// Draws the circular legend for the color field, indicating direction and magnitude void drawLegendHSV(IplImage* imgColor, int radius, int cx, int cy) { int width = radius*2 + 1; int height = width; IplImage* imgLegend = cvCreateImage( cvSize(width, height), 8, 3 ); IplImage* imgMask = cvCreateImage( cvSize(width, height), 8, 1 ); IplImage* sub_img = cvCreateImageHeader(cvSize(width, height),8,3); uchar* legend_ptr; float angle, h, s, v, legend_max_s; uchar r,g,b; int deltaX, deltaY; legend_max_s = radius*sqrt(2); for(int y=0; y < imgLegend->height; y++) { legend_ptr = (uchar*)(imgLegend->imageData + y*imgLegend->widthStep); for(int x=0; x < imgLegend->width; x++) { deltaX = x-radius; deltaY = -(y-radius); angle = atan2(deltaY,deltaX); if(angle < 0) angle += 2*M_PI; h = angle * 180 / M_PI; s = sqrt(deltaX*deltaX + deltaY*deltaY) / legend_max_s; v = 0.9; hsv2rgb(h, s, v, r, g, b); legend_ptr[3*x] = b; legend_ptr[3*x+1] = g; legend_ptr[3*x+2] = r; } } cvZero(imgMask); cvCircle( imgMask, cvPoint(radius,radius) , radius, CV_RGB(255,255,255), -1,8,0 ); sub_img->origin = imgColor->origin; sub_img->widthStep = imgColor->widthStep; sub_img->imageData = imgColor->imageData + (cy-radius) * imgColor->widthStep + (cx-radius) * imgColor->nChannels; cvCopy(imgLegend, sub_img, imgMask); cvCircle( imgColor, cvPoint(cx,cy) , radius, CV_RGB(0,0,0), 1,CV_AA,0 ); cvReleaseImage(&imgLegend); cvReleaseImage(&imgMask); cvReleaseImageHeader(&sub_img); }
mininode_geometry_band_path::mininode_geometry_band_path(const minipath &path,const minidyna<double> &width,double minv,double maxv,double sat,double val) { minicoord ecef; minidyna<miniv3d> pos; miniv3d n; minidyna<miniv3d> nrm,col; minidyna<double> wdt; double v; float hue,rgb[3]; if (path.getsize()<2) return; if (path.getsize()!=width.getsize()) return; for (unsigned int i=0; i<path.getsize(); i++) { ecef=path[i]; ecef.convert2ecef(); n=ecef.vec; n.normalize(); v=path[i].velocity; hue=(1.0-(v-minv)/(maxv-minv))*240.0; if (hue<0.0f) hue=0.0f; else if (hue>240.0f) hue=240.0f; hsv2rgb(hue,sat,val,rgb); if (path[i].start) if (i>0) { miniv3d lp=pos.last(); miniv3d ln=nrm.last(); miniv3d lc=col.last(); pos.append(lp); nrm.append(ln); col.append(lc); wdt.append(0.0); pos.append(ecef.vec); nrm.append(n); col.append(miniv3d(rgb)); wdt.append(0.0); } pos.append(ecef.vec); nrm.append(n); col.append(miniv3d(rgb)); wdt.append(width[i]); } *this=mininode_geometry_band_path(pos,nrm,col,wdt); }
void setColourHSVf(float h, float s, float v) { hsv tmp; tmp.h = h; tmp.s = s; tmp.v = v; rgb result = hsv2rgb(tmp); _setRGBA(result.r, result.g, result.b, 1.0); }
//------------------------------------------------------------------------------ // setHue() -- set the HSV hue //------------------------------------------------------------------------------ bool Hsv::setHue(Number* const msg) { if (msg == nullptr) return false; LCreal value = msg->getReal(); bool ok = (value >= 0 && value <= 360); if (ok) { hsv[HUE] = value; hsv2rgb(color,hsv); } else std::cerr << "Hsv::setHue: invalid entry(" << value << "), valid range: 0 to 360" << std::endl; return ok; }
//------------------------------------------------------------------------------ // setSaturation() -- set the HSV saturation //------------------------------------------------------------------------------ bool Hsv::setSaturation(Number* const msg) { if (msg == nullptr) return false; LCreal value = msg->getReal(); bool ok = (value >= 0 && value <= 1); if (ok) { hsv[SATURATION] = value; hsv2rgb(color,hsv); } else std::cerr << "Hsv::setSaturation: invalid entry(" << value << "), valid range: 0 to 1" << std::endl; return ok; }
void CColorPicker::SetHSV(float h, float s, float v) { fNewColor.m_Hue = h; hsv2rgb(h, s, v, fNewColor.m_Red, fNewColor.m_Green, fNewColor.m_Blue); fON->SetNewColor(f2rgb(fNewColor.m_Red, fNewColor.m_Green, fNewColor.m_Blue, fNewColor.m_Alpha)); fRGB->SetColor(fNewColor); } /* CColorPicker::SetHSV */
//setColourRGBf(palette[index].r, palette[index].g, palette[index].b); void calcPalette() { uint16_t i; float palette_scale = 1.0f / PALETTE_SIZE; for (i = 0; i < PALETTE_SIZE; i++) { hsv in; in.h = i * palette_scale; in.s = 1.0; in.v = 1.0; palette[i] = hsv2rgb(in); } }
rgb getRGBValue(double startValue, double endValue, double value) { rgb rgbNegativeMax; rgbNegativeMax.r = 230; rgbNegativeMax.g = 0; rgbNegativeMax.b = 0; rgb rgbPositiveMax; rgbPositiveMax.r = 0; rgbPositiveMax.g = 0; rgbPositiveMax.b = 230; hsv hsvNegativeMax = rgb2hsv(rgbNegativeMax); hsv hsvPositiveMax = rgb2hsv(rgbPositiveMax); double scale; rgb result; if(startValue < 0) { if(value < 0) { scale = log10(-value+1)/log10(-startValue+1); hsvNegativeMax.s *= scale; return hsv2rgb(hsvNegativeMax); } else { scale = log10(value+1)/log10(endValue+1); hsvPositiveMax.s *= scale; return hsv2rgb(hsvPositiveMax); } } else { scale = log10(value+1)/log10(endValue+1); hsvPositiveMax.s *= scale; return hsv2rgb(hsvPositiveMax); } }
SEXP do_hsv(SEXP call, SEXP op, SEXP args, SEXP env) { SEXP c, h, s, v, gm, a; double hh, ss, vv, gg, aa, r, g, b; int i, max, nh, ns, nv, ng, na; checkArity(op, args); PROTECT(h = coerceVector(CAR(args),REALSXP)); args = CDR(args); PROTECT(s = coerceVector(CAR(args),REALSXP)); args = CDR(args); PROTECT(v = coerceVector(CAR(args),REALSXP)); args = CDR(args); PROTECT(gm = coerceVector(CAR(args),REALSXP)); args = CDR(args); PROTECT(a = coerceVector(CAR(args),REALSXP)); args = CDR(args); nh = LENGTH(h); ns = LENGTH(s); nv = LENGTH(v); ng = LENGTH(gm); na = LENGTH(a); if (nh <= 0 || ns <= 0 || nv <= 0 || ng <= 0 || na <= 0) { UNPROTECT(5); return(allocVector(STRSXP, 0)); } max = nh; if (max < ns) max = ns; if (max < nv) max = nv; if (max < ng) max = ng; if (max < na) max = na; PROTECT(c = allocVector(STRSXP, max)); if(max == 0) return(c); for (i = 0; i < max; i++) { hh = REAL(h)[i % nh]; ss = REAL(s)[i % ns]; vv = REAL(v)[i % nv]; gg = REAL(gm)[i % ng]; aa = REAL(a)[i % na]; if (hh < 0 || hh > 1 || ss < 0 || ss > 1 || vv < 0 || vv > 1 || aa < 0 || aa > 1) errorcall(call, _("invalid HSV color")); hsv2rgb(hh, ss, vv, &r, &g, &b); r = pow(r, gg); g = pow(g, gg); b = pow(b, gg); SET_STRING_ELT(c, i, mkChar(RGBA2rgb(ScaleColor(r), ScaleColor(g), ScaleColor(b), ScaleAlpha(aa)))); } UNPROTECT(6); return c; }
bool Ppm::hsv2rgbpix(void){ var_pos pos; pos = filter.p1; while(pos.y < filter.p2.y){ pos.x = filter.p1.x; while(pos.x < filter.p2.x){ setpix(pos,hsv2rgb(getpix(pos))); pos.x++; } pos.y++; } return (true); }
int flam3_get_palette(int n, flam3_palette c, double hue_rotation) { int cmap_len = 256; int idx, i, j; if (NULL == the_palettes) { char *d = getenv("flam3_palettes"); init_palettes(d ? d : (PACKAGE_DATA_DIR "/flam3-palettes.xml")); } if (flam3_palette_random == n) n = the_palettes[random()%npalettes].number; for (idx = 0; idx < npalettes; idx++) { if (n == the_palettes[idx].number) { /* Loop over elements of cmap */ for (i = 0; i < cmap_len; i++) { int ii = (i * 256) / cmap_len; double rgb[3], hsv[3]; /* Colors are in 0-1 space */ for (j = 0; j < 3; j++) rgb[j] = the_palettes[idx].colors[ii][j] / 255.0; rgb2hsv(rgb, hsv); hsv[0] += hue_rotation * 6.0; hsv2rgb(hsv, rgb); c[i].index = i; for (j = 0; j < 3; j++) c[i].color[j] = rgb[j]; c[i].color[3] = 1.0; } return n; } } fprintf(stderr, "warning: palette number %d not found, using white.\n", n); for (i = 0; i < cmap_len; i++) { c[i].index = i; for (j = 0; j < 4; j++) c[i].color[j] = 1.0; } return flam3_palette_random; }
void heatmap(float val, float min, float max, unsigned char *r, unsigned char *g, unsigned char *b) { val = (val-min)/(max-min); if( val>1 ) val=1; if( val<0 ) val=0; // In HSV color space, h=0 is red, h=240 is deep blue. // With the following formula, we have red for max values of val, and blue // for low values. const float h = 240 * (1-val); hsv2rgb(h, 1, 1, r, g, b); }