2011-05-05 12:50:04 -07:00
|
|
|
/*
|
|
|
|
* Copyright 2011, The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _ANDROID_MEDIA_UTILS_H_
|
|
|
|
#define _ANDROID_MEDIA_UTILS_H_
|
|
|
|
|
Enable reading a thumbnail from RAW image files in MtpDatabase
Also introduce new supported RAW image file formats, PEF and SRW.
RAW image file formats are not defined in PTP 1.2 specification except
for DNG. They are mostly built on top of TIFF or TIFF/EP. (Fuji's RAF
is the exception).
In this CL, image file formats are classified newly as below:
DNG: dng
TIFF: cr2, nrw, arw, rw2, orf, pef, srw
TIFF/EP: nef
Unknown Image Formats(FORMAT_DEFINED): wbmap, webp, raf
I referred to the following documents for defining MTP formats of RAW
images:
* http://www.rags-int-inc.com/PhotoTechStuff/RawStandards/RawSummary.html
* https://en.wikipedia.org/wiki/Raw_image_format
Bug: 26552863, Bug: 26626825
Change-Id: Ia218f6320c4c1ff051a23ca0060ceac46134b0d7
2016-01-19 10:48:30 +09:00
|
|
|
#include "src/piex_types.h"
|
|
|
|
#include "src/piex.h"
|
2011-05-05 12:50:04 -07:00
|
|
|
|
Enable reading a thumbnail from RAW image files in MtpDatabase
Also introduce new supported RAW image file formats, PEF and SRW.
RAW image file formats are not defined in PTP 1.2 specification except
for DNG. They are mostly built on top of TIFF or TIFF/EP. (Fuji's RAF
is the exception).
In this CL, image file formats are classified newly as below:
DNG: dng
TIFF: cr2, nrw, arw, rw2, orf, pef, srw
TIFF/EP: nef
Unknown Image Formats(FORMAT_DEFINED): wbmap, webp, raf
I referred to the following documents for defining MTP formats of RAW
images:
* http://www.rags-int-inc.com/PhotoTechStuff/RawStandards/RawSummary.html
* https://en.wikipedia.org/wiki/Raw_image_format
Bug: 26552863, Bug: 26626825
Change-Id: Ia218f6320c4c1ff051a23ca0060ceac46134b0d7
2016-01-19 10:48:30 +09:00
|
|
|
#include <android_runtime/AndroidRuntime.h>
|
2016-02-25 15:04:56 +09:00
|
|
|
#include <camera3.h>
|
|
|
|
#include <gui/CpuConsumer.h>
|
Enable reading a thumbnail from RAW image files in MtpDatabase
Also introduce new supported RAW image file formats, PEF and SRW.
RAW image file formats are not defined in PTP 1.2 specification except
for DNG. They are mostly built on top of TIFF or TIFF/EP. (Fuji's RAF
is the exception).
In this CL, image file formats are classified newly as below:
DNG: dng
TIFF: cr2, nrw, arw, rw2, orf, pef, srw
TIFF/EP: nef
Unknown Image Formats(FORMAT_DEFINED): wbmap, webp, raf
I referred to the following documents for defining MTP formats of RAW
images:
* http://www.rags-int-inc.com/PhotoTechStuff/RawStandards/RawSummary.html
* https://en.wikipedia.org/wiki/Raw_image_format
Bug: 26552863, Bug: 26626825
Change-Id: Ia218f6320c4c1ff051a23ca0060ceac46134b0d7
2016-01-19 10:48:30 +09:00
|
|
|
#include <jni.h>
|
|
|
|
#include <JNIHelp.h>
|
2011-05-05 12:50:04 -07:00
|
|
|
#include <utils/KeyedVector.h>
|
|
|
|
#include <utils/String8.h>
|
2016-02-25 15:04:56 +09:00
|
|
|
#include <SkStream.h>
|
2011-05-05 12:50:04 -07:00
|
|
|
|
|
|
|
namespace android {
|
|
|
|
|
2016-02-25 15:04:56 +09:00
|
|
|
class AssetStream : public piex::StreamInterface {
|
|
|
|
private:
|
|
|
|
SkStream *mStream;
|
|
|
|
size_t mPosition;
|
|
|
|
|
|
|
|
public:
|
2016-08-29 14:49:57 -07:00
|
|
|
explicit AssetStream(SkStream* stream);
|
2016-02-25 15:04:56 +09:00
|
|
|
~AssetStream();
|
|
|
|
|
|
|
|
// Reads 'length' amount of bytes from 'offset' to 'data'. The 'data' buffer
|
|
|
|
// provided by the caller, guaranteed to be at least "length" bytes long.
|
|
|
|
// On 'kOk' the 'data' pointer contains 'length' valid bytes beginning at
|
|
|
|
// 'offset' bytes from the start of the stream.
|
|
|
|
// Returns 'kFail' if 'offset' + 'length' exceeds the stream and does not
|
|
|
|
// change the contents of 'data'.
|
|
|
|
piex::Error GetData(
|
|
|
|
const size_t offset, const size_t length, std::uint8_t* data) override;
|
|
|
|
};
|
|
|
|
|
|
|
|
class BufferedStream : public piex::StreamInterface {
|
|
|
|
private:
|
|
|
|
SkStream *mStream;
|
|
|
|
// Growable memory stream
|
|
|
|
SkDynamicMemoryWStream mStreamBuffer;
|
|
|
|
|
|
|
|
// Minimum size to read on filling the buffer.
|
|
|
|
const size_t kMinSizeToRead = 8192;
|
|
|
|
|
|
|
|
public:
|
2016-08-29 14:49:57 -07:00
|
|
|
explicit BufferedStream(SkStream* stream);
|
2016-02-25 15:04:56 +09:00
|
|
|
~BufferedStream();
|
|
|
|
|
|
|
|
// Reads 'length' amount of bytes from 'offset' to 'data'. The 'data' buffer
|
|
|
|
// provided by the caller, guaranteed to be at least "length" bytes long.
|
|
|
|
// On 'kOk' the 'data' pointer contains 'length' valid bytes beginning at
|
|
|
|
// 'offset' bytes from the start of the stream.
|
|
|
|
// Returns 'kFail' if 'offset' + 'length' exceeds the stream and does not
|
|
|
|
// change the contents of 'data'.
|
|
|
|
piex::Error GetData(
|
|
|
|
const size_t offset, const size_t length, std::uint8_t* data) override;
|
|
|
|
};
|
|
|
|
|
Enable reading a thumbnail from RAW image files in MtpDatabase
Also introduce new supported RAW image file formats, PEF and SRW.
RAW image file formats are not defined in PTP 1.2 specification except
for DNG. They are mostly built on top of TIFF or TIFF/EP. (Fuji's RAF
is the exception).
In this CL, image file formats are classified newly as below:
DNG: dng
TIFF: cr2, nrw, arw, rw2, orf, pef, srw
TIFF/EP: nef
Unknown Image Formats(FORMAT_DEFINED): wbmap, webp, raf
I referred to the following documents for defining MTP formats of RAW
images:
* http://www.rags-int-inc.com/PhotoTechStuff/RawStandards/RawSummary.html
* https://en.wikipedia.org/wiki/Raw_image_format
Bug: 26552863, Bug: 26626825
Change-Id: Ia218f6320c4c1ff051a23ca0060ceac46134b0d7
2016-01-19 10:48:30 +09:00
|
|
|
class FileStream : public piex::StreamInterface {
|
|
|
|
private:
|
|
|
|
FILE *mFile;
|
|
|
|
size_t mPosition;
|
|
|
|
|
|
|
|
public:
|
2016-08-29 14:49:57 -07:00
|
|
|
explicit FileStream(const int fd);
|
|
|
|
explicit FileStream(const String8 filename);
|
Enable reading a thumbnail from RAW image files in MtpDatabase
Also introduce new supported RAW image file formats, PEF and SRW.
RAW image file formats are not defined in PTP 1.2 specification except
for DNG. They are mostly built on top of TIFF or TIFF/EP. (Fuji's RAF
is the exception).
In this CL, image file formats are classified newly as below:
DNG: dng
TIFF: cr2, nrw, arw, rw2, orf, pef, srw
TIFF/EP: nef
Unknown Image Formats(FORMAT_DEFINED): wbmap, webp, raf
I referred to the following documents for defining MTP formats of RAW
images:
* http://www.rags-int-inc.com/PhotoTechStuff/RawStandards/RawSummary.html
* https://en.wikipedia.org/wiki/Raw_image_format
Bug: 26552863, Bug: 26626825
Change-Id: Ia218f6320c4c1ff051a23ca0060ceac46134b0d7
2016-01-19 10:48:30 +09:00
|
|
|
~FileStream();
|
|
|
|
|
|
|
|
// Reads 'length' amount of bytes from 'offset' to 'data'. The 'data' buffer
|
|
|
|
// provided by the caller, guaranteed to be at least "length" bytes long.
|
|
|
|
// On 'kOk' the 'data' pointer contains 'length' valid bytes beginning at
|
|
|
|
// 'offset' bytes from the start of the stream.
|
|
|
|
// Returns 'kFail' if 'offset' + 'length' exceeds the stream and does not
|
|
|
|
// change the contents of 'data'.
|
|
|
|
piex::Error GetData(
|
|
|
|
const size_t offset, const size_t length, std::uint8_t* data) override;
|
|
|
|
bool exists() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Reads EXIF metadata from a given raw image via piex.
|
|
|
|
// And returns true if the operation is successful; otherwise, false.
|
|
|
|
bool GetExifFromRawImage(
|
2016-02-25 15:04:56 +09:00
|
|
|
piex::StreamInterface* stream, const String8& filename, piex::PreviewImageData& image_data);
|
Enable reading a thumbnail from RAW image files in MtpDatabase
Also introduce new supported RAW image file formats, PEF and SRW.
RAW image file formats are not defined in PTP 1.2 specification except
for DNG. They are mostly built on top of TIFF or TIFF/EP. (Fuji's RAF
is the exception).
In this CL, image file formats are classified newly as below:
DNG: dng
TIFF: cr2, nrw, arw, rw2, orf, pef, srw
TIFF/EP: nef
Unknown Image Formats(FORMAT_DEFINED): wbmap, webp, raf
I referred to the following documents for defining MTP formats of RAW
images:
* http://www.rags-int-inc.com/PhotoTechStuff/RawStandards/RawSummary.html
* https://en.wikipedia.org/wiki/Raw_image_format
Bug: 26552863, Bug: 26626825
Change-Id: Ia218f6320c4c1ff051a23ca0060ceac46134b0d7
2016-01-19 10:48:30 +09:00
|
|
|
|
|
|
|
// Returns true if the conversion is successful; otherwise, false.
|
2011-05-05 12:50:04 -07:00
|
|
|
bool ConvertKeyValueArraysToKeyedVector(
|
Enable reading a thumbnail from RAW image files in MtpDatabase
Also introduce new supported RAW image file formats, PEF and SRW.
RAW image file formats are not defined in PTP 1.2 specification except
for DNG. They are mostly built on top of TIFF or TIFF/EP. (Fuji's RAF
is the exception).
In this CL, image file formats are classified newly as below:
DNG: dng
TIFF: cr2, nrw, arw, rw2, orf, pef, srw
TIFF/EP: nef
Unknown Image Formats(FORMAT_DEFINED): wbmap, webp, raf
I referred to the following documents for defining MTP formats of RAW
images:
* http://www.rags-int-inc.com/PhotoTechStuff/RawStandards/RawSummary.html
* https://en.wikipedia.org/wiki/Raw_image_format
Bug: 26552863, Bug: 26626825
Change-Id: Ia218f6320c4c1ff051a23ca0060ceac46134b0d7
2016-01-19 10:48:30 +09:00
|
|
|
JNIEnv *env, jobjectArray keys, jobjectArray values,
|
|
|
|
KeyedVector<String8, String8>* vector);
|
2011-05-05 12:50:04 -07:00
|
|
|
|
2012-02-21 11:47:18 -08:00
|
|
|
struct AMessage;
|
|
|
|
status_t ConvertMessageToMap(
|
|
|
|
JNIEnv *env, const sp<AMessage> &msg, jobject *map);
|
|
|
|
|
|
|
|
status_t ConvertKeyValueArraysToMessage(
|
|
|
|
JNIEnv *env, jobjectArray keys, jobjectArray values,
|
|
|
|
sp<AMessage> *msg);
|
|
|
|
|
2016-02-25 16:00:38 -08:00
|
|
|
// -----------Utility functions used by ImageReader/Writer JNI-----------------
|
|
|
|
|
|
|
|
typedef CpuConsumer::LockedBuffer LockedImage;
|
|
|
|
|
|
|
|
bool usingRGBAToJpegOverride(int32_t imageFormat, int32_t containerFormat);
|
|
|
|
|
|
|
|
int32_t applyFormatOverrides(int32_t imageFormat, int32_t containerFormat);
|
|
|
|
|
|
|
|
uint32_t Image_getJpegSize(LockedImage* buffer, bool usingRGBAOverride);
|
|
|
|
|
|
|
|
bool isFormatOpaque(int format);
|
|
|
|
|
|
|
|
bool isPossiblyYUV(PixelFormat format);
|
|
|
|
|
|
|
|
status_t getLockedImageInfo(LockedImage* buffer, int idx, int32_t containerFormat,
|
|
|
|
uint8_t **base, uint32_t *size, int *pixelStride, int *rowStride);
|
|
|
|
|
|
|
|
status_t lockImageFromBuffer(sp<GraphicBuffer> buffer, uint32_t inUsage,
|
|
|
|
const Rect& rect, int fenceFd, LockedImage* outputImage);
|
|
|
|
|
|
|
|
status_t lockImageFromBuffer(BufferItem* bufferItem, uint32_t inUsage,
|
|
|
|
int fenceFd, LockedImage* outputImage);
|
|
|
|
|
|
|
|
int getBufferWidth(BufferItem *buffer);
|
|
|
|
|
|
|
|
int getBufferHeight(BufferItem *buffer);
|
|
|
|
|
2011-05-05 12:50:04 -07:00
|
|
|
}; // namespace android
|
|
|
|
|
|
|
|
#endif // _ANDROID_MEDIA_UTILS_H_
|