Revision: 60173
Updated Code
at October 24, 2012 21:20 by akiko
Updated Code
// This code snippet demonstrates the simplest bresenham image scaling algorithm. // I use it for fast, non-interpolated image upsampling on an 16bit 20MHz MCU. // You will notice that all inner loops are quite easy on cpu - there are // only additions and a few cmp's. // Also, all memory addressing (in inner loops) is done indirectly, which is // in general much faster than recalculating absolute addresses. // Note that in my case pixels are not 24 bit RGB triplets, but 8bit 422 packed // format. You can easily extend this to 3 lookups and writes instead of 1 (for // genuine 24bit RGB). // // Hope it helps :) // written by akiko / agt, 2012 // http://dev.modmancer.com #define DEMO_WIDTH 64 #define DEMO_HEIGHT 64 #define FB_WIDTH 320 #define FB_HEIGHT 240 unsigned int pixels_written = 0; UINT8 *src = framebuffer; // input buffer of size DEMO_WIDTH * DEMO_HEIGHT UINT8 *dst = buffer; // output buffer of size FB_WIDTH * FB_HEIGHT int xint_part = DEMO_WIDTH / FB_WIDTH; int xfrac_part = DEMO_WIDTH % FB_WIDTH; int yint_part = DEMO_HEIGHT / FB_HEIGHT; int yfrac_part = DEMO_HEIGHT % FB_HEIGHT; int ye = 0; int dsty = 0; int xe = 0; while (dsty < FB_HEIGHT) { int num_pixels = FB_WIDTH; while (num_pixels-- > 0) { *dst++ = *src; src += xint_part; xe += xfrac_part; if (xe >= FB_WIDTH) { xe -= FB_WIDTH; src++; } } // use bresenham to increase line counter dsty += yint_part; ye += yfrac_part; if(ye >= FB_HEIGHT) { ye -= FB_HEIGHT; dsty++; } }
Revision: 60172
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at October 24, 2012 21:09 by akiko
Initial Code
// This code snippet demonstrates the simplest bresenham image scaling algorithm. // I use it for fast, non-interpolated image upsampling on an 16bit 20MHz MCU. // You will notice that all inner loops are quite easy on cpu - there are // only additions and a few cmp's. // Also, all memory addressing (in inner loops) is done indirectly, which is // in general much faster than recalculating absolute addresses. // Note that in my case pixels are not 24 bit RGB triplets, but 8bit 422 packed // format. You can easily extend this to 3 lookups and writes instead of 1 (for // genuine 24bit RGB). // // Hope it helps :) // written by akiko / agt, 2012 // http://dev.modmancer.com #define DEMO_WIDTH 64 #define DEMO_HEIGHT 64 #define FB_WIDTH 320 #define FB_HEIGHT 240 unsigned int pixels_written = 0; UINT8 *src = framebuffer; // input buffer of size DEMO_WIDTH * DEMO_HEIGHT UINT8 *dst = buffer; // output buffer of size FB_WIDTH * FB_HEIGHT int xint_part = DEMO_WIDTH / FB_WIDTH; int xfrac_part = DEMO_WIDTH % FB_WIDTH; int yint_part = DEMO_HEIGHT / FB_HEIGHT; int yfrac_part = DEMO_HEIGHT % FB_HEIGHT; int ye = 0; int num_pixels = FB_WIDTH; int dsty = 0; int xe = 0; while (dsty < FB_HEIGHT) { while (num_pixels-- > 0) { *dst++ = *src; src += xint_part; xe += xfrac_part; if (xe >= FB_WIDTH) { xe -= FB_WIDTH; src++; } } // use bresenham to increase line counter dsty += yint_part; ye += yfrac_part; if(ye >= FB_HEIGHT) { ye -= FB_HEIGHT; dsty++; } }
Initial URL
bresenham scaling
Initial Description
simple and fast bresenham image scaler, no interpolation
Initial Title
fast bresenham bitmap scaler in C
Initial Tags
Initial Language
C