edith
Clone
https://git.tahinli.com/Tahinli/edith.git
0 watching0 forksRust18.3 MiBff99ad6Tahinli6 days ago1055 commits
| 1 | //! A still's own EXIF orientation, applied. |
| 2 | //! |
| 3 | //! A phone photographs a portrait picture and stores it as landscape plus a tag |
| 4 | //! saying which way up it is. Before this the engine read neither: the `image` |
| 5 | //! crate keeps the orientation in its decoder and applies nothing, so the |
| 6 | //! preview, the timeline clip box, the poster thumbnail, the canvas seed and an |
| 7 | //! export of that clip were all the stored shape -- a portrait photo on its |
| 8 | //! side, silently, in every one of them. |
| 9 | //! |
| 10 | //! The fixture is **built here**, because none of the ones in `assets/` carry |
| 11 | //! an orientation tag (`scripts/gen_fixtures.sh` writes PNG stills, and PNG has |
| 12 | //! no such tag). It is a real JPEG: four coloured quadrants, an APP1 segment |
| 13 | //! holding a TIFF IFD whose tag `0x0112` states the orientation. A single |
| 14 | //! sampled pixel per corner then names the layout, and a *wrong direction* |
| 15 | //! cannot pass -- 90 the other way, 180, or "ignore it" each produce a |
| 16 | //! different set of four corners. |
| 17 | //! |
| 18 | //! ```text |
| 19 | //! cargo test -p engine --test exif_orientation -- --test-threads=1 |
| 20 | //! ``` |
| 21 | |
| 22 | use PathBuf; |
| 23 | |
| 24 | use Scratch; |
| 25 | use ; |
| 26 | |
| 27 | /// A built fixture and the directory holding it, which is removed when the |
| 28 | /// guard drops -- [`Scratch`]'s own contract, so a run leaves nothing behind |
| 29 | /// and two runs cannot race for a name. |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | /// Which of the four colours a pixel is, by name. The quadrants are far enough |
| 38 | /// apart that a 4:2:0 chroma boundary cannot colour a sample taken deep inside |
| 39 | /// one, and JPEG's own chroma subsampling cannot either. |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | /// The four corners of one tightly packed BGRA picture, top-left first and |
| 52 | /// clockwise -- sampled deep enough inside each quadrant that no boundary can |
| 53 | /// colour the sample. |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | /// The quadrants of the picture as it is **written into the file**, in the same |
| 70 | /// order [`corners`] reads them. The file is landscape 64x32 whatever the |
| 71 | /// orientation says, because that is what a phone does: it stores the sensor's |
| 72 | /// own shape and says the rest in the tag. |
| 73 | const STORED: = ; |
| 74 | |
| 75 | /// The stored picture, as a JPEG with no orientation tag: 64x32, four coloured |
| 76 | /// quadrants (`tests/data/quadrants_64x32.jpg`, written once with a JPEG |
| 77 | /// encoder and checked in, so this suite needs no encoder at run time). |
| 78 | const BASE_JPEG: & = include_bytes!; |
| 79 | |
| 80 | /// The fixture with an APP1/EXIF segment stating `exif` as the orientation. |
| 81 | /// |
| 82 | /// The EXIF is written by hand rather than through a crate: the segment is six |
| 83 | /// bytes of `Exif\0\0` followed by a little-endian TIFF header and one IFD |
| 84 | /// entry, which is the whole of what tag `0x0112` is, and writing it out is what |
| 85 | /// makes this a fixture rather than a dependency. |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | /// A complete APP1 segment carrying `exif` as EXIF tag `0x0112`: the `Exif\0\0` |
| 99 | /// identifier, a little-endian TIFF header pointing its IFD0 at offset 8, one |
| 100 | /// entry (tag, type SHORT, count 1, the value), and a zero "next IFD" pointer. |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | /// One frame of `path` and the size it came out at -- the same funnel |
| 124 | /// `PlaybackSession` paints from, so this is what a poster thumbnail and the |
| 125 | /// preview would each hold. |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | /// Software everywhere, so the suite proves the path every machine has. |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | /// The whole of the defect, asserted through **both** doors that used to |
| 142 | /// disagree: the header-only size a library row reads before anything places |
| 143 | /// the file, and the first decoded frame a preview shows after. They are |
| 144 | /// separate code paths over the same tag, so a fix to one that skipped the |
| 145 | /// other would leave a file that is one shape in the library and another on the |
| 146 | /// timeline. |
| 147 | /// |
| 148 | /// EXIF 6 is the portrait case -- a quarter turn clockwise -- so the stored |
| 149 | /// 64x32 is shown 32x64, and each stored corner moves one place clockwise. |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 | |
| 155 | |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | |
| 161 | |
| 162 | |
| 163 | |
| 164 | |
| 165 | |
| 166 | |
| 167 | |
| 168 | |
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 | |
| 175 | |
| 176 | |
| 177 | |
| 178 | |
| 179 | |
| 180 | /// The other quarter turns, so a fix that turned *something* rather than |
| 181 | /// turning *right* cannot pass: EXIF 3 is 180 (opposite corners swap), 8 is a |
| 182 | /// quarter turn anticlockwise (the other way round), and 1 states no turn. |
| 183 | /// |
| 184 | /// Each is asserted against the corners its own turn produces, indexed off the |
| 185 | /// stored layout rather than written out, so the expectation cannot drift away |
| 186 | /// from the fixture it describes. |
| 187 | |
| 188 | |
| 189 | |
| 190 | |
| 191 | |
| 192 | |
| 193 | |
| 194 | |
| 195 | |
| 196 | |
| 197 | |
| 198 | |
| 199 | |
| 200 | |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | |
| 207 | |
| 208 | |
| 209 | |
| 210 | |
| 211 | |
| 212 | |
| 213 | |
| 214 | |
| 215 | |
| 216 | |
| 217 | |
| 218 | |
| 219 | |
| 220 | |
| 221 | |
| 222 | |
| 223 | |
| 224 | |
| 225 | |
| 226 | /// A mirroring is not a turn, and this engine has no flip anywhere in its |
| 227 | /// pipeline -- not in the still's decode, not in `Render`, not in an export's |
| 228 | /// `place_picture`. So EXIF 2, 4, 5 and 7 are refused **by name** at the door, |
| 229 | /// the way a display matrix that is not a quarter turn is |
| 230 | /// (`engine::UnsupportedRotation`): a mirrored photo shown the wrong way round |
| 231 | /// is a wrong picture, not a missing feature, and quietly treating a mirror as |
| 232 | /// a rotation is exactly the bug this door exists to stop. |
| 233 | /// |
| 234 | /// All four values are checked, so a fix that refused only the first mirror is |
| 235 | /// caught. |
| 236 | |
| 237 | |
| 238 | |
| 239 | |
| 240 | |
| 241 | |
| 242 | |
| 243 | |
| 244 | |
| 245 | |
| 246 | |
| 247 | |
| 248 | |
| 249 | |
| 250 | |
| 251 | |
| 252 | |
| 253 | |
| 254 | |
| 255 | |
| 256 | |
| 257 | |
| 258 | |
| 259 | |
| 260 | |
| 261 | |
| 262 | |
| 263 | |
| 264 | |
| 265 | |
| 266 | |
| 267 | |
| 268 | |
| 269 | /// A picture that states no turn is the whole of an ordinary library, and it |
| 270 | /// must come out the way it always did: the turn is a branch on a bool, and |
| 271 | /// this is the assertion that it stays one. |
| 272 | |
| 273 | |
| 274 | |
| 275 | |
| 276 | |
| 277 | |
| 278 | |
| 279 | |
| 280 | |
| 281 | |
| 282 | |
| 283 | |
| 284 | |
| 285 | |
| 286 | |
| 287 | |
| 288 | |
| 289 | |
| 290 | /// The export, which is the door the turn was most expensive to get wrong: it |
| 291 | /// is a re-encode of the *coded* planes, so a still whose turn was applied |
| 292 | /// only on the preview side would be written out sideways and would then play |
| 293 | /// sideways in every player that is not this one, forever, with no matrix left |
| 294 | /// to correct it. |
| 295 | /// |
| 296 | /// The written file must therefore be portrait **and** state no matrix of its |
| 297 | /// own -- a file that kept the landscape pixels and declared a turn would |
| 298 | /// satisfy neither half. |
| 299 | |
| 300 | |
| 301 | |
| 302 | |
| 303 | |
| 304 | |
| 305 | |
| 306 | |
| 307 | |
| 308 | |
| 309 | |
| 310 | |
| 311 | |
| 312 | |
| 313 | |
| 314 | |
| 315 | |
| 316 | |
| 317 | |
| 318 | |
| 319 | |
| 320 | |
| 321 | |
| 322 | |
| 323 | |
| 324 | |
| 325 | |
| 326 | |
| 327 | |
| 328 | |
| 329 | |
| 330 | |
| 331 | |
| 332 | |
| 333 | |
| 334 | |
| 335 | |
| 336 | |
| 337 | |
| 338 | |
| 339 | |
| 340 | |
| 341 | |
| 342 | |
| 343 | |
| 344 |