On Tue, Aug 19, 2025 at 06:33:03PM +0300, [email protected] wrote: > The branch, master has been updated > via 4c3f94f2651ce4d6834fbef10e5c287f25720ac9 (commit) > via fe496b0308f1911138698b92bbafac582fa455d7 (commit) > via 535a07d14e16eb2930d2b1e16605eafa95959139 (commit) > via 8132ee046d1a03c5913759c50fce7beda8d3d627 (commit) > via 5d4f873ff31f86f9ae1927f37ca0fcb78da70512 (commit) > via 1e816ebefee0ef479fa76bd2a1fb9ec5d5e807df (commit) > via 93a8091015978c44462626409af71789080bbef4 (commit) > via 303f60684f25ce63951480ef0f759acf41aac938 (commit) > via 5caaadee7954f2014d9e0a17d1edfb961893bcf1 (commit) <--- we are here > via d3190a64c366a79091fe47fddf93c09a7d988802 (commit) > via 44af3829796427b89c4b76b56652cc5932ada616 (commit) > via f5ad1c910c168d05cb01315773ab0bd094c9372f (commit) > via e3aa1154aab2656c91ce61915f79516d9b563b61 (commit) > via c6cc2115f45ac26ae42442f8796996eb410f4028 (commit) > via 52dba25661305e3c4a6209d46aea43cd327c960e (commit) > via bfb17d26306592c85cf0c4e909099c621177b062 (commit) > via ba2ea285e0f270a0a885b414cafaace6a89b9a91 (commit) > via ad77345a5d14862f4701e5ad422b03b14934a5b9 (commit) > via bb90b262d6d23f1bca3587a48abc15b951cbbf05 (commit) > via a99fff4e2d4058c57599ba0b968862af82bdad5b (commit) > from a6b5a382dd7ecdd27c5d0ebba688e1db409d18fd (commit) [...] > commit 5caaadee7954f2014d9e0a17d1edfb961893bcf1 > Author: Leo Izen <[email protected]> > AuthorDate: Tue Mar 25 17:09:07 2025 -0400 > Commit: Leo Izen <[email protected]> > CommitDate: Tue Aug 19 11:26:47 2025 -0400 > > avcodec/exif: add orientation ID and matrix conversion routines > > Takes existing code that makes display matricies work with EXIF > orientation tags and expose the conversion as a public API. > > Signed-off-by: Leo Izen <[email protected]> > > diff --git a/libavcodec/exif.c b/libavcodec/exif.c > index fa46202874..d174d16ddc 100644 > --- a/libavcodec/exif.c > +++ b/libavcodec/exif.c > @@ -811,7 +811,7 @@ static int attach_displaymatrix(void *logctx, AVFrame > *frame, int orientation) > int32_t *matrix; > /* invalid orientation */ > if (orientation < 2 || orientation > 8) > - return 0; > + return AVERROR_INVALIDDATA; > sd = av_frame_new_side_data(frame, AV_FRAME_DATA_DISPLAYMATRIX, > sizeof(int32_t) * 9); > if (!sd) { > av_log(logctx, AV_LOG_ERROR, "Could not allocate frame side data\n"); > @@ -819,37 +819,7 @@ static int attach_displaymatrix(void *logctx, AVFrame > *frame, int orientation) > } > matrix = (int32_t *) sd->data; > > - switch (orientation) { > - case 2: > - av_display_rotation_set(matrix, 0.0); > - av_display_matrix_flip(matrix, 1, 0); > - break; > - case 3: > - av_display_rotation_set(matrix, 180.0); > - break; > - case 4: > - av_display_rotation_set(matrix, 180.0); > - av_display_matrix_flip(matrix, 1, 0); > - break; > - case 5: > - av_display_rotation_set(matrix, 90.0); > - av_display_matrix_flip(matrix, 1, 0); > - break; > - case 6: > - av_display_rotation_set(matrix, 90.0); > - break; > - case 7: > - av_display_rotation_set(matrix, -90.0); > - av_display_matrix_flip(matrix, 1, 0); > - break; > - case 8: > - av_display_rotation_set(matrix, -90.0); > - break; > - default: > - av_assert0(0); > - } > - > - return 0; > + return av_exif_orientation_to_matrix(matrix, orientation); > } > > #define COLUMN_SEP(i, c) ((i) ? ((i) % (c) ? ", " : "\n") : "") > @@ -1215,31 +1185,59 @@ end: > return ret; > } > > -static int exif_get_orientation(const int32_t *display_matrix) > +static const int rotation_lut[2][4] = { > + {1, 8, 3, 6}, {4, 7, 2, 5}, > +}; > + > +int av_exif_matrix_to_orientation(const int32_t *matrix) > { > - double rotation = av_display_rotation_get(display_matrix); > + double rotation = av_display_rotation_get(matrix); > // determinant > - int vflip = ((int64_t)display_matrix[0] * (int64_t)display_matrix[4] > - - (int64_t)display_matrix[1] * (int64_t)display_matrix[3]) < > 0; > + int vflip = ((int64_t)matrix[0] * (int64_t)matrix[4] > + - (int64_t)matrix[1] * (int64_t)matrix[3]) < 0; > if (!isfinite(rotation)) > - return 1; > + return 0;
av_exif_matrix_to_orientation() now returns 0 for non-finite rotation,
while ff_exif_get_buffer() blindly uses that return value as an EXIF
Orientation tag value and may also add a new Orientation tag when none existed.
The code should not change the orientation if conversion fails
> - if (vflip) {
> - if (rotation > 181.0 || rotation > -179.0 && rotation < -89.0)
> - return 5;
> - if (rotation > 91.0 || rotation < -179.0 && rotation > -269.0)
> - return 2;
> - if (rotation > 1.0 || rotation < -269.0)
> - return 7;
> - return 4;
> - } else {
> - if (rotation > 181.0 || rotation > -179.0 && rotation < -89.0)
> - return 6;
> - if (rotation > 91.0 || rotation < -179.0 && rotation > -269.0)
> - return 3;
> - if (rotation > 1.0 || rotation < -269.0)
> - return 8;
> - return 1;
> + int rot = (int)(rotation + 0.5);
this is incorrectly rounding for negative numbers
> + rot = (((rot % 360) + 360) % 360) / 90;
This does not seem to round to the closest
and what i missed, the code from f5ad1c910c168d05cb01315773ab0bd094c9372f
also did not
-45 .. 45 -> 0 NOT -89..1
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
The day soldiers stop bringing you their problems is the day you have stopped
leading them. They have either lost confidence that you can help or concluded
you do not care. Either case is a failure of leadership. - Colin Powell
signature.asc
Description: PGP signature
_______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
