79 lines
2.0 KiB
C
79 lines
2.0 KiB
C
#include "config.h"
|
|
#include "hvif-cairo.h"
|
|
#include "hvif-light.h"
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
int
|
|
main(int argc, char* argv[argc + 1])
|
|
{
|
|
puts(PACKAGE_STRING);
|
|
|
|
if (argc < 2) {
|
|
if (argc > 0) printf("Usage: %s FILE [SIZE]\n", argv[0]);
|
|
return EXIT_FAILURE;
|
|
}
|
|
|
|
FILE* imagefile = fopen(argv[1], "rb");
|
|
if (!imagefile) {
|
|
fputs("fopen failed.\n", stderr);
|
|
return EXIT_FAILURE;
|
|
}
|
|
|
|
hvif_result result = hvif_from_file(imagefile);
|
|
fclose(imagefile);
|
|
|
|
if (result.status != SUCCESS) {
|
|
fputs("Reading image failed.\n", stderr);
|
|
switch (result.status) {
|
|
case ERROR_EOF: fputs("File ended prematurely.\n", stderr); break;
|
|
case ERROR_NOMEM: fputs("Out of memory.\n", stderr); break;
|
|
case ERROR_MAGIC: fputs("Wrong magic number.\n", stderr); break;
|
|
case ERROR_STYLE: fputs("Incorrect style definition.\n", stderr); break;
|
|
case ERROR_PATH: fputs("Incorrect path definition.\n", stderr); break;
|
|
case ERROR_SHAPE: fputs("Incorrect shape definition.\n", stderr); break;
|
|
default: break;
|
|
}
|
|
return EXIT_FAILURE;
|
|
}
|
|
puts("Reading image succeeded.");
|
|
|
|
const char* pf = ".png";
|
|
size_t out_len = strlen(argv[1]) + strlen(pf) + 1;
|
|
|
|
char out_filename[out_len];
|
|
strcpy(out_filename, argv[1]);
|
|
strcat(out_filename, pf);
|
|
|
|
unsigned pixel_size = 64;
|
|
if (argc > 2) {
|
|
int n = atoi(argv[2]);
|
|
if (n <= 1)
|
|
fputs("Illegal image size. Using default of 64.\n", stderr);
|
|
else
|
|
pixel_size = n;
|
|
}
|
|
|
|
printf(
|
|
"Creating %s with a size of %dx%d\n", out_filename, pixel_size, pixel_size);
|
|
|
|
hvif_cairo_status out_result =
|
|
hvif_cairo_png_render(out_filename, result.image, pixel_size);
|
|
hvif_free(result.image);
|
|
|
|
if (out_result != HVIF_CAIRO_SUCCESS) {
|
|
switch (out_result) {
|
|
case HVIF_CAIRO_UNSUPPORTED:
|
|
puts("Image uses features no supported by cairo renderer.");
|
|
break;
|
|
case HVIF_CAIRO_ERROR_NOMEM: fputs("Out of memory.", stderr); break;
|
|
case HVIF_CAIRO_ERROR: fputs("Error rendering picture.", stderr); break;
|
|
default: break;
|
|
}
|
|
return EXIT_FAILURE;
|
|
}
|
|
return EXIT_SUCCESS;
|
|
}
|