summaryrefslogtreecommitdiffstats
path: root/media/jni/android_media_MediaMetadataRetriever.cpp
diff options
context:
space:
mode:
authorJames Dong <jdong@google.com>2011-03-18 17:55:06 -0700
committerJames Dong <jdong@google.com>2011-03-20 14:46:30 -0700
commit9f2cde3cdb3e2de97f450d0f4e2b52aae86ce5a3 (patch)
treeb9e8f36150c9abdd11ced360c1a89f6071460d05 /media/jni/android_media_MediaMetadataRetriever.cpp
parentdf66797771550d243500943e1b9a177667f77f7a (diff)
downloadframeworks_base-9f2cde3cdb3e2de97f450d0f4e2b52aae86ce5a3.zip
frameworks_base-9f2cde3cdb3e2de97f450d0f4e2b52aae86ce5a3.tar.gz
frameworks_base-9f2cde3cdb3e2de97f450d0f4e2b52aae86ce5a3.tar.bz2
Scale the thumbnail if display dimension is different from the actual buffer size
bug - 3379293 Change-Id: I31c08010c97387716433da99d648bd364847b6aa
Diffstat (limited to 'media/jni/android_media_MediaMetadataRetriever.cpp')
-rw-r--r--media/jni/android_media_MediaMetadataRetriever.cpp43
1 files changed, 37 insertions, 6 deletions
diff --git a/media/jni/android_media_MediaMetadataRetriever.cpp b/media/jni/android_media_MediaMetadataRetriever.cpp
index 3d7dbf9..70e73ba 100644
--- a/media/jni/android_media_MediaMetadataRetriever.cpp
+++ b/media/jni/android_media_MediaMetadataRetriever.cpp
@@ -37,6 +37,7 @@ struct fields_t {
jclass bitmapClazz;
jfieldID nativeBitmap;
jmethodID createBitmapMethod;
+ jmethodID createScaledBitmapMethod;
jclass configClazz;
jmethodID createConfigMethod;
};
@@ -219,12 +220,14 @@ static jobject android_media_MediaMetadataRetriever_getFrameAtTime(JNIEnv *env,
SkBitmap::kRGB_565_Config);
size_t width, height;
+ bool swapWidthAndHeight = false;
if (videoFrame->mRotationAngle == 90 || videoFrame->mRotationAngle == 270) {
- width = videoFrame->mDisplayHeight;
- height = videoFrame->mDisplayWidth;
+ width = videoFrame->mHeight;
+ height = videoFrame->mWidth;
+ swapWidthAndHeight = true;
} else {
- width = videoFrame->mDisplayWidth;
- height = videoFrame->mDisplayHeight;
+ width = videoFrame->mWidth;
+ height = videoFrame->mHeight;
}
jobject jBitmap = env->CallStaticObjectMethod(
@@ -240,11 +243,30 @@ static jobject android_media_MediaMetadataRetriever_getFrameAtTime(JNIEnv *env,
bitmap->lockPixels();
rotate((uint16_t*)bitmap->getPixels(),
(uint16_t*)((char*)videoFrame + sizeof(VideoFrame)),
- videoFrame->mDisplayWidth,
- videoFrame->mDisplayHeight,
+ videoFrame->mWidth,
+ videoFrame->mHeight,
videoFrame->mRotationAngle);
bitmap->unlockPixels();
+ if (videoFrame->mDisplayWidth != videoFrame->mWidth ||
+ videoFrame->mDisplayHeight != videoFrame->mHeight) {
+ size_t displayWidth = videoFrame->mDisplayWidth;
+ size_t displayHeight = videoFrame->mDisplayHeight;
+ if (swapWidthAndHeight) {
+ displayWidth = videoFrame->mDisplayHeight;
+ displayHeight = videoFrame->mDisplayWidth;
+ }
+ LOGV("Bitmap dimension is scaled from %dx%d to %dx%d",
+ width, height, displayWidth, displayHeight);
+ jobject scaledBitmap = env->CallStaticObjectMethod(fields.bitmapClazz,
+ fields.createScaledBitmapMethod,
+ jBitmap,
+ displayWidth,
+ displayHeight,
+ true);
+ return scaledBitmap;
+ }
+
return jBitmap;
}
@@ -352,6 +374,15 @@ static void android_media_MediaMetadataRetriever_native_init(JNIEnv *env)
"Can't find Bitmap.createBitmap(int, int, Config) method");
return;
}
+ fields.createScaledBitmapMethod =
+ env->GetStaticMethodID(fields.bitmapClazz, "createScaledBitmap",
+ "(Landroid/graphics/Bitmap;IIZ)"
+ "Landroid/graphics/Bitmap;");
+ if (fields.createScaledBitmapMethod == NULL) {
+ jniThrowException(env, "java/lang/RuntimeException",
+ "Can't find Bitmap.createScaledBitmap(Bitmap, int, int, boolean) method");
+ return;
+ }
fields.nativeBitmap = env->GetFieldID(fields.bitmapClazz, "mNativeBitmap", "I");
if (fields.nativeBitmap == NULL) {
jniThrowException(env, "java/lang/RuntimeException",