From 838a46dbb7124125947bfdafe8ddf97810c5de47 Mon Sep 17 00:00:00 2001 From: Laurenz Stampfl <47084093+LaurenzV@users.noreply.github.com> Date: Thu, 27 Mar 2025 11:59:32 +0100 Subject: [PATCH] Test all exif rotation types and fix two of them (#6102) --- Cargo.lock | 2 +- Cargo.toml | 2 +- .../src/visualize/image/raster.rs | 4 ++-- tests/ref/image-exif-rotation.png | Bin 0 -> 1392 bytes tests/ref/issue-870-image-rotation.png | Bin 200 -> 0 bytes tests/suite/visualize/image.typ | 19 ++++++++++++------ 6 files changed, 17 insertions(+), 10 deletions(-) create mode 100644 tests/ref/image-exif-rotation.png delete mode 100644 tests/ref/issue-870-image-rotation.png diff --git a/Cargo.lock b/Cargo.lock index d63cec880..630eade2f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2803,7 +2803,7 @@ dependencies = [ [[package]] name = "typst-dev-assets" version = "0.13.1" -source = "git+https://github.com/typst/typst-dev-assets?rev=9879589#9879589f4b3247b12c5e694d0d7fa86d4d8a198e" +source = "git+https://github.com/typst/typst-dev-assets?rev=fddbf8b#fddbf8b99506bc370ac0edcd4959add603a7fc92" [[package]] name = "typst-docs" diff --git a/Cargo.toml b/Cargo.toml index a14124d65..a73241832 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,7 +33,7 @@ typst-syntax = { path = "crates/typst-syntax", version = "0.13.1" } typst-timing = { path = "crates/typst-timing", version = "0.13.1" } typst-utils = { path = "crates/typst-utils", version = "0.13.1" } typst-assets = { git = "https://github.com/typst/typst-assets", rev = "ab1295f" } -typst-dev-assets = { git = "https://github.com/typst/typst-dev-assets", rev = "9879589" } +typst-dev-assets = { git = "https://github.com/typst/typst-dev-assets", rev = "fddbf8b" } arrayvec = "0.7.4" az = "1.2" base64 = "0.22" diff --git a/crates/typst-library/src/visualize/image/raster.rs b/crates/typst-library/src/visualize/image/raster.rs index 0883fe71d..453b94066 100644 --- a/crates/typst-library/src/visualize/image/raster.rs +++ b/crates/typst-library/src/visualize/image/raster.rs @@ -325,12 +325,12 @@ fn apply_rotation(image: &mut DynamicImage, rotation: u32) { ops::flip_horizontal_in_place(image); *image = image.rotate270(); } - 6 => *image = image.rotate90(), + 6 => *image = image.rotate270(), 7 => { ops::flip_horizontal_in_place(image); *image = image.rotate90(); } - 8 => *image = image.rotate270(), + 8 => *image = image.rotate90(), _ => {} } } diff --git a/tests/ref/image-exif-rotation.png b/tests/ref/image-exif-rotation.png new file mode 100644 index 0000000000000000000000000000000000000000..a319a5c5b446afa08c7ec2084f2d1965c1405607 GIT binary patch literal 1392 zcmV-$1&{iPP)^-HEZ{nY`bQwA_ZT&Q_1tbE48? znBbGR>9Wk*f~@4B!NDnV%1DOELW0RegV0)%%~Fl=&)@m$^7Gc@(`A|6in7Q+f!1)K z&sdS!dZ)`vh|N%o-i))pA8XQNnfdAP%S?&RRgdbo&)kHr_v7r~l(_cZ>Cjx0_~q`> zVVCmK;nZrJd)o!2e!q@xo_4L@~%~6cMA#C&2 z*m$P=_4wzk$kS(< z#>U3!v(3lH$L+z^UteF_fU8kPR8QV_!%zH`B}w-S>}l_UUhLpKSJaFEb%LJUl!+ zJQJ6q_!vmMo>&pV#3#f;67ZK@F0KVsOj24Vj_7~|*(w(qIab(R9n(r;Rzj;6SbVOK8Sx%&|7HnlOV zWjWd1%GMn|0%M%KKyKWONP6YLL$?|B{6%^Be1^S#^|Hzc7sQ!b2{)B9blpPa0|YcS5sq8i@?aV=6`)Lqr;<33EN4hrX)nl$OUAV%$*D zW1~N#uwZ*ko3zX8_4~a(pHD6ACT@>&WMo8PwBhtntd^#o0)4%%@Y1e-&9qCC^nlfB z>*?-wdsNKZZ}02uVn6n-&OUp;S5}zE-P_$`vswqjO8aF)Zr(H+g#}u9xdz#`p}*mjW&sTne~kB9P9ae+DHNrqVf z27RL{?YGGp#G#gUkPO-84+*E{TFK*cL3Zea7V$NC#ur8*W#XxdpGX!QI*D1 z4NpHjCGj-Xoisj=;B$-ar18lQpAe%g9XB(sgE&yyK|1KaRCT}dSH{1&aA_{BQM!Hj y8)R5dtes#!&iD?Qt|#`M|9*johlht};_?GLgY!0Dq{rU?0000F!$v^BJ8WOKO3hZ{* zmD@UlOU(EH<6qshG)CrK(Pu0i?9!4vqHSu`1TNf85^K{H5c{he$G@cR??2!C?wOLe z*2(Vr`~Uudl;sEh?`J=dq*m7U;eS2bx#P-eeUTDojG7Dfe);~f>%aZ~fASpN;f%@^ zSCVc;=e*C@|NsB|i_6ZhIJ#J@KguS{P>+G(z@>Nge%mrGft={+>gTe~DWM4f<3&-k diff --git a/tests/suite/visualize/image.typ b/tests/suite/visualize/image.typ index 7ce0c8c0a..9a77870af 100644 --- a/tests/suite/visualize/image.typ +++ b/tests/suite/visualize/image.typ @@ -247,12 +247,6 @@ A #box(image("/assets/images/tiger.jpg", height: 1cm, width: 80%)) B format: "rgba8", ) ---- issue-870-image-rotation --- -// Ensure that EXIF rotation is applied. -// https://github.com/image-rs/image/issues/1045 -// File is from https://magnushoff.com/articles/jpeg-orientation/ -#image("/assets/images/f2t.jpg", width: 10pt) - --- issue-measure-image --- // Test that image measurement doesn't turn `inf / some-value` into 0pt. #context { @@ -267,3 +261,16 @@ A #box(image("/assets/images/tiger.jpg", height: 1cm, width: 80%)) B --- issue-3733-dpi-svg --- #set page(width: 200pt, height: 200pt, margin: 0pt) #image("/assets/images/relative.svg") + +--- image-exif-rotation --- +#let data = read("/assets/images/f2t.jpg", encoding: none) + +#let rotations = range(1, 9) +#let rotated(v) = image(data.slice(0, 49) + bytes((v,)) + data.slice(50), width: 10pt) + +#set page(width: auto) +#table( + columns: rotations.len(), + ..rotations.map(v => raw(str(v), lang: "typc")), + ..rotations.map(rotated) +)