| // Copyright (C) 2016 The Android Open Source Project |
| // |
| // Licensed under the Apache License, Version 2.0 (the "License"); |
| // you may not use this file except in compliance with the License. |
| // You may obtain a copy of the License at |
| // |
| // http://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, software |
| // distributed under the License is distributed on an "AS IS" BASIS, |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| // See the License for the specific language governing permissions and |
| // limitations under the License. |
| |
| package image |
| |
| import "android.googlesource.com/platform/tools/gpu/framework/binary" |
| |
| type fmtRGBA1010102 struct{ binary.Generate } |
| |
| func (f *fmtRGBA1010102) Key() interface{} { return *f } |
| func (*fmtRGBA1010102) String() string { return "RGBA1010102" } |
| func (*fmtRGBA1010102) Size(w, h int) int { return w * h * 4 } |
| func (*fmtRGBA1010102) Check(d []byte, w, h int) error { return checkSize(d, w, h, 32) } |
| |
| // RGBA1010102 returns a format containing a 10-bit red, green and blue |
| // channel and 2-bits of alpha per pixel. |
| func RGBA1010102() Format { return &fmtRGBA1010102{} } |
| |
| func init() { |
| RegisterConverter(RGBA1010102(), RGBA(), |
| func(src []byte, width, height int) ([]byte, error) { |
| dst, j := make([]byte, width*height*4), 0 |
| for y := 0; y < height; y++ { |
| for x := 0; x < width; x++ { |
| abgr := (uint32(src[3]) << 24) | (uint32(src[2]) << 16) | |
| (uint32(src[1]) << 8) | uint32(src[0]) |
| src = src[4:] |
| a := uint8(((abgr & 0xc0000000) >> 30) * 85) // 255 / 3 is exactly 85 |
| b := uint8(((abgr & 0x3fc00000) >> 22)) |
| g := uint8(((abgr & 0x000ff000) >> 12)) |
| r := uint8(((abgr & 0x000003fc) >> 2)) |
| dst[j+0], dst[j+1], dst[j+2], dst[j+3] = r, g, b, a |
| j += 4 |
| } |
| } |
| |
| return dst, nil |
| }) |
| } |