awtk/tools/image_gen/main.c

83 lines
1.9 KiB
C
Raw Normal View History

2018-02-21 19:36:38 +08:00
/**
* File: main.c
2018-05-15 09:31:58 +08:00
* Author: AWTK Develop Team
2018-02-21 19:36:38 +08:00
* Brief: bitmap font generator
*
2019-01-07 10:58:36 +08:00
* Copyright (c) 2018 - 2019 Guangzhou ZHIYUAN Electronics Co.,Ltd.
2018-02-21 19:36:38 +08:00
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* License file for more details.
*
*/
/**
* History:
* ================================================================
* 2018-01-21 Li XianJing <xianjimli@hotmail.com> created
*
*/
#include "tkc/mem.h"
2018-02-21 19:36:38 +08:00
#include "image_gen.h"
2018-03-18 11:29:31 +08:00
#include "common/utils.h"
#include "base/image_manager.h"
2018-02-21 19:36:38 +08:00
#include "image_loader/image_loader_stb.h"
int main(int argc, char** argv) {
bitmap_t image;
2018-03-18 11:29:31 +08:00
uint32_t size = 0;
uint8_t* buff = NULL;
2019-08-12 10:47:09 +08:00
bool_t mono = FALSE;
bool_t require_bgra = FALSE;
bool_t enable_bgr565 = FALSE;
2018-02-21 19:36:38 +08:00
const char* in_filename = NULL;
const char* out_filename = NULL;
2018-05-04 11:45:09 +08:00
TKMEM_INIT(4 * 1024 * 1024);
2018-02-21 19:36:38 +08:00
if (argc < 3) {
2019-08-12 10:47:09 +08:00
printf("Usage: %s in_filename out_filename (bgra|bgr565|mono)\n", argv[0]);
2018-02-21 19:36:38 +08:00
return 0;
}
if (argc >= 4) {
const char* options = argv[3];
2019-08-12 10:47:09 +08:00
if (strstr(options, "mono") != NULL) {
mono = TRUE;
}
if (strstr(options, "bgra") != NULL) {
require_bgra = TRUE;
}
if (strstr(options, "bgr565") != NULL) {
enable_bgr565 = TRUE;
}
}
2018-02-21 19:36:38 +08:00
in_filename = argv[1];
out_filename = argv[2];
2018-11-02 11:51:14 +08:00
exit_if_need_not_update(in_filename, out_filename);
2018-03-18 11:29:31 +08:00
buff = (uint8_t*)read_file(in_filename, &size);
2018-03-18 17:02:10 +08:00
if (buff != NULL) {
2018-11-25 18:57:44 +08:00
if (stb_load_image(0, buff, size, &image, require_bgra, enable_bgr565) == RET_OK) {
2019-08-12 10:47:09 +08:00
if (image_gen(&image, out_filename, mono) == RET_OK) {
2018-03-18 11:29:31 +08:00
printf("done\n");
} else {
printf("gen %s failed\n", out_filename);
}
2018-02-21 19:36:38 +08:00
} else {
2018-03-18 11:29:31 +08:00
printf("load %s failed\n", in_filename);
2018-02-21 19:36:38 +08:00
}
2018-10-08 16:37:20 +08:00
TKMEM_FREE(buff);
2018-02-21 19:36:38 +08:00
}
return 0;
}