14b6f4942fcef3300b407d9a07a680c07b162333fWei-Ta Chen/* 24b6f4942fcef3300b407d9a07a680c07b162333fWei-Ta Chen * Copyright (C) 2009 The Android Open Source Project 34b6f4942fcef3300b407d9a07a680c07b162333fWei-Ta Chen * 44b6f4942fcef3300b407d9a07a680c07b162333fWei-Ta Chen * Licensed under the Apache License, Version 2.0 (the "License"); 54b6f4942fcef3300b407d9a07a680c07b162333fWei-Ta Chen * you may not use this file except in compliance with the License. 64b6f4942fcef3300b407d9a07a680c07b162333fWei-Ta Chen * You may obtain a copy of the License at 74b6f4942fcef3300b407d9a07a680c07b162333fWei-Ta Chen * 84b6f4942fcef3300b407d9a07a680c07b162333fWei-Ta Chen * http://www.apache.org/licenses/LICENSE-2.0 94b6f4942fcef3300b407d9a07a680c07b162333fWei-Ta Chen * 104b6f4942fcef3300b407d9a07a680c07b162333fWei-Ta Chen * Unless required by applicable law or agreed to in writing, software 114b6f4942fcef3300b407d9a07a680c07b162333fWei-Ta Chen * distributed under the License is distributed on an "AS IS" BASIS, 124b6f4942fcef3300b407d9a07a680c07b162333fWei-Ta Chen * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 134b6f4942fcef3300b407d9a07a680c07b162333fWei-Ta Chen * See the License for the specific language governing permissions and 144b6f4942fcef3300b407d9a07a680c07b162333fWei-Ta Chen * limitations under the License. 154b6f4942fcef3300b407d9a07a680c07b162333fWei-Ta Chen */ 164b6f4942fcef3300b407d9a07a680c07b162333fWei-Ta Chen 174b6f4942fcef3300b407d9a07a680c07b162333fWei-Ta Chen#ifndef OMXJPEGIMAGEDECODER 184b6f4942fcef3300b407d9a07a680c07b162333fWei-Ta Chen#define OMXJPEGIMAGEDECODER 194b6f4942fcef3300b407d9a07a680c07b162333fWei-Ta Chen 204b6f4942fcef3300b407d9a07a680c07b162333fWei-Ta Chen#include <stdlib.h> 214b6f4942fcef3300b407d9a07a680c07b162333fWei-Ta Chen#include <string.h> 224b6f4942fcef3300b407d9a07a680c07b162333fWei-Ta Chen#include <unistd.h> 234b6f4942fcef3300b407d9a07a680c07b162333fWei-Ta Chen 244b6f4942fcef3300b407d9a07a680c07b162333fWei-Ta Chen#include <media/stagefright/JPEGSource.h> 254b6f4942fcef3300b407d9a07a680c07b162333fWei-Ta Chen#include <media/stagefright/MediaSource.h> 264b6f4942fcef3300b407d9a07a680c07b162333fWei-Ta Chen#include <media/stagefright/OMXClient.h> 274b6f4942fcef3300b407d9a07a680c07b162333fWei-Ta Chen#include <media/stagefright/OMXCodec.h> 284b6f4942fcef3300b407d9a07a680c07b162333fWei-Ta Chen#include <SkImageDecoder.h> 294b6f4942fcef3300b407d9a07a680c07b162333fWei-Ta Chen#include <SkStream.h> 304b6f4942fcef3300b407d9a07a680c07b162333fWei-Ta Chen 314b6f4942fcef3300b407d9a07a680c07b162333fWei-Ta Chenusing namespace android; 324b6f4942fcef3300b407d9a07a680c07b162333fWei-Ta Chen 33987dbde838014e5f0c55a63acdd2a9a002b140ccAndreas Huberextern int storeBitmapToFile(SkBitmap* bitmap, const char* filename); 344b6f4942fcef3300b407d9a07a680c07b162333fWei-Ta Chen 354b6f4942fcef3300b407d9a07a680c07b162333fWei-Ta Chenclass OmxJpegImageDecoder : public SkImageDecoder { 364b6f4942fcef3300b407d9a07a680c07b162333fWei-Ta Chenpublic: 374b6f4942fcef3300b407d9a07a680c07b162333fWei-Ta Chen OmxJpegImageDecoder(); 384b6f4942fcef3300b407d9a07a680c07b162333fWei-Ta Chen ~OmxJpegImageDecoder(); 394b6f4942fcef3300b407d9a07a680c07b162333fWei-Ta Chen 404b6f4942fcef3300b407d9a07a680c07b162333fWei-Ta Chen virtual Format getFormat() const { 414b6f4942fcef3300b407d9a07a680c07b162333fWei-Ta Chen return kJPEG_Format; 424b6f4942fcef3300b407d9a07a680c07b162333fWei-Ta Chen } 434b6f4942fcef3300b407d9a07a680c07b162333fWei-Ta Chen 444b6f4942fcef3300b407d9a07a680c07b162333fWei-Ta Chenprotected: 45945a9df6e31cf951d6f323a85a7e75c19c7f60f6Mike Reed virtual bool onDecode(SkStream* stream, SkBitmap* bm, Mode mode); 464b6f4942fcef3300b407d9a07a680c07b162333fWei-Ta Chen 474b6f4942fcef3300b407d9a07a680c07b162333fWei-Ta Chenprivate: 484b6f4942fcef3300b407d9a07a680c07b162333fWei-Ta Chen JPEGSource* prepareMediaSource(SkStream* stream); 49987dbde838014e5f0c55a63acdd2a9a002b140ccAndreas Huber sp<MediaSource> getDecoder(OMXClient* client, const sp<MediaSource>& source); 50987dbde838014e5f0c55a63acdd2a9a002b140ccAndreas Huber bool decodeSource(sp<MediaSource> decoder, const sp<MediaSource>& source, 514b6f4942fcef3300b407d9a07a680c07b162333fWei-Ta Chen SkBitmap* bm); 52987dbde838014e5f0c55a63acdd2a9a002b140ccAndreas Huber void installPixelRef(MediaBuffer* buffer, sp<MediaSource> decoder, 534b6f4942fcef3300b407d9a07a680c07b162333fWei-Ta Chen SkBitmap* bm); 544b6f4942fcef3300b407d9a07a680c07b162333fWei-Ta Chen void configBitmapSize(SkBitmap* bm, SkBitmap::Config pref, int width, 554b6f4942fcef3300b407d9a07a680c07b162333fWei-Ta Chen int height); 564b6f4942fcef3300b407d9a07a680c07b162333fWei-Ta Chen SkBitmap::Config getColorSpaceConfig(SkBitmap::Config pref); 574b6f4942fcef3300b407d9a07a680c07b162333fWei-Ta Chen 584b6f4942fcef3300b407d9a07a680c07b162333fWei-Ta Chen OMXClient mClient; 594b6f4942fcef3300b407d9a07a680c07b162333fWei-Ta Chen}; 604b6f4942fcef3300b407d9a07a680c07b162333fWei-Ta Chen 614b6f4942fcef3300b407d9a07a680c07b162333fWei-Ta Chen#endif 62