Skip to content

Instantly share code, notes, and snippets.

@ailabs-software
Created December 22, 2014 01:09
Show Gist options
  • Select an option

  • Save ailabs-software/e6ad217001fef8b4580f to your computer and use it in GitHub Desktop.

Select an option

Save ailabs-software/e6ad217001fef8b4580f to your computer and use it in GitHub Desktop.
Converting CAIRO BRBA to RGBA
func swap_bgra_rgba(img_buf *image.RGBA) image.Image {
var wtf = &bytes.Buffer{};
png.Encode(wtf, img_buf);
pic, _ := png.Decode( wtf ); // FIXMEIFMXE FIXME!!!!!!! -- WASTING CPU!!!
b := pic.Bounds();
// Get an interface which can set pixels
picSet := pic.(ImageSet);
for y := b.Min.Y; y < b.Max.Y; y++ {
for x := b.Min.X; x < b.Max.X; x++ {
col := pic.At(x, y);
r, g, b, a := col.RGBA();
// Swap blue and red
newCol := color.RGBA{uint8(b >> 8), uint8(g >> 8), uint8(r >> 8), uint8(a >> 8)};
picSet.Set(x, y, newCol);
}
}
return pic;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment