You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: decompress_test.go
    path of file: ./repos/gapid/core/image
    
    the code of the file until where you have to start completion: // Copyright (C) 2017 Google Inc.
//
// 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 (
	"bytes"
	"fmt"
	"io/ioutil"
	"os"
	"path/filepath"
	"testing"

	"github.com/google/gapid/core/data/endian"
	"github.com/google/gapid/core/image"
	"github.com/google/gapid/core/image/astc"
	"github.com/google/gapid/core/math/sint"
	"github.com/google/gapid/core/os/d
    
func loadKTX(data []byte) (*image.Data, error) {
	r := endian.Reader(bytes.NewBuffer(data), device.LittleEndian)

	var ident [12]byte
	r.Data(ident[:])
	if ident != [12]byte{0xAB, 0x4B, 0x54, 0x58, 0x20, 0x31, 0x31, 0xBB, 0x0D, 0x0A, 0x1A, 0x0A} {
		return nil, fmt.Errorf("Invalid header. Got: %x", ident)
	}

	if endianness := r.Uint32(); endianness != 0x04030201 {
		return nil, fmt.Errorf("Unexpected endianness")
	}

	glType := r.Uint32()
	glTypeSize := r.Uint32()
	glFormat := r.Uint32()
	glInternalFormat := r.Uint32()
	glBaseInternalFormat := r.Uint32()
	texelWidth := r.Uint32()
	texelHeight := r.Uint32()
	pixelDepth := r.Uint32()
	numberOfArrayElements := r.Uint32()
	numberOfFaces := r.Uint32()
	numberOfMipmapLevels := r.Uint32()
	bytesOfKeyValueData := r.Uint32()

	for keyValueOffset := uint32(0); keyValueOffset < bytesOfKeyValueData; {
		keyAndValueByteSize := r.Uint32()
		keyAndValue := make([]byte, keyAndValueByteSize)
		r.Data(keyAndValue)
		padding := make([]byte, 3-((keyAndValueByteSize+3)%4))
		r.Data(padding)
		keyValueOffset += 4 + keyAndValueByteSize + uint32(len(padding))
	}

	if numberOfMipmapLevels != 1 {
		return nil, fmt.Errorf("Cannot handle multiple mipmap levels (%v)", numberOfMipmapLevels)
	}
	if numberOfArrayElements != 0 {
		return nil, fmt.Errorf("Cannot handle array elements (%v)", numberOfArrayElements)
	}
	if numberOfFaces != 1 {
		return nil, fmt.Errorf("Cannot handle multiple faces (%v)", numberOfFaces)
	}
	if pixelDepth != 0 {
		return nil, fmt.Errorf("Cannot handle 3D textures (%v)", pixelDepth)
	}

	formats := map[uint32]*image.Format{
		0x9270: image.ETC2_R_U11_NORM,          // GL_COMPRESSED_R11_EAC
		0x9271: image.ETC2_R_S11_NORM,          // GL_COMPRESSED_SIGNED_R11_EAC
		0x9272: image.ETC2_RG_U11_NORM,         // GL_COMPRESSED_RG11_EAC
		0x9273: image.ETC2_RG_S11_NORM,         // GL_COMPRESSED_SIGNED_RG11_EAC
		0x9274: image.ETC2_RGB_U8_NORM,         // GL_COMPRESSED_RGB8_ETC2
		0x9275: image.ETC2_SRGB_U8_NORM,        // GL_COMPRESSED_SRGB8_ETC2
		0x9276: image.ETC2_RGBA_U8U8U8U1_NORM,  // GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
		0x9277: image.ETC2_SRGBA_U8U8U8U1_NORM, // GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
		0x9278: image.ETC2_RGBA_U8_NORM,        // GL_COMPRESSED_RGBA8_ETC2_EAC
		0x9279: image.ETC2_SRGBA_U8_NORM,       // GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
	}
	format, ok := formats[glInternalFormat]
	if !ok {
		panic(fmt.Errorf(`Unsupported KTX format:
glType=0x%x
glTypeSize=0x%x
glFormat=0x%x
glInternalFormat=0x%x
glBaseInternalFormat=0x%x
`, glType, glTypeSize, glFormat, glInternalFormat, glBaseInternalFormat))
	}

	imageSize := r.Uint32()
	texelData := make([]byte, imageSize)
	r.Data(texelData)

	if err := r.Error(); err != nil {
		return nil, err
	}

	return &image.Data{
		Format: format,
		Width:  texelWidth,
		Height: texelHeight,
		Depth:  1,
		Bytes:  texelData,
	}, nil
}