Created
December 22, 2014 01:09
-
-
Save ailabs-software/e6ad217001fef8b4580f to your computer and use it in GitHub Desktop.
Converting CAIRO BRBA to RGBA
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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