예제 #1
0
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++;
    }
}
예제 #2
0
bool IPNGHandler::saveImage(const std::string fileName, const PixelBuffer* bufferToSave)
{
    bool success = false;
    
    png_image image;
    
    memset(&image, 0, (sizeof image));
    image.height = bufferToSave->getHeight();
    image.width = bufferToSave->getWidth();
    image.version = PNG_IMAGE_VERSION;
    image.opaque = NULL;
    image.format = PNG_FORMAT_RGBA;
    
    png_bytep buffer = new png_byte[PNG_IMAGE_SIZE(image)];
    
    for (int y = image.height-1; y >= 0; y--) {
        for (int x = 0; x < image.width; x++) {
            ColorData currentPixel = bufferToSave->getPixel(x, y);
            buffer[((image.height-(y+1))*image.width+x)*4] = (png_byte) (currentPixel.getRed()*255.0);
            buffer[((image.height-(y+1))*image.width+x)*4+1] = (png_byte) (currentPixel.getGreen()*255.0);
            buffer[((image.height-(y+1))*image.width+x)*4+2] = (png_byte) (currentPixel.getBlue()*255.0);
            buffer[((image.height-(y+1))*image.width+x)*4+3] = (png_byte) (currentPixel.getAlpha()*255.0);
        }
    }
    
    if (png_image_write_to_file(&image, fileName.c_str(), 0/*convert_to_8bit*/,
                                buffer, 0/*row_stride*/, NULL/*colormap*/) != 0) {
        success = true;
    } else {
        success = false;
    }
    
    delete[] buffer;
    return success;
}
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);
}
예제 #4
0
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);
		}
	}
}