/*
 *  Load an image, convert all pixels equal to (254,254,1)
 *  into pixels from a second image. Essentially, yellow
 *  becomes pixels from another source.
 */

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "app.h"

int main(int argc, char *argv[])
{
	int i;
	Image *img1;
	Image *img2;
	int x, y;
	Rect area;
	Colour c;
	char *background;
	char *input_mask;
	char *outputfile;

	input_mask = argv[1];
	background = argv[2];
	outputfile = argv[3];

	img1 = app_read_image(background, 32);
	if (! img1)
		return 1;

	img2 = app_read_image(input_mask, 32);
	if (img2 == NULL)
		return 2;
	area = app_get_image_area(img2);

	for (y = 0; y < area.height; y++)
	{
		for (x = 0; x < area.width; x++)
		{
			c = img2->data32[y][x];
			if ((c.red == 254) && (c.green == 254) && (c.blue == 1))
				c = img1->data32[y][x];
			img2->data32[y][x] = c;
		}
	}

	if (app_write_image(img2, outputfile))
		printf("Created image file: %s\n", outputfile);

	return 0;
}
