Пример #1
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;
}
Пример #2
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)]);
  }
}
PixelBuffer * Filter::generateFilteredBuffer(const PixelBuffer & input_buffer) {
    PixelBuffer * output_buffer = new PixelBuffer(input_buffer.getWidth(), input_buffer.getHeight(), input_buffer.getBackground());
    for (int i = 0; i < input_buffer.getWidth(); i++) {
        for (int j = 0; j < input_buffer.getHeight(); j++) {
            ColorData p = generatePixel(input_buffer, i, j);
            output_buffer->setPixel(i, j, p.clampedColor());
        }
    }
    return output_buffer;
}
Пример #4
0
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);
		}
	}
}
Пример #5
0
void ImageManager::ApplyBorder(ILuint DevilImageID, int32_t BorderColorID)
{
    ilBindImage(DevilImageID);
    uint8_t* ImageData = ilGetData();

    uint32_t bpp = ilGetInteger(IL_IMAGE_BYTES_PER_PIXEL);
    uint32_t width = ilGetInteger(IL_IMAGE_WIDTH);
    uint32_t height = ilGetInteger(IL_IMAGE_HEIGHT);

    uint8_t Red, Green, Blue;
    ColorData* BorderColor = DATA->getColorData(BorderColorID);

    if(BorderColor != NULL)
    {
        Red = BorderColor->getRed();
        Green = BorderColor->getGreen();
        Blue = BorderColor->getBlue();

        if(ImageData != NULL)
        {
            for(uint32_t i = 0; i < width; i++)
            {
                ImageData[(i * width * bpp) +  0] = Blue;   // Blue
                ImageData[(i * width * bpp) +  1] = Green;  // Green
                ImageData[(i * width * bpp) +  2] = Red;    // Red

                ImageData[(i * width * bpp) +  3] = 255;    // Alpha

                ImageData[(i * width * bpp) + ((height - 1) * bpp) + 0] = Blue;     // Blue
                ImageData[(i * width * bpp) + ((height - 1) * bpp) + 1] = Green;    // Green
                ImageData[(i * width * bpp) + ((height - 1) * bpp) + 2] = Red;      // Red

                ImageData[(i * width * bpp) + ((height - 1) * bpp) + 3] = 255;      // Alpha
            }

            for(uint32_t j = 0; j < height; j++)
            {
                ImageData[((width - 1) * height * bpp) + (j * bpp) + 0] = Blue;     // Blue
                ImageData[((width - 1) * height * bpp) + (j * bpp) + 1] = Green;    // Green
                ImageData[((width - 1) * height * bpp) + (j * bpp) + 2] = Red;      // Red

                ImageData[((width - 1) * height * bpp) + (j * bpp) + 3] = 255;      // Alpha

                ImageData[(j * bpp) + 0] = Blue;    // Blue
                ImageData[(j * bpp) + 1] = Green;   // Green
                ImageData[(j * bpp) + 2] = Red;     // Red

                ImageData[(j * bpp) + 3] = 255;     // Alpha
            }
        }
    }
}
Пример #6
0
/// A filter that reduce the number of possible colors  by binning each color value into the the
///number of bins specified.
/// Inherits from Filter
ColorData FQuantize::generatePixel(const PixelBuffer &buffer, int x, int y) const {
    ColorData c = buffer.getPixel(x, y);
    float red = c.getRed();
    float blue = c.getBlue();
    float green = c.getGreen();
    int steps = m_bins-1;
    red = round(red*steps)/steps;
    green = round(green*steps)/steps;
    blue = round(blue*steps)/steps;
    ColorData output(red, green, blue);

    return output;
}
Пример #7
0
// Default implementation of 2D convolution
void ConvolutionTool::applyToolOnCanvas(PixelBuffer* pixel_buffer){

	// check if the tool mask is valid
	if(m_mask == NULL){
		cerr << "[ConvolutionTool] mask is null" << endl;
		return;
	}

	// Dimensions of the canvas and mask
	int width = pixel_buffer->getWidth();
	int height = pixel_buffer->getHeight();
	int mw = m_mask->getWidth();
	int mh = m_mask->getHeight();
	
	// Coordinates to access the canvas
	int posx,posy;

	// Declare variable to store intermediate results
	ColorData tmp;
	PixelBuffer tmpPb(width,height, ColorData(0.0,0.0,0.0));

	// 2D Convolution
	for(int x = 0; x < width; x++){
	    for(int y = 0; y < height; y++){ 
	       
	        tmp = ColorData(0.0,0.0,0.0);

	        // Multiply every value of the mask a corresponding image pixel 
	        for(int mx = 0; mx < mw; mx++){
		        for(int my = 0; my < mh; my++){ 
		            posx = (x - mw / 2 + mx); 
		            posy = (y - mh / 2 + my);

		            // If trying to access out of bounds indicies, skip
		            if(posx < 0 || posy < 0 || posx >= width || posy >= height)	continue;

		            // Accumulate values
		            tmp = tmp + (pixel_buffer->getPixel(posx,posy) * m_mask->getValue(mx,my));
		        } 
		    }  
	        tmpPb.setPixel(x,y,tmp.clampedColor());
	    }
	}    
	// Set result
	PixelBuffer::copyPixelBuffer(&tmpPb,pixel_buffer);
}
Пример #8
0
///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));

    }
  }
}
Пример #9
0
static jintArray movie_frameColorData(JNIEnv* env, jobject movie,jint frameIndex){
	jintArray colIntArray = NULL;
	GifMovie* m = J2Movie(env, movie);
	if(m!=NULL&&frameIndex>=0){
		ColorData *data = m->getFrameColorData(frameIndex);
		if(data!=NULL){
			int width = data->getWidth();
			int height = data->getHeight();
			int *col = data->getColorData();
			if(width>0&&height>0&&col!=NULL){
				colIntArray = env->NewIntArray(width*height);
				env->SetIntArrayRegion(colIntArray,0,width*height,col);
			}
		}
	}
	return colIntArray;
}
Пример #10
0
void JpegFacade::save(int width,int height, PixelBuffer* pixelbuffer){
	int r,g,b,a;
	struct jpeg_compress_struct cinfo;
	struct jpeg_error_mgr jerr;
	FILE *outfile = fopen(m_filename.c_str(), "wb");
	JSAMPROW buffer[1];
	//int row_stride;
	cinfo.err = jpeg_std_error(&jerr);
	jpeg_create_compress(&cinfo);
	jpeg_stdio_dest(&cinfo, outfile);
	cinfo.image_width = width;
	cinfo.image_height = height;
	cinfo.input_components = 3;
	cinfo.in_color_space = JCS_RGB;
	jpeg_set_defaults(&cinfo);
	jpeg_set_quality(&cinfo, 100, TRUE);
	jpeg_start_compress(&cinfo, TRUE);
	//row_stride = cinfo.image_width * 3;
	//(unsigned char*)raw_image = (unsigned char*)malloc( cinfo.image_width*cinfo.image_height*cinfo.num_components );
	//number of total elements per row
	buffer[0] = (unsigned char *)malloc( cinfo.image_width*cinfo.num_components );
	int row_stride = cinfo.image_width*cinfo.input_components;
	while (cinfo.next_scanline < cinfo.image_height) {
		//buffer[0] = &raw_image[ cinfo.next_scanline * cinfo.image_width * cinfo.input_components];
		for (int i  = 0 ; i < row_stride; i=i+3){
				ColorData color = pixelbuffer->getPixel((int)i/3,cinfo.image_height-cinfo.next_scanline-1);
				r = color.getRed()*255;
				g = color.getGreen()*255;
				b = color.getBlue()*255;

				buffer[0][i] = r;
				buffer[0][i+1] = g;
				buffer[0][i+2] = b;

			}
		(void) jpeg_write_scanlines(&cinfo, buffer, 1);
	}
	//Don't need to motify, save memory
	jpeg_finish_compress(&cinfo);
	fclose(outfile);
	delete buffer[0];
	jpeg_destroy_compress(&cinfo);
}
Пример #11
0
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));
    }
  }
}
Пример #12
0
void Tool::Apply(int x, int y, int m_height, PixelBuffer* m_displayBuffer, ColorData color)
{
	x = x - centerX;
	y = y + centerY;
	float trans;
	for (int i = 0; i < maskHeight; i++)
	{
		for (int j = 0; j < maskWidth; j++)
		{
      	                trans = mask[i][j];
			ColorData curColor = m_displayBuffer->getPixel(x + j, m_height - y + i);
			if (mask[i][j] < 1 && mask[i][j] > 0){
				trans = curColor.getLuminance() * mask[i][j];
				//std::cout << "High " << trans << std::endl;  //fot test only
                                //std::cout << "High2 " << mask[i][j] << std::endl;  //fot test only
			}
			m_displayBuffer->setPixel(x + j, m_height - y + i, color * trans + curColor * (1 - trans));
		}
	}
}
Пример #13
0
///Tells you if x and y are equal colors
bool FillTool::compareColorData(ColorData x, ColorData y) {
	if (x.getRed() == y.getRed() && x.getBlue() == y.getBlue() && x.getGreen() == y.getGreen()) {
		return true;
	} else {
		return false;
	}
}
Пример #14
0
//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));
}
Пример #15
0
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);
        }
    }
}
Пример #16
0
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);
		}
	}
}
Пример #17
0
///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;
}
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);
}
Пример #19
0
ILuint ImageManager::GeneratedOverLayImage(ILuint TextureDevILID, int16_t PrimaryColorID, int16_t BorderColorID)
{
    ILuint TextureImageID;
    ilGenImages(1, &TextureImageID);
    ilBindImage(TextureImageID);
    ilCopyImage(TextureDevILID);
    ilConvertImage(IL_LUMINANCE_ALPHA, IL_UNSIGNED_BYTE);

    uint8_t* TextureImageData = ilGetData();
    uint32_t width = ilGetInteger(IL_IMAGE_WIDTH);
    uint32_t height = ilGetInteger(IL_IMAGE_HEIGHT);

    ColorData* PrimaryColor = DATA->getColorData(PrimaryColorID);

    ILuint NewImageID;
    ilGenImages(1, &NewImageID);
    ilBindImage(NewImageID);
    ilTexImage(width, height, 1, 4, IL_BGRA, IL_UNSIGNED_BYTE, NULL);
    uint8_t* NewImageData = ilGetData();

    uint32_t bpp = ilGetInteger(IL_IMAGE_BYTES_PER_PIXEL);

    if(PrimaryColor != NULL)
    {
        for(uint32_t i = 0; i < width; i++)
        {
            for(uint32_t j = 0; j < height; j++)
            {
                float Base  = TextureImageData[(i * width * 2) + (j * 2) + 0];
                uint8_t Alpha =  TextureImageData[(i * width * 2) + (j * 2) + 1];
                Base /= 255.0;

                float OriginalBlue = PrimaryColor->getBlue();
                OriginalBlue /= 255.0;

                float OriginalGreen = PrimaryColor->getGreen();
                OriginalGreen /= 255.0;

                float OriginalRed = PrimaryColor->getRed();
                OriginalRed /= 255.0;

                // coloring using overlay mode
                if(Base >= 0.5)
                {
                    NewImageData[(i * width * bpp) + (j * bpp) + 0] = (1.0 - 2.0 * (1.0 - OriginalBlue) * (1.0 - Base)) * 255; // Blue
                    NewImageData[(i * width * bpp) + (j * bpp) + 1] = (1.0 - 2.0 * (1.0 - OriginalGreen) * (1.0 - Base)) * 255; // Green
                    NewImageData[(i * width * bpp) + (j * bpp) + 2] = (1.0 - 2.0 * (1.0 - OriginalRed) * (1.0 - Base)) * 255; // Red
                    NewImageData[(i * width * bpp) + (j * bpp) + 3] = Alpha;
                }
                else
                {
                    NewImageData[(i * width * bpp) + (j * bpp) + 0] = (2.0 * OriginalBlue * Base) * 255; // Blue
                    NewImageData[(i * width * bpp) + (j * bpp) + 1] = (2.0 * OriginalGreen * Base) * 255; // Green
                    NewImageData[(i * width * bpp) + (j * bpp) + 2] = (2.0 * OriginalRed * Base) * 255; // Red
                    NewImageData[(i * width * bpp) + (j * bpp) + 3] = Alpha;
                }
            }
        }
    }

    if (BorderColorID != -1)
    {
        ApplyBorder(NewImageID, BorderColorID);
    }

    return NewImageID;
}
Пример #20
0
ILuint ImageManager::GenerateGradientImage(ILuint TextureDevILID, int16_t PrimaryColorID, int16_t SecondaryColorID, int16_t BorderColorID)
{
    ILuint TextureImageID;
    ilGenImages(1, &TextureImageID);
    ilBindImage(TextureImageID);
    ilCopyImage(TextureDevILID);
    ilConvertImage(IL_LUMINANCE, IL_UNSIGNED_BYTE);  //Load as IL_LUMINANCE to avoid convertion?

    uint8_t* TextureImageData = ilGetData();
    uint32_t width = ilGetInteger(IL_IMAGE_WIDTH);
    uint32_t height = ilGetInteger(IL_IMAGE_HEIGHT);

    ILuint MaskImageID;
    ilGenImages(1, &MaskImageID);
    ilBindImage(MaskImageID);
    ilTexImage(width, height, 1, 4, IL_BGRA, IL_UNSIGNED_BYTE, NULL);
    uint8_t* MaskImageData = ilGetData();

    ColorData* PrimaryColor = DATA->getColorData(PrimaryColorID);
    ColorData* SecondaryColor = DATA->getColorData(SecondaryColorID);

    uint32_t bpp = ilGetInteger(IL_IMAGE_BYTES_PER_PIXEL);
    if(SecondaryColor != NULL)
    {
        for(uint32_t i = 0; i < width; i++)
        {
            for(uint32_t j = 0; j < height; j++)
            {
                MaskImageData[(i * width * bpp) + (j * bpp) + 0] = SecondaryColor->getBlue();     // Blue
                MaskImageData[(i * width * bpp) + (j * bpp) + 1] = SecondaryColor->getGreen();    // Green
                MaskImageData[(i * width * bpp) + (j * bpp) + 2] = SecondaryColor->getRed();      // Red
                MaskImageData[(i * width * bpp) + (j * bpp) + 3] = 255 - TextureImageData[(i * width) + j]; // Alpha
            }
        }
    }

    ILuint NewImageID;
    ilGenImages(1, &NewImageID);
    ilBindImage(NewImageID);
    ilTexImage(width, height, 1, 4, IL_BGRA, IL_UNSIGNED_BYTE, NULL);
    uint8_t* NewImageData = ilGetData();

    if(PrimaryColor != NULL)
    {
        for(uint32_t i = 0; i < width; i++)
        {
            for(uint32_t j = 0; j < height; j++)
            {
                NewImageData[(i * width * bpp) + (j * bpp) + 0] = PrimaryColor->getBlue(); // Blue
                NewImageData[(i * width * bpp) + (j * bpp) + 1] = PrimaryColor->getGreen(); // Green
                NewImageData[(i * width * bpp) + (j * bpp) + 2] = PrimaryColor->getRed(); // Red
                NewImageData[(i * width * bpp) + (j * bpp) + 3] = 255; // Alpha
            }
        }
    }

    ilOverlayImage(MaskImageID, 0, 0, 0);

    if (BorderColorID != -1)
    {
        ApplyBorder(NewImageID, BorderColorID);
    }

    return NewImageID;
}
Пример #21
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++;
    }
}
Пример #22
0
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;
}
Пример #23
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);
		}
	}
}
Пример #24
0
void Stamp::setCurrentColor(ColorData color){
	m_r = color.getRed();
	m_g = color.getGreen();
	m_b = color.getBlue();
}