Implemented a progress monitor - I'll implement support for this in ShowImage next.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20644 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
af56b5b233
commit
646dadb991
@ -93,6 +93,20 @@ y_flipped(int32 orientation)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
void
|
||||||
|
dump_to_disk(void* data, size_t length)
|
||||||
|
{
|
||||||
|
FILE* file = fopen("/tmp/RAW.out", "wb");
|
||||||
|
if (file == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
fwrite(data, length, 1, file);
|
||||||
|
fclose(file);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
@ -105,7 +119,7 @@ DCRaw::DCRaw(BPositionIO& stream)
|
|||||||
fDNGVersion(0),
|
fDNGVersion(0),
|
||||||
fIsTIFF(false),
|
fIsTIFF(false),
|
||||||
fThreshold(0),
|
fThreshold(0),
|
||||||
fHalfSize(true),
|
fHalfSize(false),
|
||||||
fUseCameraWhiteBalance(true),
|
fUseCameraWhiteBalance(true),
|
||||||
fUseAutoWhiteBalance(true),
|
fUseAutoWhiteBalance(true),
|
||||||
fRawColor(true),
|
fRawColor(true),
|
||||||
@ -126,7 +140,8 @@ DCRaw::DCRaw(BPositionIO& stream)
|
|||||||
fDecodeLeaf(0),
|
fDecodeLeaf(0),
|
||||||
fDecodeBitsZeroAfterMax(false),
|
fDecodeBitsZeroAfterMax(false),
|
||||||
fFilters(~0),
|
fFilters(~0),
|
||||||
fEXIFOffset(-1)
|
fEXIFOffset(-1),
|
||||||
|
fProgressMonitor(NULL)
|
||||||
{
|
{
|
||||||
fImages = new image_data_info[kImageBufferCount];
|
fImages = new image_data_info[kImageBufferCount];
|
||||||
fDecodeBuffer = new decode[kDecodeBufferCount];
|
fDecodeBuffer = new decode[kDecodeBufferCount];
|
||||||
@ -888,6 +903,9 @@ DCRaw::_FixupValues()
|
|||||||
void
|
void
|
||||||
DCRaw::_ScaleColors()
|
DCRaw::_ScaleColors()
|
||||||
{
|
{
|
||||||
|
if (fProgressMonitor != NULL)
|
||||||
|
fProgressMonitor("Scale Colors", 5, fProgressData);
|
||||||
|
|
||||||
int dblack, c, val, sum[8];
|
int dblack, c, val, sum[8];
|
||||||
uint32 row, col, x, y;
|
uint32 row, col, x, y;
|
||||||
double dsum[8], dmin, dmax;
|
double dsum[8], dmin, dmax;
|
||||||
@ -1008,6 +1026,9 @@ DCRaw::_WaveletDenoise()
|
|||||||
void
|
void
|
||||||
DCRaw::_PreInterpolate()
|
DCRaw::_PreInterpolate()
|
||||||
{
|
{
|
||||||
|
if (fProgressMonitor != NULL)
|
||||||
|
fProgressMonitor("Pre-Interpolate", 10, fProgressData);
|
||||||
|
|
||||||
uint32 row, col;
|
uint32 row, col;
|
||||||
|
|
||||||
if (fShrink) {
|
if (fShrink) {
|
||||||
@ -1488,6 +1509,9 @@ DCRaw::_BorderInterpolate(uint32 border)
|
|||||||
void
|
void
|
||||||
DCRaw::_AHDInterpolate()
|
DCRaw::_AHDInterpolate()
|
||||||
{
|
{
|
||||||
|
if (fProgressMonitor != NULL)
|
||||||
|
fProgressMonitor("Interpolate", 30, fProgressData);
|
||||||
|
|
||||||
#define TS 256 /* Tile Size */
|
#define TS 256 /* Tile Size */
|
||||||
|
|
||||||
int i, j, tr, tc, fc, c, d, val, hm[2];
|
int i, j, tr, tc, fc, c, d, val, hm[2];
|
||||||
@ -1508,8 +1532,15 @@ DCRaw::_AHDInterpolate()
|
|||||||
rgb = (ushort(*)[TS][TS][3])buffer;
|
rgb = (ushort(*)[TS][TS][3])buffer;
|
||||||
lab = (short (*)[TS][TS][3])(buffer + 12*TS*TS);
|
lab = (short (*)[TS][TS][3])(buffer + 12*TS*TS);
|
||||||
homo = (char (*)[TS][TS])(buffer + 24*TS*TS);
|
homo = (char (*)[TS][TS])(buffer + 24*TS*TS);
|
||||||
|
float percentage = 30;
|
||||||
|
float percentageStep = 55.0f / (fInputHeight / (TS - 6));
|
||||||
|
|
||||||
for (top = 0; top < fInputHeight; top += TS - 6) {
|
for (top = 0; top < fInputHeight; top += TS - 6) {
|
||||||
|
if (fProgressMonitor) {
|
||||||
|
fProgressMonitor("Interpolate", percentage, fProgressData);
|
||||||
|
percentage += percentageStep;
|
||||||
|
}
|
||||||
|
|
||||||
for (left = 0; left < fInputWidth; left += TS - 6) {
|
for (left = 0; left < fInputWidth; left += TS - 6) {
|
||||||
memset(rgb, 0, 12 * TS * TS);
|
memset(rgb, 0, 12 * TS * TS);
|
||||||
|
|
||||||
@ -1677,6 +1708,9 @@ DCRaw::_PseudoInverse(double (*in)[3], double (*out)[3], uint32 size)
|
|||||||
void
|
void
|
||||||
DCRaw::_ConvertToRGB()
|
DCRaw::_ConvertToRGB()
|
||||||
{
|
{
|
||||||
|
if (fProgressMonitor != NULL)
|
||||||
|
fProgressMonitor("Convert to RGB", 85, fProgressData);
|
||||||
|
|
||||||
uint32 row, col, c, i, j, k;
|
uint32 row, col, c, i, j, k;
|
||||||
float out[3], out_cam[3][4];
|
float out[3], out_cam[3][4];
|
||||||
double num, inverse[3][3];
|
double num, inverse[3][3];
|
||||||
@ -2190,16 +2224,6 @@ DCRaw::_CanonHasLowBits()
|
|||||||
return hasLowBits;
|
return hasLowBits;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
dump_to_disk(void* data, size_t length)
|
|
||||||
{
|
|
||||||
FILE* file = fopen("/tmp/RAW.out", "wb");
|
|
||||||
if (file == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
fwrite(data, length, 1, file);
|
|
||||||
fclose(file);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
DCRaw::_LoadRAWCanonCompressed(const image_data_info& image)
|
DCRaw::_LoadRAWCanonCompressed(const image_data_info& image)
|
||||||
@ -2354,7 +2378,7 @@ DCRaw::_LoadRAWLosslessJPEG(const image_data_info& image)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dump_to_disk(fImageData, fInputWidth * fColors * 100);
|
//dump_to_disk(fImageData, fInputWidth * fColors * 100);
|
||||||
free(jh.row);
|
free(jh.row);
|
||||||
|
|
||||||
if (rawWidth > fInputWidth)
|
if (rawWidth > fInputWidth)
|
||||||
@ -2393,6 +2417,9 @@ DCRaw::_LoadRAW(const image_data_info& image)
|
|||||||
void
|
void
|
||||||
DCRaw::_WriteRGB32(image_data_info& image, uint8* outputBuffer)
|
DCRaw::_WriteRGB32(image_data_info& image, uint8* outputBuffer)
|
||||||
{
|
{
|
||||||
|
if (fProgressMonitor != NULL)
|
||||||
|
fProgressMonitor("Write RGB", 95, fProgressData);
|
||||||
|
|
||||||
uint8* line, lookUpTable[0x10000];
|
uint8* line, lookUpTable[0x10000];
|
||||||
|
|
||||||
uint32 width = image.flip > 4 ? fOutputHeight : fOutputWidth;
|
uint32 width = image.flip > 4 ? fOutputHeight : fOutputWidth;
|
||||||
@ -3393,3 +3420,17 @@ DCRaw::GetEXIFTag(off_t& offset, size_t& length, bool& bigEndian) const
|
|||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
DCRaw::SetProgressMonitor(monitor_hook hook, void* data)
|
||||||
|
{
|
||||||
|
fProgressMonitor = hook;
|
||||||
|
fProgressData = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
DCRaw::SetHalfSize(bool half)
|
||||||
|
{
|
||||||
|
fHalfSize = half;
|
||||||
|
}
|
||||||
|
@ -50,6 +50,8 @@ struct image_data_info {
|
|||||||
bool is_raw;
|
bool is_raw;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef void (*monitor_hook)(const char* message, float percentage, void* data);
|
||||||
|
|
||||||
class DCRaw {
|
class DCRaw {
|
||||||
public:
|
public:
|
||||||
DCRaw(BPositionIO& stream);
|
DCRaw(BPositionIO& stream);
|
||||||
@ -65,6 +67,9 @@ class DCRaw {
|
|||||||
|
|
||||||
status_t GetEXIFTag(off_t& offset, size_t& length,
|
status_t GetEXIFTag(off_t& offset, size_t& length,
|
||||||
bool& bigEndian) const;
|
bool& bigEndian) const;
|
||||||
|
void SetProgressMonitor(monitor_hook hook, void* data);
|
||||||
|
|
||||||
|
void SetHalfSize(bool half);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int32 _AllocateImage();
|
int32 _AllocateImage();
|
||||||
@ -185,6 +190,9 @@ class DCRaw {
|
|||||||
uint32 fEXIFLength;
|
uint32 fEXIFLength;
|
||||||
|
|
||||||
off_t fCurveOffset;
|
off_t fCurveOffset;
|
||||||
|
|
||||||
|
monitor_hook fProgressMonitor;
|
||||||
|
void* fProgressData;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // RAW_H
|
#endif // RAW_H
|
||||||
|
@ -16,8 +16,10 @@
|
|||||||
|
|
||||||
|
|
||||||
// Extensions that ShowImage supports
|
// Extensions that ShowImage supports
|
||||||
const char *kDocumentCount = "/documentCount";
|
const char* kDocumentCount = "/documentCount";
|
||||||
const char *kDocumentIndex = "/documentIndex";
|
const char* kDocumentIndex = "/documentIndex";
|
||||||
|
const char* kProgressMonitor = "/progressMonitor";
|
||||||
|
|
||||||
|
|
||||||
// The input formats that this translator supports.
|
// The input formats that this translator supports.
|
||||||
translation_format sInputFormats[] = {
|
translation_format sInputFormats[] = {
|
||||||
@ -62,6 +64,10 @@ const uint32 kNumOutputFormats = sizeof(sOutputFormats) / sizeof(translation_for
|
|||||||
const uint32 kNumDefaultSettings = sizeof(sDefaultSettings) / sizeof(TranSetting);
|
const uint32 kNumDefaultSettings = sizeof(sDefaultSettings) / sizeof(TranSetting);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
RAWTranslator::RAWTranslator()
|
RAWTranslator::RAWTranslator()
|
||||||
: BaseTranslator("RAW Images", "RAW Image Translator",
|
: BaseTranslator("RAW Images", "RAW Image Translator",
|
||||||
RAW_TRANSLATOR_VERSION,
|
RAW_TRANSLATOR_VERSION,
|
||||||
@ -133,6 +139,37 @@ RAWTranslator::DerivedIdentify(BPositionIO *stream,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bigtime_t gStart;
|
||||||
|
|
||||||
|
|
||||||
|
/*static*/ void
|
||||||
|
RAWTranslator::_ProgressMonitor(const char* message, float percentage,
|
||||||
|
void* data)
|
||||||
|
{
|
||||||
|
BMessenger& messenger = *(BMessenger*)data;
|
||||||
|
|
||||||
|
BMessage update;
|
||||||
|
update.AddString("message", message);
|
||||||
|
update.AddFloat("percent", percentage);
|
||||||
|
update.AddInt64("time", system_time());
|
||||||
|
|
||||||
|
#if 1
|
||||||
|
static bigtime_t last;
|
||||||
|
static int32 lastHash;
|
||||||
|
int32 hash = *(int32*)message;
|
||||||
|
|
||||||
|
if (system_time() - last > 500000 || hash != lastHash) {
|
||||||
|
printf("%6.3fs: %3.1f%% %s\n",
|
||||||
|
(system_time() - gStart) / 1000000.0, percentage, message);
|
||||||
|
last = system_time();
|
||||||
|
lastHash = hash;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
messenger.SendMessage(&update);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
RAWTranslator::DerivedTranslate(BPositionIO* source,
|
RAWTranslator::DerivedTranslate(BPositionIO* source,
|
||||||
const translator_info* info, BMessage* settings,
|
const translator_info* info, BMessage* settings,
|
||||||
@ -143,17 +180,27 @@ RAWTranslator::DerivedTranslate(BPositionIO* source,
|
|||||||
if (outType != B_TRANSLATOR_BITMAP || baseType != 0)
|
if (outType != B_TRANSLATOR_BITMAP || baseType != 0)
|
||||||
return B_NO_TRANSLATOR;
|
return B_NO_TRANSLATOR;
|
||||||
|
|
||||||
|
DCRaw raw(*source);
|
||||||
|
|
||||||
bool headerOnly = false;
|
bool headerOnly = false;
|
||||||
if (settings != NULL)
|
BMessenger monitor;
|
||||||
|
|
||||||
|
if (settings != NULL) {
|
||||||
settings->FindBool(B_TRANSLATOR_EXT_HEADER_ONLY, &headerOnly);
|
settings->FindBool(B_TRANSLATOR_EXT_HEADER_ONLY, &headerOnly);
|
||||||
|
|
||||||
DCRaw raw(*source);
|
if (settings->FindMessenger(kProgressMonitor, &monitor) == B_OK) {
|
||||||
|
raw.SetProgressMonitor(&_ProgressMonitor, &monitor);
|
||||||
|
_ProgressMonitor("Reading Image Data", 0, &monitor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int32 imageIndex = 0;
|
int32 imageIndex = 0;
|
||||||
uint8* buffer = NULL;
|
uint8* buffer = NULL;
|
||||||
size_t bufferSize;
|
size_t bufferSize;
|
||||||
status_t status;
|
status_t status;
|
||||||
|
|
||||||
|
gStart = system_time();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
status = raw.Identify();
|
status = raw.Identify();
|
||||||
|
|
||||||
@ -176,6 +223,8 @@ RAWTranslator::DerivedTranslate(BPositionIO* source,
|
|||||||
if (status < B_OK)
|
if (status < B_OK)
|
||||||
return B_NO_TRANSLATOR;
|
return B_NO_TRANSLATOR;
|
||||||
|
|
||||||
|
printf("TOTAL: %6.3fs\n", (system_time() - gStart) / 1000000.0);
|
||||||
|
|
||||||
image_meta_info meta;
|
image_meta_info meta;
|
||||||
raw.GetMetaInfo(meta);
|
raw.GetMetaInfo(meta);
|
||||||
|
|
||||||
|
@ -18,11 +18,11 @@
|
|||||||
#include <ByteOrder.h>
|
#include <ByteOrder.h>
|
||||||
|
|
||||||
|
|
||||||
#define RAW_TRANSLATOR_VERSION B_TRANSLATION_MAKE_VERSION(0, 1, 0)
|
#define RAW_TRANSLATOR_VERSION B_TRANSLATION_MAKE_VERSION(0, 5, 0)
|
||||||
#define RAW_IMAGE_FORMAT 'RAWI'
|
#define RAW_IMAGE_FORMAT 'RAWI'
|
||||||
|
|
||||||
#define RAW_IN_QUALITY 0.95
|
#define RAW_IN_QUALITY 0.90
|
||||||
#define RAW_IN_CAPABILITY 0.95
|
#define RAW_IN_CAPABILITY 0.90
|
||||||
#define BITS_IN_QUALITY 1
|
#define BITS_IN_QUALITY 1
|
||||||
#define BITS_IN_CAPABILITY 1
|
#define BITS_IN_CAPABILITY 1
|
||||||
|
|
||||||
@ -45,7 +45,11 @@ class RAWTranslator : public BaseTranslator {
|
|||||||
const translator_info *inInfo, BMessage *ioExtension,
|
const translator_info *inInfo, BMessage *ioExtension,
|
||||||
uint32 outType, BPositionIO *outDestination, int32 baseType);
|
uint32 outType, BPositionIO *outDestination, int32 baseType);
|
||||||
|
|
||||||
virtual BView *NewConfigView(TranslatorSettings *settings);
|
virtual BView *NewConfigView(TranslatorSettings *settings);
|
||||||
|
|
||||||
|
private:
|
||||||
|
static void _ProgressMonitor(const char* message, float percentage,
|
||||||
|
void* data);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // RAW_TRANSLATOR_H
|
#endif // RAW_TRANSLATOR_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user