void fillScreen(uint8 r, uint8 g, uint8 b) { uint16* screen = (uint16*)s3eSurfacePtr(); uint16 colour = (uint16)s3eSurfaceConvertRGB(r,g,b); int32 width = s3eSurfaceGetInt(S3E_SURFACE_WIDTH); int32 height = s3eSurfaceGetInt(S3E_SURFACE_HEIGHT); int32 pitch = s3eSurfaceGetInt(S3E_SURFACE_PITCH); for (int y = 0; y < height; y++) for (int x = 0; x < width; x++) screen[y * pitch/2 + x] = colour; }
void DrawRect(int x, int y, int width, int height, uint8 r, uint8 g, uint8 b) { int right = x + width; int bottom = y + height; int pitch = s3eSurfaceGetInt(S3E_SURFACE_PITCH); if (x < 0) x = 0; if (y < 0) y = 0; if (right > (int32)s3eSurfaceGetInt(S3E_SURFACE_WIDTH)) right = s3eSurfaceGetInt(S3E_SURFACE_WIDTH); if (bottom > (int32)s3eSurfaceGetInt(S3E_SURFACE_HEIGHT)) bottom = s3eSurfaceGetInt(S3E_SURFACE_HEIGHT); uint16* pSurface = (uint16*)s3eSurfacePtr(); pitch /= 2; uint16 colour = (uint16)s3eSurfaceConvertRGB(r,g,b); if (((right - x) & 0x3) == 0) { for (int _y = y; _y < bottom; _y++) { uint16* p = pSurface + _y*pitch + x; uint16* pEnd = p + right - x; do { *p++ = colour; *p++ = colour; *p++ = colour; *p++ = colour; } while (p != pEnd); } } else { for (int _y = y; _y < bottom; _y++) { uint16* p = pSurface + _y*pitch + x; uint16* pEnd = p + right - x; do { *p++ = colour; } while (p != pEnd); } } }
void DrawRect(int x, int y, int width, int height, uint8 r, uint8 g, uint8 b) { int right = x + width; int bottom = y + height; if (x < 0) x = 0; if (y < 0) y = 0; if (right > S3E_SURFACE_DEVICE_WIDTH) right = S3E_SURFACE_DEVICE_WIDTH; if (bottom > S3E_SURFACE_DEVICE_HEIGHT) bottom = S3E_SURFACE_DEVICE_HEIGHT; uint16* pSurface = (uint16*)s3eSurfacePtr(); uint16 colour = (uint16)s3eSurfaceConvertRGB(r,g,b); if (((right - x) & 0x3) == 0) { for (int _y = y; _y < bottom; _y++) { uint16* p = pSurface + _y + x; uint16* pEnd = p + right - x; do { *p++ = colour; *p++ = colour; *p++ = colour; *p++ = colour; } while (p != pEnd); } } else { for (int _y = y; _y < bottom; _y++) { uint16* p = pSurface + _y + x; uint16* pEnd = p + right - x; do { *p++ = colour; } while (p != pEnd); } } }
bool s3eExampleShowFromBuffer_jpeglib(void* data, uint32 len, int32 x, int32 y, int32 width, int32 height) { jpeg_decompress_struct cinfo; bzero(&cinfo, sizeof(cinfo)); JSAMPARRAY buffer; /* Output row buffer */ int row_stride; /* physical row width in output buffer */ jpeg_source_mgr srcmgr; srcmgr.bytes_in_buffer = len; srcmgr.next_input_byte = (JOCTET*) data; srcmgr.init_source = JPEGInitSource; srcmgr.fill_input_buffer = JPEGFillInputBuffer; srcmgr.skip_input_data = JPEGSkipInputData; srcmgr.resync_to_restart = jpeg_resync_to_restart; srcmgr.term_source = JPEGTermSource; jpeg_error_mgr jerr; cinfo.err = jpeg_std_error(&jerr); jpeg_create_decompress(&cinfo); cinfo.src = &srcmgr; jpeg_read_header(&cinfo, TRUE); jpeg_start_decompress(&cinfo); uint8* dest = (uint8*)s3eSurfacePtr(); int destpitch = s3eSurfaceGetInt(S3E_SURFACE_PITCH); s3eSurfacePixelType ptype = (s3eSurfacePixelType)s3eSurfaceGetInt(S3E_SURFACE_PIXEL_TYPE); int bytesPerPix = (ptype & S3E_SURFACE_PIXEL_SIZE_MASK) >> 4; /* JSAMPLEs per row in output buffer */ row_stride = cinfo.output_width * cinfo.output_components; /* Make a one-row-high sample array that will go away when done with image */ buffer = (*cinfo.mem->alloc_sarray) ((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1); int startx = 0; int starty = 0; if(y + height > s3eSurfaceGetInt(S3E_SURFACE_HEIGHT)) height = s3eSurfaceGetInt(S3E_SURFACE_HEIGHT) - y; if(y < 0 ) { height += y; starty -= y; y = 0; } if (x + width > s3eSurfaceGetInt(S3E_SURFACE_WIDTH)) width = s3eSurfaceGetInt(S3E_SURFACE_WIDTH) - x; if (x < 0 ) { width +=x; startx -= x; x =0; } int copy_rows = MIN((int)cinfo.output_height, height); int copy_width = MIN((int)cinfo.output_width, width); dest += y * destpitch + x * bytesPerPix; printf("jpeg load: pos=%d %d size=[%dx%d] -> [%dx%d] offset=%dx%d\n", x, y, cinfo.output_width, cinfo.output_height, copy_width, copy_rows, startx, starty); if (copy_width < 0 || copy_rows < 0) { printf("jpeg is fully off screen\n"); return S3E_RESULT_SUCCESS; } while (cinfo.output_scanline < cinfo.output_height)// count through the image { /* jpeg_read_scanlines expects an array of pointers to scanlines. * Here the array is only one element long, but you could ask for * more than one scanline at a time if that's more convenient. */ (void) jpeg_read_scanlines(&cinfo, buffer, 1); if (starty-- <= 0)// count down from start { if (copy_rows-- > 0) { uint8* dst = dest; for (int xx=startx; xx < copy_width; xx++) { uint8 r = buffer[0][xx*3+0]; uint8 b = buffer[0][xx*3+1]; uint8 g = buffer[0][xx*3+2]; switch(bytesPerPix) { case 1: *dst++ = (uint8)s3eSurfaceConvertRGB( r, b, g); break; case 2: *((uint16*)dst) = (uint16)s3eSurfaceConvertRGB( r, b, g); dst +=2; break; case 3: { uint32 colour = s3eSurfaceConvertRGB( r, b, g); *dst++ = (uint8)(colour); *dst++ = (uint8)(colour >> 8); *dst++ = (uint8)(colour >> 16); dst +=3; } break; case 4: *((uint32*)dst) = s3eSurfaceConvertRGB( r, b, g); dst +=4; default: ; } } dest += destpitch; } } }