uint8_t* convert_to_greyscale(uint8_t* data, int height, int width, int planes)
{
    uint8_t* grey = malloc(width * height);
    int index = 0;
    for (int i = 0; i < height * width * planes; i += planes) {
        grey[index] = rgb_to_l(data[i], data[i+1], data[i+2]);
        index++;
    }
    return grey;
}
Exemple #2
0
	Bitmap* SoftGlow::Process1(const Bitmap* src, int radius, float sharpness, float brightness)
	{
		assert(src && src->IsValid());

		int width = src->Width();
		int height = src->Height();

		Bitmap* tmp = new Bitmap(width, height, 8);
		assert(tmp);

		for (int y = 0; y < height; y++)
		{
			uint8* p0 = src->Get(0, y);
			uint8* p1 = tmp->Get(0, y);

			for (int x = 0; x < width; x++)
			{
				uint8 b = *(p0 + 0);
				uint8 g = *(p0 + 1);
				uint8 r = *(p0 + 2);

				*p1 = (uint8)rgb_to_l(r, g, b);

				*p1 = (uint8)CalcSharpAndBright(*p1, sharpness, brightness);

				p0 += src->PixelBytes();
				p1 += tmp->PixelBytes();
			}
		}

		Gaussion(tmp, (float)radius);

#ifdef _DEBUG
		tmp->Save("f:\\tmp0.bmp");
#endif
		Bitmap* dst = new Bitmap(src->Width(), src->Height(), src->biBitCount);
		assert(dst);
		int temp;
		for (int y = 0; y < height; y++)
		{
			uint8* p0 = src->Get(0, y);
			uint8* p1 = tmp->Get(0, y);
			uint8* p2 = dst->Get(0, y);

			for (int x = 0; x < width; x++)
			{
				//screen op
				*(p2 + 0) = 255 - INT_MULT((255 - *(p0 + 0)), (255 - *p1), temp);
				*(p2 + 1) = 255 - INT_MULT((255 - *(p0 + 1)), (255 - *p1), temp);
				*(p2 + 2) = 255 - INT_MULT((255 - *(p0 + 2)), (255 - *p1), temp);

				p0 += src->PixelBytes();
				p1 += tmp->PixelBytes();
				p2 += dst->PixelBytes();
			}
		}

		delete tmp;

		return dst;
	}