summaryrefslogtreecommitdiff
authorChaomin Zheng <chaomin.zheng@amlogic.com>2017-10-27 13:17:13 (GMT)
committer Tellen Yu <tellen.yu@amlogic.com>2017-10-30 02:27:33 (GMT)
commit22517dfe2841decac94db7b389117bbae79c886a (patch)
tree7781060645d64eb81a91aa9f3fbbdd65b252eefa
parentaa09ed54126ee248363d9837a9475986daa7bd56 (diff)
downloadframeworks-22517dfe2841decac94db7b389117bbae79c886a.zip
frameworks-22517dfe2841decac94db7b389117bbae79c886a.tar.gz
frameworks-22517dfe2841decac94db7b389117bbae79c886a.tar.bz2
ImageServer:after tiff decode,free the malloc memorry[1/1]
PD# 150929 imageserver release tiff decoder Change-Id: I4e9ee9335c6e8240b110ea74c5e3ebb7ffe7baa0
Diffstat
-rw-r--r--services/imageplayer/ImagePlayerService.cpp19
-rw-r--r--services/imageplayer/ImagePlayerService.h3
-rw-r--r--services/imageplayer/TIFF2RGBA.cpp58
-rw-r--r--services/imageplayer/TIFF2RGBA.h11
4 files changed, 62 insertions, 29 deletions
diff --git a/services/imageplayer/ImagePlayerService.cpp b/services/imageplayer/ImagePlayerService.cpp
index a97d7f7..22d93f6 100644
--- a/services/imageplayer/ImagePlayerService.cpp
+++ b/services/imageplayer/ImagePlayerService.cpp
@@ -18,7 +18,6 @@
#define LOG_TAG "ImagePlayerService"
#include "utils/Log.h"
-#include "TIFF2RGBA.h"
#include "ImagePlayerService.h"
#include <stdlib.h>
@@ -640,7 +639,7 @@ void ImagePlayerService::instantiate() {
ImagePlayerService::ImagePlayerService()
: mWidth(0), mHeight(0), mBitmap(NULL), mBufBitmap(NULL),
- mSampleSize(1), mFileDescription(-1), mFrameIndex(0),
+ mSampleSize(1), mFileDescription(-1), mFrameIndex(0), mTif(NULL),
surfaceWidth(SURFACE_4K_WIDTH), surfaceHeight(SURFACE_4K_HEIGHT),
mScalingDirect(SCALE_NORMAL), mScalingStep(1.0f), mScalingBitmap(NULL),
mRotateBitmap(NULL), mMovieImage(false), mMovieThread(NULL), mNeedResetHWScale(false),
@@ -1294,6 +1293,11 @@ int ImagePlayerService::release() {
mFrameIndex = 0;
}
+ if (NULL != mTif) {
+ delete mTif;
+ mTif = NULL;
+ }
+
resetRotateScale();
resetTranslate();
resetHWScale();
@@ -1366,14 +1370,21 @@ SkBitmap* ImagePlayerService::decodeTiff(const char *filePath) {
int width = 0;
int height = 0;
- TIFF2RGBA::tiffDecodeBound(filePath, &width, &height);
+ if (NULL != mTif) {
+ delete mTif;
+ mTif = NULL;
+ }
+ mTif = new TIFF2RGBA();
+ mTif->tiffDecodeBound(filePath, &width, &height);
if ((width > MAX_PIC_SIZE) || (height > MAX_PIC_SIZE)) {
ALOGE("decode tiff size is too large, we only support w < %d and h < %d, now image size w:%d, h:%d",
MAX_PIC_SIZE, MAX_PIC_SIZE, width, height);
+ delete mTif;
+ mTif = NULL;
}
else {
SkBitmap *bitmap = new SkBitmap();
- int ret = TIFF2RGBA::tiffDecoder(filePath, bitmap);
+ int ret = mTif->tiffDecoder(filePath, bitmap);
ALOGI("decode tiff result:%d, width:%d, height:%d", ret, bitmap->width(), bitmap->height());
mWidth = bitmap->width();
diff --git a/services/imageplayer/ImagePlayerService.h b/services/imageplayer/ImagePlayerService.h
index 4454adb..20952eb 100644
--- a/services/imageplayer/ImagePlayerService.h
+++ b/services/imageplayer/ImagePlayerService.h
@@ -26,6 +26,7 @@
#include <SkStream.h>
#include <IImagePlayerService.h>
#include "ISystemControlService.h"
+#include "TIFF2RGBA.h"
#include <binder/Binder.h>
#define MAX_FILE_PATH_LEN 1024
@@ -147,6 +148,8 @@ class ImagePlayerService : public BnImagePlayerService {
SkBitmap* fillSurface(SkBitmap *bitmap);
bool isSupportFromat(const char *uri, SkBitmap **bitmap);
+ TIFF2RGBA *mTif;
+
mutable Mutex mLock;
int mWidth, mHeight;
SkBitmap *mBitmap;
diff --git a/services/imageplayer/TIFF2RGBA.cpp b/services/imageplayer/TIFF2RGBA.cpp
index f6f3abb..0457a00 100644
--- a/services/imageplayer/TIFF2RGBA.cpp
+++ b/services/imageplayer/TIFF2RGBA.cpp
@@ -26,9 +26,6 @@
#include "TIFF2RGBA.h"
#include "ImagePlayerService.h"
-#include "tiffiop.h"
-#include "tiffio.h"
-
using namespace android;
namespace android {
@@ -447,8 +444,6 @@ int TIFF2RGBA::tiffDecodeBound(const char *filePath, int *width, int *height) {
*
*---------------------------------------------------------------*/
int TIFF2RGBA::tiffDecoder(const char *filePath, SkBitmap *pBitmap) {
- TIFF *in = NULL;
- uint32* raster = NULL; /* retrieve RGBA image */
uint32 width, height; /* image width & height */
int ret = 0;
size_t pixel_count;
@@ -460,15 +455,15 @@ int TIFF2RGBA::tiffDecoder(const char *filePath, SkBitmap *pBitmap) {
}
TIFFSetErrorHandler(TIFFErrorHandler);
- in = TIFFOpen(filePath, "r");
- if (NULL == in) {
+ mTif = TIFFOpen(filePath, "r");
+ if (NULL == mTif) {
ALOGE("tiff decoder, open file:%s error", filePath);
ret = -1;
goto exit;
}
- TIFFGetField(in, TIFFTAG_IMAGEWIDTH, &width);
- TIFFGetField(in, TIFFTAG_IMAGELENGTH, &height);
+ TIFFGetField(mTif, TIFFTAG_IMAGEWIDTH, &width);
+ TIFFGetField(mTif, TIFFTAG_IMAGELENGTH, &height);
if (width > MAX_PIC_SIZE || height > MAX_PIC_SIZE) {
ALOGE("tiff decoder size too large, not support");
@@ -479,25 +474,26 @@ int TIFF2RGBA::tiffDecoder(const char *filePath, SkBitmap *pBitmap) {
/* XXX: Check the integer overflow. */
if (!width || !height || pixel_count / width != height) {
- ALOGE(TIFFFileName(in),
+ ALOGE(TIFFFileName(mTif),
"Malformed input file; can't allocate buffer for raster of %lux%lu size",
(unsigned long)width, (unsigned long)height);
ret = -1;
goto exit;
}
- raster = (uint32*)_TIFFCheckMalloc(in, pixel_count, sizeof(uint32), "raster buffer");
- if (raster == NULL) {
- ALOGE(TIFFFileName(in), "Failed to allocate buffer (%lu elements of %lu each)",
+ mRaster = (int*)_TIFFCheckMalloc(mTif, pixel_count, sizeof(uint32), "raster buffer");
+ if (mRaster == NULL) {
+ ALOGE(TIFFFileName(mTif), "Failed to allocate buffer (%lu elements of %lu each)",
(unsigned long)pixel_count, (unsigned long)sizeof(uint32));
ret = -1;
goto exit;
}
/* Read the image in one chunk into an RGBA array */
- if (!TIFFReadRGBAImageOriented(in, width, height, raster,
+ if (!TIFFReadRGBAImageOriented(mTif, width, height, (uint32*)mRaster,
ORIENTATION_TOPLEFT, 0)) {
- _TIFFfree(raster);
+ _TIFFfree(mRaster);
+ mRaster = NULL;
ret = -1;
goto exit;
}
@@ -507,28 +503,46 @@ int TIFF2RGBA::tiffDecoder(const char *filePath, SkBitmap *pBitmap) {
* we should rearrange it here.
*/
#if HOST_BIGENDIAN
- TIFFSwabArrayOfLong(raster, width * height);
+ TIFFSwabArrayOfLong(mRaster, width * height);
#endif
pBitmap->setInfo(SkImageInfo::Make(width, height,
kN32_SkColorType, kPremul_SkAlphaType));
- pBitmap->setPixels((void*)raster);
- TIFFClose(in);
+ pBitmap->setPixels((void*)mRaster);
+ TIFFClose(mTif);
+ mTif = NULL;
return ret;
exit:
- if (NULL != in)
- TIFFClose(in);
+ if (NULL != mTif) {
+ TIFFClose(mTif);
+ }
- if (NULL != raster)
- _TIFFfree(raster);
+ if (NULL != mRaster) {
+ _TIFFfree(mRaster);
+ mRaster = NULL;
+ }
return ret;
}
+void TIFF2RGBA::close() {
+ if (NULL != mTif) {
+ TIFFClose(mTif);
+ mTif = NULL;
+ }
+
+ if (NULL != mRaster) {
+ _TIFFfree(mRaster);
+ mRaster = NULL;
+ }
+}
+
TIFF2RGBA::TIFF2RGBA() {
+ mTif = NULL;
}
TIFF2RGBA::~TIFF2RGBA() {
+ close();
}
}
diff --git a/services/imageplayer/TIFF2RGBA.h b/services/imageplayer/TIFF2RGBA.h
index f0c53bc..839ec88 100644
--- a/services/imageplayer/TIFF2RGBA.h
+++ b/services/imageplayer/TIFF2RGBA.h
@@ -19,6 +19,9 @@
#include <SkBitmap.h>
+#include "tiffiop.h"
+#include "tiffio.h"
+
#define MAX_PIC_SIZE 8000
namespace android {
@@ -28,9 +31,11 @@ class TIFF2RGBA {
TIFF2RGBA();
~TIFF2RGBA();
- static int tiffDecodeBound(const char *filePath, int *width, int *height);
- static int tiffDecoder(const char *filePath, SkBitmap *pBitmap);
-
+ int tiffDecodeBound(const char *filePath, int *width, int *height);
+ int tiffDecoder(const char *filePath, SkBitmap *pBitmap);
+ void close();
+ TIFF* mTif;
+ int* mRaster;
};
} // namespace android