-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcontainer_encode.go
More file actions
55 lines (42 loc) · 1.38 KB
/
container_encode.go
File metadata and controls
55 lines (42 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// SPDX-License-Identifier: MIT
// Copyright (c) 2026 WoozyMasta
// Source: github.com/woozymasta/bcn
package bcn
import "image"
// encodeFacesWithOptions validates face dimensions and produces encoded face mip payloads.
// It is shared by DDS and KTX container encoders to keep container behavior identical.
func encodeFacesWithOptions(images []image.Image, format Format, opts *EncodeOptions) ([]Face, int, int, error) {
if len(images) != 1 && len(images) != 6 {
return nil, 0, 0, ErrExpectedOneOrSixImages
}
options := normalizeEncodeOptions(opts)
width := images[0].Bounds().Dx()
height := images[0].Bounds().Dy()
for _, img := range images[1:] {
if img.Bounds().Dx() != width || img.Bounds().Dy() != height {
return nil, 0, 0, ErrFacesDifferentDimensions
}
}
faces := make([]Face, len(images))
for i, img := range images {
if options.GenerateMipmaps {
mips := GenerateMipmaps(img, options.UseSRGB)
mipData := make([][]byte, len(mips))
for level, mip := range mips {
data, _, _, err := EncodeImageWithOptions(mip, format, &options)
if err != nil {
return nil, 0, 0, err
}
mipData[level] = data
}
faces[i] = Face{Mipmaps: mipData}
continue
}
data, _, _, err := EncodeImageWithOptions(img, format, &options)
if err != nil {
return nil, 0, 0, err
}
faces[i] = Face{Mipmaps: [][]byte{data}}
}
return faces, width, height, nil
}