// ------------------------------------------------------------------ Color::Color(const std::string& str) { mV[0] = mV[1] = mV[2] = mV[3] = 0.0f; bool isHSV; if (str[0] == '#') { isHSV = false; } else if (str[0] == '%') { isHSV = true; } else { if (boost::algorithm::to_lower_copy(str) != "none") { throw Error("Color", "Invalid value: '" + str + "'"); } return; } // remove the @ or % std::string value = str.substr(1, str.length()); boost::algorithm::to_lower(value); if (value.find_first_of("01234567890abcdef") == std::string::npos) { throw Error("Color", "Invalid value: '" + str + "'"); } switch (value.length()) { case 3: // XYZ mV[0] = charToInt(value[0]) / 15.0f; mV[1] = charToInt(value[1]) / 15.0f; mV[2] = charToInt(value[2]) / 15.0f; mV[3] = 1.0f; break; case 4: // XYZA mV[0] = charToInt(value[0]) / 15.0f; mV[1] = charToInt(value[1]) / 15.0f; mV[2] = charToInt(value[2]) / 15.0f; mV[3] = charToInt(value[4]) / 15.0f; break; case 6: // #XXYYZZ mV[0] = ((charToInt(value[0]) << 4) + charToInt(value[1])) / 255.0f; mV[1] = ((charToInt(value[2]) << 4) + charToInt(value[3])) / 255.0f; mV[2] = ((charToInt(value[4]) << 4) + charToInt(value[5])) / 255.0f; mV[3] = 1.0f; break; case 8: // #XXYYZZAA mV[0] = ((charToInt(value[0]) << 4) + charToInt(value[1])) / 255.0f; mV[1] = ((charToInt(value[2]) << 4) + charToInt(value[3])) / 255.0f; mV[2] = ((charToInt(value[4]) << 4) + charToInt(value[5])) / 255.0f; mV[3] = ((charToInt(value[6]) << 4) + charToInt(value[7])) / 255.0f; break; default: throw Error("Color", "Invalid value: '" + str + "'"); } if (isHSV) { HSVtoRGB(); } }
int makeColors(Display *dsply, int scrn, Colormap *colorMap, unsigned long **colorIndex, int *total_Shades) { int h, s; static unsigned long *hiya; /* keep colortable around for next time */ HSV hsv; RGB rgb; XColor color; int okay = yes; /* is true (1) so long as XAllocColor is * working ok. if 0, then we ran out of room * on the color table. */ int colorNum; /* shade5 definition */ static float saturations[5] = {0.90, 0.80, 0.74, 0.50, 0.18}; static float values[5] = {0.38, 0.58, 0.75, 0.88, 0.94}; /* static float values[5] = {0.34, 0.52, 0.80, 0.88, 0.94}; */ /* fprintf(stderr,"makeColors called\n");*/ /* printf("making new colors....\n"); */ *total_Shades = totalShadesConst; /* space for color table */ hiya = (unsigned long *) saymem("spadcolors30.c", totalHuesConst * (*total_Shades) + 2, sizeof(unsigned long)); *colorIndex = hiya; for (h = 0, colorNum = 0; okay && h < 60; h += (hueStep - 6)) { for (s = 0; okay && s < *total_Shades; s++) { hsv.h = h; hsv.s = saturations[s]; hsv.v = values[s]; rgb = HSVtoRGB(hsv); color.red = rgb.r *((1<<16)-1); color.green = rgb.g *((1<<16)-1); color.blue = rgb.b *((1<<16)-1); color.flags = DoRed | DoGreen | DoBlue; /* fprintf(stderr,"%f\t%f\t%f\n",rgb.r,rgb.g,rgb.b); fprintf(stderr,"%d\t%d\t%d\n",color.red,color.green,color.blue); */ if ((okay = XAllocColor(dsply, *colorMap, &color))) hiya[colorNum++] = color.pixel; /* hiya points to table */ } /* for s */ } /* for h */ for (h = 60; okay && h < 180; h += 20) { for (s = 0; okay && s < *total_Shades; s++) { hsv.h = h; hsv.s = saturations[s]; hsv.v = values[s]; rgb = HSVtoRGB(hsv); color.red = rgb.r *((1<<16)-1); color.green = rgb.g *((1<<16)-1); color.blue = rgb.b *((1<<16)-1); color.flags = DoRed | DoGreen | DoBlue; /* fprintf(stderr,"%f\t%f\t%f\n",rgb.r,rgb.g,rgb.b); fprintf(stderr,"%d\t%d\t%d\n",color.red,color.green,color.blue); */ if ((okay = XAllocColor(dsply, *colorMap, &color))) hiya[colorNum++] = color.pixel; } } for (h = 180; okay && h <= 300; h += hueStep) { for (s = 0; okay && s < *total_Shades; s++) { hsv.h = h; hsv.s = saturations[s]; hsv.v = values[s]; rgb = HSVtoRGB(hsv); color.red = rgb.r *((1<<16)-1); color.green = rgb.g *((1<<16)-1); color.blue = rgb.b *((1<<16)-1); color.flags = DoRed | DoGreen | DoBlue; /* fprintf(stderr,"%f\t%f\t%f\n",rgb.r,rgb.g,rgb.b); fprintf(stderr,"%d\t%d\t%d\n",color.red,color.green,color.blue); */ if ((okay = XAllocColor(dsply, *colorMap, &color))) hiya[colorNum++] = color.pixel; } } hiya[colorNum++] = BlackPixel(dsply, scrn); hiya[colorNum++] = WhitePixel(dsply, scrn); if (colorNum < (totalShadesConst * totalHuesConst + 2)) { free(*colorIndex); fprintf(stderr, " > Warning: cannot allocate all the necessary colors - switching to monochrome mode\n"); *colorIndex = (unsigned long *) saymem("while allocating the colormap for FriCAS ", 2, sizeof(unsigned long)); (*colorIndex)[0] = BlackPixel(dsply, scrn); (*colorIndex)[1] = WhitePixel(dsply, scrn); return (-1); } return (colorNum); }
void * spi_handler(void) { lpd8806_buffer buf; int fd; int return_value; lpd8806_color *p; int i; double h, r, g, b; /* Open the device file using Low-Level IO */ fd = open(device,O_WRONLY); if(fd<0) { fprintf(stderr,"Error %d: %s\n",errno,strerror(errno)); pthread_exit(NULL); } /* Initialize the SPI bus for Total Control Lighting */ return_value = spi_init(fd); if(return_value==-1) { fprintf(stderr,"SPI initialization error %d: %s\n",errno, strerror(errno)); pthread_exit(NULL); } /* Initialize pixel buffer */ if(lpd8806_init(&buf,leds)<0) { fprintf(stderr,"Pixel buffer initialization error: Not enough memory.\n"); pthread_exit(NULL); } /* Set the gamma correction factors for each color */ set_gamma(2.2,2.2,2.2); /* Blank the pixels */ for(i=0;i<leds;i++) { write_gamma_color(&buf.pixels[i],0x00,0x00,0x00); } send_buffer(fd,&buf); h = 0.0; printf("Entering spi loop\n"); /* Loop while continue_looping is true */ for(;;){ pthread_mutex_lock(&playback_status_lock); if(is_playing){ h+=2.0; if(h>=360.0) h=0.0; memmove(buf.pixels+1,buf.pixels,sizeof(lpd8806_color)*(leds-2)); HSVtoRGB(h,1.0,1.0,&r,&g,&b); p = &buf.pixels[0]; write_gamma_color(p,(int)(r*255.0),(int)(g*255.0),(int)floor(b*255.0)); send_buffer(fd,&buf); } else { for(i=0;i<leds;i++) { p = &buf.pixels[i]; write_gamma_color(p,0x00,0x00,0x00); } send_buffer(fd,&buf); } pthread_mutex_unlock(&playback_status_lock); usleep(10000); } for(i=0;i<leds;i++) { p = &buf.pixels[i]; write_gamma_color(p,0x00,0x00,0x00); } send_buffer(fd,&buf); lpd8806_free(&buf); close(fd); printf("lpd thread terminated.\n"); pthread_exit(NULL); }
void LEDStripe::addHSVColor( int i, int h, int s, int v ) { uint8_t r, g, b; HSVtoRGB( h, s, v, r, g, b ); addRGBColor( i , r, g, b ); }
GColor GColor::operator+(GLfloat amt) { GLfloat h, s, v; GLfloat change = 0; RGBtoHSV(red, green, blue, &h, &s, &v); if (v > 0.75) { if (alpha < 0.4) { alpha = 0.7; change = 0.5; } if (alpha > 0.4) { //alpha; change = -0.5; } } else if (v > 0.50) { if (alpha < 0.4) { alpha = 0.7; //change = 0.50; } else { change = 0.25; //alpha = 0.75; } } else if (alpha < 0.4) { alpha = 0.7; change = 0.5; } else change = 0.5; HSVtoRGB(&red, &green, &blue, h, s, v); red = red + change; green = green + change; blue = blue + change; if (red > 1.0) red = 1.0; if (blue > 1.0) blue = 1.0; if (green > 1.0) green = 1.0; if (red < 0.0) red = 0.0; if (blue < 0.0) blue = 0.0; if (green < 0.0) green = 0.0; return GColor(red, green, blue, alpha); }
int main(int argc, char** argv) { if(!depth_open()) { printf("Unable to open libkipr_link_depth_sensor\n"); return 1; } int depth_image_height = -1; int depth_image_width = -1; int mouse_x; int mouse_y; int last_max_depth = 6000 /* mm */; int max_depth; if(set_depth_camera_resolution(DEPTH_CAMERA_RESOLUTION_640_480) == 0) { printf("Failed to set the depth camera resolution to 640 x 480\n"); return 1; } #ifdef CAMERA_IS_UPSIDE_DOWN if(set_depth_camera_orientation(DEPTH_CAMERA_ORIENTATION_UPSIDE_DOWN) == 0) { printf("Failed to set the depth camera orientation\n"); return 1; } #endif printf("Press 'Q' to stop\n"); while(!get_key_state('Q')) { if(depth_update()) { if(depth_image_height == -1) { // initialize the graphics output depth_image_height = depth_image_get_height(); depth_image_width = depth_image_get_width(); graphics_open(depth_image_width, depth_image_height); } get_mouse_position(&mouse_x, &mouse_y); max_depth = 0; // display depth image for(int y = 0; y < depth_image_height; y++) { for(int x = 0; x < depth_image_width; x++) { int depth = get_depth_value(x, y); // save max depth if(depth > max_depth) { max_depth = depth; } // color invalid depth pixel red if((depth != INVALID_COORDINATE) && last_max_depth) { int r; int g; int b; HSVtoRGB(360*0xFF*depth/last_max_depth, &r, &g, &b); graphics_pixel(x, y, r, g, b); } else { graphics_pixel(x, y, 0xFF, 0xFF, 0xFF); } #ifdef SHOW_DEPTH_UNDER_MOUSE if(mouse_x == x && mouse_y == y) { console_clear(); if(depth != INVALID_COORDINATE) { printf("(%d, %d): Depth: %d mm; World coordinate: (%d, %d, %d)\n", x, y, depth, get_world_x(x, y), get_world_y(x, y), get_world_z(x, y)); } else { printf("(%d, %d): No information available\n", x, y); } } #endif } } last_max_depth = max_depth; graphics_update(); } else { printf("No depth image received yet\n"); msleep(2000); } } graphics_close(); depth_close(); return 0; }
void LEDStripe::setHSVColor( int i, int h, int s, int v ) { uint8_t r, g, b; HSVtoRGB( h, s, v, r, g, b ); setRGBColor( i, r, g, b ); }
static void R_CreatePlayerTranslation (float h, float s, float v, const FPlayerColorSet *colorset, FPlayerSkin *skin, FRemapTable *table, FRemapTable *alttable, FRemapTable *pillartable) { int i; BYTE start = skin->range0start; BYTE end = skin->range0end; float r, g, b; float bases, basev; float sdelta, vdelta; float range; // Set up the base translation for this skin. If the skin was created // for the current game, then this is just an identity translation. // Otherwise, it remaps the colors from the skin's original palette to // the current one. if (skin->othergame) { memcpy (table->Remap, OtherGameSkinRemap, table->NumEntries); memcpy (table->Palette, OtherGameSkinPalette, sizeof(*table->Palette) * table->NumEntries); } else { for (i = 0; i < table->NumEntries; ++i) { table->Remap[i] = i; } memcpy(table->Palette, GPalette.BaseColors, sizeof(*table->Palette) * table->NumEntries); } for (i = 1; i < table->NumEntries; ++i) { table->Palette[i].a = 255; } // [GRB] Don't translate skins with color range 0-0 (APlayerPawn default) if (start == 0 && end == 0) { table->Inactive = true; table->UpdateNative(); return; } table->Inactive = false; range = (float)(end-start+1); bases = s; basev = v; if (colorset != NULL && colorset->Lump >= 0 && Wads.LumpLength(colorset->Lump) < 256) { // Bad table length. Ignore it. colorset = NULL; } if (colorset != NULL) { bool identity = true; // Use the pre-defined range instead of a custom one. if (colorset->Lump < 0) { identity &= SetRange(table, start, end, colorset->FirstColor, colorset->LastColor); for (i = 0; i < colorset->NumExtraRanges; ++i) { identity &= SetRange(table, colorset->Extra[i].RangeStart, colorset->Extra[i].RangeEnd, colorset->Extra[i].FirstColor, colorset->Extra[i].LastColor); } } else { FMemLump translump = Wads.ReadLump(colorset->Lump); const BYTE *trans = (const BYTE *)translump.GetMem(); for (i = start; i <= end; ++i) { table->Remap[i] = GPalette.Remap[trans[i]]; identity &= (trans[i] == i); table->Palette[i] = GPalette.BaseColors[table->Remap[i]]; table->Palette[i].a = 255; } } // If the colorset created an identity translation mark it as inactive table->Inactive = identity; } else if (gameinfo.gametype & GAME_DoomStrifeChex) { // Build player sprite translation s -= 0.23f; v += 0.1f; sdelta = 0.23f / range; vdelta = -0.94112f / range; for (i = start; i <= end; i++) { float uses, usev; uses = clamp (s, 0.f, 1.f); usev = clamp (v, 0.f, 1.f); HSVtoRGB (&r, &g, &b, h, uses, usev); SetRemap(table, i, r, g, b); s += sdelta; v += vdelta; } } else if (gameinfo.gametype == GAME_Heretic) { float vdelta = 0.418916f / range; // Build player sprite translation for (i = start; i <= end; i++) { v = vdelta * (float)(i - start) + basev - 0.2352937f; v = clamp (v, 0.f, 1.f); HSVtoRGB (&r, &g, &b, h, s, v); SetRemap(table, i, r, g, b); } // Build rain/lifegem translation if (alttable) { bases = MIN (bases*1.3f, 1.f); basev = MIN (basev*1.3f, 1.f); for (i = 145; i <= 168; i++) { s = MIN (bases, 0.8965f - 0.0962f*(float)(i - 161)); v = MIN (1.f, (0.2102f + 0.0489f*(float)(i - 144)) * basev); HSVtoRGB (&r, &g, &b, h, s, v); SetRemap(alttable, i, r, g, b); SetPillarRemap(pillartable, i, h, s, v); } alttable->UpdateNative(); } } else if (gameinfo.gametype == GAME_Hexen) { if (memcmp (sprites[skin->sprite].name, "PLAY", 4) == 0) { // The fighter is different! He gets a brown hairy loincloth, but the other // two have blue capes. float vs[9] = { .28f, .32f, .38f, .42f, .47f, .5f, .58f, .71f, .83f }; // Build player sprite translation //h = 45.f; v = MAX (0.1f, v); for (i = start; i <= end; i++) { HSVtoRGB (&r, &g, &b, h, s, vs[(i-start)*9/(int)range]*basev); SetRemap(table, i, r, g, b); } } else { float ms[18] = { .95f, .96f, .89f, .97f, .97f, 1.f, 1.f, 1.f, .97f, .99f, .87f, .77f, .69f, .62f, .57f, .47f, .43f }; float mv[18] = { .16f, .19f, .22f, .25f, .31f, .35f, .38f, .41f, .47f, .54f, .60f, .65f, .71f, .77f, .83f, .89f, .94f, 1.f }; // Build player sprite translation v = MAX (0.1f, v); for (i = start; i <= end; i++) { HSVtoRGB (&r, &g, &b, h, ms[(i-start)*18/(int)range]*bases, mv[(i-start)*18/(int)range]*basev); SetRemap(table, i, r, g, b); } } } if (gameinfo.gametype == GAME_Hexen && alttable != NULL) { // Build Hexen's lifegem translation. // Is the player's translation range the same as the gem's and we are using a // predefined translation? If so, then use the same one for the gem. Otherwise, // build one as per usual. if (colorset != NULL && start == 164 && end == 185) { *alttable = *table; } else { for (i = 164; i <= 185; ++i) { const PalEntry *base = &GPalette.BaseColors[i]; float dummy; RGBtoHSV (base->r/255.f, base->g/255.f, base->b/255.f, &dummy, &s, &v); HSVtoRGB (&r, &g, &b, h, s*bases, v*basev); SetRemap(alttable, i, r, g, b); } } alttable->UpdateNative(); } table->UpdateNative(); }
//----------------------------------------------------------------------------- // Purpose: // TFTODO: Make the sniper dot get brighter the more damage it will do. //----------------------------------------------------------------------------- int CSniperDot::DrawModel( int flags ) { // Get the owning player. C_TFPlayer *pPlayer = ToTFPlayer( GetOwnerEntity() ); if ( !pPlayer ) return -1; // Get the sprite rendering position. Vector vecEndPos; float flSize = 6.0; if ( !pPlayer->IsDormant() ) { Vector vecAttachment, vecDir; QAngle angles; float flDist = MAX_TRACE_LENGTH; // Always draw the dot in front of our faces when in first-person. if ( pPlayer->IsLocalPlayer() ) { // Take our view position and orientation vecAttachment = CurrentViewOrigin(); vecDir = CurrentViewForward(); // Clamp the forward distance for the sniper's firstperson flDist = 384; flSize = 2.0; } else { // Take the owning player eye position and direction. vecAttachment = pPlayer->EyePosition(); QAngle angles = pPlayer->EyeAngles(); AngleVectors( angles, &vecDir ); } trace_t tr; UTIL_TraceLine( vecAttachment, vecAttachment + ( vecDir * flDist ), MASK_SHOT, pPlayer, COLLISION_GROUP_NONE, &tr ); // Backup off the hit plane, towards the source vecEndPos = tr.endpos + vecDir * -4; } else { // Just use our position if we can't predict it otherwise. vecEndPos = GetAbsOrigin(); } // Draw our laser dot in space. CMatRenderContextPtr pRenderContext( materials ); pRenderContext->Bind( m_hSpriteMaterial, this ); float flLifeTime = gpGlobals->curtime - m_flChargeStartTime; float flStrength = RemapValClamped( flLifeTime, 0.0, TF_WEAPON_SNIPERRIFLE_DAMAGE_MAX / TF_WEAPON_SNIPERRIFLE_CHARGE_PER_SEC, 0.1, 1.0 ); color32 innercolor = { 255, 255, 255, 255 }; color32 outercolor = { 255, 255, 255, 128 }; // PistonMiner: DM sniper point coloring if (TFGameRules()->IsDeathmatch()) { // Get the color of the mercenary we are drawing the dot of. C_TF_PlayerResource *tf_PR = dynamic_cast<C_TF_PlayerResource *>(g_PR); Color ownercolor = tf_PR->GetPlayerColor(pPlayer->index); // Convert to HSV so we can edit the color better. Vector hsv, rgb; RGBtoHSV(Vector(ownercolor.r() / 255.f, ownercolor.g() / 255.f, ownercolor.b() / 255.f), hsv); // Set the Value to max for constant brightness. hsv.z = 1.0; // Convert back to RGB HSVtoRGB(hsv, rgb); // Apply the color to our sprite. m_hSpriteMaterial->ColorModulate( rgb.x, rgb.y, rgb.z ); } DrawSprite( vecEndPos, flSize, flSize, outercolor ); DrawSprite( vecEndPos, flSize * flStrength, flSize * flStrength, innercolor ); // Successful. return 1; }
void HexagonView::Draw(sf::RenderTarget* rt) const { if(!m_model) { return; } const double time = m_model->GetTime(); const double hexagonRadius = 1.0 + 0.15 * sin(time * 10); const double playerRadius = 1.4; const int numSides = m_model->GetNumSides(); const double zoom = 1.0; const double w = zoom * 16; const double h = zoom * 9; sf::View view(sf::FloatRect(-w/2,-h/2,w,h)); view.setRotation(m_model->GetRotation()); rt->setView(view); //Draw bg sf::ConvexShape bgSide(4); for(int i = 0; i < numSides; ++i) { bgSide.setFillColor(HSVtoRGB(Hue(), Sat(), 0.8)); const double in = hexagonRadius - 0.1 + 0.05 * sin(time * 5); ConstructSideShape(bgSide, i, numSides, in, hexagonRadius); rt->draw(bgSide); bgSide.setFillColor(HSVtoRGB(Hue(), Sat(), 0.2)); ConstructSideShape(bgSide, i, numSides, 0, in); rt->draw(bgSide); if(i % 2) { bgSide.setFillColor(HSVtoRGB(Hue(), Sat(), 0.2)); } else { bgSide.setFillColor(HSVtoRGB(Hue(), Sat(), 0.3)); } ConstructSideShape(bgSide, i, numSides, hexagonRadius, 32); rt->draw(bgSide); } //Draw obstacles sf::ConvexShape obsShape(4); obsShape.setFillColor(HSVtoRGB(Hue(), Sat(), 0.8)); for(int i = 0; i < numSides; i++) { Obstacle* obs = m_model->GetObstacle(i); while(obs) { const double pd = m_model->GetPlayerDistance(); double start = obs->start - pd + playerRadius; const double end = start + obs->end - obs->start; if(start < hexagonRadius) { start = hexagonRadius; } if(end > hexagonRadius) { ConstructSideShape(obsShape, i, numSides, start, end); rt->draw(obsShape); } obs = obs->next; } } //Draw player if(m_drawPlayer) { sf::ConvexShape playerShape(3); const double pos = m_model->GetPlayerPosition(); //Get the two corners the player is between const int posMin = floor(pos); const int posMax = ceil(pos); const double posMinX = playerRadius * cos(posMin * 2 * M_PI / numSides); const double posMinY = playerRadius * sin(posMin * 2 * M_PI / numSides); const double posMaxX = playerRadius * cos(posMax * 2 * M_PI / numSides); const double posMaxY = playerRadius * sin(posMax * 2 * M_PI / numSides); const double lerp = pos - posMin; const double posX = LInterp(lerp, posMinX, posMaxX); const double posY = LInterp(lerp, posMinY, posMaxY); const double pulseScale = 0.1 + 0.025 * sin(time * 10); const double turnMod = m_model->IsGameOver() ? 0 : m_model->GetPlayerDirection() * 15; playerShape.setPoint(0, sf::Vector2f( -0.20, -pulseScale ) ); playerShape.setPoint(1, sf::Vector2f( 0, 0 ) ); playerShape.setPoint(2, sf::Vector2f( -0.20, pulseScale ) ); playerShape.setFillColor(HSVtoRGB(Hue(), Sat(), 1.0)); playerShape.setPosition(posX,posY); playerShape.setRotation(pos * 360 / numSides + turnMod); rt->draw(playerShape); } }
CornellBox::CornellBox() { Ray c(Vec3<double>(50,52,295.6),Vec3<double>(0,-0.042612,-1).norm()); setCamera(c); std::mt19937 gen(RANDOM()); std::normal_distribution<> sized(sizecenter,5); std::normal_distribution<> posd(40,10); auto hsv2vec3 = [](float h, float s, float v) { float r,g,b; HSVtoRGB(&r,&g,&b,h,s,v); return Vec3<double>(r,g,b); }; auto clamp = [](float v) { if(v < 0) return 0.0f; if(v > 1) return 1.0f; return v; }; auto randColor = [&](){ const float rate = 2; std::exponential_distribution<> d(rate+1); std::uniform_real_distribution<float> h(0,360); return hsv2vec3( h(gen), clamp((rate-d(gen))/rate), clamp((rate-d(gen))/rate) ); }; // Set objects auto makeWall = [&](Vec3<double> p, Vec3<double> c) { auto s = new Sphere(1e5); s->position = p; s->color = c; s->material_type = M_DIFFUSE; addShape(s); }; auto makeLight = [&](Vec3<double> p, Vec3<double> c) { auto s = new Sphere(600); s->position = p; s->emission = c; s->material_type = M_DIFFUSE; addShape(s); }; auto makeGlass = [&](double size, Vec3<double> p) { if(size == -1) { size = sized(gen); if(size < 1) size = 1; p.y += size; if(p.x - size < 0) p.x = size; if(p.z - size < 0) p.z = size; if(p.x + size > 81.6) p.x = 81.6 - size; if(p.z + size > 81.6) p.z = 81.6 - size; } auto s = new Sphere(size); s->position = p; s->color = Vec3<double>(1,1,1)*.999; s->material_type = M_REFRACTION; addShape(s); }; auto makeMirror = [&](double size, Vec3<double> p) { if(size == -1) { size = sized(gen); if(size < 1) size = 1; p.y += size; if(p.x - size < 0) p.x = size; if(p.z - size < 0) p.z = size; if(p.x + size > 81.6) p.x = 81.6 - size; if(p.z + size > 81.6) p.z = 81.6 - size; } auto s = new Sphere(size); s->position = p; s->color = Vec3<double>(1,1,1)*.999; s->material_type = M_SPECULAR; addShape(s); }; makeWall(Vec3<double>(1e5+1,40.8,81.6), randColor()); // right makeWall(Vec3<double>(-1e5+99,40.8,81.6), randColor());// left makeWall(Vec3<double>(50,40.8, 1e5), Vec3<double>(.75,.75,.75)); // back makeWall(Vec3<double>(50, 1e5, 81.6),Vec3<double>(.75,.75,.75)); // top makeWall(Vec3<double>(50,-1e5+81.6,81.6),Vec3<double>(.75,.75,.75)); // bottom makeGlass(-1, Vec3<double>(posd(gen)+5,posd(gen),posd(gen)/2+40)); makeMirror(-1, Vec3<double>(posd(gen)-5,0,posd(gen))); makeLight(Vec3<double>(50,681.6-0.27,81.6),Vec3<double>(12,12,12)); enumerateLights(); }
void HSVtoRGB (const Vector3f &hsv, Vector3f &rgb) { HSVtoRGB (hsv, rgb.r, rgb.g, rgb.b); }
void HSVtoRGB (const Vector3f &hsv, float &r,float &g,float &b) { HSVtoRGB (hsv.x, hsv.y, hsv.z, r, g, b); }
static void render(ThreadInfo* t) { RS_IMAGE16 *image = t->tmp; RSDcp *dcp = t->dcp; gint x, y; gfloat h, s, v; gfloat r, g, b; RS_VECTOR3 pix; gboolean do_contrast = (dcp->contrast > 1.001f); gboolean do_highrec = (dcp->contrast < 0.999f); float contr_base = 0.5; float exposure_simple = MAX(1.0, powf(2.0f, dcp->exposure)); float recover_radius = 0.5 * exposure_simple; float inv_recover_radius = 1.0f / recover_radius; recover_radius = 1.0 - recover_radius; RS_VECTOR3 clip; clip.R = dcp->camera_white.R; clip.G = dcp->camera_white.G; clip.B = dcp->camera_white.B; for(y = t->start_y ; y < t->end_y; y++) { for(x=t->start_x; x < image->w; x++) { gushort *pixel = GET_PIXEL(image, x, y); /* Convert to float */ r = _F(pixel[R]); g = _F(pixel[G]); b = _F(pixel[B]); if (dcp->use_profile) { r = MIN(clip.R, r); g = MIN(clip.G, g); b = MIN(clip.B, b); } pix.R = r; pix.G = g; pix.B = b; pix = vector3_multiply_matrix(&pix, &dcp->camera_to_prophoto); r = pix.R; g = pix.G; b = pix.B; r = CLAMP(r * dcp->channelmixer_red, 0.0, 1.0); g = CLAMP(g * dcp->channelmixer_green, 0.0, 1.0); b = CLAMP(b * dcp->channelmixer_blue, 0.0, 1.0); /* To HSV */ RGBtoHSV(r, g, b, &h, &s, &v); if (dcp->huesatmap) huesat_map(dcp->huesatmap, &h, &s, &v); /* Saturation */ if (dcp->saturation > 1.0) { /* Apply curved saturation, when we add saturation */ float sat_val = dcp->saturation - 1.0f; s = (sat_val * (s * 2.0f - (s * s))) + ((1.0f - sat_val) * s); s = MIN(s, 1.0); } else { s *= dcp->saturation; s = MIN(s, 1.0); } /* Hue */ h += dcp->hue; /* Back to RGB */ HSVtoRGB(h, s, v, &r, &g, &b); /* Exposure Compensation */ r = exposure_ramp(dcp, r); g = exposure_ramp(dcp, g); b = exposure_ramp(dcp, b); /* Contrast in gamma 2.0 */ if (do_contrast) { r = MAX((sqrtf(r) - contr_base) * dcp->contrast + contr_base, 0.0f); r *= r; g = MAX((sqrtf(g) - contr_base) * dcp->contrast + contr_base, 0.0f); g *= g; b = MAX((sqrtf(b) - contr_base) * dcp->contrast + contr_base, 0.0f); b *= b; } else if (do_highrec) { /* Distance from 1.0 - radius */ float dist = v - recover_radius; /* Scale so distance is normalized, clamp */ float dist_scaled = MIN(1.0, dist * inv_recover_radius); float mul_val = 1.0 - dist_scaled * (1.0 - dcp->contrast); r = r * mul_val; g = g * mul_val; b = b * mul_val; } /* To HSV */ r = MIN(r, 1.0f); g = MIN(g, 1.0f); b = MIN(b, 1.0f); RGBtoHSV(r, g, b, &h, &s, &v); /* Curve */ if (dcp->read_out_curve) { gfloat t1 = v,t2,t3; if (dcp->tone_curve_lut) { t2 = t3 = v; rgb_tone(&t1, &t2, &t3, dcp->tone_curve_lut); } int input = (int)(CLAMP(sqrtf(t1) * 256.0f, 0.0f, 255.9999f)); t->curve_input_values[input]++; } if (!dcp->curve_is_flat) { gfloat lookup = CLAMP(v * 256.0f, 0.0f, 255.9999f); gfloat v0 = dcp->curve_samples[(gint)lookup*2]; gfloat v1 = dcp->curve_samples[(gint)lookup*2 + 1]; lookup -= floorf(lookup); v = v0 * (1.0f - lookup) + v1 * lookup; } if (dcp->looktable) huesat_map(dcp->looktable, &h, &s, &v); /* Back to RGB */ HSVtoRGB(h, s, v, &r, &g, &b); /* Apply tone curve */ if (dcp->tone_curve_lut) rgb_tone(&r, &g, &b, dcp->tone_curve_lut); /* Save as gushort */ pixel[R] = _S(r); pixel[G] = _S(g); pixel[B] = _S(b); } } }
static void R_LoadLightmaps( lump_t *l, const char *psMapName, world_t &worldData ) { byte *buf, *buf_p; int len; byte image[LIGHTMAP_SIZE*LIGHTMAP_SIZE*4]; int i, j; float maxIntensity = 0; double sumIntensity = 0; int count; if (&worldData == &s_worldData) { tr.numLightmaps = 0; } len = l->filelen; if ( !len ) { return; } buf = fileBase + l->fileofs; // we are about to upload textures //R_SyncRenderThread(); // create all the lightmaps worldData.startLightMapIndex = tr.numLightmaps; count = len / (LIGHTMAP_SIZE * LIGHTMAP_SIZE * 3); tr.numLightmaps += count; // if we are in r_vertexLight mode, we don't need the lightmaps at all if ( r_vertexLight->integer ) { return; } char sMapName[MAX_QPATH]; COM_StripExtension(psMapName,sMapName, sizeof(sMapName)); for ( i = 0 ; i < count ; i++ ) { // expand the 24 bit on-disk to 32 bit buf_p = buf + i * LIGHTMAP_SIZE*LIGHTMAP_SIZE * 3; if ( r_lightmap->integer == 2 ) { // color code by intensity as development tool (FIXME: check range) for ( j = 0; j < LIGHTMAP_SIZE * LIGHTMAP_SIZE; j++ ) { float r = buf_p[j*3+0]; float g = buf_p[j*3+1]; float b = buf_p[j*3+2]; float intensity; float out[3]; intensity = 0.33f * r + 0.685f * g + 0.063f * b; if ( intensity > 255 ) intensity = 1.0f; else intensity /= 255.0f; if ( intensity > maxIntensity ) maxIntensity = intensity; HSVtoRGB( intensity, 1.00, 0.50, out ); image[j*4+0] = out[0] * 255; image[j*4+1] = out[1] * 255; image[j*4+2] = out[2] * 255; image[j*4+3] = 255; sumIntensity += intensity; } } else { for ( j = 0 ; j < LIGHTMAP_SIZE * LIGHTMAP_SIZE; j++ ) { R_ColorShiftLightingBytes( &buf_p[j*3], &image[j*4] ); image[j*4+3] = 255; } } tr.lightmaps[worldData.startLightMapIndex+i] = R_CreateImage( va("$%s/lightmap%d",sMapName,worldData.startLightMapIndex+i), image, LIGHTMAP_SIZE, LIGHTMAP_SIZE, GL_RGBA, qfalse, qfalse, r_ext_compressed_lightmaps->integer, GL_CLAMP ); } if ( r_lightmap->integer == 2 ) { ri.Printf( PRINT_ALL, "Brightest lightmap value: %d\n", ( int ) ( maxIntensity * 255 ) ); } }
int* quantize(char r, char g, char b){ //convert from uint8 to int32, if you try to pass directly you FAIL!!! int tempr, tempb, tempg; tempr = r&0xFF; tempg = g&0xFF; tempb = b&0xFF; //printf("%d, %d, %d\n", tempr, tempg, tempb); float* Qhsv, *HSV = RGBtoHSV(tempr/256.f, tempg/256.f, tempb/256.f); int* RGB = (int*)malloc(sizeof(int)*3); float h, s, v; h = HSV[0]; s = HSV[1]; v = HSV[2]; //clamp h if (((h >= -15.0f) && (h < 15.0f)) || ((h >= 345.0f) && (h < 375.0f))){ h = 0.f; } else if ((h >= 15.0f) && (h < 45.0f)){ h = 30.0f; } else if ((h >= 45.0f) && (h < 75.0f)){ h = 60.0f; } else if ((h >= 75.0f) && (h < 105.0f)){ h = 90.0f; } else if ((h >= 105.0f) && (h < 135.0f)){ h = 120.0f; } else if ((h >= 135.0f) && (h < 165.0f)){ h = 150.0f; } else if ((h >= 165.0f) && (h < 195.0f)){ h = 180.0f; } else if ((h >= 195.0f) && (h < 225.0f)){ h = 210.0f; } else if ((h >=225.0f) && (h < 255.0f)) { h = 240.0f; } else if ((h >= 255.0f) && (h < 285.0f)){ h = 270.0f; } else if ((h >=285.0f) && (h < 315.0f)){ h = 300.0f; } else if ((h >= 315.0f) && (h < 345.0f)){ h = 330.0f; } //clamp s // SMR: My modified clamping to handle boundery conditions /* if(s < .15) s = .0f; else if(s >= .15 && s < .45) s = .3f; else if(s >= .45 && s < .75) s = .6f; else s = 1.f; */ if(v < .15) v = .0f; else if(v >= .15 && v < .45) v = .3f; else if(v >= .45 && v < .75) v = .6f; else v = 1.f; Qhsv = HSVtoRGB(h,s,v); RGB[0] = (int)Qhsv[0]; RGB[1] = (int)Qhsv[1]; RGB[2] = (int)Qhsv[2]; free(HSV); free(Qhsv); return RGB; }
Color HsvColorf(double h, double s, double v) { double r, g, b; HSVtoRGB(h, s, v, r, g, b); return Color(min(int(r * 255), 255), min(int(g * 255), 255), min(int(b * 255), 255)); }
/* * draw * * This function performs the OpenGL drawing everything it is necessary. This * usually happens when the window is first presented, or any time all or * part of the window is unhidden. */ int IColorSelect::execGL(void) { unsigned char red, green, blue; /* our selected color */ //HSVtoRGB(ourhue, 1.0, 1.0, red, green, blue); HSVtoRGB(ourhue, 1.0, 1.0, &red, &green, &blue); /* draw the s and v box */ /*************************** White to Pure Color part ***************************/ glBegin(GL_QUADS); /* white s=0, v=1 */ HSVtoRGB(ourhue, 0.0, 1.0, &red, &green, &blue); GColor(red / 255.0, green / 255.0, blue / 255.0).execGL(); glVertex3f((2 * OUTER_R) + 5.0 + location.getX(), location.getY(), 0.0); glVertex3f((2 * OUTER_R) + 5.0 + 5.0 + location.getX(), location.getY(), 0.0); /* Pure Color (Hue) s=1,v=1)*/ HSVtoRGB(ourhue, 1.0, 1.0, &red, &green, &blue); GColor(red / 255.0, green / 255.0, blue / 255.0).execGL(); glVertex3f((2 * OUTER_R) + 5.0 + 5.0 + location.getX(), -(2*OUTER_R) + location.getY(), 0.0); glVertex3f((2 * OUTER_R) + 5.0 + location.getX(), -(2*OUTER_R) + location.getY(), 0.0); glEnd(); /*************************** Pure Color to Black part ***************************/ glBegin(GL_QUADS); /* Pure Color (Hue) s=1,v=1)*/ HSVtoRGB(ourhue, 0.0, 0.0, &red, &green, &blue); GColor(red / 255.0, green / 255.0, blue / 255.0).execGL(); glVertex3f((2 * OUTER_R) + 15.0 + location.getX(), location.getY(), 0.0); glVertex3f((2 * OUTER_R) + 15.0 + 5.0 + location.getX(), location.getY(), 0.0); /* Pure Color (Hue) s=1,v=1)*/ HSVtoRGB(ourhue, 1.0, 1.0, &red, &green, &blue); GColor(red / 255.0, green / 255.0, blue / 255.0).execGL(); glVertex3f((2 * OUTER_R) + 15.0 + 5.0 + location.getX(), -(2*OUTER_R) + location.getY(), 0.0); glVertex3f((2 * OUTER_R) + 15.0 + location.getX(), -(2*OUTER_R) + location.getY(), 0.0); glEnd(); /* the circle */ GColor(1.0, 0.0, 1.0).execGL(); glBegin(GL_TRIANGLE_STRIP); int i; float theta; GLfloat x, y; for (i = 0; i < CIRCLE_PTS; i++) { theta = (4 * PI) * ((i / (float) CIRCLE_PTS) / 2); /* if even, inner radius */ if (i % 2) { x = INNER_R * sin(theta); y = INNER_R * cos(theta); } /* else odd, outer radius */ else { x = OUTER_R * sin(theta); y = OUTER_R * cos(theta); } float color_deg = (theta/20*PI) * 360; HSVtoRGB(color_deg, 1.0, 1.0, &red, &green, &blue); GColor(red / 255.0, green / 255.0, blue / 255.0).execGL(); glVertex3f(location.getX() + OUTER_R + x, y - OUTER_R + location.getY(), 0.0); } glEnd(); /* -------------- Marker Circles ---------------*/ /* inner circle that points to color positions (inner marker)*/ GColor(1.0, 1.0, 1.0).execGL(); glBegin(GL_TRIANGLE_STRIP); int a; float theta_1; GLfloat ax, ay; for (a = 0; a < 1000; a++) { theta_1 = (4 * PI) * ((a / (float) 1000 ) / 2); /* if even, inner radius */ if (a % 2) { //ax = 0.05 * sin(theta_1) + imark_x; //ay = 0.05 * cos(theta_1) + imark_y; ax = 1.0 * sin(theta_1) + imark_x; ay = 1.0 * cos(theta_1) + imark_y; } /* else odd, outer radius */ else { //ax = 0.1 * sin(theta_1) + imark_x; //ay = 0.1 * cos(theta_1) + imark_y; ax = 0.5 * sin(theta_1) + imark_x; ay = 0.5 * cos(theta_1) + imark_y; } glVertex3f(ax,ay, 0.2); } glEnd(); /* outer circle that points to color positions(outer marker)*/ GColor(1.0, 1.0, 1.0).execGL(); glBegin(GL_TRIANGLE_STRIP); for (a = 0; a < 1000; a++) { theta_1 = (4 * PI) * ((a / (float) 1000 ) / 2); /* if even, inner radius */ if (a % 2) { ax = 1.0 * sin(theta_1) + omark_x; ay = 1.0 * cos(theta_1) + omark_y; } /* else odd, outer radius */ else { ax = 0.5 * sin(theta_1) + omark_x; ay = 0.5 * cos(theta_1) + omark_y; } glVertex3f(ax,ay, 0.2); } glEnd(); GColor(1.0, 1.0, 1.0).execGL(); glBegin(GL_TRIANGLE_STRIP); for (a = 0; a < 1000; a++) { theta_1 = (4 * PI) * ((a / (float) 1000 ) / 2); /* if even, inner radius */ if (a % 2) { ax = 1.0 * sin(theta_1) + fmark_x; ay = 1.0 * cos(theta_1) + fmark_y; } /* else odd, outer radius */ else { ax = 0.5 * sin(theta_1) + fmark_x; ay = 0.5 * cos(theta_1) + fmark_y; } glVertex3f(ax,ay, 0.2); } glEnd(); HSVtoRGB(ourhue, s_val, v_val, &red, &green, &blue); GColor(red / 255.0, green / 255.0, blue / 255.0).execGL(); exportRed = red / 255.0; exportGreen = green / 255.0; exportBlue = blue / 255.0; return 1; }
static void DoPrintStr(const char *cp, HWND edit, HANDLE StdOut) { if (edit == NULL && StdOut == NULL) return; char buf[256]; wchar_t wbuf[countof(buf)]; int bpos = 0; CHARRANGE selection; CHARRANGE endselection; LONG lines_before = 0, lines_after; CHARFORMAT format; if (edit != NULL) { // Store the current selection and set it to the end so we can append text. SendMessage(edit, EM_EXGETSEL, 0, (LPARAM)&selection); endselection.cpMax = endselection.cpMin = GetWindowTextLength(edit); SendMessage(edit, EM_EXSETSEL, 0, (LPARAM)&endselection); // GetWindowTextLength and EM_EXSETSEL can disagree on where the end of // the text is. Find out what EM_EXSETSEL thought it was and use that later. SendMessage(edit, EM_EXGETSEL, 0, (LPARAM)&endselection); // Remember how many lines there were before we added text. lines_before = (LONG)SendMessage(edit, EM_GETLINECOUNT, 0, 0); } while (*cp != 0) { // 28 is the escape code for a color change. if ((*cp == 28 && bpos != 0) || bpos == 255) { buf[bpos] = 0; if (edit != NULL) { ToEditControl(edit, buf, wbuf, bpos); } if (StdOut != NULL) { DWORD bytes_written; WriteFile(StdOut, buf, bpos, &bytes_written, NULL); } bpos = 0; } if (*cp != 28) { buf[bpos++] = *cp++; } else { const BYTE *color_id = (const BYTE *)cp + 1; EColorRange range = V_ParseFontColor(color_id, CR_UNTRANSLATED, CR_YELLOW); cp = (const char *)color_id; if (range != CR_UNDEFINED) { // Change the color of future text added to the control. PalEntry color = V_LogColorFromColorRange(range); if (StdOut != NULL && FancyStdOut) { // Unfortunately, we are pretty limited here: There are only // eight basic colors, and each comes in a dark and a bright // variety. float h, s, v, r, g, b; WORD attrib = 0; RGBtoHSV(color.r / 255.f, color.g / 255.f, color.b / 255.f, &h, &s, &v); if (s != 0) { // color HSVtoRGB(&r, &g, &b, h, 1, 1); if (r == 1) attrib = FOREGROUND_RED; if (g == 1) attrib |= FOREGROUND_GREEN; if (b == 1) attrib |= FOREGROUND_BLUE; if (v > 0.6) attrib |= FOREGROUND_INTENSITY; } else { // gray if (v < 0.33) attrib = FOREGROUND_INTENSITY; else if (v < 0.90) attrib = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; else attrib = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY; } SetConsoleTextAttribute(StdOut, attrib); } if (edit != NULL) { // GDI uses BGR colors, but color is RGB, so swap the R and the B. swapvalues(color.r, color.b); // Change the color. format.cbSize = sizeof(format); format.dwMask = CFM_COLOR; format.dwEffects = 0; format.crTextColor = color; SendMessage(edit, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&format); } } } } if (bpos != 0) { buf[bpos] = 0; if (edit != NULL) { ToEditControl(edit, buf, wbuf, bpos); } if (StdOut != NULL) { DWORD bytes_written; WriteFile(StdOut, buf, bpos, &bytes_written, NULL); } } if (edit != NULL) { // If the old selection was at the end of the text, keep it at the end and // scroll. Don't scroll if the selection is anywhere else. if (selection.cpMin == endselection.cpMin && selection.cpMax == endselection.cpMax) { selection.cpMax = selection.cpMin = GetWindowTextLength (edit); lines_after = (LONG)SendMessage(edit, EM_GETLINECOUNT, 0, 0); if (lines_after > lines_before) { SendMessage(edit, EM_LINESCROLL, 0, lines_after - lines_before); } } // Restore the previous selection. SendMessage(edit, EM_EXSETSEL, 0, (LPARAM)&selection); // Give the edit control a chance to redraw itself. I_GetEvent(); } if (StdOut != NULL && FancyStdOut) { // Set text back to gray, in case it was changed. SetConsoleTextAttribute(StdOut, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE); } }
void Libration_Process( void *pvParameters ) // { unsigned char i=0,j=0,k=0; struct led_channel hsv_channels_lib[LED_CHNL_NUM]= { {100,155,149}, {110,175,10}, {120,200,20}, {130,240,149} }; unsigned char vol_flags[]={0,0,0,0}; unsigned char hue_flags[]={0,0,0,0}; unsigned char sat_flags[]={0,0,0,0}; while(1) { vTaskDelay(20); for(i=0;i<4;i++) { HSVtoRGB(i+1,hsv_channels_lib[i].hue,hsv_channels_lib[i].saturation,hsv_channels_lib[i].volume); if(hue_flags[i]==0) { hsv_channels_lib[i].hue++; if(hsv_channels_lib[i].hue==150) { hue_flags[i]=1; } } else { hsv_channels_lib[i].hue--; if(hsv_channels_lib[i].hue==0) { hue_flags[i]=0; } } if(k==3) { k=0; if(sat_flags[i]==0) { hsv_channels_lib[i].saturation++; if(hsv_channels_lib[i].saturation==255) { sat_flags[i]=1; } } else { hsv_channels_lib[i].saturation--; if(hsv_channels_lib[i].saturation==120) { sat_flags[i]=0; } } } k++; if(j==2) { j=0; if(vol_flags[i]==0) { hsv_channels_lib[i].volume++; if(hsv_channels_lib[i].volume==255) { vol_flags[i]=1; } } else { hsv_channels_lib[i].volume--; if(hsv_channels_lib[i].volume==50) { vol_flags[i]=0; } } } j++; } } }
void LEDStripe::setHSVLineColor( int start, int end, int h, int s, int v ) { uint8_t r, g, b; HSVtoRGB( h, s, v, r, g, b ); setRGBLineColor( start, end, r, g, b ); }
Color HSVtoRGB(double h, double s, double v) { double r, g, b; HSVtoRGB(h, s, v, r, g, b); return Color(fround(r * 255.0), fround(g * 255.0), fround(b * 255.0)); }
void LEDStripe::addFullHSVColor( int h, int s, int v ) { uint8_t r, g, b; HSVtoRGB( h, s, v, r, g, b ); addFullRGBColor( r, g, b ); }
void ColourChannel_OnPaint(HWND hWnd) { PAINTSTRUCT ps; RECT rect; HDC hDC; HBITMAP hBM, hBMOld; BITMAPINFO bmi; int height, width, x, y, slider_pos; ColourChannel_Data *ccd; UINT * ptPixels; // Start painting BeginPaint(hWnd, &ps); // Find our area to paint GetClientRect(hWnd, &rect); // Find the height/width height = (rect.bottom - rect.top); width = (rect.right - rect.left); // Prep bitmap info ZeroMemory(&bmi,sizeof(BITMAPINFO)); bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bmi.bmiHeader.biWidth = width; bmi.bmiHeader.biHeight = height; bmi.bmiHeader.biPlanes = 1; bmi.bmiHeader.biBitCount = 32; // Off-screen DC hDC = CreateCompatibleDC(ps.hdc); hBM = CreateDIBSection(hDC, &bmi, DIB_RGB_COLORS, (void **)&ptPixels, NULL, 0); hBMOld = (HBITMAP)SelectObject(hDC, hBM); ccd = (ColourChannel_Data*)GetWindowLong(hWnd, GWL_USERDATA); for (y = 0; y < height; y++) { COLORREF col; switch (ccd->mode) { case CHANNEL_MODE_H: { col = HSVtoRGB(y * 359 / (height-1), 100, 100); slider_pos = ccd->c->h * (height-1) / 359; break; } case CHANNEL_MODE_S: { col = RealRGB(y * 255 / (height-1), y * 255 / (height-1), y * 255 / (height-1)); slider_pos = ccd->c->s * (height-1) / 100; break; } case CHANNEL_MODE_V: { col = RealRGB(y * 255 / (height-1), y * 255 / (height-1), y * 255 / (height-1)); slider_pos = ccd->c->v * (height-1) / 100; break; } case CHANNEL_MODE_R: { col = RealRGB(y * 255 / (height-1), 0, 0); slider_pos = ccd->c->r * (height-1) / 255; break; } case CHANNEL_MODE_G: { col = RealRGB(0, y * 255 / (height-1), 0); slider_pos = ccd->c->g * (height-1) / 255; break; } case CHANNEL_MODE_B: { col = RealRGB(0, 0, y * 255 / (height-1)); slider_pos = ccd->c->b * (height-1) / 255; break; } } for (x = 0; x < width; x++) ptPixels[x + y * width] = col; } // Left slider bit for (y = slider_pos - 2; y <= slider_pos + 2; y++) { if (y < 0 || y >= height) continue; ptPixels[y * width] = 0x00000000; } for (y = slider_pos - 1; y <= slider_pos + 1; y++) { if (y < 0 || y >= height) continue; ptPixels[y * width + 1] = 0x00000000; } ptPixels[slider_pos * width + 2] = 0x00000000; ptPixels[slider_pos * width + 3] = 0x00000000; // Right slider bit for (y = slider_pos - 2; y <= slider_pos + 2; y++) { if (y < 0 || y >= height) continue; ptPixels[(width - 1) + y * width] = 0x00FFFFFF; } for (y = slider_pos - 1; y <= slider_pos + 1; y++) { if (y < 0 || y >= height) continue; ptPixels[(width - 2) + y * width] = 0x00FFFFFF; } ptPixels[(width - 3) + slider_pos * width] = 0x00FFFFFF; ptPixels[(width - 4) + slider_pos * width] = 0x00FFFFFF; // Copy data over to real DC BitBlt(ps.hdc, rect.left, rect.top, (rect.right - rect.left), (rect.bottom - rect.top), hDC, rect.left, rect.top, SRCCOPY); SelectObject(hDC, hBMOld); DeleteObject(hBM); DeleteDC(hDC); // End painting EndPaint(hWnd, &ps); }