2020-06-23 07:17:07 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
2020-06-29 19:27:59 +01:00
|
|
|
#include <string.h>
|
|
|
|
|
#include <cairo.h>
|
2020-06-23 07:17:07 +01:00
|
|
|
|
2020-08-31 20:01:08 +01:00
|
|
|
#include "xbm/parse.h"
|
2020-08-10 17:24:17 +01:00
|
|
|
#include "common/grab-file.h"
|
2020-06-23 07:17:07 +01:00
|
|
|
|
2020-08-31 20:01:08 +01:00
|
|
|
static float red[] = { 1.0, 0.0, 0.0, 1.0 };
|
|
|
|
|
|
2020-06-23 07:17:07 +01:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
|
{
|
|
|
|
|
struct token *tokens;
|
|
|
|
|
|
|
|
|
|
if (argc != 2) {
|
|
|
|
|
fprintf(stderr, "usage: %s <xbm-file>\n", argv[0]);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-10 17:24:17 +01:00
|
|
|
char *buffer = grab_file(argv[1]);
|
2020-06-23 07:17:07 +01:00
|
|
|
if (!buffer)
|
|
|
|
|
exit(EXIT_FAILURE);
|
2020-08-10 17:24:17 +01:00
|
|
|
tokens = tokenize_xbm(buffer);
|
2020-06-23 07:17:07 +01:00
|
|
|
free(buffer);
|
2020-08-31 20:01:08 +01:00
|
|
|
parse_set_color(red);
|
2020-08-10 17:24:17 +01:00
|
|
|
struct pixmap pixmap = parse_xbm_tokens(tokens);
|
2020-06-23 07:17:07 +01:00
|
|
|
free(tokens);
|
2020-06-26 21:52:38 +01:00
|
|
|
|
2020-06-29 19:27:59 +01:00
|
|
|
cairo_surface_t *g_surface;
|
|
|
|
|
g_surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
|
|
|
|
|
pixmap.width, pixmap.height);
|
|
|
|
|
if (!g_surface) {
|
2020-06-26 21:52:38 +01:00
|
|
|
fprintf(stderr, "no surface\n");
|
2020-06-29 19:27:59 +01:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
}
|
|
|
|
|
unsigned char *surface_data = cairo_image_surface_get_data(g_surface);
|
|
|
|
|
cairo_surface_flush(g_surface);
|
|
|
|
|
memcpy(surface_data, pixmap.data, pixmap.width * pixmap.height * 4);
|
|
|
|
|
if (pixmap.data)
|
|
|
|
|
free(pixmap.data);
|
|
|
|
|
cairo_surface_mark_dirty(g_surface);
|
|
|
|
|
|
2020-06-26 21:52:38 +01:00
|
|
|
char png_name[1024];
|
|
|
|
|
snprintf(png_name, sizeof(png_name), "%s.png", argv[1]);
|
2020-06-29 19:27:59 +01:00
|
|
|
if (cairo_surface_write_to_png(g_surface, png_name)) {
|
2020-06-26 21:52:38 +01:00
|
|
|
fprintf(stderr, "cannot save png\n");
|
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
}
|
2020-06-29 19:27:59 +01:00
|
|
|
cairo_surface_destroy(g_surface);
|
2020-06-26 21:52:38 +01:00
|
|
|
exit(EXIT_SUCCESS);
|
2020-06-23 07:17:07 +01:00
|
|
|
}
|