Skip to content

Instantly share code, notes, and snippets.

@pkrumins
Created May 18, 2010 10:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pkrumins/404855 to your computer and use it in GitHub Desktop.
Save pkrumins/404855 to your computer and use it in GitHub Desktop.
unsigned char *
rgba_to_rgb(unsigned char *rgba, int rgba_size)
{
int rgb_size = rgba_size/4*3;
unsigned char *rgb = malloc(sizeof(unsigned char)*rgb_size);
if (!rgb) return NULL;
int i, j;
for (i=0,j=0;i<rgba_size;i+=4,j+=3) {
rgb[j] = *(rgba+i);
rgb[j+1] = *(rgba+i+1);
rgb[j+2] = *(rgba+i+2);
}
return rgb;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment