// JPEG perf test // Written by Larry Bank // // Will open an arbitrary JPEG file if passed on the command line // or will use the sample image (tulips) // #include #include #include #include "JPEGDEC.h" #include "jpeg.inl" #include "../test_images/tulips.h" // Human readable error messages const char *szErrors[] = {"Success", "Invalid parameter", "Decode error", "Unsupported feature", "Invalid file"}; /* Windows BMP header for RGB565 images */ uint8_t winbmphdr_rgb565[138] = {0x42,0x4d,0,0,0,0,0,0,0,0,0x8a,0,0,0,0x7c,0, 0,0,0,0,0,0,0,0,0,0,1,0,8,0,3,0, 0,0,0,0,0,0,0x13,0x0b,0,0,0x13,0x0b,0,0,0,0, 0,0,0,0,0,0,0,0xf8,0,0,0xe0,0x07,0,0,0x1f,0, 0,0,0,0,0,0,0x42,0x47,0x52,0x73,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0}; /* Windows BMP header for 8/24/32-bit images (54 bytes) */ uint8_t winbmphdr[54] = {0x42,0x4d, 0,0,0,0, /* File size */ 0,0,0,0,0x36,4,0,0,0x28,0,0,0, 0,0,0,0, /* Xsize */ 0,0,0,0, /* Ysize */ 1,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* number of planes, bits per pel */ 0,0,0,0}; JPEGIMAGE jpg; uint8_t *pFrame; int iDestPitch; //uint8_t ucDitherBuffer[1024 * 16]; int ucPixelType = RGB565_BIG_ENDIAN; // default output used for SPI LCDs // // Minimal code to save frames as Windows BMP files // void WriteBMP(char *fname, uint8_t *pBitmap, uint8_t *pPalette, int cx, int cy, int bpp, int iDestPitch) { FILE * oHandle; int i, bsize, lsize; uint32_t *l; uint8_t *s; uint8_t *ucTemp; uint8_t *pHdr; int iHeaderSize; ucTemp = (uint8_t *)malloc(cx * 4); if (bpp == 16) { pHdr = winbmphdr_rgb565; iHeaderSize = sizeof(winbmphdr_rgb565); } else { pHdr = winbmphdr; iHeaderSize = sizeof(winbmphdr); } oHandle = fopen(fname, "w+b"); bsize = (cx * bpp) >> 3; lsize = (bsize + 3) & 0xfffc; /* Width of each line */ pHdr[26] = 1; // number of planes pHdr[28] = (uint8_t)bpp; /* Write the BMP header */ l = (uint32_t *)&pHdr[2]; i =(cy * lsize) + iHeaderSize; if (bpp <= 8) i += 1024; *l = (uint32_t)i; /* Store the file size */ l = (uint32_t *)&pHdr[34]; // data size i = (cy * lsize); *l = (uint32_t)i; // store data size l = (uint32_t *)&pHdr[18]; *l = (uint32_t)cx; /* width */ *(l+1) = (uint32_t)cy; /* height */ l = (uint32_t *)&pHdr[10]; // OFFBITS if (bpp <= 8) { *l = iHeaderSize + 1024; } else { // no palette *l = iHeaderSize; } fwrite(pHdr, 1, iHeaderSize, oHandle); if (bpp <= 8) { if (pPalette == NULL) {// create a grayscale palette int iDelta, iCount = 1<=0; i--) { s = &pBitmap[i*iDestPitch]; if (bpp == 24) { // swap R/B for Windows BMP byte order int j, iBpp = bpp/8; uint8_t *d = ucTemp; for (j=0; j \n\n"); if (argc == 1 || argc == 2) { rc = PerfTest(argc, argv); } else if (argc == 3) { rc = ConvertFileTest(argv, 1); // change the 1 to 2/4/8 for fractional decode } else { printf("Invalid number of parameters (re-read the above)\n"); return rc; } return rc; } /* main() */