void enable_bootsplash(void) { if (!CONFIG_BOOTSPLASH) return; dprintf(3, "Checking for bootsplash\n"); u32 file = romfile_find("bootsplash.jpg"); if (!file) return; int filesize = romfile_size(file); u8 *picture = NULL; u8 *filedata = malloc_tmphigh(filesize); struct vesa_info *vesa_info = malloc_tmplow(sizeof(*vesa_info)); struct vesa_mode_info *mode_info = malloc_tmplow(sizeof(*mode_info)); struct jpeg_decdata *jpeg = jpeg_alloc(); if (!filedata || !jpeg || !vesa_info || !mode_info) { warn_noalloc(); goto done; } /* Check whether we have a VESA 2.0 compliant BIOS */ memset(vesa_info, 0, sizeof(struct vesa_info)); vesa_info->vesa_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->vesa_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_name_ptr); char *product = SEGOFF_TO_FLATPTR(vesa_info->oem_product_name_ptr); dprintf(3, "VESA %d.%d\nVENDOR: %s\nPRODUCT: %s\n", vesa_info->vesa_version>>8, vesa_info->vesa_version&0xff, vendor, product); // Parse jpeg and get image size. dprintf(5, "Copying bootsplash.jpg\n"); romfile_copy(file, filedata, filesize); dprintf(5, "Decoding bootsplash.jpg\n"); int ret = jpeg_decode(jpeg, filedata); if (ret) { dprintf(1, "jpeg_decode failed with return code %d...\n", ret); goto done; } int width, height; jpeg_get_size(jpeg, &width, &height); // Try to find a graphics mode with the corresponding dimensions. int videomode = find_videomode(vesa_info, mode_info, width, height); if (videomode < 0) goto done; void *framebuffer = mode_info->phys_base_ptr; 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 = width * height * (depth / 8); picture = malloc_tmphigh(imagesize); if (!picture) { warn_noalloc(); goto done; } dprintf(5, "Decompressing bootsplash.jpg\n"); ret = jpeg_show(jpeg, picture, width, height, depth); if (ret) { dprintf(1, "jpeg_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 = (1 << 14) | videomode; call16_int10(&br); if (br.ax != 0x4f) { dprintf(1, "set_mode failed.\n"); goto done; } /* Show the picture */ dprintf(5, "Showing bootsplash.jpg\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); return; }
void FAR * jpeg_get_large(j_common_ptr cinfo, size_t size) { return jpeg_alloc(cinfo, size, "JPEG large internal data allocation"); }
int main(int argc, char *argv[]) { SDL_Surface *screen; TPool *tpool; CIList *cil; CImage *ci; int i, ch; unsigned int rw, rh; // requested window size unsigned long int fcount, do_jpeg; double ticks_start, load_fade, aspect; /* Copyright notice */ printf("\n Continuous Imaging 'fly'\n Copyright (C) 2008-2012 David Lowy & Tom Rathborne\n\n"); /* Get options --jpeg / -j and --geometry / -g */ static struct option longopts[] = { { "jpeg", no_argument, NULL, 'j' }, { "geometry", required_argument, NULL, 'g' }, { NULL, 0, NULL, 0 } }; /* Defaults */ do_jpeg = 0; rw = 0; rh = 0; while ((ch = getopt_long(argc, argv, "jg:", longopts, NULL)) != -1) switch(ch) { case 'j': do_jpeg = 1; break; case 'g': if (sscanf(optarg, "%ux%u", &rw, &rh) != 2) { printf("Unhandled geometry '%s': format is WxH\n", optarg); rw = 0; rh = 0; } break; default: printf("Unrecognized option %c ignored\n", ch); } argc -= optind; argv += optind; /* Get SDL+GL screen */ screen = init_sdl_gl(CI_BPC, CI_BITS, rw, rh); if(!screen) { fprintf(stderr, "Failed to init SDL GL context.\n"); return (0); } #ifndef CI_LINUX SDL_ShowCursor(SDL_DISABLE); #endif SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE); /* Set up JPEG if necessary */ if (do_jpeg) jpeg_alloc(screen->w, screen->h); aspect = CI_ASPECT / ((double)screen->w / (double)screen->h); /* time entire program */ ticks_start = SDL_GetTicks(); /* Init texture pool */ tpool = tp_create(65535, 800); // This was supposed to keep fewer textures in VRAM, but it just fills VRAM. /* create CI List */ cil = cil_create(tpool, "thumb/%s.jpg", "image/%s.jpg"); /* Load all dbs, make links */ cil_load_scidb(cil, "cidb.db"); /* Load image data and textures - and draw 'em! */ for(i = 0; i < cil->rcount; i++) { ci = cil->list[i]; assert(ci); assert(ci->subs); cil_ci_imgprep(cil, ci, 0); /* load images to N levels */ ci_load_tx(ci, 0); /* load textures to N level */ // Render load_fade = sqrt(1.0 - ((double) i / (double) cil->rcount)); glLoadIdentity(); glScalef(load_fade, load_fade / aspect, 1.0); // glRotatef(360.0 * ((double) i / (double) cil->rcount), 0.0, 0.0, 1.0); glTranslatef(-0.5, -0.5, 0.0); glClear(GL_COLOR_BUFFER_BIT); glColor4f(1.0, 1.0, 1.0, sqrt(load_fade)); glBindTexture(GL_TEXTURE_2D, ci->tid); glCallList(cil->gl_list); SDL_GL_SwapBuffers(); } for(i = 0; i < cil->rcount; i++) { ci = cil->list[i]; assert(ci); assert(ci->subs); ci_mklist(ci, cil->gl_list); } printf("Startup took %.2fs.\n", (SDL_GetTicks() - ticks_start) / 1000.0); /* Main loop */ ticks_start = SDL_GetTicks(); SDL_WarpMouse(screen->w/2, screen->h/2); SDL_EventState(SDL_MOUSEMOTION, SDL_ENABLE); fcount = fly(screen, cil, do_jpeg); printf("Average FPS: %.2f\n", fcount * 1000.0 / (SDL_GetTicks() - ticks_start)); printf("Cleaning up ...\n"); cil_cleanup(cil); /* cleanup */ cil_delete(cil); /* drop our data */ tp_delete(tpool); /* JPEG cleanup */ if (do_jpeg) jpeg_free(); SDL_Quit(); return (0); }
void * jpeg_get_small(j_common_ptr cinfo, size_t size) { return jpeg_alloc(cinfo, size, "JPEG small internal data allocation"); }
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; }