extern JPEG_OUTPUT_TYPE *jpg_ptr;extern int jpg_w;extern int jpg_h;/* Renders a jpg to the screen/vram (0x6000000) using tons of fun features like rotation and scaling along the way; screen format is 16-bit 0BBBBBGGGGGRRRRR pixels of 240x160: x - x coordinate of where to start in image (upper-left corner) y - y coordinate of where to start in image (upper-left corner) w0 - width of image to display (<240 or <160 as appropraite) h0 - height of image to display (<160 or <240 as appropriate) wi - scaled width of image hi - scaled height of image mode - 0 = default, 1 = aspect fit to screen, 2 = stretch fit to screen this is passed in to know whether or not to do image anti-aliasing rotate - 0 = normal, 1 = left to right, 2 = bottom to top, 3 = right to left toshift - 0 = don't shift (ie, don't anti-alias), 1 = do shift (if appropriate)*/void render_jpg(int x, int y, int w0, int h0, int wi, int hi, int mode, int scale, int rotate, int toshift){ //Anti-aliasing buffers static unsigned int high[240]; static unsigned short low[240]; unsigned short *src, *dst, *s, *d; int w, h; int dh, dw; int dx, dy; int mw, mh; int shift, l, m; //Shift (ie, whether to run at double resolution so we can downsample) shift = (toshift && (mode || (scale < 0))) ? 1 : 0; dst = (unsigned short *)0x06000000; //vram //rotate magic switch(rotate) { case 3: dx = 240; dy = -1; dst += 240-1; break; case 2: dx = -1; dy = -240; dst += 240*160-1; break; case 1: dx = -240; dy = 1; dst += (160-1)*240; break; default: dx = 1; dy = 240; break; } // Figure out margin width/height mw = (((rotate&1) ? 160 : 240)-w0)>>1; mh = (((rotate&1) ? 240 : 160)-h0)>>1; if (mode) src = jpg_ptr; else src = &jpg_ptr[x + y * jpg_w]; hi <<= shift; wi <<= shift; h = h0<<shift; dh = 0; //Fill in top margin if (mh) { l = mh; while (l--) { d = dst; m = (rotate&1) ? 160 : 240; while(m--) { *d = 0x0; d += dx; } dst += dy; } } while (h--) { s = src; d = dst; dw = 0; w = w0<<shift; l = mw; //left margin while(l--) { *dst = 0x0; dst += dx; } // Split so we can have a fast inner loop for the non-shift case if (shift) { // This might be optimizable. x = 0; high[0] = low[0] = 0; while (w--) { /* Four pixel anti-aliasing; splitting is done to prevent B, G, and R from bleeding into each other */ if (!(w&h&1)) { //Mask out top 3 bits for B, G, and R high[x] += *src & 0x739c; //Mask out bottom 2 bits for B, G, and R low[x] += *src & 0x0c63; } else { high[x] = *src & 0x739c; low[x] = *src & 0x0c63; } if (!(w&1) && !(h&1)) { //Rejoin after masking *dst = ((high[x]>>2)&0x739c)|((low[x]>>2)&0xc63); dst += dx; } if (!(w&1)) x++; dw += jpg_w; while (dw >= wi) { dw -= wi; src++; } } //right margin if (!(h&1)) { l = ((rotate&1) ? 160 : 240)-w0-mw; while(l--) { *dst = 0x0; dst += dx; } } dst = d; if (!(h&1)) dst += dy; } else { while (w--) { *dst = *src; dst += dx; dw += jpg_w; while (dw >= wi) { dw -= wi; src++; } } //right margin l = ((rotate&1) ? 160 : 240)-w0-mw; while(l--) { *dst = 0x0; dst += dx; } dst = d + dy; } src = s; dh += jpg_h; while (dh >= hi) { dh -= hi; src += jpg_w; } } //Bottom margin if (mh) { l = ((rotate&1) ? 240 : 160)-h0-mh; while (l--) { d = dst; m = (rotate&1) ? 160 : 240; while(m--) { *d = 0x0; d += dx; } dst += dy; } }}