overview pics

This commit is contained in:
olikraus 2015-11-14 18:44:51 +01:00
parent ea2c902010
commit 01e9cdc054
6 changed files with 429 additions and 13 deletions

View File

@ -290,8 +290,18 @@ uint8_t u8g2_IsIntersection(u8g2_t *u8g2, u8g2_uint_t x0, u8g2_uint_t y0, u8g2_u
#define U8G2_FONT_HEIGHT_MODE_ALL 2
void u8g2_SetFont(u8g2_t *u8g2, const uint8_t *font);
uint8_t u8g2_IsGlyph(u8g2_t *u8g2, uint16_t requested_encoding);
int8_t u8g2_GetGlyphWidth(u8g2_t *u8g2, uint16_t requested_encoding);
u8g2_uint_t u8g2_DrawGlyph(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, uint16_t encoding);
void u8g2_SetFontDirection(u8g2_t *u8g2, uint8_t dir);
u8g2_uint_t u8g2_DrawString(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, const char *str);
#define u8g2_GetMaxCharHeight(u8g2) ((u8g2)->font_info.max_char_height)
#define u8g2_GetMaxCharWidth(u8g2) ((u8g2)->font_info.max_char_height)
#define u8g2_GetAscent(u8g2) ((u8g2)->font_info.ascent_A)
#define u8g2_GetDescent(u8g2) ((u8g2)->font_info.descent_g)
/*==========================================*/
/* u8x8_d_sdl_128x64.c */

View File

@ -614,7 +614,7 @@ static u8g2_uint_t u8g2_font_draw_glyph(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t
uint8_t u8g2_IsGlyph(u8g2_t *u8g2, uint8_t requested_encoding)
uint8_t u8g2_IsGlyph(u8g2_t *u8g2, uint16_t requested_encoding)
{
/* updated to new code */
if ( u8g2_font_get_glyph_data(u8g2, requested_encoding) != NULL )

View File

@ -11,6 +11,9 @@
#define DEFAULT_HEIGHT (FACTOR*64)
uint16_t tga_max_x;
uint16_t tga_max_y;
static uint16_t tga_width;
static uint16_t tga_height;
static uint8_t *tga_data = NULL;
@ -24,6 +27,8 @@ uint8_t tga_desc_b = 255;
int tga_init(uint16_t w, uint16_t h)
{
tga_max_x = 0;
tga_max_y = 0;
tga_width = 0;
tga_height = 0;
if ( tga_data != NULL )

View File

@ -1,21 +1,29 @@
# works within ubuntu and min-gw (win7) environment
CFLAGS = -g -Wall
CFLAGS = -g -DBUILD2 -Wall -I../../../csrc/
#CFLAGS = -O4 -Wall
SRC = build.c
SRC1 = build.c
SRC2 = build.c u8x8_font_list.c u8g2_font_list.c u8g2_d_tga.c $(shell ls ../../../csrc/*.c)
OBJ = $(SRC:.c=.o)
ASM = $(SRC:.c=.s)
OBJ1 = $(SRC1:.c=.o)
OBJ2 = $(SRC2:.c=.o)
ASM1 = $(SRC1:.c=.s)
ASM2 = $(SRC2:.c=.s)
.c.s:
$(CC) $(CFLAGS) -S -o $@ $<
build: $(OBJ) $(ASM)
$(CC) $(CFLAGS) $(LDFLAGS) $(OBJ) -o build
build1: $(SRC1)
$(CC) $(LDFLAGS) $(SRC1) -o build1
build2: $(OBJ2)
$(CC) $(CFLAGS) $(LDFLAGS) $(OBJ2) -o build2
clean:
-rm $(OBJ) $(ASM) build
-rm $(OBJ1) $(ASM1) build1 $(OBJ2) $(ASM2) build2
test:
./build
./build1

View File

@ -3,6 +3,20 @@
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdint.h>
#ifdef BUILD2
#include "u8g2.h"
#endif
extern const uint8_t *u8x8_font_list[] ;
extern char *u8x8_font_names[] ;
extern const uint8_t *u8g2_font_list[] ;
extern char *u8g2_font_names[] ;
#ifdef BUILD2
extern void u8g2_Setup_TGA(u8g2_t *u8g2, const u8g2_cb_t *u8g2_cb);
extern void tga_save(const char *name);
#endif
/*===================================*/
@ -225,6 +239,9 @@ struct fontinfo fi[] = {
};
char *bdf_path = "../bdf/";
char *bdfconv_path = "../bdfconv/bdfconv";
FILE *u8g2_font_list_fp;
@ -237,6 +254,115 @@ char *u8x8_fonts_filename = "../../../csrc/u8x8_fonts.c";
char target_font_identifier[1024];
char bdf_cmd[2048];
char font_prototype[2048];
char tga_filename[2048];
char convert_cmd[2048];
#ifdef BUILD2
u8g2_t u8g2;
int u8g2_fnt_cnt = 0;
void overview_draw_line(int i, uint16_t encoding_start, uint16_t x, uint16_t y, uint16_t w)
{
int j;
u8g2_SetFont(&u8g2, u8g2_font_list[u8g2_fnt_cnt]);
u8g2_SetFontDirection(&u8g2, 0);
u8g2_DrawString(&u8g2, 0, 40, u8g2_font_names[u8g2_fnt_cnt]);
for( j = 0; j < 16; j++)
{
if ( u8g2_IsGlyph(&u8g2, encoding_start + j) != 0 )
{
u8g2_DrawGlyph(&u8g2, x+j*w, y, encoding_start + j);
}
}
}
int is_overview_line_empty(uint16_t encoding_start)
{
int j;
for( j = 0; j < 16; j++)
{
if ( u8g2_IsGlyph(&u8g2, encoding_start + j) != 0 )
{
return 0;
}
}
return 1;
}
void overview_draw_table(int i, uint16_t x, uint16_t y)
{
int cw, ch;
int line;
uint16_t encoding;
u8g2_SetFont(&u8g2, u8g2_font_7x13_tr);
u8g2_DrawString(&u8g2, 0, 20, u8g2_font_names[u8g2_fnt_cnt]);
u8g2_SetFont(&u8g2, u8g2_font_list[u8g2_fnt_cnt]);
u8g2_SetFontDirection(&u8g2, 0);
ch = u8g2_GetMaxCharHeight(&u8g2);
cw = u8g2_GetMaxCharWidth(&u8g2);
line = 0;
for(;;)
{
encoding = line*16;
if ( is_overview_line_empty(encoding) == 0 )
{
overview_draw_line(i, encoding, x, y, cw);
y += ch;
}
line++;
if ( line > 16 )
break;
}
}
void overviewpic(int i, int fm, char *fms, int bm, char *bms, int mm, char *mms)
{
int cw, ch;
//if ( fm == FM_8 )
if ( fm == FM_C )
{
printf("overview picture %s\n", target_font_identifier);
u8g2_Setup_TGA(&u8g2, &u8g2_cb_r0);
u8x8_display_Init(u8g2_GetU8x8(&u8g2));
u8x8_display_SetPowerSave(u8g2_GetU8x8(&u8g2), 0);
//u8g2_SetFont(&u8g2, u8g2_font_helvB14_tr);
u8g2_FirstPage(&u8g2);
do
{
u8g2_SetFont(&u8g2, u8g2_font_list[u8g2_fnt_cnt]);
u8g2_SetFontDirection(&u8g2, 0);
u8g2_DrawString(&u8g2, 0, 40, u8g2_font_names[u8g2_fnt_cnt]);
ch = u8g2_GetMaxCharHeight(&u8g2);
cw = u8g2_GetMaxCharWidth(&u8g2);
overview_draw_table(i, 0, 60);
//overviewline(i, '@', 0, 80, cw);
} while( u8g2_NextPage(&u8g2) );
strcpy(tga_filename, target_font_identifier);
strcat(tga_filename, ".tga");
tga_save("font.tga");
sprintf(convert_cmd, "convert font.tga -trim %s.png", target_font_identifier );
system(convert_cmd);
u8g2_fnt_cnt++;
}
}
#endif
void bdfconv(int i, int fm, char *fms, int bm, char *bms, int mm, char *mms)
{
@ -414,6 +540,8 @@ int main(void)
{
//unlink(u8x8_fonts_filename);
//unlink(u8g2_fonts_filename);
#ifndef BUILD2
if ( file_copy("u8x8_fonts.pre", u8x8_fonts_filename) == 0 )
return 0;
@ -429,14 +557,14 @@ int main(void)
fprintf(u8x8_font_list_fp, "/* u8x8_font_list.c */\n");
fprintf(u8g2_font_list_fp, "#include \"u8g2.h\"\n");
fprintf(u8x8_font_list_fp, "#include \"u8g2.h\"\n");
fprintf(u8g2_font_list_fp, "uint8_t *u8g2_font_list[] = {\n");
fprintf(u8x8_font_list_fp, "uint8_t *u8x8_font_list[] = {\n");
fprintf(u8g2_font_list_fp, "const uint8_t *u8g2_font_list[] = {\n");
fprintf(u8x8_font_list_fp, "const uint8_t *u8x8_font_list[] = {\n");
do_font_loop(fontlist_identifier);
fprintf(u8g2_font_list_fp, " NULL\n};\n");
fprintf(u8x8_font_list_fp, " NULL\n};\n");
fprintf(u8g2_font_list_fp, "uint8_t *u8g2_font_names[] = {\n");
fprintf(u8x8_font_list_fp, "uint8_t *u8x8_font_names[] = {\n");
fprintf(u8g2_font_list_fp, "char *u8g2_font_names[] = {\n");
fprintf(u8x8_font_list_fp, "char *u8x8_font_names[] = {\n");
do_font_loop(fontlist_name);
fprintf(u8g2_font_list_fp, " NULL\n};\n");
fprintf(u8x8_font_list_fp, " NULL\n};\n");
@ -450,6 +578,12 @@ int main(void)
insert_into_file("../../../csrc/u8x8.h", u8x8_prototypes, "/* start font list */", "/* end font list */");
unlink("font.c");
#endif
#ifdef BUILD2
u8g2_fnt_cnt = 0;
do_font_loop(overviewpic);
#endif
return 0;
}

View File

@ -0,0 +1,259 @@
#include "u8g2.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define FACTOR 3
#define XOFFSET (FACTOR*32)
#define YOFFSET (FACTOR*32)
#define DEFAULT_WIDTH (FACTOR*128)
#define DEFAULT_HEIGHT (FACTOR*64)
uint16_t tga_max_x;
uint16_t tga_max_y;
static uint16_t tga_width;
static uint16_t tga_height;
static uint8_t *tga_data = NULL;
uint8_t tga_r = 0;
uint8_t tga_g = 0;
uint8_t tga_b = 0;
uint8_t tga_desc_r = 0;
uint8_t tga_desc_g = 0;
uint8_t tga_desc_b = 255;
int tga_init(uint16_t w, uint16_t h)
{
tga_max_x = 0;
tga_max_y = 0;
tga_width = 0;
tga_height = 0;
if ( tga_data != NULL )
free(tga_data);
tga_data = (uint8_t *)malloc(w*h*3);
if ( tga_data == NULL )
return 0;
tga_width = w;
tga_height = h;
memset(tga_data, 255, tga_width*tga_height*3);
return 1;
}
void tga_set_pixel(uint16_t x, uint16_t y, uint16_t f)
{
uint8_t *p;
uint16_t xx,yy;
for( yy = y; yy < y+f; yy++ )
{
for( xx = x; xx < x+f; xx++ )
{
if ( yy < tga_height && xx < tga_width )
{
//printf ("(%d %d) ", xx, yy);
p = tga_data + (tga_height-yy-1)*tga_width*3 + xx*3;
*p++ = tga_b;
*p++ = tga_g;
*p++ = tga_r;
}
}
}
}
void tga_clr_pixel(uint16_t x, uint16_t y, uint16_t f)
{
uint8_t *p;
uint16_t xx,yy;
for( yy = y; yy < y+f; yy++ )
{
for( xx = x; xx < x+f; xx++ )
{
p = tga_data + (tga_height-yy-1)*tga_width*3 + xx*3;
*p++ = 255;
*p++ = 255;
*p++ = 255;
}
}
}
void tga_set_8pixel(int x, int y, uint8_t pixel, uint16_t f)
{
int cnt = 8;
while( cnt > 0 )
{
if ( (pixel & 1) != 0 )
{
tga_set_pixel(x,y, f);
}
else
{
tga_clr_pixel(x,y, f);
}
pixel >>= 1;
y+=f;
cnt--;
}
}
void tga_set_multiple_8pixel(int x, int y, int cnt, uint8_t *pixel, uint16_t f)
{
uint8_t b;
while( cnt > 0 )
{
b = *pixel;
tga_set_8pixel(x, y, b, f);
x+=f;
pixel++;
cnt--;
}
}
void tga_write_byte(FILE *fp, uint8_t byte)
{
fputc(byte, fp);
}
void tga_write_word(FILE *fp, uint16_t word)
{
tga_write_byte(fp, word&255);
tga_write_byte(fp, word>>8);
}
void tga_save(const char *name)
{
FILE *fp;
if ( tga_data == NULL )
return;
printf("tga_save: File %s with %dx%d pixel\n", name, tga_width, tga_height);
fp = fopen(name, "wb");
if ( fp != NULL )
{
tga_write_byte(fp, 0); /* no ID */
tga_write_byte(fp, 0); /* no color map */
tga_write_byte(fp, 2); /* uncompressed true color */
tga_write_word(fp, 0);
tga_write_word(fp, 0);
tga_write_byte(fp, 0);
tga_write_word(fp, 0); /* x origin */
tga_write_word(fp, 0); /* y origin */
tga_write_word(fp, tga_width); /* width */
tga_write_word(fp, tga_height); /* height */
tga_write_byte(fp, 24); /* color depth */
tga_write_byte(fp, 0);
fwrite(tga_data, tga_width*tga_height*3, 1, fp);
tga_write_word(fp, 0);
tga_write_word(fp, 0);
tga_write_word(fp, 0);
tga_write_word(fp, 0);
fwrite("TRUEVISION-XFILE.", 18, 1, fp);
fclose(fp);
}
}
/*==========================================*/
/* tga procedures */
static const u8x8_display_info_t u8x8_tga_info =
{
/* chip_enable_level = */ 0,
/* chip_disable_level = */ 1,
/* post_chip_enable_wait_ns = */ 0,
/* pre_chip_disable_wait_ns = */ 0,
/* reset_pulse_width_ms = */ 0,
/* post_reset_wait_ms = */ 0,
/* sda_setup_time_ns = */ 0,
/* sck_pulse_width_ns = */ 0,
/* sck_takeover_edge = */ 1,
/* i2c_bus_clock_100kHz = */ 0,
/* data_setup_time_ns = */ 0,
/* write_pulse_width_ns = */ 0,
/* tile_width = */ (DEFAULT_WIDTH)/8,
/* tile_hight = */ (DEFAULT_HEIGHT)/8,
#if U8X8_DEFAULT_FLIP_MODE == 0
/* default_x_offset = */ 0,
#else
/* default_x_offset = */ 0,
#endif
};
uint8_t u8x8_d_tga(u8x8_t *u8g2, uint8_t msg, uint8_t arg_int, void *arg_ptr)
{
u8g2_uint_t x, y, c;
uint8_t *ptr;
switch(msg)
{
case U8X8_MSG_DISPLAY_SETUP:
u8x8_d_helper_display_setup(u8g2, &u8x8_tga_info);
break;
case U8X8_MSG_DISPLAY_INIT:
u8x8_d_helper_display_init(u8g2);
if ( tga_data == NULL )
tga_init(DEFAULT_WIDTH, DEFAULT_HEIGHT);
break;
case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
break;
case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
break;
case U8X8_MSG_DISPLAY_SET_CONTRAST:
break;
case U8X8_MSG_DISPLAY_DRAW_TILE:
tga_r = tga_desc_r;
tga_g = tga_desc_g;
tga_b = tga_desc_b;
x = ((u8x8_tile_t *)arg_ptr)->x_pos;
//printf("U8X8_MSG_DISPLAY_DRAW_TILE x=%d, ", x);
x *= 8;
x += u8g2->x_offset;
y = ((u8x8_tile_t *)arg_ptr)->y_pos;
//printf("y=%d, c=%d\n", y, ((u8x8_tile_t *)arg_ptr)->cnt);
y *= 8;
do
{
c = ((u8x8_tile_t *)arg_ptr)->cnt;
ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
tga_set_multiple_8pixel(x, y, c*8, ptr, 1);
arg_int--;
} while( arg_int > 0 );
break;
default:
return 0;
}
return 1;
}
void u8x8_Setup_TGA(u8x8_t *u8x8)
{
/* setup defaults */
u8x8_SetupDefaults(u8x8);
/* setup specific callbacks */
u8x8->display_cb = u8x8_d_tga;
/* setup display info */
u8x8_display_Setup(u8x8);
}
void u8g2_Setup_TGA(u8g2_t *u8g2, const u8g2_cb_t *u8g2_cb)
{
static uint8_t buf[(DEFAULT_WIDTH)*8];
u8x8_Setup_TGA(u8g2_GetU8x8(u8g2));
u8g2_Setup(u8g2, buf, 1, u8g2_cb);
}