mirror of
git://projects.qi-hardware.com/antorcha.git
synced 2024-11-25 17:43:44 +02:00
tools/libtxt/font.c: split load_image_file (load from open file) off load_image
This commit is contained in:
parent
21e4fb267e
commit
236ef1dad0
@ -99,19 +99,11 @@ static const char *read_xbm_file(FILE *file, struct image *img)
|
||||
}
|
||||
|
||||
|
||||
struct image *load_image(const char *name, const char **error)
|
||||
struct image *load_image_file(FILE *file, const char **error)
|
||||
{
|
||||
FILE *file;
|
||||
struct image *img;
|
||||
const char *err;
|
||||
|
||||
file = fopen(name, "r");
|
||||
if (!file) {
|
||||
if (error)
|
||||
*error = alloc_sprintf("%s: %s", name, strerror(errno));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
img = alloc_type(struct image);
|
||||
err = read_xbm_file(file, img);
|
||||
if (err) {
|
||||
@ -124,6 +116,23 @@ struct image *load_image(const char *name, const char **error)
|
||||
}
|
||||
|
||||
|
||||
struct image *load_image(const char *name, const char **error)
|
||||
{
|
||||
FILE *file;
|
||||
struct image *img;
|
||||
|
||||
file = fopen(name, "r");
|
||||
if (!file) {
|
||||
if (error)
|
||||
*error = alloc_sprintf("%s: %s", name, strerror(errno));
|
||||
return NULL;
|
||||
}
|
||||
img = load_image_file(file, error);
|
||||
fclose(file);
|
||||
return img;
|
||||
}
|
||||
|
||||
|
||||
void free_image(struct image *img)
|
||||
{
|
||||
if (img) {
|
||||
|
@ -13,6 +13,9 @@
|
||||
#ifndef LIBTXT_H
|
||||
#define LIBTXT_H
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
struct image;
|
||||
|
||||
struct font;
|
||||
@ -51,6 +54,7 @@ struct edit {
|
||||
* Newline leaves one blank row between text lines.
|
||||
*/
|
||||
|
||||
struct image *load_image_file(FILE *file, const char **error);
|
||||
struct image *load_image(const char *name, const char **error);
|
||||
void free_image(struct image *img);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user