static bool nsico_redraw(struct content *c, struct content_redraw_data *data, const struct rect *clip, const struct redraw_context *ctx) { nsico_content *ico = (nsico_content *)c; struct bmp_image *bmp; /* select most appropriate sized icon for size */ bmp = ico_find(ico->ico, data->width, data->height); if (bmp == NULL) { /* return error */ LOG("Failed to select icon"); return false; } /* ensure its decided */ if (bmp->decoded == false) { if (bmp_decode(bmp) != BMP_OK) { return false; } else { LOG("Decoding bitmap"); guit->bitmap->modified(bmp->bitmap); } } return image_bitmap_plot(bmp->bitmap, data, clip, ctx); }
bool nsico_redraw(struct content *c, int x, int y, int width, int height, int clip_x0, int clip_y0, int clip_x1, int clip_y1, float scale, colour background_colour) { struct bmp_image *bmp = ico_find(c->data.ico.ico, width, height); if (!bmp->decoded) if (bmp_decode(bmp) != BMP_OK) return false; c->bitmap = bmp->bitmap; return plot.bitmap(x, y, width, height, c->bitmap, background_colour, BITMAPF_NONE); }
int main(const int argc, const char **argv){ initstdio(); if(argc<2){ fprintf(stderr, "codeiq124 in.bmp >out.txt\n" "codeiq124 io.bmp <in.txt\n" ); return -1; } int pixels=0,count=0,color,last; if(isatty(fileno(stdin))){ //decode struct stat st; int x,y; FILE *in=fopen(argv[1],"rb"); if(!in){ fprintf(stderr,"cannot open %s\n",argv[2]); return 1; } fstat(fileno(in),&st); void *imgbuf=malloc(st.st_size); fread(imgbuf,1,st.st_size,in); fclose(in); bmp_image gif; bmp_bitmap_callback_vt vt={ bitmap_create, bitmap_destroy, bitmap_set_suspendable, bitmap_get_buffer, bitmap_get_bpp }; bmp_create(&gif,&vt); if(bmp_analyse(&gif, st.st_size, imgbuf)||bmp_decode(&gif)){fprintf(stderr,"decode error\n");bmp_finalise(&gif);free(imgbuf);return 1;} free(imgbuf); for(y=0;y<gif.height;y++){ for(x=0;x<gif.width;x++){ u32 coor=y*gif.width+x; u8 b=((((u32*)gif.bitmap)[coor]&0xff0000)>>16)&0xff; u8 g=((((u32*)gif.bitmap)[coor]&0x00ff00)>>8)&0xff; u8 r=((((u32*)gif.bitmap)[coor]&0x0000ff)>>0)&0xff; u8 mes=((r&7)<<5)|((g&3)<<3)|((b&7)<<0); if(!mes)break; putchar(mes); } } bmp_finalise(&gif); }else{ //encode
bool nsico_set_bitmap_from_size(hlcache_handle *h, int width, int height) { struct content *c = hlcache_handle_get_content(h); struct bmp_image *bmp; assert(c != NULL); bmp = ico_find(c->data.ico.ico, width, height); if (bmp == NULL) return false; if ((bmp->decoded == false) && (bmp_decode(bmp) != BMP_OK)) return false; c->bitmap = bmp->bitmap; return true; }
static bool nsbmp_redraw(struct content *c, struct content_redraw_data *data, const struct rect *clip, const struct redraw_context *ctx) { nsbmp_content *bmp = (nsbmp_content *) c; bitmap_flags_t flags = BITMAPF_NONE; if (bmp->bmp->decoded == false) if (bmp_decode(bmp->bmp) != BMP_OK) return false; bmp->bitmap = bmp->bmp->bitmap; if (data->repeat_x) flags |= BITMAPF_REPEAT_X; if (data->repeat_y) flags |= BITMAPF_REPEAT_Y; return ctx->plot->bitmap(data->x, data->y, data->width, data->height, bmp->bitmap, data->background_colour, flags); }
bool nsico_redraw_tiled(struct content *c, int x, int y, int width, int height, int clip_x0, int clip_y0, int clip_x1, int clip_y1, float scale, colour background_colour, bool repeat_x, bool repeat_y) { struct bmp_image *bmp = ico_find(c->data.ico.ico, width, height); bitmap_flags_t flags = BITMAPF_NONE; if (!bmp->decoded) if (bmp_decode(bmp) != BMP_OK) return false; c->bitmap = bmp->bitmap; if (repeat_x) flags |= BITMAPF_REPEAT_X; if (repeat_y) flags |= BITMAPF_REPEAT_Y; return plot.bitmap(x, y, width, height, c->bitmap, background_colour, flags); }
static void *nsico_get_internal(const struct content *c, void *context) { nsico_content *ico = (nsico_content *) c; /* TODO: Pick best size for purpose. * Currently assumes it's for a URL bar. */ struct bmp_image *bmp; bmp = ico_find(ico->ico, 16, 16); if (bmp == NULL) { /* return error */ LOG("Failed to select icon"); return NULL; } if (bmp->decoded == false) { if (bmp_decode(bmp) != BMP_OK) { return NULL; } else { guit->bitmap->modified(bmp->bitmap); } } return bmp->bitmap; }
/** * Decode a BMP using "limited transparency" * * Bitmaps do not have native transparency support. However, there is a * "trick" that is used in some instances in which the first pixel of the * bitmap becomes the "transparency index". The decoding application can * replace this index with whatever background colour it chooses to * create the illusion of transparency. * * When to use transparency is at the discretion of the decoding * application. * * \param bmp the BMP image to decode * \param colour the colour to use as "transparent" * \return BMP_OK on success */ bmp_result bmp_decode_trans(bmp_image *bmp, uint32_t colour) { bmp->limited_trans = true; bmp->trans_colour = colour; return bmp_decode(bmp); }
void enable_bootsplash(void) { if (!CONFIG_BOOTSPLASH) return; /* splash picture can be bmp or jpeg file */ dprintf(3, "Checking for bootsplash\n"); u8 type = 0; /* 0 means jpg, 1 means bmp, default is 0=jpg */ int filesize; u8 *filedata = romfile_loadfile("bootsplash.jpg", &filesize); if (!filedata) { filedata = romfile_loadfile("bootsplash.bmp", &filesize); if (!filedata) return; type = 1; } dprintf(3, "start showing bootsplash\n"); u8 *picture = NULL; /* data buff used to be flushed to the video buf */ struct jpeg_decdata *jpeg = NULL; struct bmp_decdata *bmp = NULL; struct vbe_info *vesa_info = malloc_tmplow(sizeof(*vesa_info)); struct vbe_mode_info *mode_info = malloc_tmplow(sizeof(*mode_info)); if (!vesa_info || !mode_info) { warn_noalloc(); goto done; } /* Check whether we have a VESA 2.0 compliant BIOS */ memset(vesa_info, 0, sizeof(struct vbe_info)); vesa_info->signature = VBE2_SIGNATURE; struct bregs br; memset(&br, 0, sizeof(br)); br.ax = 0x4f00; br.di = FLATPTR_TO_OFFSET(vesa_info); br.es = FLATPTR_TO_SEG(vesa_info); call16_int10(&br); if (vesa_info->signature != VESA_SIGNATURE) { dprintf(1,"No VBE2 found.\n"); goto done; } /* Print some debugging information about our card. */ char *vendor = SEGOFF_TO_FLATPTR(vesa_info->oem_vendor_string); char *product = SEGOFF_TO_FLATPTR(vesa_info->oem_product_string); dprintf(3, "VESA %d.%d\nVENDOR: %s\nPRODUCT: %s\n", vesa_info->version>>8, vesa_info->version&0xff, vendor, product); int ret, width, height; int bpp_require = 0; if (type == 0) { jpeg = jpeg_alloc(); if (!jpeg) { warn_noalloc(); goto done; } /* Parse jpeg and get image size. */ dprintf(5, "Decoding bootsplash.jpg\n"); ret = jpeg_decode(jpeg, filedata); if (ret) { dprintf(1, "jpeg_decode failed with return code %d...\n", ret); goto done; } jpeg_get_size(jpeg, &width, &height); } else { bmp = bmp_alloc(); if (!bmp) { warn_noalloc(); goto done; } /* Parse bmp and get image size. */ dprintf(5, "Decoding bootsplash.bmp\n"); ret = bmp_decode(bmp, filedata, filesize); if (ret) { dprintf(1, "bmp_decode failed with return code %d...\n", ret); goto done; } bmp_get_size(bmp, &width, &height); bpp_require = 24; } /* jpeg would use 16 or 24 bpp video mode, BMP use 24bpp mode only */ // Try to find a graphics mode with the corresponding dimensions. int videomode = find_videomode(vesa_info, mode_info, width, height, bpp_require); if (videomode < 0) { dprintf(1, "failed to find a videomode with %dx%d %dbpp (0=any).\n", width, height, bpp_require); goto done; } void *framebuffer = (void *)mode_info->phys_base; int depth = mode_info->bits_per_pixel; dprintf(3, "mode: %04x\n", videomode); dprintf(3, "framebuffer: %p\n", framebuffer); dprintf(3, "bytes per scanline: %d\n", mode_info->bytes_per_scanline); dprintf(3, "bits per pixel: %d\n", depth); // Allocate space for image and decompress it. int imagesize = height * mode_info->bytes_per_scanline; picture = malloc_tmphigh(imagesize); if (!picture) { warn_noalloc(); goto done; } if (type == 0) { dprintf(5, "Decompressing bootsplash.jpg\n"); ret = jpeg_show(jpeg, picture, width, height, depth, mode_info->bytes_per_scanline); if (ret) { dprintf(1, "jpeg_show failed with return code %d...\n", ret); goto done; } } else { dprintf(5, "Decompressing bootsplash.bmp\n"); ret = bmp_show(bmp, picture, width, height, depth, mode_info->bytes_per_scanline); if (ret) { dprintf(1, "bmp_show failed with return code %d...\n", ret); goto done; } } /* Switch to graphics mode */ dprintf(5, "Switching to graphics mode\n"); memset(&br, 0, sizeof(br)); br.ax = 0x4f02; br.bx = videomode | VBE_MODE_LINEAR_FRAME_BUFFER; call16_int10(&br); if (br.ax != 0x4f) { dprintf(1, "set_mode failed.\n"); goto done; } /* Show the picture */ dprintf(5, "Showing bootsplash picture\n"); iomemcpy(framebuffer, picture, imagesize); dprintf(5, "Bootsplash copy complete\n"); BootsplashActive = 1; done: free(filedata); free(picture); free(vesa_info); free(mode_info); free(jpeg); free(bmp); return; }