diff --git a/internal/cgen/base/magic-submodule.c b/internal/cgen/base/magic-submodule.c index 96b9ecb0..26aa9549 100644 --- a/internal/cgen/base/magic-submodule.c +++ b/internal/cgen/base/magic-submodule.c @@ -167,6 +167,7 @@ wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix_data, {+0x514F4920, "\x03\x71\x6F\x69\x66"}, // QOI {+0x5A4C4942, "\x01\x78\x9C"}, // ZLIB {+0x504E4720, "\x03\x89\x50\x4E\x47"}, // PNG + {+0x54482020, "\x02\xC3\xBE\xFE"}, // TH {+0x585A2020, "\x04\xFD\x37\x7A\x58\x5A"}, // XZ {+0x4A504547, "\x01\xFF\xD8"}, // JPEG }; diff --git a/lang/builtin/builtin.go b/lang/builtin/builtin.go index 8b81ca1e..7ce3152f 100644 --- a/lang/builtin/builtin.go +++ b/lang/builtin/builtin.go @@ -78,6 +78,7 @@ var FourCCs = [...][2]string{ {"TAR ", "Tape Archive"}, {"TEXT", "Text"}, {"TGA ", "Truevision Advanced Raster Graphics Adapter"}, + {"TH ", "Thumbhash"}, {"TIFF", "Tagged Image File Format"}, {"TOML", "Tom's Obvious Minimal Language"}, {"WAVE", "Waveform"}, diff --git a/release/c/wuffs-unsupported-snapshot.c b/release/c/wuffs-unsupported-snapshot.c index 665c4b8b..929ead80 100644 --- a/release/c/wuffs-unsupported-snapshot.c +++ b/release/c/wuffs-unsupported-snapshot.c @@ -916,6 +916,9 @@ typedef struct wuffs_base__transform__output__struct { // Truevision Advanced Raster Graphics Adapter. #define WUFFS_BASE__FOURCC__TGA 0x54474120 +// Thumbhash. +#define WUFFS_BASE__FOURCC__TH 0x54482020 + // Tagged Image File Format. #define WUFFS_BASE__FOURCC__TIFF 0x54494646 @@ -22391,6 +22394,7 @@ wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix_data, {+0x514F4920, "\x03\x71\x6F\x69\x66"}, // QOI {+0x5A4C4942, "\x01\x78\x9C"}, // ZLIB {+0x504E4720, "\x03\x89\x50\x4E\x47"}, // PNG + {+0x54482020, "\x02\xC3\xBE\xFE"}, // TH {+0x585A2020, "\x04\xFD\x37\x7A\x58\x5A"}, // XZ {+0x4A504547, "\x01\xFF\xD8"}, // JPEG }; diff --git a/test/data/artificial-thumbhash/1QcSHQRnh493V4dIh4eXh1h4kJUI.th b/test/data/artificial-thumbhash/1QcSHQRnh493V4dIh4eXh1h4kJUI.th new file mode 100644 index 00000000..434219a5 --- /dev/null +++ b/test/data/artificial-thumbhash/1QcSHQRnh493V4dIh4eXh1h4kJUI.th @@ -0,0 +1 @@ +þþÕg‡�wW‡H‡‡—‡Xx�• \ No newline at end of file diff --git a/test/data/artificial-thumbhash/2IqDBQQnxnj0JoLYdM3f8ahpuDeHiHdwZw.th b/test/data/artificial-thumbhash/2IqDBQQnxnj0JoLYdM3f8ahpuDeHiHdwZw.th new file mode 100644 index 00000000..77f9a363 --- /dev/null +++ b/test/data/artificial-thumbhash/2IqDBQQnxnj0JoLYdM3f8ahpuDeHiHdwZw.th @@ -0,0 +1 @@ +þþØŠƒ'Æxô&‚ØtÍßñ¨i¸7‡ˆwpg \ No newline at end of file diff --git a/test/data/artificial-thumbhash/2fcZFIB3iId_h3iJh4aIYJ2V8g.th b/test/data/artificial-thumbhash/2fcZFIB3iId_h3iJh4aIYJ2V8g.th new file mode 100644 index 00000000..ce497b86 --- /dev/null +++ b/test/data/artificial-thumbhash/2fcZFIB3iId_h3iJh4aIYJ2V8g.th @@ -0,0 +1 @@ +þþÙ÷€wˆ‡‡x‰‡†ˆ`�•ò \ No newline at end of file diff --git a/test/data/artificial-thumbhash/3OcRJYB4d3h_iIeHeEh3eIhw-j3A.th b/test/data/artificial-thumbhash/3OcRJYB4d3h_iIeHeEh3eIhw-j3A.th new file mode 100644 index 00000000..1662f24e --- /dev/null +++ b/test/data/artificial-thumbhash/3OcRJYB4d3h_iIeHeEh3eIhw-j3A.th @@ -0,0 +1 @@ +þþÜç%€xwxˆ‡‡xHwxˆpú=À \ No newline at end of file diff --git a/test/data/artificial-thumbhash/3PcNNYSFeXh_d3eld0iHZoZgVwh2.th b/test/data/artificial-thumbhash/3PcNNYSFeXh_d3eld0iHZoZgVwh2.th new file mode 100644 index 00000000..5c6490cb --- /dev/null +++ b/test/data/artificial-thumbhash/3PcNNYSFeXh_d3eld0iHZoZgVwh2.th @@ -0,0 +1 @@ +þþÜ÷ 5„…yxww¥wH‡f†`Wv \ No newline at end of file diff --git a/test/data/artificial-thumbhash/HBkSHYSIeHiPiHh8eJd4eTN0EEQG.th b/test/data/artificial-thumbhash/HBkSHYSIeHiPiHh8eJd4eTN0EEQG.th new file mode 100644 index 00000000..23ce751a --- /dev/null +++ b/test/data/artificial-thumbhash/HBkSHYSIeHiPiHh8eJd4eTN0EEQG.th @@ -0,0 +1 @@ +þþ„ˆxx�ˆx|x—xy3tD \ No newline at end of file diff --git a/test/data/artificial-thumbhash/IQgSLYZ6iHePh4h1eFeHh4dwgwg3.th b/test/data/artificial-thumbhash/IQgSLYZ6iHePh4h1eFeHh4dwgwg3.th new file mode 100644 index 00000000..27b529fa --- /dev/null +++ b/test/data/artificial-thumbhash/IQgSLYZ6iHePh4h1eFeHh4dwgwg3.th @@ -0,0 +1 @@ +þþ!-†zˆw�‡ˆuxW‡‡‡pƒ7 \ No newline at end of file diff --git a/test/data/artificial-thumbhash/VggKDYAW6lZvdYd6d2iZh_p4GE_k.th b/test/data/artificial-thumbhash/VggKDYAW6lZvdYd6d2iZh_p4GE_k.th new file mode 100644 index 00000000..8ee9ae53 --- /dev/null +++ b/test/data/artificial-thumbhash/VggKDYAW6lZvdYd6d2iZh_p4GE_k.th @@ -0,0 +1,2 @@ +þþV + €êVou‡zwh™‡úxOä \ No newline at end of file diff --git a/test/data/artificial-thumbhash/YJqGPQw7sFlslqhFafSE-Q6oJ1h2iHB2Rw.th b/test/data/artificial-thumbhash/YJqGPQw7sFlslqhFafSE-Q6oJ1h2iHB2Rw.th new file mode 100644 index 00000000..cea2dce9 --- /dev/null +++ b/test/data/artificial-thumbhash/YJqGPQw7sFlslqhFafSE-Q6oJ1h2iHB2Rw.th @@ -0,0 +1 @@ +þþ`š†= ;°Yl–¨Eiô„ù¨'XvˆpvG \ No newline at end of file diff --git a/test/data/artificial-thumbhash/make.go b/test/data/artificial-thumbhash/make.go new file mode 100644 index 00000000..e08922d7 --- /dev/null +++ b/test/data/artificial-thumbhash/make.go @@ -0,0 +1,84 @@ +// Copyright 2024 The Wuffs Authors. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. +// +// SPDX-License-Identifier: Apache-2.0 OR MIT + +//go:build ignore +// +build ignore + +package main + +// make.go writes the https://evanw.github.io/thumbhash/ examples to individual +// files, prepending a 3-byte magic string so that /usr/bin/file or similar +// programs can identify the data as thumbhash-formatted data. +// +// That 3-byte magic string is "\xC3\xBE\xFE", which is arbitrary and not part +// of the original thumbhash description or implementation. But "\xC3\xBE" is +// the UTF-8 encoding of 'þ' (U+00FE LATIN SMALL LETTER THORN) and "\xFE" is +// invalid UTF-8 but is the ISO-8859-1 encoding of 'þ'. The Old English letter +// 'þ' is pronounced like the "th" that starts "thumbhash". +// +// The filenames are the base64.RawURLEncoding of the data (similar to but +// slightly different from the base64.RawStdEncoding used on that web page) +// plus a ".th" extension. +// +// Usage: go run make.go + +import ( + "encoding/base64" + "os" +) + +func main() { + if err := main1(); err != nil { + os.Stderr.WriteString(err.Error() + "\n") + os.Exit(1) + } +} + +func main1() error { + for _, d := range data { + filename := convertBase64StdToBase64URL(d) + ".th" + in, err := base64.RawStdEncoding.DecodeString(d) + if err != nil { + return err + } + out := append([]byte(magic), in...) + if err := os.WriteFile(filename, out, 0666); err != nil { + return err + } + } + return nil + +} + +func convertBase64StdToBase64URL(s string) string { + b := []byte(s) + for i, c := range b { + if c == '+' { + b[i] = '-' + } else if c == '/' { + b[i] = '_' + } + } + return string(b) +} + +const magic = "\xC3\xBE\xFE" + +var data = []string{ + "1QcSHQRnh493V4dIh4eXh1h4kJUI", + "3PcNNYSFeXh/d3eld0iHZoZgVwh2", + "3OcRJYB4d3h/iIeHeEh3eIhw+j3A", + "HBkSHYSIeHiPiHh8eJd4eTN0EEQG", + "VggKDYAW6lZvdYd6d2iZh/p4GE/k", + "2fcZFIB3iId/h3iJh4aIYJ2V8g", + "IQgSLYZ6iHePh4h1eFeHh4dwgwg3", + "YJqGPQw7sFlslqhFafSE+Q6oJ1h2iHB2Rw", + "2IqDBQQnxnj0JoLYdM3f8ahpuDeHiHdwZw", +}