2013-02-03 19:03:36 +00:00
|
|
|
#include "common/image.h"
|
2012-07-03 22:04:53 +00:00
|
|
|
|
2013-03-22 17:19:53 +00:00
|
|
|
#include <SDL.h>
|
2012-07-03 22:04:53 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
/* For now, just a simple test: loading a file from image
|
|
|
|
* and saving it to another in PNG. */
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
if (argc != 3)
|
|
|
|
{
|
|
|
|
printf("Usage: %s in_image out_image\n", argv[0]);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
CImage image;
|
|
|
|
|
|
|
|
if (! image.Load(argv[1]))
|
|
|
|
{
|
|
|
|
std::string err = image.GetError();
|
2013-01-17 19:54:35 +00:00
|
|
|
printf("Error loading '%s': %s\n", argv[1], err.c_str());
|
2012-07-03 22:04:53 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2012-09-13 18:40:07 +00:00
|
|
|
Gfx::Color color;
|
|
|
|
std::string str;
|
|
|
|
|
|
|
|
color = image.GetPixel(Math::IntPoint(0, 0));
|
|
|
|
str = color.ToString();
|
|
|
|
printf("pixel @ (0,0): %s\n", str.c_str());
|
|
|
|
|
|
|
|
color = image.GetPixel(Math::IntPoint(0, 1));
|
|
|
|
str = color.ToString();
|
|
|
|
printf("pixel @ (0,1): %s\n", str.c_str());
|
|
|
|
|
|
|
|
color = image.GetPixel(Math::IntPoint(1, 0));
|
|
|
|
str = color.ToString();
|
|
|
|
printf("pixel @ (1,0): %s\n", str.c_str());
|
|
|
|
|
|
|
|
color = image.GetPixel(Math::IntPoint(1, 1));
|
|
|
|
str = color.ToString();
|
|
|
|
printf("pixel @ (1,1): %s\n", str.c_str());
|
|
|
|
|
|
|
|
image.SetPixel(Math::IntPoint(0, 0), Gfx::Color(0.1f, 0.2f, 0.3f, 0.0f));
|
|
|
|
image.SetPixel(Math::IntPoint(1, 0), Gfx::Color(0.3f, 0.2f, 0.1f, 1.0f));
|
|
|
|
image.SetPixel(Math::IntPoint(0, 1), Gfx::Color(1.0f, 1.0f, 1.0f, 1.0f));
|
|
|
|
image.SetPixel(Math::IntPoint(1, 1), Gfx::Color(0.0f, 0.0f, 0.0f, 1.0f));
|
2012-07-03 22:04:53 +00:00
|
|
|
|
|
|
|
if (! image.SavePNG(argv[2]))
|
|
|
|
{
|
|
|
|
std::string err = image.GetError();
|
2013-01-17 19:54:35 +00:00
|
|
|
printf("Error saving PNG '%s': %s\n", argv[2], err.c_str());
|
2012-07-03 22:04:53 +00:00
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|