From 53ec09fa9e7e2e8ac533fd19691701bdbadd3784 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Mon, 16 Nov 2020 19:02:45 +1100 Subject: [PATCH] Tighten the NIE spec to always be in BGRA order --- doc/spec/nie-related-work.md | 11 +++++------ doc/spec/nie-spec.md | 20 +++++++++----------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/doc/spec/nie-related-work.md b/doc/spec/nie-related-work.md index e3436685..f2dafdbb 100644 --- a/doc/spec/nie-related-work.md +++ b/doc/spec/nie-related-work.md @@ -14,12 +14,11 @@ more suitable. Amongst uncompressed formats, [Farbfeld](https://tools.suckless.org/farbfeld/) is a very similar design. The main difference is that NIE is little-endian (the same as the vast majority of CPUs) where Farbfeld is big-endian. NIE/NII/NIA -also allows animated images, not just still images, and is also configurable -with respect to BGRA versus RGBA order, non-premultiplied versus premultiplied -alpha, and 8 versus 16 bit channels. Configurability is admittedly a trade-off: -one person's configuration parameter is another person's unnecessary bloat. -We're not saying that Farbfeld is a bad design, just a different design that -has chosen different trade-offs. +also allows animated images, not just still images, and is also configurable: +non-premultiplied versus premultiplied alpha and 8- versus 16-bit channels. +Configurability is admittedly a trade-off. One person's configuration parameter +is another person's unnecessary bloat. We're not saying that Farbfeld is a bad +design, just a different design that has chosen different trade-offs. [PAM](http://netpbm.sourceforge.net/doc/pam.html) (Portable Arbitrary Map) and its related formats (PBM, PGM, PPM) are also very similar. The main difference diff --git a/doc/spec/nie-spec.md b/doc/spec/nie-spec.md index be6a6603..bf35609a 100644 --- a/doc/spec/nie-spec.md +++ b/doc/spec/nie-spec.md @@ -1,6 +1,6 @@ # Naïve Image Formats: NIE, NII, NIA -Status: Draft (as of May 2020). There is no compatibility guarantee yet. +Status: Draft (as of November 2020). There is no compatibility guarantee yet. A companion document has further discussion of [NIE related work](/doc/spec/nie-related-work.md). @@ -12,14 +12,13 @@ NIE is an easily parsed, uncompressed, lossless format for still (single frame) images. The 16 byte header: - 4 bytes of 'magic': \[0x6E, 0xC3, 0xAF, 0x45\], the UTF-8 encoding of "nïE". -- 4 bytes of version-and-configuration: \[0xFF, 0x62 or 0x72, 0x6E or 0x70, - 0x34 or 0x38\]. +- 4 bytes of version-and-configuration: \[0xFF, 0x62, 0x6E or 0x70, 0x34 or + 0x38\]. - The first byte denotes the overall NIE/NII/NIA format version. 0xFF (which is not valid UTF-8) denotes version 1. There are no other valid versions at this time. - - The second byte, either an ASCII 'b' or an ASCII 'r', denotes whether the - pixel's data is in BGRA or RGBA order (in memory order, independent of CPU - endianness). + - The second byte must be an ASCII 'b'. This denotes that the payload is in + BGRA order (in terms of the wire format, independent of CPU endianness). - The third byte, either an ASCII 'n' or an ASCII 'p', denotes whether the payload contains non-premultiplied or premultiplied alpha. - The fourth byte, either an ASCII '4' or an ASCII '8', denotes whether there @@ -31,11 +30,10 @@ images. The 16 byte header: The payload: -- 4 or 8 bytes per pixel. W×H pixels in row-major order. Row-major means that - horizontally adjacent pixels are adjacent in memory. Values are - little-endian. For example, with BGRA order and 8 bytes per pixel, those +- 4 or 8 bytes per pixel. W×H pixels in row-major order (horizontally adjacent + pixels are adjacent in memory). For example, with 8 bytes per pixel, those bytes are \[B₀, B₁, G₀, G₁, R₀, R₁, A₀, A₁\]. The ₀ and ₁ subscripts denote - the low and high bytes of the `uint16`. + the low and high bytes of each little-endian `uint16`. That's it. @@ -371,4 +369,4 @@ in a long "E", "I" or "A" sound. It's definitely a hard "N", not a soft one. --- -Updated on May 2020. +Updated on November 2020.