<commit_before>// 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 gles

import (
	"bytes"
	"context"
	"encoding/base64"
	"fmt"
	goimg "image"
	"image/color"
	"image/png"
	"io/ioutil"
	"os"
	"path/filepath"

	"github.com/google/gapid/core/data/endian"
	gpuimg "github.com/google/gapid/core/image"
	"github.com/google/gapid/core/log"
	"github.com/google/gapid/core/os/device"
	"github.com/google/gapid/core/stream"
)

// storeReferenceImage replaces the reference image with img.
func storeReferenceImage(ctx context.Context, outputDir string, name string, img *gpuimg.Image2D) {
	ctx = log.V{"name": name}.Bind(ctx)
	data := &bytes.Buffer{}
	i, err := toGoImage(img)
	if err != nil {
		log.F(ctx, "Failed to convert GPU image to Go image: %v", err)
	}
	if err := png.Encode(data, i); err != nil {
		log.F(ctx, "Failed to encode reference image: %v", err)
	}
	if err := os.MkdirAll(outputDir, 0755); err != nil {
		log.F(ctx, "Failed to create reference image directory: %v", err)
	}
	path := filepath.Join(outputDir, name+".png")
	if err := ioutil.WriteFile(path, data.Bytes(), 0666); err != nil {
		log.F(ctx, "Failed to store reference image: %v", err)
	}
}

// loadReferenceImage loads the reference image with the specified name.
func loadReferenceImage(ctx context.Context, name string) *gpuimg.Image2D {
	ctx = log.V{"name": name}.Bind(ctx)
	b64, found := embedded[fmt.Sprintf("reference/%s.png", name)]
	if !found {
		log.F(ctx, "Embedded reference image '%s' not found", name)
	}<commit_msg>Fix GLES integration tests on windows.<commit_after>// 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 gles

import (
	"bytes"
	"context"
	"encoding/base64"
	"fmt"
	goimg "image"
	"image/color"
	"image/png"
	"io/ioutil"
	"os"
	"path/filepath"

	"github.com/google/gapid/core/data/endian"
	gpuimg "github.com/google/gapid/core/image"
	"github.com/google/gapid/core/log"
	"github.com/google/gapid/core/os/device"
	"github.com/google/gapid/core/stream"
)

// storeReferenceImage replaces the reference image with img.
func storeReferenceImage(ctx context.Context, outputDir string, name string, img *gpuimg.Image2D) {
	ctx = log.V{"name": name}.Bind(ctx)
	data := &bytes.Buffer{}
	i, err := toGoImage(img)
	if err != nil {
		log.F(ctx, "Failed to convert GPU image to Go image: %v", err)
	}
	if err := png.Encode(data, i); err != nil {
		log.F(ctx, "Failed to encode reference image: %v", err)
	}
	if err := os.MkdirAll(outputDir, 0755); err != nil {
		log.F(ctx, "Failed to create reference image directory: %v", err)
	}
	path := filepath.Join(outputDir, name+".png")
	if err := ioutil.WriteFile(path, data.Bytes(), 0666); err != nil {
		log.F(ctx, "Failed to store reference image: %v", err)
	}
}

// loadReferenceImage loads the reference image with the specified name.
func loadReferenceImage(ctx context.Context, name string) *gpuimg.Image2D {
	ctx = log.V{"name": name}.Bind(ctx)
	b64, found := embedded[filepath.Join("reference", name+".png")]
	if !found {
		log.F(ctx, "Embedded reference image '%s' not found", name)
	}
{'fraction_non_alphanumeric': 0.14012121212121212, 'fraction_numerical': 0.010666666666666666, 'mean_word_length': 3.9591346153846154, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2749341', 'n_tokens_mistral': 1421, 'n_tokens_neox': 1365, 'n_words': 447}