3 * Author : Robin Krens <robin@robinkrens.nl>
5 * Last Modified Date: 12.06.2022
6 * Last Modified By : Robin Krens <robin@robinkrens.nl>
13 #include <SDL2/SDL_image.h>
19 void bmp_info(SDL_Surface * img)
21 SDL_PixelFormat * fmt;
23 fprintf(stdout,"WIDTH: %d, HEIGHT: %d, BPP: %d\n", img->w, img->h, fmt->BitsPerPixel);
27 void generate_4bpp_tile_planar(unsigned char *buf, void * userdata, int sz)
29 unsigned char * ptr = (unsigned char *) userdata;
30 for (int i = 0; i < 32; i+=4) {
31 /* fprintf(stdout, "userdata: pos: %d - %d\n", i, *ptr++); */
32 for (int j = 0; j < 4; ++j) {
33 for (int x = 0; x < 8; ++x) {
34 buf[i + j] = ptr[x] << j;
36 /* printf("%d: %x\n", i+j, buf[i+j]); */
42 void generate_4bpp_tile_packed(unsigned char *buf, void * userdata, int sz)
44 unsigned char * ptr = (unsigned char *) userdata;
45 for (int i = 0; i < 32; i+=4) {
46 for (int j = 0; j < 4; ++j) {
47 buf[i+j] = ptr[0] << 4;
50 printf("%d: %x\n", i+j, buf[i+j]);
58 SDL_PixelFormat * fmt;
59 char filename[] = "test.bmp";
60 rawbmp = SDL_LoadBMP(filename);
63 fprintf(stderr, "can not load .bmp file\n");
69 SDL_LockSurface(rawbmp);
70 rawbmp->userdata = rawbmp->pixels;
71 SDL_UnlockSurface(rawbmp);
73 unsigned char *tile_buf = malloc(sizeof(unsigned char) * TILE_SZ);
75 generate_4bpp_tile_packed(tile_buf, rawbmp->userdata, 64);
77 /* if (rawbmp->format->BitsPerPixel != 24) {
78 fprintf(stderr, "format %d not supported\n", rawbmp->format->BitsPerPixel);
83 SDL_FreeSurface(rawbmp);