Permalink
Browse files

Alexey Danilchenko's GH5S/G9-hires patch

disable rawspeed for new panasonic decoder
  • Loading branch information...
alextutubalin committed Feb 23, 2018
1 parent d4420a4 commit 9fc4e05565ccda07e8479b197cf8f166f94f53c6
Showing with 206 additions and 72 deletions.
  1. +97 −33 dcraw/dcraw.c
  2. +97 −33 internal/dcraw_common.cpp
  3. +1 −1 internal/libraw_internal_funcs.h
  4. +2 −0 internal/var_defines.h
  5. +4 −4 libraw/libraw_internal.h
  6. +5 −1 src/libraw_cxx.cpp
@@ -3153,65 +3153,130 @@ void CLASS canon_rmf_load_raw()
maximum = curve[0x3ff];
}

unsigned CLASS pana_bits(int nbits)
unsigned CLASS pana_data(int nb, unsigned *bytes)
{
#ifndef LIBRAW_NOTHREADS
#define buf tls->pana_bits.buf
#define vbits tls->pana_bits.vbits
#define vpos tls->pana_data.vpos
#define buf tls->pana_data.buf
#else
static uchar buf[0x4000];
static int vbits;
static int vpos;
#endif
int byte;

if (!nbits)
return vbits = 0;
if (!vbits)
if (!nb && !bytes)
return vpos = 0;

if (!vpos)
{
fread(buf + load_flags, 1, 0x4000 - load_flags, ifp);
fread(buf, 1, load_flags, ifp);
}
vbits = (vbits - nbits) & 0x1ffff;
byte = vbits >> 3 ^ 0x3ff0;
return (buf[byte] | buf[byte + 1] << 8) >> (vbits & 7) & ~((~0u) << nbits);

if (pana_encoding == 5)
{
for (byte = 0; byte < 16; byte++)
{
bytes[byte] = buf[vpos++];
vpos &= 0x3FFF;
}
}
else
{
vpos = (vpos - nb) & 0x1ffff;
byte = vpos >> 3 ^ 0x3ff0;
return (buf[byte] | buf[byte + 1] << 8) >> (vpos & 7) & ~((~0u) << nb);
}
return 0;
#ifndef LIBRAW_NOTHREADS
#undef vpos
#undef buf
#undef vbits
#endif
}

void CLASS panasonic_load_raw()
{
int row, col, i, j, sh = 0, pred[2], nonz[2];
unsigned bytes[16];
ushort *raw_block_data;
int enc_blck_size = pana_bpp == 12 ? 10 : 9;

pana_bits(0);
for (row = 0; row < raw_height; row++)
pana_data(0, 0);
if (pana_encoding == 5)
{
for (row = 0; row < raw_height; row++)
{
raw_block_data = raw_image + row * raw_width;

#ifdef LIBRAW_LIBRARY_BUILD
checkCancel();
checkCancel();
#endif
for (col = 0; col < raw_width; col++)
for (col = 0; col < raw_width; col += enc_blck_size)
{
pana_data(0, bytes);

if (pana_bpp == 12)
{
raw_block_data[col] = ((bytes[1] & 0xF) << 8) + bytes[0];
raw_block_data[col + 1] = 16 * bytes[2] + (bytes[1] >> 4);
raw_block_data[col + 2] = ((bytes[4] & 0xF) << 8) + bytes[3];
raw_block_data[col + 3] = 16 * bytes[5] + (bytes[4] >> 4);
raw_block_data[col + 4] = ((bytes[7] & 0xF) << 8) + bytes[6];
raw_block_data[col + 5] = 16 * bytes[8] + (bytes[7] >> 4);
raw_block_data[col + 6] = ((bytes[10] & 0xF) << 8) + bytes[9];
raw_block_data[col + 7] = 16 * bytes[11] + (bytes[10] >> 4);
raw_block_data[col + 8] = ((bytes[13] & 0xF) << 8) + bytes[12];
raw_block_data[col + 9] = 16 * bytes[14] + (bytes[13] >> 4);
}
else if (pana_bpp == 14)
{
raw_block_data[col] = bytes[0] + ((bytes[1] & 0x3F) << 8);
raw_block_data[col + 1] = (bytes[1] >> 6) + 4 * (bytes[2]) +
((bytes[3] & 0xF) << 10);
raw_block_data[col + 2] = (bytes[3] >> 4) + 16 * (bytes[4]) +
((bytes[5] & 3) << 12);
raw_block_data[col + 3] = ((bytes[5] & 0xFC) >> 2) + (bytes[6] << 6);
raw_block_data[col + 4] = bytes[7] + ((bytes[8] & 0x3F) << 8);
raw_block_data[col + 5] = (bytes[8] >> 6) + 4 * bytes[9] + ((bytes[10] & 0xF) << 10);
raw_block_data[col + 6] = (bytes[10] >> 4) + 16 * bytes[11] + ((bytes[12] & 3) << 12);
raw_block_data[col + 7] = ((bytes[12] & 0xFC) >> 2) + (bytes[13] << 6);
raw_block_data[col + 8] = bytes[14] + ((bytes[15] & 0x3F) << 8);
}
}
}
}
else
{
for (row = 0; row < raw_height; row++)
{
if ((i = col % 14) == 0)
pred[0] = pred[1] = nonz[0] = nonz[1] = 0;
if (i % 3 == 2)
sh = 4 >> (3 - pana_bits(2));
if (nonz[i & 1])
#ifdef LIBRAW_LIBRARY_BUILD
checkCancel();
#endif
for (col = 0; col < raw_width; col++)
{
if ((j = pana_bits(8)))
if ((i = col % 14) == 0)
pred[0] = pred[1] = nonz[0] = nonz[1] = 0;
if (i % 3 == 2)
sh = 4 >> (3 - pana_data(2, 0));
if (nonz[i & 1])
{
if ((pred[i & 1] -= 0x80 << sh) < 0 || sh == 4)
pred[i & 1] &= ~((~0u) << sh);
pred[i & 1] += j << sh;
if ((j = pana_data(8, 0)))
{
if ((pred[i & 1] -= 0x80 << sh) < 0 || sh == 4)
pred[i & 1] &= ~((~0u) << sh);
pred[i & 1] += j << sh;
}
}
else if ((nonz[i & 1] = pana_data(8, 0)) || i > 11)
pred[i & 1] = nonz[i & 1] << 4 | pana_data(4, 0);
if ((RAW(row, col) = pred[col & 1]) > 4098 && col < width && row < height)
derror();
}
else if ((nonz[i & 1] = pana_bits(8)) || i > 11)
pred[i & 1] = nonz[i & 1] << 4 | pana_bits(4);
if ((RAW(row, col) = pred[col & 1]) > 4098 && col < width && row < height)
derror();
}
}
}


void CLASS olympus_load_raw()
{
ushort huff[4096];
@@ -13901,7 +13966,7 @@ int CLASS parse_tiff_ifd(int base)
case 10:
if (pana_raw && len == 1 && type == 3)
{
libraw_internal_data.unpacker_data.pana_bpp = get2();
pana_bpp = get2();
}
break;
#endif
@@ -13961,8 +14026,7 @@ int CLASS parse_tiff_ifd(int base)
break;

case 0x2009:
if ((libraw_internal_data.unpacker_data.pana_encoding == 4) ||
(libraw_internal_data.unpacker_data.pana_encoding == 5))
if ((pana_encoding == 4) || (pana_encoding == 5))
{
int n = MIN (8, len);
int permut[8] = {3, 2, 1, 0, 3+4, 2+4, 1+4, 0+4};
@@ -13972,7 +14036,7 @@ int CLASS parse_tiff_ifd(int base)
for (int i=0; i < n; i++)
{
imgdata.makernotes.panasonic.BlackLevel[permut[i]] =
(float) (get2()) / (float) (powf(2.f, 14.f-libraw_internal_data.unpacker_data.pana_bpp));
(float) (get2()) / (float) (powf(2.f, 14.f-pana_bpp));
}
}
break;
@@ -14034,7 +14098,7 @@ int CLASS parse_tiff_ifd(int base)
case 45:
if (pana_raw && len == 1 && type == 3)
{
libraw_internal_data.unpacker_data.pana_encoding = get2();
pana_encoding = get2();
}
break;
#endif
@@ -2856,65 +2856,130 @@ void CLASS canon_rmf_load_raw()
maximum = curve[0x3ff];
}

unsigned CLASS pana_bits(int nbits)
unsigned CLASS pana_data(int nb, unsigned *bytes)
{
#ifndef LIBRAW_NOTHREADS
#define buf tls->pana_bits.buf
#define vbits tls->pana_bits.vbits
#define vpos tls->pana_data.vpos
#define buf tls->pana_data.buf
#else
static uchar buf[0x4000];
static int vbits;
static int vpos;
#endif
int byte;

if (!nbits)
return vbits = 0;
if (!vbits)
if (!nb && !bytes)
return vpos = 0;

if (!vpos)
{
fread(buf + load_flags, 1, 0x4000 - load_flags, ifp);
fread(buf, 1, load_flags, ifp);
}
vbits = (vbits - nbits) & 0x1ffff;
byte = vbits >> 3 ^ 0x3ff0;
return (buf[byte] | buf[byte + 1] << 8) >> (vbits & 7) & ~((~0u) << nbits);

if (pana_encoding == 5)
{
for (byte = 0; byte < 16; byte++)
{
bytes[byte] = buf[vpos++];
vpos &= 0x3FFF;
}
}
else
{
vpos = (vpos - nb) & 0x1ffff;
byte = vpos >> 3 ^ 0x3ff0;
return (buf[byte] | buf[byte + 1] << 8) >> (vpos & 7) & ~((~0u) << nb);
}
return 0;
#ifndef LIBRAW_NOTHREADS
#undef vpos
#undef buf
#undef vbits
#endif
}

void CLASS panasonic_load_raw()
{
int row, col, i, j, sh = 0, pred[2], nonz[2];
unsigned bytes[16];
ushort *raw_block_data;
int enc_blck_size = pana_bpp == 12 ? 10 : 9;

pana_bits(0);
for (row = 0; row < raw_height; row++)
pana_data(0, 0);
if (pana_encoding == 5)
{
for (row = 0; row < raw_height; row++)
{
raw_block_data = raw_image + row * raw_width;

#ifdef LIBRAW_LIBRARY_BUILD
checkCancel();
checkCancel();
#endif
for (col = 0; col < raw_width; col++)
for (col = 0; col < raw_width; col += enc_blck_size)
{
pana_data(0, bytes);

if (pana_bpp == 12)
{
raw_block_data[col] = ((bytes[1] & 0xF) << 8) + bytes[0];
raw_block_data[col + 1] = 16 * bytes[2] + (bytes[1] >> 4);
raw_block_data[col + 2] = ((bytes[4] & 0xF) << 8) + bytes[3];
raw_block_data[col + 3] = 16 * bytes[5] + (bytes[4] >> 4);
raw_block_data[col + 4] = ((bytes[7] & 0xF) << 8) + bytes[6];
raw_block_data[col + 5] = 16 * bytes[8] + (bytes[7] >> 4);
raw_block_data[col + 6] = ((bytes[10] & 0xF) << 8) + bytes[9];
raw_block_data[col + 7] = 16 * bytes[11] + (bytes[10] >> 4);
raw_block_data[col + 8] = ((bytes[13] & 0xF) << 8) + bytes[12];
raw_block_data[col + 9] = 16 * bytes[14] + (bytes[13] >> 4);
}
else if (pana_bpp == 14)
{
raw_block_data[col] = bytes[0] + ((bytes[1] & 0x3F) << 8);
raw_block_data[col + 1] = (bytes[1] >> 6) + 4 * (bytes[2]) +
((bytes[3] & 0xF) << 10);
raw_block_data[col + 2] = (bytes[3] >> 4) + 16 * (bytes[4]) +
((bytes[5] & 3) << 12);
raw_block_data[col + 3] = ((bytes[5] & 0xFC) >> 2) + (bytes[6] << 6);
raw_block_data[col + 4] = bytes[7] + ((bytes[8] & 0x3F) << 8);
raw_block_data[col + 5] = (bytes[8] >> 6) + 4 * bytes[9] + ((bytes[10] & 0xF) << 10);
raw_block_data[col + 6] = (bytes[10] >> 4) + 16 * bytes[11] + ((bytes[12] & 3) << 12);
raw_block_data[col + 7] = ((bytes[12] & 0xFC) >> 2) + (bytes[13] << 6);
raw_block_data[col + 8] = bytes[14] + ((bytes[15] & 0x3F) << 8);
}
}
}
}
else
{
for (row = 0; row < raw_height; row++)
{
if ((i = col % 14) == 0)
pred[0] = pred[1] = nonz[0] = nonz[1] = 0;
if (i % 3 == 2)
sh = 4 >> (3 - pana_bits(2));
if (nonz[i & 1])
#ifdef LIBRAW_LIBRARY_BUILD
checkCancel();
#endif
for (col = 0; col < raw_width; col++)
{
if ((j = pana_bits(8)))
if ((i = col % 14) == 0)
pred[0] = pred[1] = nonz[0] = nonz[1] = 0;
if (i % 3 == 2)
sh = 4 >> (3 - pana_data(2, 0));
if (nonz[i & 1])
{
if ((pred[i & 1] -= 0x80 << sh) < 0 || sh == 4)
pred[i & 1] &= ~((~0u) << sh);
pred[i & 1] += j << sh;
if ((j = pana_data(8, 0)))
{
if ((pred[i & 1] -= 0x80 << sh) < 0 || sh == 4)
pred[i & 1] &= ~((~0u) << sh);
pred[i & 1] += j << sh;
}
}
else if ((nonz[i & 1] = pana_data(8, 0)) || i > 11)
pred[i & 1] = nonz[i & 1] << 4 | pana_data(4, 0);
if ((RAW(row, col) = pred[col & 1]) > 4098 && col < width && row < height)
derror();
}
else if ((nonz[i & 1] = pana_bits(8)) || i > 11)
pred[i & 1] = nonz[i & 1] << 4 | pana_bits(4);
if ((RAW(row, col) = pred[col & 1]) > 4098 && col < width && row < height)
derror();
}
}
}


void CLASS olympus_load_raw()
{
ushort huff[4096];
@@ -12564,7 +12629,7 @@ int CLASS parse_tiff_ifd(int base)
case 10:
if (pana_raw && len == 1 && type == 3)
{
libraw_internal_data.unpacker_data.pana_bpp = get2();
pana_bpp = get2();
}
break;
#endif
@@ -12624,8 +12689,7 @@ int CLASS parse_tiff_ifd(int base)
break;

case 0x2009:
if ((libraw_internal_data.unpacker_data.pana_encoding == 4) ||
(libraw_internal_data.unpacker_data.pana_encoding == 5))
if ((pana_encoding == 4) || (pana_encoding == 5))
{
int n = MIN (8, len);
int permut[8] = {3, 2, 1, 0, 3+4, 2+4, 1+4, 0+4};
@@ -12635,7 +12699,7 @@ int CLASS parse_tiff_ifd(int base)
for (int i=0; i < n; i++)
{
imgdata.makernotes.panasonic.BlackLevel[permut[i]] =
(float) (get2()) / (float) (powf(2.f, 14.f-libraw_internal_data.unpacker_data.pana_bpp));
(float) (get2()) / (float) (powf(2.f, 14.f-pana_bpp));
}
}
break;
@@ -12697,7 +12761,7 @@ int CLASS parse_tiff_ifd(int base)
case 45:
if (pana_raw && len == 1 && type == 3)
{
libraw_internal_data.unpacker_data.pana_encoding = get2();
pana_encoding = get2();
}
break;
#endif
Oops, something went wrong.

0 comments on commit 9fc4e05

Please sign in to comment.