| 1 | // Copyright 2015 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | // Package swizzle provides functions for converting between RGBA pixel |
| 6 | // formats. |
| 7 | package swizzle // import "golang.org/x/exp/shiny/driver/internal/swizzle" |
| 8 | |
| 9 | // BGRA converts a pixel buffer between Go's RGBA and other systems' BGRA byte |
| 10 | // orders. |
| 11 | // |
| 12 | // It panics if the input slice length is not a multiple of 4. |
| 13 | func BGRA(p []byte) { |
| 14 | if len(p)%4 != 0 { |
| 15 | panic("input slice length is not a multiple of 4") |
| 16 | } |
| 17 | |
| 18 | // Use asm code for 16- or 4-byte chunks, if supported. |
| 19 | if useBGRA16 { |
| 20 | n := len(p) &^ (16 - 1) |
| 21 | bgra16(p[:n]) |
| 22 | p = p[n:] |
| 23 | } else if useBGRA4 { |
| 24 | bgra4(p) |
| 25 | return |
| 26 | } |
| 27 | |
| 28 | for i := 0; i < len(p); i += 4 { |
| 29 | p[i+0], p[i+2] = p[i+2], p[i+0] |
| 30 | } |
| 31 | } |