void set_bgimage(void) { bmphandle_t bh; if (chat_count > 0 || no_count > 10) return; bh = bmp_open(bg_image); if (bh == NULL) { perror("bmp_open"); clear_screen(); return; } if (bmp_width(bh) > 320 || bmp_height(bh) > 240) { clear_screen(); fprintf(stderr, "bmp size is too large: %d x %d\n", bmp_width(bh), bmp_height(bh)); bmp_close(bh); return; } buf_bmp(bh, 0, 0); bmp_close(bh); show_vfb(vfb_list[0]); }
void setear_buffer(buffer_info_t *buffer, BMP *bmp) { buffer->bytes = bmp_data(bmp); buffer->width = bmp_width(bmp); buffer->height = bmp_height(bmp); buffer->width_with_padding = bmp_bytes_per_row(bmp); }
void gbm_generate_code_from_buffer(char *output_file_name) { int i; FILE *f = fopen(output_file_name, "w+"); fprintf(f, "0x%x, ", (bmp_width() & 0xff)); fprintf(f, "0x%x, ", (bmp_height() & 0xff)); printf("%d\n", gbm_buffer_size); for(i = 2; i < gbm_buffer_size; i++) { fprintf(f, "0x%x, ", gbm_buffer[i]); } fclose(f); }
void gbm_plot(uint8_t x, uint8_t y, enum glcd_color_t color) { uint8_t page, bit, byte; uint16_t index; page = (y / 8); bit = (y % 8); index = (page * bmp_width()) + x + 2; byte = gbm_buffer[index]; if(color) { byte |= 1 << bit; } else { byte &= ~(1 << bit); } gbm_buffer[index] = byte; }
static int file_to_fb(const char * srcpath) { int ret = -1; BMP_READ * bmp = NULL; struct FB * fb = NULL; int sw, sh; int srcbpp, dstbpp; void * pdata = NULL, * bmpdata = NULL; RGB_CONVERT_FUN convert_func = NULL; do { bmp = bmp_open(srcpath); if (!bmp) { break; } fb = fb_create(0); if (!fb) { break; } sw = bmp_width(bmp); sh = bmp_height(bmp); bmpdata = bmp_data(bmp); srcbpp = bmp_bpp(bmp); dstbpp = fb_bpp(fb); convert_func = get_convert_func(srcbpp, dstbpp); if (convert_func) { pdata = convert_func(bmpdata, sw, sh); bmpdata = pdata; } if (!bmp_forward(bmp)) { line_reversal(bmpdata, sw, sh, dstbpp); } rgb_copy(bmpdata, fb_bits(fb), sw, sh, fb_width(fb), fb_height(fb), dstbpp); ret = 0; } while (0); fb_destory(fb); bmp_close(bmp); if (pdata) { free(pdata); } return ret; }
static int file_to_file(const char * srcpath, const char * dstpath, int output_rgb) { int ret = -1; BMP_READ * bmp = NULL; int w, h; int srcbpp, dstbpp; void * pdata = NULL, * bmpdata = NULL; RGB_CONVERT_FUN convert_func = NULL; do { bmp = bmp_open(srcpath); if (!bmp) { break; } w = bmp_width(bmp); h = bmp_height(bmp); bmpdata = bmp_data(bmp); srcbpp = bmp_bpp(bmp); dstbpp = g_rgbbpp[output_rgb]; convert_func = get_convert_func(srcbpp, dstbpp); if (convert_func) { pdata = convert_func(bmpdata, w, h); bmpdata = pdata; } if (!bmp_forward(bmp)) { line_reversal(bmpdata, w, h, dstbpp); } ret = save_bmp(dstpath, w, h, bmpdata, dstbpp); } while (0); bmp_close(bmp); if (pdata) { free(pdata); } return ret; }
void draw_icon(struct icon *icon) { int i, j; bmphandle_t bh; if (icon->mode) { bh = bmp_open(icon->name); if (bh == NULL) { perror("bmp_open"); return; } for (i=icon->y; i<icon->y+bmp_height(bh); i++) for (j=icon->x; j<icon->x+bmp_width(bh); j++) *(myfb->fb + i*myfb->fbvar.xres +j) = makepixel(bmp_getpixel(bh, j-icon->x, i-icon->y)); bmp_close(bh); } else { drow_rect(icon->x, icon->y, icon->x + icon->w, icon->y + icon->h, icon->color); put_string_center(icon->x + icon->w/2, icon->y + icon->h/2, icon->name, icon->color); } }
//for libgd2 < 2.99.999 gdImagePtr gdImageCreateFromBmpPtr(int size, void *data) { gdImagePtr ret; bmphandle_t bh; int h, w, i, j; struct bgrpixel r; int color; bh = bmp_open(data, size); if (bh == NULL) return NULL; h = bmp_height(bh); w = bmp_width(bh); ret = gdImageCreateTrueColor(w, h); for (i = 0; i < w; i++) { for (j = 0; j < h; j++) { r = bmp_getpixel(bh, i, j); color = gdImageColorResolve(ret, r.r, r.g, r.b); gdImageSetPixel(ret, i, j, color); } } bmp_close(bh); return ret; }
/* * Copy a tile from our tile image, loaded previously, into tile RAM. In the * case of tiles with a width or height larger than 8 pixels, this will result * in multiple tile positions being occupied in video RAM. */ void nds_load_graphics_tile(int tile_idx, coord_t coords) { int glyph = map->glyphs[coords.y][coords.x]; int i, j, x; int width, height, bpp, row_bytes; int bmp_tile_x, bmp_tile_y; u8 *bmp_row_start; u16 *tile_row_start; /* Next, get a few fields from the BMP headers that we'll need. */ width = bmp_width(&tiles); height = bmp_height(&tiles); bpp = bmp_bpp(&tiles); /* * Compute the number of bytes in each row of 8-pixel tiles. * * This works explicitely because each tile component is 8 pixels wide. * Thus, the number of bytes in a row is (8 * (bpp / 8)), which just * ends up being bpp. */ row_bytes = tile_width_in_tiles * bpp; /* Now calculate the pointer which points to the start of the BMP row */ bmp_tile_y = glyph2tile[glyph] / width_in_tiles; bmp_tile_x = width_in_tiles - glyph2tile[glyph] % width_in_tiles; bmp_row_start = tiles.bitmap + tiles.bitmap_length - bmp_tile_y * TILE_HEIGHT * width_in_tiles * row_bytes - bmp_tile_x * row_bytes ; for (j = 0; j < tile_height_in_tiles; j++) { int y; for (y = 0; y < 8; y++) { for (i = 0; i < tile_width_in_tiles; i++) { tile_row_start = tile_ram + (tile_idx + j * tile_width_in_tiles + i) * bpp * 8 / 2 + y * bpp / 2; /* Again, this works because 8 * (bpp / 8) == bpp */ for (x = 0; x < bpp; x += 2, bmp_row_start += 2) { if (bpp == 4) { u16 a, b, c, d; a = (bmp_row_start[0] & 0xF0) >> 4; b = (bmp_row_start[0] & 0x0F); c = (bmp_row_start[1] & 0xF0) >> 4; d = (bmp_row_start[1] & 0x0F); tile_row_start[x / 2] = (d << 12) | (c << 8) | (b << 4) | (a << 0); } else { tile_row_start[x / 2] = (bmp_row_start[1] << 8) | bmp_row_start[0]; } } } bmp_row_start -= row_bytes * width_in_tiles + row_bytes; }
void gbm_init() { gbm_buffer_size = bmp_width() * (bmp_height() / 8) + 2; gbm_buffer = (uint8_t *) malloc(gbm_buffer_size); }