mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-24 08:52:18 +01:00
Have make-red-blue-gradient use iCCP profile name
This commit is contained in:
1 parent
8f9a4f40c2
commit
f40ef01244
2 files changed
+34
-2
No files matched your search
@@ -25,6 +25,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"compress/zlib"
|
"compress/zlib"
|
||||||
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
"hash/crc32"
|
"hash/crc32"
|
||||||
"image"
|
"image"
|
||||||
@@ -32,6 +33,8 @@ import (
|
|||||||
"image/png"
|
"image/png"
|
||||||
"math"
|
"math"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -111,9 +114,14 @@ func main1() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
name, err := iccpName(*iccp)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
data := &bytes.Buffer{}
|
data := &bytes.Buffer{}
|
||||||
data.WriteString("icc\x00") // An arbitrary NUL terminated name.
|
data.WriteString(name)
|
||||||
data.WriteByte(0x00) // 0x00 means zlib compression.
|
data.WriteByte(0x00) // The name is NUL terminated.
|
||||||
|
data.WriteByte(0x00) // 0x00 means zlib compression.
|
||||||
w := zlib.NewWriter(data)
|
w := zlib.NewWriter(data)
|
||||||
w.Write(raw)
|
w.Write(raw)
|
||||||
w.Close()
|
w.Close()
|
||||||
@@ -147,3 +155,27 @@ func appendPNGChunk(b []byte, name string, chunk ...byte) []byte {
|
|||||||
byte(c>>0),
|
byte(c>>0),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// iccpName determines a "bar" iCCP profile name (that satisifes the PNG
|
||||||
|
// specification re the iCCP chunk) based on the "foo/bar.icc" filename.
|
||||||
|
func iccpName(filename string) (string, error) {
|
||||||
|
s := filepath.Base(filename)
|
||||||
|
if i := strings.IndexByte(s, '.'); i >= 0 {
|
||||||
|
s = s[:i]
|
||||||
|
}
|
||||||
|
s = strings.TrimSpace(s)
|
||||||
|
if strings.Index(s, " ") >= 0 {
|
||||||
|
return "", errors.New("ICCP name cannot contain consecutive spaces")
|
||||||
|
} else if (len(s) < 1) || (79 < len(s)) {
|
||||||
|
return "", errors.New("ICCP name has invalid length.")
|
||||||
|
}
|
||||||
|
for i := 0; i < len(s); i++ {
|
||||||
|
if (s[i] < ' ') || ('~' < s[i]) {
|
||||||
|
// Strictly speaking, the PNG specification allows the iCCP name to
|
||||||
|
// be printable Latin-1, not just printable ASCII, but printable
|
||||||
|
// ASCII is easier and avoids any later Latin-1 vs UTF-8 ambiguity.
|
||||||
|
return "", errors.New("ICCP name is not printable ASCII")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return s, nil
|
||||||
|
}
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
Reference in new issue
Block a user