Revision701 JPEG Test
From Go-OS
Nature of the test
libjpeg has been compiled with the 五SDK, and I wanted to test the result.
Code
void jpeg_test() { struct jpeg_decompress_struct cinfo; struct jpeg_error_mgr jerr; unsigned char *image; FILE *img = fopen("root:/girl_742.jpg", "rb"); if (img == NULL) { perror("open jpeg image"); return; } cinfo.err = jpeg_std_error(&jerr); jpeg_create_decompress(&cinfo); jpeg_stdio_src(&cinfo, img); jpeg_read_header(&cinfo, TRUE); jpeg_start_decompress(&cinfo); image = malloc(cinfo.output_width * cinfo.output_height * 3); for(int i=0; i < cinfo.output_height; i++) { unsigned char * ptr = image + i * 3 * cinfo.output_width; jpeg_read_scanlines(&cinfo, &ptr, 1); } printf("JPEG image loaded: %ix%i\n", cinfo.output_width, cinfo.output_height); // we assume gfx mode is at 0xffffffffe0000000, with 1024x768x32 mode pixels FILE *out = fopen("memory://ffffffffe0000000/25165824", "wb"); if (out == NULL) { perror("opening ram"); fclose(img); free(image); return; } // write to memory. Memory is RGBA, we have RGB for(int i = 0; i < cinfo.output_width * cinfo.output_height; i++) { int offset = i*3; for(int j = 0; j < 3; j++) { fwrite(image+offset+(2-j), 1, 1, out); } offset = 0; fwrite(&offset, 1, 1, out); // write "0" } free(image); fclose(out); fclose(img); sleep(2); return; }
