/* raster callback (virtual HBLANK) */ static void raster_callback (int line) { int pos =- 1; RGB color; if (line==1) pos = pos_background[0]; else if (line==32) pos = pos_background[1]; else if (line==48) pos = pos_background[2]; else if (line==64) pos = pos_background[3]; else if (line==112) pos = pos_background[4]; else if (line >= 152) pos = lerp (line, 152,224, pos_background[4], pos_background[5]); if (pos != -1) TLN_SetLayerPosition (LAYER_BACKGROUND, fix2int(pos), 0); /* background color gradients */ if (line < 112) { InterpolateColor (line, 0,112, &sky[0], &sky[1], &color); TLN_SetBGColor (color.r, color.g, color.b); } else if (line >= 144) { InterpolateColor (line, 144,HEIGHT, &sky[2], &sky[3], &color); TLN_SetBGColor (color.r, color.g, color.b); } }
void CGradientEditor::OnDraw(HDC hDC, const LPRECT clientRect) { this->clientRect = clientRect; for (int x = clientRect->left; x < clientRect->right; x++) { double point = Interpolate(x, clientRect->left, clientRect->right, 0.0, 1.0); COLORREF color = MultiplyColors(tint, gradient->ColorAtPoint(point)); SelectObject(hDC, GetStockObject(DC_PEN)); SetDCPenColor(hDC, color); MoveToEx(hDC, x, clientRect->bottom - 23, NULL); LineTo(hDC, x, clientRect->bottom); SetPixel(hDC, x, clientRect->bottom - 24, InterpolateColor(color, 0xFFFFFF, 0.125)); } SetTextColor(hDC, 0xFFFFFF); int count = bitmap.GetCellCount(); for (int i = 1; i < count; i++) { int x = i * (clientRect->right - clientRect->left) / count; BitBlt(hDC, x - 3, clientRect->bottom - 4, 7, 4, cellMarkerBmpDC, 0, 0, SRCINVERT); } for (std::vector<CStepHandle*>::iterator i = stepHandles.begin(); i != stepHandles.end(); i++) { (*i)->SetPositioningInfo(clientRect->left, clientRect->right, clientRect->bottom - 24); } CCompoundDispItem::OnDraw(hDC, clientRect); }
void ImageData::ChangeColorSpace( const ImageSpectralMode& new_color_mode, const bool luminance_only) { CHECK(IsColorImage(spectral_mode_)) << "Cannot convert non-color (monochrome or hyperspectral) " << "images to a different color space."; CHECK(IsColorImage(new_color_mode)) << "Invalid color space. new_color_mode must be SPECTRAL_MODE_COLOR_*."; // If it's already the same color mode, there's nothing to do. if (new_color_mode == spectral_mode_) { LOG(WARNING) << "This image is already set to the given color mode. " << "Image was not modified."; return; } // Set the OpenCV conversion mode value. int opencv_color_conversion_mode = 0; if (spectral_mode_ == SPECTRAL_MODE_COLOR_BGR && new_color_mode == SPECTRAL_MODE_COLOR_YCRCB) { // BGR => YCrCb. opencv_color_conversion_mode = CV_BGR2YCrCb; luminance_channel_only_ = luminance_only; } else if (spectral_mode_ == SPECTRAL_MODE_COLOR_YCRCB && new_color_mode == SPECTRAL_MODE_COLOR_BGR) { // YCrCb => BGR. opencv_color_conversion_mode = CV_YCrCb2BGR; } else { LOG(WARNING) << "Unsupported color mode: " << new_color_mode << ". " << "Image was not modified."; return; } // If going to BGR and luminance_channels_only_ is enabled, interpolate color // channels first to the appropriate size. if (new_color_mode == SPECTRAL_MODE_COLOR_BGR && luminance_channel_only_) { InterpolateColor(channels_, &channels_); } // Perform the conversion. Conversion is only supported in CV_32F mode, so we // need to convert to CV_32F and then back again. // Merge the 3 channels into a single cv::Mat image. cv::Mat converted_image; cv::merge(channels_, converted_image); // Convert to CV_32F format. const int original_type = converted_image.type(); converted_image.convertTo(converted_image, CV_32F); // Convert to new color space. cv::cvtColor(converted_image, converted_image, opencv_color_conversion_mode); // Convert back to original format (double precision). converted_image.convertTo(converted_image, original_type); // Split the image back into individual ImageData channels. channels_.clear(); cv::split(converted_image, channels_); spectral_mode_ = new_color_mode; }
void ImageData::InterpolateColorFrom(const ImageData& color_image) { CHECK_EQ(GetNumChannels(), 1) // If other 2 channels are hidden, ignore them. << "Color can only be interpolated for single-channel images."; CHECK_EQ(color_image.channels_.size(), 3) // Consider hidden channels. << "The given image must have color information for interpolation."; channels_.resize(3); InterpolateColor(color_image.channels_, &channels_); spectral_mode_ = color_image.spectral_mode_; luminance_channel_only_ = false; }
vec4 SampleGradientColor( float at ) \n\ { \n\ if( gradientStops == 0 ) return brushColor; \n\ if( gradientStops == 1 ) return GradientSampler_GetColor(0); \n\ if( at < 0.0 ) at = 0.0; \n\ if( at > 1.0 ) at = 1.0; \n\ if( at < GradientSampler_GetStop(0) || at > GradientSampler_GetStop(gradientStops-1) ){ \n\ vec4 C1 = GradientSampler_GetColor(gradientStops-1); \n\ vec4 C2 = GradientSampler_GetColor(0); \n\ float start = GradientSampler_GetStop(gradientStops-1); \n\ float end = GradientSampler_GetStop(0) + 1.0; \n\ if( at < start ) at += 1.0; \n\ return InterpolateColor( C1, C2, start, at, end ); \n\ } \n\ for(int i=1; i<gradientStops; ++i){ \n\ vec4 C1 = GradientSampler_GetColor(i-1); \n\ vec4 C2 = GradientSampler_GetColor(i); \n\ float start = GradientSampler_GetStop(i-1); \n\ float end = GradientSampler_GetStop(i); \n\ if( at >= start && at <= end ) return InterpolateColor( C1, C2, start, at, end ); \n\ } \n\ return brushColor; \n\ }\n\