Exemplo n.º 1
0
uint8_t u8x8_d_tga_lcd(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_MEMORY:
      u8x8_d_helper_display_setup_memory(u8g2, &u8x8_tga_lcd_info);
      break;
    case U8X8_MSG_DISPLAY_INIT:
      u8x8_d_helper_display_init(u8g2);
      if ( tga_data == NULL )
	tga_init(2*XOFFSET+DEFAULT_WIDTH, 2*YOFFSET+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_fg_r = tga_lcd_fg_r;
      tga_fg_g = tga_lcd_fg_g;
      tga_fg_b = tga_lcd_fg_b;

      tga_bg_r = tga_lcd_bg_r;
      tga_bg_g = tga_lcd_bg_g;
      tga_bg_b = tga_lcd_bg_b;
    
      x = ((u8x8_tile_t *)arg_ptr)->x_pos;
      //printf("U8X8_MSG_DISPLAY_DRAW_TILE x=%d, ", x);
      x *= 8;
      x += u8g2->x_offset;
      x *= FACTOR;
      x += XOFFSET;
    
      y = ((u8x8_tile_t *)arg_ptr)->y_pos;
      //printf("y=%d, c=%d\n", y, ((u8x8_tile_t *)arg_ptr)->cnt);
      y *= 8;
      y *= FACTOR;
      y += YOFFSET;
    
      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, FACTOR);
	arg_int--;
	x += c*8*FACTOR;
      } while( arg_int > 0 );

      break;
    default:
      return 0;
  }
  return 1;
}
Exemplo n.º 2
0
Arquivo: main.c Projeto: gnkarn/ucglib
void prepare_picture(ucg_t *ucg)
{
    tga_init(128,64);
    ucg_Init(ucg, &ucg_dev_tga, ucg_ext_none, (ucg_com_fnptr)0);
    ucg_SetFontMode(ucg, UCG_FONT_MODE_TRANSPARENT);
    ucg_SetMaxClipRange(ucg);
    ucg_SetColor(ucg, 0, 0, 0, 0);
    ucg_DrawBox(ucg, ox, 0, 128, 64);
}
Exemplo n.º 3
0
Arquivo: main.c Projeto: gnkarn/ucglib
int main(void)
{

    tga_init(128,64);
    ucg_Init(&ucg, &ucg_dev_tga, ucg_ext_none, (ucg_com_fnptr)0);
    ucg_SetFontMode(&ucg, UCG_FONT_MODE_TRANSPARENT);

    ucg_SetColor(&ucg, 0, 0, 0, 0);
    ucg_DrawBox(&ucg, 0, 0, 128, 64);



    ucg_SetFont(&ucg, ucg_font_ncenB18_tf);

    ucg_SetColor(&ucg, 0, 0, 0, 255);
    ucg_DrawPixel(&ucg, 70,20);
    ucg_SetColor(&ucg, 0, 255, 0, 0);

    //ucg_SetFontPosBottom(&ucg);
    /*
    ucg_DrawGlyph(&ucg, 70, 20, 0, 'A');
    ucg_DrawGlyph(&ucg, 70, 20, 1, 'A');
    ucg_DrawGlyph(&ucg, 70, 20, 2, 'A');
    ucg_DrawGlyph(&ucg, 70, 20, 3, 'A');

    ucg_SetColor(&ucg, 0, 255, 255, 255);

    vrule(&ucg, 30, 0, 20, 1);
    vrule(&ucg, 30, 0, 20, 0);
    */
    //pos(&ucg, 70, 20, 0);

    //hrule(&ucg, 0, 20, 70, 1);
    //hrule(&ucg, 0, 20, 70, 0);


    ucg_SetColor(&ucg, 0, 255, 0, 0);
    ucg_SetColor(&ucg, 1, 0, 255, 0);
    ucg_SetColor(&ucg, 2, 255, 0, 255);
    ucg_SetColor(&ucg, 3, 0, 255, 255);

    ucg_DrawGradientLine(&ucg, 10, 40, 100, 0);

    ucg_DrawGradientBox(&ucg, 10, 43, 100, 20);


    tga_save("test.tga");

    draw_pixel(&ucg);
    draw_hline(&ucg);
    draw_vline(&ucg);
    set_clip_range(&ucg);
    draw_text_baseline(&ucg);
    draw_text_bottom(&ucg);
    draw_text_top(&ucg);
    draw_text_center(&ucg);
    draw_text_ascent_descent(&ucg);
    draw_text_dir1(&ucg);
    draw_box(&ucg);
    draw_frame(&ucg);
    draw_rbox(&ucg);
    draw_rframe(&ucg);
    draw_gradient_box(&ucg);
    draw_gradient_line(&ucg);
    draw_disc(&ucg);
    draw_circle(&ucg);
    draw_triangle(&ucg);
    set_scale2x2(&ucg);
    set_font_mode_1(&ucg);
    set_font_mode_2(&ucg);
    solid_font_variants(&ucg);
    string_overwrite(&ucg, 1);
    string_overwrite(&ucg, 5);
    string_overwrite(&ucg, 10);
    return 0;

}
Exemplo n.º 4
0
static void populate_asset_dir(
    const char* rootdir,
    const char* assetdir)
{
    uint32_t* hmap;
    uint32_t* smap;
    uint32_t* vmap;
    uint8_t* image;
    int32_t i;
    tga_header tga;
    tga_init(IMAGE_WIDTH, IMAGE_HEIGHT, 32, 0, &tga);

    hmap = (uint32_t*) malloc(IMAGE_WIDTH * IMAGE_HEIGHT * sizeof(*hmap));
    smap = (uint32_t*) malloc(IMAGE_WIDTH * IMAGE_HEIGHT * sizeof(*hmap));
    vmap = (uint32_t*) malloc(IMAGE_WIDTH * IMAGE_HEIGHT * sizeof(*hmap));
    image = (uint8_t*) malloc(IMAGE_WIDTH * IMAGE_HEIGHT * 4);
    for(i = 0; i < NUM_IMAGES; ++i)
    {
        char fname[16];
        char path[taa_PATH_SIZE];
        FILE* fp;        
        int32_t j;
        diamondsquare(IMAGE_WIDTH, IMAGE_HEIGHT, 0xffff, hmap);
        diamondsquare(IMAGE_WIDTH, IMAGE_HEIGHT, 0xffff, smap);
        diamondsquare(IMAGE_WIDTH, IMAGE_HEIGHT, 0xffff, vmap);
        // convert the hsv data into bgra
        for(j = 0; j < IMAGE_WIDTH * IMAGE_HEIGHT; ++j)
        {
            float b, g, r;
            float h, s, v;
            float h1, c, x, m;
            h = hmap[j] * (360.0f/0xffff); // hue in range 0 - 360
            s = smap[j] * (  1.0f/0xffff); // sat in range 0 - 1
            v = vmap[j] * (  1.0f/0xffff); // val in range 0 - 1
            s = s * 0.5f + 0.5f;
            c = v * s; // chroma
            h1 = h/60.0f; // h'
            x = c * (1.0f - (float) fabs(fmod(h1, 2) - 1.0f));
            if(h1 < FLT_EPSILON)
            {
                r = 0; g = 0; b = 0;
            }
            else if(h1 < 1.0f)
            {
                r = c; g = x; b = 0;
            }
            else if(h1 < 2.0f)
            {
                r = x; g = c; b = 0;
            }
            else if(h1 < 3.0f)
            {
                r = 0; g = c; b = x;
            }
            else if(h1 < 4.0f)
            {
                r = 0; g = x; b = c;
            }
            else if(h1 < 5.0f)
            {
                r = x; g = 0; b = c;
            }
            else
            {
                r = c; g = 0; b = x;            
            }
            m = v - c;
            image[j*4+0] = (uint8_t) ((b + m) * 0xff);
            image[j*4+1] = (uint8_t) ((g + m) * 0xff);
            image[j*4+2] = (uint8_t) ((r + m) * 0xff);
            image[j*4+3] = 0xff;
        }
        sprintf(fname, "%i.tga", i);
        taa_path_set(path, sizeof(path), rootdir);
        taa_path_append(path, sizeof(path), assetdir);
        taa_path_append(path, sizeof(path), fname);
        fp = fopen(path, "wb");
        if(fp != NULL)
        {
            unsigned char hbuf[tga_HEADER_SIZE];
            tga_write(&tga, hbuf);
            fwrite(hbuf, 1, sizeof(hbuf), fp);
            fwrite(image, 1, IMAGE_WIDTH*IMAGE_HEIGHT*4, fp);
            assert(ftell(fp) == (tga_HEADER_SIZE+IMAGE_WIDTH*IMAGE_HEIGHT*4));
            fclose(fp);
        }
    }
    free(image);
    free(vmap);
    free(smap);
    free(hmap);
}
Exemplo n.º 5
0
int main(int argc, char **argv)
{
  bf_t *bf_desc_font;
  bf_t *bf;
  char *bdf_filename = NULL;
  int is_verbose = 0;
  char *map_str ="*";
  char *desc_font_str = "";
  unsigned y;
  
  argv++;
  /*
  if ( *argv == NULL )
  {
    help();
    exit(1);
  }
  */
  for(;;)
  {
    if ( *argv == NULL )
      break;
    if ( is_arg(&argv, 'h') != 0 )
    {
      help();
      exit(1);
    }
    else if ( is_arg(&argv, 'v') != 0 )
    {
      is_verbose = 1;
    }
    else if ( is_arg(&argv, 'a') != 0 )
    {
      font_picture_extra_info = 1;
    }
    else if ( is_arg(&argv, 't') != 0 )
    {
      font_picture_test_string = 1;
    }
    else if ( is_arg(&argv, 'r') != 0 )
    {
      runtime_test = 1;
    }
    else if ( get_num_arg(&argv, 'b', &build_bbx_mode) != 0 )
    {
    }
    else if ( get_num_arg(&argv, 'f', &font_format) != 0 )
    {
    }
    else if ( get_num_arg(&argv, 'l', &left_margin) != 0 )
    {
    }
    else if ( get_str_arg(&argv, 'd', &desc_font_str) != 0 )
    {      
    }
    else if ( get_str_arg(&argv, 'o', &c_filename) != 0 )
    {      
    }
    else if ( get_str_arg(&argv, 'n', &target_fontname) != 0 )
    {      
    }
    else if ( get_str_arg(&argv, 'm', &map_str) != 0 )
    {      
    }
    else
    {
      bdf_filename = *argv;
      argv++;
    }
  }
  
  if ( bdf_filename  == NULL )
  {
    help();
    exit(1);
  }

  bf_desc_font = NULL;
  if ( desc_font_str[0] != '\0' )
  {
    bf_desc_font = bf_OpenFromFile(desc_font_str, 0, BDF_BBX_MODE_MINIMAL, "*", 0);	/* assume format 0 for description */
    if ( bf_desc_font == NULL )
    {
      exit(1);
    }
  }

  if ( font_format == 1 )
  {
    build_bbx_mode = BDF_BBX_MODE_M8;
    /* issue the following log message later, when there is a valid bf object */
    /* bf_Log(bf, "Font mode 1: BBX mode set to 3"); */
  }
  
  bf = bf_OpenFromFile(bdf_filename, is_verbose, build_bbx_mode, map_str, font_format);
  
  if ( bf == NULL )
  {
    exit(1);
  }

  if ( font_format == 1 )
  {
    /* now generate the log message */
    bf_Log(bf, "Note: For font format 1 BBX mode has been set to 3");
  }

  if ( bf_desc_font != NULL )
  {
    tga_init(1024, 600);
    y = tga_draw_font(0, bdf_filename, bf_desc_font, bf);
    
    if ( runtime_test != 0 )
    {
      long i;
      clock_t c = clock();
      fd_t fd;
      fd_init(&fd);
      fd_set_font(&fd, bf->target_data);
      for( i = 0; i < 10000; i++ )
	fd_draw_string(&fd, left_margin, y, "Woven silk pyjamas exchanged for blue quartz.");
      bf_Log(bf, "Runtime test: %.2lf sec", (double)(clock()-c)/(double)CLOCKS_PER_SEC);
    }
    
    tga_save("bdf.tga");
  }
  
  
  if ( c_filename != NULL )
  {
    /* write the encoded data in bf->target_data */
    if ( font_format == 0 )
    {
      bf_WriteUCGCByFilename(bf, c_filename, target_fontname, "  ");
    }
    else
    {
      bf_WriteU8G2CByFilename(bf, c_filename, target_fontname, "  ");
    }
  }

  
  bf_Close(bf);
  return 0;
}