RGB coarse scaler

Simple sample to show you how to coarse scale an image using hardware.

Using library

GP2X minimal library by rlyeh, 2005

License

  • Free for non-commercial projects (it would be nice receiving a mail from you).  Other cases, ask me first.
  • GamePark Holdings is not allowed to use this library and/or use parts from it.

Source code

#include "minimal.h"

int main(int argc, char *argv[])
{
int i, j;

gp2x_init(1000, 15, 11025,16,1,60, 1);

//put a 32x32 bitmap at (0,0) coordiantes of screen
for(j=0;j<32;j++)
for(i=0;i<32;i++)
gp2x_video_RGB[0].screen16[i+j*320]=gp2x_video_RGB_color15(i*8,j*8,i*4+j*4,0);

//show image
gp2x_video_RGB_flip(0);

while(1)
{
unsigned long pad=gp2x_joystick_read();
static unsigned char scaled=0;

if(pad & GP2X_VOL_DOWN) if(pad & GP2X_START) exit(0);

//enable 32x32 image to fit the 320x240 display area (aka, enable scaling)
if(pad & GP2X_A) gp2x_video_RGB_setscaling(32,32);

//enable 320x240 image to fit the 320x240 display area (aka, disable scaling)
if(pad & GP2X_B) gp2x_video_RGB_setscaling(320,240);
}
}

void gp2x_sound_frame(void *blah, void *buff, int samples) { }

Explanation

C Compilation

arm-linux-gcc minimal.c scaler.c -static -lpthread -lm

C++ Compilation

arm-linux-g++ minimal.c scaler.c -static -lpthread -lm

Output

  • this program shows a 32x32 bitmap at (0,0) coordinates.
  • press A to enable fullscreen coarse scaling.
  • press B to disable fullscreen coarse scaling.
  • press volume down and start buttons to exit.
void gp2x_init(int ticks_per_second,
int bpp,
int rate,
int bits,
int stereo,
int Hz,
int solid_font)
This function sets up the whole library.
unsigned long gp2x_joystick_read(void)
This function returns the active GP2X joystick values.
gp2x_video_layer gp2x_video_RGB[1]
This struct allows you to work directly with RGB video layer.
unsigned short gp2x_video_RGB_color15(int R,
int G,
int B,
int A)
This function returns the 16bits color for a given triad of R,G,B components.
void gp2x_video_RGB_flip(int layer)
This function flips video buffers.
void gp2x_video_RGB_setscaling(int W,
int H)
This function adjusts a given resolution to fit the whole display (320,240).
extern void gp2x_sound_frame(void *blah,
void *buffer,
int samples)
This function is automatically called by the library, and expects a sound buffer to be filled in.