| // 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_test |
| |
| import ( |
| "testing" |
| |
| "android.googlesource.com/platform/tools/gpu/framework/assert" |
| "android.googlesource.com/platform/tools/gpu/gapid/image" |
| ) |
| |
| func TestRGBA4444Conversion(t *testing.T) { |
| ctx := assert.Context(t) |
| |
| // Generate a 16*16*16*16 image with all possible 4444 colors. |
| in := make([]byte, 2*16*16*16*16) |
| for o, r := 0, 0; r < 16; r++ { |
| for g := 0; g < 16; g++ { |
| for b := 0; b < 16; b++ { |
| for a := 0; a < 16; a++ { |
| rgba := (r << 12) | (g << 8) | (b << 4) | a |
| in[o+0] = uint8(rgba & 0xff) |
| in[o+1] = uint8((rgba >> 8) & 0xff) |
| o += 2 |
| } |
| } |
| } |
| } |
| |
| out, err := image.Convert(in, 16*16, 16*16, image.RGBA4444(), image.RGBA()) |
| assert.With(ctx).ThatError(err).Succeeded() |
| assert.With(ctx).ThatSlice(out).IsLength(2 * len(in)) |
| |
| r, g, b, a := make(intmap), make(intmap), make(intmap), make(intmap) |
| for i := 0; i < len(out); i += 4 { |
| r[int(out[i+0])]++ |
| g[int(out[i+1])]++ |
| b[int(out[i+2])]++ |
| a[int(out[i+3])]++ |
| } |
| |
| assertHasEvenDistribution(ctx.Tag("r"), r, 16) |
| assertHasEvenDistribution(ctx.Tag("g"), g, 16) |
| assertHasEvenDistribution(ctx.Tag("b"), b, 16) |
| assertHasEvenDistribution(ctx.Tag("a"), b, 16) |
| } |