blob: 3ada950712f45d0a1207821c5faab00ddb54f651 [file] [log] [blame]
// 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 (
"bytes"
"android.googlesource.com/platform/tools/gpu/framework/binary"
"android.googlesource.com/platform/tools/gpu/framework/binary/endian"
"android.googlesource.com/platform/tools/gpu/framework/device"
)
type fmtDepthF16 struct{ binary.Generate }
func (f *fmtDepthF16) Key() interface{} { return *f }
func (*fmtDepthF16) String() string { return "DepthF16" }
func (*fmtDepthF16) Size(w, h int) int { return w * h * 2 }
func (*fmtDepthF16) Check(d []byte, w, h int) error { return checkSize(d, w, h, 16) }
// DepthF16 returns a depth format containing a single half-float channel.
func DepthF16() Format { return &fmtDepthF16{} }
func init() {
RegisterConverter(DepthF16(), RGBA(),
func(src []byte, width, height int) ([]byte, error) {
r := endian.Reader(bytes.NewBuffer(src), device.LittleEndian)
dst, i := make([]byte, width*height*4), 0
for y := 0; y < height; y++ {
for x := 0; x < width; x++ {
depth := float64(r.Float16())
dst[i+0], dst[i+1], dst[i+2], dst[i+3] = depthToRGBA(depth)
i += 4
}
}
return dst, nil
})
}