Commit 5741037e authored by Rafaël Carré's avatar Rafaël Carré
Browse files

thumbnailer: simplify AR calculation

parent f6fd760a
...@@ -134,19 +134,15 @@ jbyteArray Java_org_videolan_vlc_android_LibVLC_getThumbnail(JNIEnv *env, jobjec ...@@ -134,19 +134,15 @@ jbyteArray Java_org_videolan_vlc_android_LibVLC_getThumbnail(JNIEnv *env, jobjec
int nbTracks = libvlc_media_get_tracks_info(m, &tracks); int nbTracks = libvlc_media_get_tracks_info(m, &tracks);
unsigned i, videoWidth, videoHeight; unsigned i, videoWidth, videoHeight;
float videoAR;
bool hasVideoTrack = false; bool hasVideoTrack = false;
for (i = 0; i < nbTracks; ++i) for (i = 0; i < nbTracks; ++i)
{
if (tracks[i].i_type == libvlc_track_video) if (tracks[i].i_type == libvlc_track_video)
{ {
videoWidth = tracks[i].u.video.i_width; videoWidth = tracks[i].u.video.i_width;
videoHeight = tracks[i].u.video.i_height; videoHeight = tracks[i].u.video.i_height;
videoAR = (float)videoWidth / videoHeight;
hasVideoTrack = true; hasVideoTrack = true;
break; break;
} }
}
free(tracks); free(tracks);
...@@ -158,18 +154,17 @@ jbyteArray Java_org_videolan_vlc_android_LibVLC_getThumbnail(JNIEnv *env, jobjec ...@@ -158,18 +154,17 @@ jbyteArray Java_org_videolan_vlc_android_LibVLC_getThumbnail(JNIEnv *env, jobjec
} }
/* Compute the size parameters of the frame to generate. */ /* Compute the size parameters of the frame to generate. */
unsigned picWidth, picHeight; unsigned picWidth = width;
float thumbnailAR = (float)width / height; unsigned picHeight = height;
if (videoAR < thumbnailAR) float videoAR = (float)videoWidth / videoHeight;
if (videoAR < ((float)width / height))
{ {
picHeight = height / videoAR; picHeight /= videoAR;
picWidth = width;
sys->thumbnailOffset = (picHeight - height) / 2 * sys->picPitch; sys->thumbnailOffset = (picHeight - height) / 2 * sys->picPitch;
} }
else else
{ {
picHeight = height; picWidth *= videoAR;
picWidth = width * videoAR;
sys->thumbnailOffset = (picWidth - width) / 2 * PIXEL_SIZE; sys->thumbnailOffset = (picWidth - width) / 2 * PIXEL_SIZE;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment