void TStamp::applyStamp(int toolX, int toolY, PixelBuffer* buffer, PixelBuffer* stamp, ColorData stampColorAdjust) { int stampHeight = stamp->getHeight(); int stampWidth = stamp->getWidth(); int stampX = 0; int stampY = 0; for (int x = toolX - (stampWidth/2); x <toolX + (stampWidth/2); x++) { stampY = 0; for (int y = toolY - (stampHeight/2); y<toolY + (stampHeight/2); y++) { ColorData stampColor = ColorData(0,0,0,0); ColorData bufferColor = ColorData(0,0,0,0); if (!(x <= 0 || x >= buffer->getWidth() || y <= 0 || y >= buffer->getHeight())) { stampColor = stamp->getPixel(stampX,stampY); bufferColor = buffer ->getPixel(x,y); stampColor.setRed(stampColor.getRed() * stampColorAdjust.getRed()); stampColor.setGreen(stampColor.getGreen() * stampColorAdjust.getGreen()); stampColor.setBlue(stampColor.getBlue() * stampColorAdjust.getBlue()); float stampDifference = stampColor.getAlpha(); float bufferDifference = (1 - stampDifference); stampColor = (stampColor * stampDifference) + (bufferColor * bufferDifference); buffer -> setPixel(x,y,stampColor); } stampY++; } stampX++; } }
ColorData TStamp::processPixel(int maskX, int maskY, ColorData toolColor, PixelBuffer* buffer, int bufferX, int bufferY) { ColorData stampColor = TStamp::m_stampBuffer->getPixel(maskX, maskY); stampColor.setRed(toolColor.getRed() * stampColor.getRed()); stampColor.setGreen(toolColor.getGreen() * stampColor.getGreen()); stampColor.setBlue(toolColor.getBlue() * stampColor.getBlue()); float alpha = stampColor.getAlpha(); return stampColor*alpha + buffer->getPixel(bufferX, bufferY)*(1-alpha); }
void Tool::apply(int xCoord, int yCoord, PixelBuffer *pixelbuff, ColorData curColor) { //creating tool mask offsets for the boundary checking int toolHeight = this->getHeight(); int toolWidth = this->getWidth(); int x_offset; int y_offset; int canvas_w = pixelbuff->getWidth(); int canvas_h = pixelbuff->getHeight(); ColorData pixel; const std::vector<std::vector<float> > &tool_mask = this->mask.get_mask(); //iterate through 2d vector for(int i = 0; i < toolHeight; i++) { y_offset = yCoord - (toolHeight/2) + i; if((y_offset < 0) || (y_offset >= canvas_h)) //Checking to see if mask goes out of bounds { continue; } for(int j = 0; j < toolWidth; j++) { x_offset = xCoord - (toolWidth/2) + j; if ((x_offset < 0) || (x_offset >= canvas_w)) //Checking to see if mask goes out of bounds { continue; } pixel = pixelbuff->getPixel(x_offset, y_offset); pixel.setRed((pixel.getRed()*(1 - tool_mask[i][j])) + (curColor.getRed()*tool_mask[i][j])); pixel.setBlue((pixel.getBlue()*(1 - tool_mask[i][j])) + (curColor.getBlue()*tool_mask[i][j])); pixel.setGreen((pixel.getGreen()*(1 - tool_mask[i][j])) + (curColor.getGreen()*tool_mask[i][j])); pixel.setAlpha((pixel.getAlpha()*(1 - tool_mask[i][j])) + tool_mask[i][j]); pixelbuff->setPixel(x_offset, y_offset, pixel); } } }
void Saturation::applyFilter(PixelBuffer* buffer, float saturation_amount) { cout<<"Saturation"; for (int x = 0; x < buffer->getWidth(); x ++) { for (int y = 0; y < buffer->getHeight(); y++) { ColorData currentColor = buffer->getPixel(x,y); float luminence = currentColor.getLuminance(); ColorData newColor = ColorData(0,0,0); float redChannel = currentColor.getRed(); float greenChannel = currentColor.getGreen(); float blueChannel = currentColor.getBlue(); float redDifference = (redChannel - luminence) * saturation_amount; float greenDifference = (greenChannel - luminence) * saturation_amount; float blueDifference = (blueChannel - luminence) * saturation_amount; newColor.setRed(luminence + redDifference); newColor.setGreen(luminence + greenDifference); newColor.setBlue(luminence + blueDifference); buffer->setPixel(x,y,newColor); } } }
void Stamp::applyToolOnCanvas(PixelBuffer * canvas){ int c_width = canvas->getWidth(); int c_height = canvas->getHeight(); int s_width = m_stamp->getWidth(); int s_height = m_stamp->getHeight(); for(int i = 0; i < s_width; i++){ for(int j = 0; j < s_height; j++){ // position on canvas int cur_x = m_startPointx + i - s_width / 2; int cur_y = m_startPointy + j - s_height / 2; if(cur_x < 0 || cur_y < 0 || cur_x >= canvas->getWidth() || cur_y >= canvas->getHeight()){ continue; } ColorData c = m_stamp->getPixel(i,j); c.setRed(c.getRed() * m_r); c.setGreen(c.getGreen() * m_g); c.setBlue(c.getBlue() * m_b); canvas->setPixel(cur_x,cur_y,c); } } }