|
发表于 2015-4-29 16:23:31
只看该作者
板凳
- #define LOG_TAG "OmxJpegDecoder"
- #include <sys/time.h>
- #include <utils/Log.h>
- #include <binder/ProcessState.h>
- #include "SkBitmap.h"
- #include "SkImageDecoder.h"
- #include "SkStream.h"
- #include "omx_jpeg_decoder.h"
- class SkJPEGImageDecoder : public SkImageDecoder {
- public:
- virtual Format getFormat() const {
- return kJPEG_Format;
- }
- protected:
- virtual bool onDecode(SkStream* stream, SkBitmap* bm, Mode);
- };
- int nullObjectReturn(const char msg[]) {
- if (msg) {
- SkDebugf("--- %s\n", msg);
- }
- return -1;
- }
- static int64_t getNowUs() {
- struct timeval tv;
- gettimeofday(&tv, NULL);
- return tv.tv_usec + (int64_t) tv.tv_sec * 1000000;
- }
- int testDecodePixels(SkImageDecoder* decoder, SkStream* stream,
- SkBitmap* bitmap) {
- int64_t startTime = getNowUs();
- SkBitmap::Config prefConfig = SkBitmap::kARGB_8888_Config;
- SkImageDecoder::Mode decodeMode = SkImageDecoder::kDecodePixels_Mode;
- // Decode the input stream and then use the bitmap.
- if (!decoder->decode(stream, bitmap, prefConfig, decodeMode)) {
- return nullObjectReturn("decoder->decode returned false");
- } else {
- int64_t delay = getNowUs() - startTime;
- printf("Decoding Time in PixelsMode %.1f msec.\n", delay / 1000.0f);
- const char* filename = "/sdcard/omxJpegDecodedBitmap.rgba";
- return storeBitmapToFile(bitmap, filename);
- }
- }
- int testDecoder(SkImageDecoder* decoder, char* filename) {
- // test DecodeMode == Pixels
- SkStream* stream = new SkFILEStream(filename);
- SkBitmap* bitmap = new SkBitmap;
- testDecodePixels(decoder, stream, bitmap);
- delete bitmap;
- delete decoder;
-
- return 0;
- }
- int main(int argc, char** argv) {
- android::ProcessState::self()->startThreadPool();
- printf("Decoding jpeg with libjpeg...\n");
- SkJPEGImageDecoder* libjpeg = new SkJPEGImageDecoder;
- testDecoder(libjpeg, argv[1]);
-
- return 0;
- }
复制代码 |
|