Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speedup for cr2 decode #3345

Merged
merged 2 commits into from
Jun 17, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Speedup for cr2 decode
  • Loading branch information
heckflosse committed Jun 12, 2016
commit f794cf684b18a9c2ca9b4ac350a10fd1ed37fc90
55 changes: 38 additions & 17 deletions rtengine/dcraw.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
/*RT*/#define LOCALTIME
/*RT*/#define DJGPP

#include "StopWatch.h"
#include "opthelper.h"
/*
dcraw.c -- Dave Coffin's raw photo decoder
Copyright 1997-2016 by Dave Coffin, dcoffin a cybercom o net
Expand Down Expand Up @@ -551,13 +553,13 @@ int CLASS canon_s2is()
return 0;
}

unsigned CLASS getbithuff_t::operator() (int nbits, ushort *huff)
inline unsigned CLASS getbithuff_t::operator() (int nbits, ushort *huff)
{
/*RT static unsigned bitbuf=0; */
/*RT static int vbits=0, reset=0; */
unsigned c;

if (nbits > 25) return 0;
if (UNLIKELY(nbits > 25)) return 0;
if (nbits < 0)
return bitbuf = vbits = reset = 0;
if (nbits == 0 || vbits < 0) return 0;
Expand Down Expand Up @@ -828,7 +830,7 @@ int CLASS ljpeg_start (struct jhead *jh, int info_only)
FORC(4) jh->huff[2+c] = jh->huff[1];
FORC(jh->sraw) jh->huff[1+c] = jh->huff[0];
}
jh->row = (ushort *) calloc (jh->wide*jh->clrs, 4);
jh->row = (ushort *) calloc (2 * jh->wide*jh->clrs, 4);
merror (jh->row, "ljpeg_start()");
return zero_after_ff = 1;
}
Expand All @@ -840,7 +842,7 @@ void CLASS ljpeg_end (struct jhead *jh)
free (jh->row);
}

int CLASS ljpeg_diff (ushort *huff)
inline int CLASS ljpeg_diff (ushort *huff)
{
int len, diff;

Expand All @@ -867,16 +869,15 @@ ushort * CLASS ljpeg_row (int jrow, struct jhead *jh)
}
getbits(-1);
}
FORC3 row[c] = jh->row + jh->wide*jh->clrs*((jrow+c) & 1);
FORC3 row[c] = (jh->row + ((jrow & 1) + 1) * (jh->wide*jh->clrs*((jrow+c) & 1)));
for (col=0; col < jh->wide; col++)
FORC(jh->clrs) {
diff = ljpeg_diff (jh->huff[c]);
if (jh->sraw && c <= jh->sraw && (col | c))
pred = spred;
else if (col) pred = row[0][-jh->clrs];
else pred = (jh->vpred[c] += diff) - diff;
if (jrow && col) switch (jh->psv) {
case 1: break;
if (jh->psv != 1 && jrow && col) switch (jh->psv) {
case 2: pred = row[1][0]; break;
case 3: pred = row[1][-jh->clrs]; break;
case 4: pred = pred + row[1][0] - row[1][-jh->clrs]; break;
Expand All @@ -885,7 +886,7 @@ ushort * CLASS ljpeg_row (int jrow, struct jhead *jh)
case 7: pred = (pred + row[1][0]) >> 1; break;
default: pred = 0;
}
if ((**row = pred + diff) >> jh->bits) derror();
if (UNLIKELY((**row = pred + diff) >> jh->bits)) derror();
if (c <= jh->sraw) spred = **row;
row[0]++; row[1]++;
}
Expand All @@ -894,22 +895,40 @@ ushort * CLASS ljpeg_row (int jrow, struct jhead *jh)

void CLASS lossless_jpeg_load_raw()
{
int jwide, jrow, jcol, val, jidx, i, j, row=0, col=0;
StopWatch Stop1("decode");
struct jhead jh;
ushort *rp;

if (!ljpeg_start (&jh, 0)) return;
jwide = jh.wide * jh.clrs;
int jwide = jh.wide * jh.clrs;
ushort *rp[2];
rp[0] = ljpeg_row (0, &jh);

for (int jrow=0; jrow < jh.high; jrow++) {
#ifdef _OPENMP
#pragma omp parallel sections
#endif
{
#ifdef _OPENMP
#pragma omp section
#endif
{
if(jrow < jh.high - 1)
rp[(jrow + 1)&1] = ljpeg_row (jrow + 1, &jh);
}
#ifdef _OPENMP
#pragma omp section
#endif
{
int row=0, col=0;

for (jrow=0; jrow < jh.high; jrow++) {
rp = ljpeg_row (jrow, &jh);
if (load_flags & 1)
row = jrow & 1 ? height-1-jrow/2 : jrow/2;
for (jcol=0; jcol < jwide; jcol++) {
val = curve[*rp++];
for (int jcol=0; jcol < jwide; jcol++) {
int val = curve[*rp[jrow&1]++];
if (cr2_slice[0]) {
jidx = jrow*jwide + jcol;
i = jidx / (cr2_slice[1]*raw_height);
int jidx = jrow*jwide + jcol;
int i = jidx / (cr2_slice[1]*raw_height);
int j;
if ((j = i >= cr2_slice[0]))
i = cr2_slice[0];
jidx -= i * (cr2_slice[1]*raw_height);
Expand All @@ -922,6 +941,8 @@ void CLASS lossless_jpeg_load_raw()
if (++col >= raw_width)
col = (row++,0);
}
}
}
}
ljpeg_end (&jh);
}
Expand Down
2 changes: 1 addition & 1 deletion rtengine/myfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ inline void fseek (IMFILE* f, int p, int how)
inline int fgetc (IMFILE* f)
{

if (f->pos < f->size) {
if (LIKELY(f->pos < f->size)) {
if (f->plistener && ++f->progress_current >= f->progress_next) {
imfile_update_progress(f);
}
Expand Down