ColorOpt::ColorOpt() : QObject(0) { connect(PsiOptions::instance(), SIGNAL(optionChanged(const QString&)), SLOT(optionChanged(const QString&))); connect(PsiOptions::instance(), SIGNAL(destroyed()), SLOT(reset())); typedef struct {const char *opt; QPalette::ColorRole role;} SourceType; SourceType source[] = { {"contactlist.status.online", QPalette::Text}, {"contactlist.status.offline", QPalette::Text}, {"contactlist.status.away", QPalette::Text}, {"contactlist.status.do-not-disturb", QPalette::Text}, {"contactlist.profile.header-foreground", QPalette::Text}, {"contactlist.profile.header-background", QPalette::Dark}, {"contactlist.grouping.header-foreground", QPalette::Text}, {"contactlist.grouping.header-background", QPalette::Base}, {"contactlist.background", QPalette::Base}, {"contactlist.status-change-animation1", QPalette::Text}, {"contactlist.status-change-animation2", QPalette::Base}, {"contactlist.status-messages", QPalette::Text}, {"messages.received", QPalette::Text}, {"messages.sent", QPalette::Text}, {"messages.informational", QPalette::Text}, {"passive-popup.border", QPalette::Window} }; for (unsigned int i = 0; i < sizeof(source) / sizeof(SourceType); i++) { QString opt = QString("options.ui.look.colors.%1").arg(source[i].opt); colors.insert(opt, ColorData(PsiOptions::instance()->getOption(opt).value<QColor>(), source[i].role)); } }
int main(int argc, char* argv[]) { FlashPhotoApp *app = new FlashPhotoApp(argc, argv, 800, 600, ColorData(1,1,0.95)); // runMainLoop returns when the user closes the graphics window. app->runMainLoop(); delete app; exit(0); }
void TBlur::applyToBuffer(int toolX, int toolY, ColorData toolColor, PixelBuffer* buf) { int left_bound = toolX-15; int right_bound = toolX+15; int lower_bound = toolY-15; int upper_bound = toolY+15; int x; int y; int width = right_bound - left_bound; int height = upper_bound - lower_bound; ColorData *colorArray = new ColorData[width*height]; for(x = left_bound; x < right_bound; x++) for(y = lower_bound; y < upper_bound; y++) { int filterY; int filterX; float red = 0.f; float green = 0.f; float blue = 0.f; //multiply every value of the filter with corresponding image pixel for(filterX = 0; filterX < t_kernel->getWidth(); filterX++) for(filterY = 0; filterY < t_kernel->getHeight(); filterY++) { float multiplier = t_kernel->getValue(filterX,filterY)/t_kernel->getFactor(); int offsetX = x-1+filterX; int offsetY = y-1+filterY; ColorData oldColor; if (offsetX>=0 && offsetX < buf->getWidth() && offsetY>=0 && offsetY < buf->getHeight()) oldColor = buf->getPixel(offsetX,offsetY); red = red + oldColor.getRed() * multiplier; green = green + oldColor.getGreen() * multiplier; blue = blue + oldColor.getBlue() * multiplier; } //truncate if (red < 0) red = 0; if (green <0) green = 0; if (blue <0 ) blue = 0; if (red >1) red = 1; if (green >1) green =1; if (blue >1) blue = 1; //store the value colorArray[width*(y-lower_bound)+(x-left_bound)] = ColorData(red,green,blue); } for(int x = left_bound; x < right_bound; x++) for(int y = lower_bound; y < upper_bound; y++) { if (x>=0 && x < buf->getWidth() && y >=0 && y < buf->getHeight()) buf->setPixel(x, y, colorArray[width*(y-lower_bound)+(x-left_bound)]); } }
ColorData ColorData::clampedColor() const { float clampedRed = ColorData::clampValue(this->getRed(), 0.f, 1.f); float clampedGreen = ColorData::clampValue(this->getGreen(), 0.f, 1.f); float clampedBlue = ColorData::clampValue(this->getBlue(), 0.f, 1.f); float clampedAlpha = ColorData::clampValue(this->getAlpha(), 0.f, 1.f); return ColorData(clampedRed, clampedGreen, clampedBlue, clampedAlpha); }
void Highlighter::draw(PixelBuffer *background, int x, int y){ for (int i=0; i<15; i++){ for (int c = 0; c < 5; c++){ ColorData get = background->getPixel(x-2+c, y-7+i); // float s=0.2126*red + 0.7152*green + 0.0722*blue; // float i=s*0.4; const ColorData& color = ColorData(red * m_mask[i][c]*get.getLuminance()+ (1-m_mask[i][c]*get.getLuminance())* get.getRed(),green * m_mask[i][c]*get.getLuminance() + (1-m_mask[i][c]*get.getLuminance()) * get.getGreen(), blue *m_mask[i][c]*get.getLuminance() + (1-m_mask[i][c]*get.getLuminance()) * get.getBlue()); background->setPixel(x-2+c,y-7+i,color); } } }
void ColorfulPen::draw(PixelBuffer *background, int x, int y){ red =((float) rand()) / (float) RAND_MAX; green =((float) rand()) / (float) RAND_MAX; blue =((float) rand()) / (float) RAND_MAX; for (int i=0; i<9; i++){ for (int c = 0; c<9; c++){ const ColorData& color = ColorData(red*m_mask[i][c],green*m_mask[i][c],blue*m_mask[i][c]); background->setPixel(x-4+c,y-4+i,color); } } }
///apply filter effect to PixelBuffer* buffer passed into this function void FThreshold::applyFilter(PixelBuffer * imageBuffer){ int width = imageBuffer -> getWidth(); int height = imageBuffer -> getHeight(); float threshold = getFloatParameter(); for(int i = 0; i < width; i++){ for(int j = 0; j < height; j++){ ColorData currPixel = imageBuffer -> getPixel(i, j); // if the grayscale is larger than parameter, then set pixel as white // otherwise, set current pixel as black int newRed = currPixel.getRed() > threshold ? 1.0: 0.0; int newBlue = currPixel.getBlue() > threshold ? 1.0 : 0.0; int newGreen = currPixel.getGreen() > threshold ? 1.0 : 0.0; imageBuffer -> setPixel(i, j, ColorData(newRed, newGreen, newBlue)); } } }
int main(int argc,char *argv[]) { FlashPhotoApp *prog = new FlashPhotoApp(argc, argv, 800,800,ColorData(1,1,0.95)); prog->m_filterParameters.sharpen_amount = 5.0; prog->loadImageTest("TestImages/brainstack/mrbrain-8bit062.png"); prog->gluiControl(FlashPhotoApp::UI_APPLY_SHARP); prog->setFileName("TestImages/brainstack_gold_sharpen_5.0/mrbrain-8bit062.png"); prog->gluiControl(FlashPhotoApp::UI_FILE_NAME); prog->gluiControl(FlashPhotoApp::UI_LOAD_STAMP_BUTTON);//saves canvas if (prog->compareBuffers()) { printf("Testing: Sharpen\t SUCCESS\n"); } else { printf("Testing: Sharpen\t FAIL\n"); } return 0; }
//applies kernel over whole canvas, should just need to define kernel in subclasses void ConvolutionFilter::applyFilter(PixelBuffer *buf, float amount, int direction) { adjustKernel(amount,direction); int i,j,width,height; ColorData tempPixel; PixelBuffer *tempBuffer; width = buf -> getWidth(); height = buf -> getHeight(); tempBuffer = new PixelBuffer(width,height,ColorData(0,0,0)); for (i = 0; i < width; i++) { for (j = 0; j < height; j++) { applyKernel(i,j,buf, tempBuffer); } } PixelBuffer::copyPixelBuffer(tempBuffer,buf); delete tempBuffer; }
void F_Channels::applyFilter(PixelBuffer *canvas) { ColorData curColor; float red; float green; float blue; for(int curX = 0; curX < canvas->getWidth(); curX++) { for (int curY = 0; curY < canvas->getHeight(); curY++) { curColor = canvas->getPixel(curX, curY); red = curColor.getRed() * m_filterParameter.red; green = curColor.getGreen() * m_filterParameter.green; blue = curColor.getBlue() * m_filterParameter.blue; canvas->setPixel(curX, curY, ColorData(red, green, blue)); } } }
int main(int argc,char *argv[]) { FlashPhotoApp *prog = new FlashPhotoApp(argc, argv, 800,800,ColorData(1,1,0.95)); prog->setTool(7); prog->setFileName("TestImages/brainstack/mrbrain-8bit018.png"); prog->gluiControl(FlashPhotoApp::UI_FILE_NAME); prog->gluiControl(FlashPhotoApp::UI_LOAD_STAMP_BUTTON); prog->leftMouseDown(300,350); prog->setFileName("golds/stamp_gold.png"); prog->gluiControl(FlashPhotoApp::UI_FILE_NAME); prog->gluiControl(FlashPhotoApp::UI_LOAD_STAMP_BUTTON);//saves canvas if (prog->compareBuffers()) { printf("Testing: Stamp\t\t SUCCESS\n"); } else { printf("Testing: Stamp\t\t FAIL\n"); } return 0; }
int main(int argc,char *argv[]) { FlashPhotoApp *prog = new FlashPhotoApp(argc, argv, 800,800,ColorData(1,1,0.95)); prog->loadImageTest("TestImages/brainstack/mrbrain-8bit062.png"); prog->m_filterParameters.channel_colorRed = 3.0; prog->m_filterParameters.channel_colorGreen = 3.0; prog->m_filterParameters.channel_colorBlue = 3.0; prog->gluiControl(FlashPhotoApp::UI_APPLY_CHANNEL); prog->setFileName("TestImages/brainstack_gold_multRGB_r3.0_g3.0_b3.0/mrbrain-8bit062.png"); prog->gluiControl(FlashPhotoApp::UI_FILE_NAME); prog->gluiControl(FlashPhotoApp::UI_LOAD_STAMP_BUTTON);//saves canvas if (prog->compareBuffers()) { printf("Testing: Channels\t SUCCESS\n"); } else { printf("Testing: Channels\t FAIL\n"); } return 0; }
//sets colors to x number of equaly spaced buckets void Quantize::apply(int bins, PixelBuffer* current) { for(int i = 0; i < current->getHeight(); i++) { for(int j = 0; j < current->getWidth(); j++) { float currentRed, currentGreen, currentBlue; float bestRed, bestGreen, bestBlue; float closeRed, closeGreen, closeBlue; currentRed = (current->getPixel(j,i)).getRed(); currentGreen = (current->getPixel(j,i)).getGreen(); currentBlue = (current->getPixel(j,i)).getBlue(); closeRed = 12; closeGreen=12; closeBlue=12; for(int m = 0; m <bins; m++) { if(std::abs(currentRed-((float)m/((float)bins-1))) < closeRed) { closeRed = std::abs(currentRed-(float)((float)m/(float)(bins-1))); bestRed = (float)((float)m/(float)(bins-1)); } if(std::abs(currentGreen-((float)m/((float)bins-1))) < closeGreen) { closeGreen = std::abs(currentGreen-(float)((float)m/(float)(bins-1))); bestGreen = (float)((float)m/(float)(bins-1)); } if(std::abs(currentBlue-((float)m/((float)bins-1))) < closeBlue) { closeBlue = std::abs(currentBlue-(float)((float)m/(float)(bins-1))); bestBlue = (float)((float)m/(float)(bins-1)); } } current->setPixel(j,i,ColorData(bestRed,bestGreen,bestBlue)); } } }
///apply filter effect to the PixelBuffer* buffer passed into this function void FBlur::applyFilter(PixelBuffer* imageBuffer){ // if kernel is already initialized, do not need initialize it again. kernel = buildKernel(std::round(getFloatParameter())); // printKernel(); if(getName() == "FEdgeDetection"){ imageBuffer -> convertToLuminance(); } int width = imageBuffer -> getWidth(); int height = imageBuffer -> getHeight(); //create a new pixel buffer for storing the convolution result. PixelBuffer* newImageBuffer = new PixelBuffer(width, height, imageBuffer -> getBackgroundColor()); for(int i = 0; i < width; i++){ for(int j = 0; j < height; j++){ float newRed = 0; float newGreen = 0; float newBlue = 0; for(size_t filterI = 0; filterI < kernel.size(); filterI++){ for(size_t filterJ = 0; filterJ < kernel[filterI].size(); filterJ++){ //The location imageI and imageJ is calculated so that //for the center element of the filter it'll be i, j int imageI = (i - kernel.size()/2 + filterI + width) % width; int imageJ = (j - kernel[filterI].size()/2 + filterJ + height) % height; ColorData currPixel = imageBuffer -> getPixel(imageI, imageJ); newRed += currPixel.getRed() * kernel[filterI][filterJ]; newGreen += currPixel.getGreen()*kernel[filterI][filterJ]; newBlue += currPixel.getBlue()*kernel[filterI][filterJ]; } } ColorData newPixel = ColorData(newRed, newGreen, newBlue); newPixel = newPixel.clampedColor(); newImageBuffer -> setPixel(i, j, newPixel); } } newImageBuffer -> copyPixelBuffer(newImageBuffer, imageBuffer); delete newImageBuffer; }
//all colors bellow =0 all above =1 void Threshold::apply(float limit, PixelBuffer* current) { for(int i = 0; i < current->getHeight(); i++) { for(int j = 0; j < current->getWidth(); j++) { float red,green,blue; if(current->getPixel(j,i).getRed() < limit) red =0; else red = 1.0; if(current->getPixel(j,i).getGreen() < limit) green =0; else green = 1.0; if(current->getPixel(j,i).getBlue() < limit) blue =0; else blue = 1.0; current->setPixel(j,i, ColorData(red,green,blue)); } } }
//applies kernel to one pixel, modifies temporary buffer void ConvolutionFilter::applyKernel(int x, int y,PixelBuffer *buf, PixelBuffer *temp) { float r=0,g=0,b=0; int i,j,xloc,yloc,w,h; ColorData pixel; w = buf->getWidth(); h = buf->getHeight(); for (i = 0; i < kernelSize; i++) { for (j = 0; j < kernelSize; j++) { xloc = x+i-(kernelSize/2); yloc = y+j-(kernelSize/2); if (xloc > -1 && xloc < w && yloc > -1 && yloc < h) { pixel = buf -> getPixel(x + i - (kernelSize/2),y + j - (kernelSize/2)); r += (kernel[i][j] * pixel.getRed()); g += (kernel[i][j] * pixel.getGreen()); b += (kernel[i][j] * pixel.getBlue()); } } } temp -> setPixel(x,y,ColorData(r,g,b)); }
ColorData F_MotionBlur::getBlurredColor(int canvasX, int canvasY) { int distance = m_kernelSize/2; ColorData blurredColor; ColorData curPixel; float red = 0; float green = 0; float blue = 0; float colorFactor = 0; int curX; int curY; float kernalVal; assert(m_filterParameter.amountI >= 0 && m_filterParameter.amountI <= 3); switch(m_filterParameter.amountI) { case 0:// N/S for(curY = 0; curY < m_kernelSize; curY++) { curX = distance; int xVal= canvasX + (curX - distance); int yVal= canvasY + (curY - distance); if ((xVal >= 0) && (xVal < m_tempCanvas->getWidth()) && (yVal >= 0) && (yVal < m_tempCanvas->getHeight())) { curPixel = m_tempCanvas->getPixel(xVal, yVal); kernalVal = m_kernel->getKernelVal(curX, curY); red += kernalVal * curPixel.getRed(); green += kernalVal * curPixel.getGreen(); blue += kernalVal * curPixel.getBlue(); colorFactor += kernalVal; } } break; case 1:// E/W for(curX = 0; curX < m_kernelSize; curX++) { curY = distance; int xVal= canvasX + (curX - distance); int yVal= canvasY + (curY - distance); if ((xVal >= 0) && (xVal < m_tempCanvas->getWidth()) && (yVal >= 0) && (yVal < m_tempCanvas->getHeight())) { curPixel = m_tempCanvas->getPixel(xVal, yVal); kernalVal = m_kernel->getKernelVal(curX, curY); red += kernalVal * curPixel.getRed(); green += kernalVal * curPixel.getGreen(); blue += kernalVal * curPixel.getBlue(); colorFactor += kernalVal; } } break; case 2:// NE/SW for(curX = 0; curX < m_kernelSize; curX++) { curY = curX; int xVal= canvasX + (curX - distance); int yVal= canvasY + (curY - distance); if ((xVal >= 0) && (xVal < m_tempCanvas->getWidth()) && (yVal >= 0) && (yVal < m_tempCanvas->getHeight())) { curPixel = m_tempCanvas->getPixel(xVal, yVal); kernalVal = m_kernel->getKernelVal(curX, curY); red += kernalVal * curPixel.getRed(); green += kernalVal * curPixel.getGreen(); blue += kernalVal * curPixel.getBlue(); colorFactor += kernalVal; } } break; case 3:// NW/SE for(curX = 0; curX < m_kernelSize; curX++) { curY = m_kernelSize - curX - 1; int xVal= canvasX + (curX - distance); int yVal= canvasY + (curY - distance); if ((xVal >= 0) && (xVal < m_tempCanvas->getWidth()) && (yVal >= 0) && (yVal < m_tempCanvas->getHeight())) { curPixel = m_tempCanvas->getPixel(xVal, yVal); kernalVal = m_kernel->getKernelVal(curX, curY); red += kernalVal * curPixel.getRed(); green += kernalVal * curPixel.getGreen(); blue += kernalVal * curPixel.getBlue(); colorFactor += kernalVal; } } break; default: for(curX = 0; curX < m_kernelSize; curX++) { for(curY = 0; curY < m_kernelSize; curY++) { int xVal= canvasX + (curX - distance); int yVal= canvasY + (curY - distance); if ((xVal >= 0) && (xVal < m_tempCanvas->getWidth()) && (yVal >= 0) && (yVal < m_tempCanvas->getHeight())) { curPixel = m_tempCanvas->getPixel(xVal, yVal); kernalVal = m_kernel->getKernelVal(curX, curY); red += kernalVal * curPixel.getRed(); green += kernalVal * curPixel.getGreen(); blue += kernalVal * curPixel.getBlue(); colorFactor += kernalVal; } } } } red /= colorFactor; green /= colorFactor; blue /= colorFactor; blurredColor = ColorData(red, green, blue); return blurredColor; }
ColorData operator- (const ColorData& a, const ColorData& b) { return ColorData(a.m_red - b.m_red, a.m_green - b.m_green, a.m_blue - b.m_blue, a.m_alpha - b.m_alpha); }
ColorData operator+ (const ColorData& a, const ColorData& b) { return ColorData(a.m_red + b.m_red, a.m_green + b.m_green, a.m_blue + b.m_blue, a.m_alpha + b.m_alpha); }
// Apply component-wise arithmatic operations ColorData operator* (const ColorData& a, float f) { return ColorData(a.m_red*f, a.m_green*f, a.m_blue*f, a.m_alpha*f); }
PixelBuffer* JpegFacade::load(){ float r,g,b,a; struct jpeg_decompress_struct cinfo; struct jpeg_error_mgr jerr; FILE* infile; JSAMPROW row_pointer[1]; unsigned long location = 0; int i = 0; if ((infile = fopen(m_filename.c_str(),"rb"))==NULL){ printf("can't read"); } cinfo.err = jpeg_std_error(&jerr); jpeg_create_decompress(&cinfo); jpeg_stdio_src(&cinfo,infile); jpeg_read_header(&cinfo, TRUE); jpeg_start_decompress(&cinfo); new_width = cinfo.output_width;; new_height = cinfo.output_height; new_pixel_buffer=new PixelBuffer(new_width,new_height,ColorData(1,1,1)); int comp = cinfo.output_components; unsigned char* raw_image = (unsigned char*)malloc( cinfo.output_width*cinfo.output_height*cinfo.num_components ); //printf("length is: %d \n",cinfo.output_width*cinfo.output_height*cinfo.num_components); row_pointer[0] = (unsigned char *)malloc( cinfo.output_width*cinfo.num_components ); while( cinfo.output_scanline < cinfo.image_height ) { jpeg_read_scanlines( &cinfo, row_pointer, 1 ); for( i=0; i<cinfo.image_width*cinfo.num_components;i++) raw_image[location++] = row_pointer[0][i]; } jpeg_finish_decompress(&cinfo); fclose(infile); if (comp == 3){ for ( int y = 0 ; y < new_height ; y++ ) { for ( int x = 0 ; x < new_width ; x++ ) { int index = (new_height - y - 1) * new_width * comp + x * comp; r = (float)raw_image[index]/255; g = (float)raw_image[index+1]/255; b = (float)raw_image[index+2]/255; new_pixel_buffer->setPixel(x,y,ColorData(r,g,b)); } } } else { for ( int y = 0 ; y < new_height ; y++ ) { for ( int x = 0 ; x < new_width ; x++ ) { int index = y * new_width * comp + x * comp; r = (float)raw_image[index]/255; b = (float)raw_image[index+1]/255; g = (float)raw_image[index+2]/255; a = (float)raw_image[index+3]/255; //printf("Color: %d %d %d \n",r,b,g); new_pixel_buffer->setPixel(x,new_height - y -1,ColorData(r,g,b,a)); } } } delete row_pointer[0]; delete raw_image; return new_pixel_buffer; }