astyled xtranscompressed.cc and cleaned code a bit
This commit is contained in:
@@ -5,7 +5,6 @@
|
||||
* Adopted to LibRaw by Alex Tutubalin, lexa@lexa.ru
|
||||
* LibRaw Fujifilm/compressed decoder
|
||||
|
||||
* Adopted to RawTherapee by Ingo Weyrich
|
||||
LibRaw is free software; you can redistribute it and/or modify
|
||||
it under the terms of the one of three licenses as you choose:
|
||||
|
||||
@@ -15,6 +14,8 @@ it under the terms of the one of three licenses as you choose:
|
||||
2. COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
|
||||
(See file LICENSE.CDDL provided in LibRaw distribution archive for details).
|
||||
|
||||
* Adopted to RawTherapee by Ingo Weyrich
|
||||
|
||||
*/
|
||||
|
||||
void CLASS init_xtrans (struct xtrans_params* info)
|
||||
@@ -22,8 +23,9 @@ void CLASS init_xtrans(struct xtrans_params* info)
|
||||
int cur_val, i;
|
||||
char *qt;
|
||||
|
||||
if (fuji_block_width % 3)
|
||||
if (fuji_block_width % 3) {
|
||||
derror();
|
||||
}
|
||||
|
||||
info->q_table = (char *) malloc (32768);
|
||||
merror (info->q_table, "init_xtrans()");
|
||||
@@ -38,53 +40,50 @@ void CLASS init_xtrans(struct xtrans_params* info)
|
||||
info->min_value = 0x40;
|
||||
|
||||
cur_val = -info->q_point[4];
|
||||
for (qt = info->q_table; cur_val<=info->q_point[4]; ++qt, ++cur_val)
|
||||
{
|
||||
if (cur_val<= -info->q_point[3])
|
||||
|
||||
for (qt = info->q_table; cur_val <= info->q_point[4]; ++qt, ++cur_val) {
|
||||
if (cur_val <= -info->q_point[3]) {
|
||||
*qt = -4;
|
||||
else if (cur_val<= -info->q_point[2])
|
||||
} else if (cur_val <= -info->q_point[2]) {
|
||||
*qt = -3;
|
||||
else if (cur_val<= -info->q_point[1])
|
||||
} else if (cur_val <= -info->q_point[1]) {
|
||||
*qt = -2;
|
||||
else if (cur_val< 0)
|
||||
} else if (cur_val < 0) {
|
||||
*qt = -1;
|
||||
else if (cur_val== 0)
|
||||
} else if (cur_val == 0) {
|
||||
*qt = 0;
|
||||
else if (cur_val< info->q_point[1])
|
||||
} else if (cur_val < info->q_point[1]) {
|
||||
*qt = 1;
|
||||
else if (cur_val< info->q_point[2])
|
||||
} else if (cur_val < info->q_point[2]) {
|
||||
*qt = 2;
|
||||
else if (cur_val< info->q_point[3])
|
||||
} else if (cur_val < info->q_point[3]) {
|
||||
*qt = 3;
|
||||
else
|
||||
} else {
|
||||
*qt = 4;
|
||||
}
|
||||
}
|
||||
|
||||
// populting gradients
|
||||
if (info->q_point[4] == 0x3FFF)
|
||||
{
|
||||
if (info->q_point[4] == 0x3FFF) {
|
||||
info->total_values = 0x4000;
|
||||
info->raw_bits = 14;
|
||||
info->max_bits = 56;
|
||||
info->maxDiff = 256;
|
||||
}
|
||||
else if (info->q_point[4] == 0xFFF)
|
||||
{
|
||||
} else if (info->q_point[4] == 0xFFF) {
|
||||
info->total_values = 4096;
|
||||
info->raw_bits = 12;
|
||||
info->max_bits = 48;
|
||||
info->maxDiff = 64;
|
||||
}
|
||||
else
|
||||
} else {
|
||||
derror();
|
||||
}
|
||||
}
|
||||
|
||||
#define XTRANS_BUF_SIZE 0x10000u
|
||||
|
||||
void CLASS fuji_fill_buffer (struct xtrans_block *info)
|
||||
{
|
||||
if (info->cur_pos >= info->cur_buf_size)
|
||||
{
|
||||
if (info->cur_pos >= info->cur_buf_size) {
|
||||
info->cur_pos = 0;
|
||||
info->cur_buf_offset += info->cur_buf_size;
|
||||
#ifdef _OPENMP
|
||||
@@ -93,15 +92,13 @@ void CLASS fuji_fill_buffer(struct xtrans_block *info)
|
||||
{
|
||||
fseek (info->input, info->cur_buf_offset, SEEK_SET);
|
||||
info->cur_buf_size = fread (info->cur_buf, 1, std::min (info->max_read_size, XTRANS_BUF_SIZE), info->input);
|
||||
}
|
||||
if (info->cur_buf_size < 1) // nothing read
|
||||
;//throw LIBRAW_EXCEPTION_IO_EOF;
|
||||
|
||||
info->max_read_size -= info->cur_buf_size;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#define _min(a,b) ((a) < (b) ? (a) : (b))
|
||||
|
||||
void CLASS init_xtrans_block (struct xtrans_block* info, const struct xtrans_params *params, INT64 raw_offset, unsigned dsize)
|
||||
{
|
||||
@@ -110,11 +107,13 @@ void CLASS init_xtrans_block(struct xtrans_block* info, const struct xtrans_para
|
||||
|
||||
info->input = ifp;
|
||||
INT64 fsize = info->input->size;
|
||||
info->max_read_size = _min(unsigned(fsize-raw_offset),dsize+16); // Data size may be incorrect?
|
||||
info->max_read_size = std::min (unsigned (fsize - raw_offset), dsize + 16); // Data size may be incorrect?
|
||||
|
||||
info->linebuf[_R0] = info->linealloc;
|
||||
for(int i = _R1; i<=_B4;i++)
|
||||
|
||||
for (int i = _R1; i <= _B4; i++) {
|
||||
info->linebuf[i] = info->linebuf[i - 1] + params->line_width + 2;
|
||||
}
|
||||
|
||||
// init buffer
|
||||
info->cur_buf = (uchar*)malloc (XTRANS_BUF_SIZE);
|
||||
@@ -122,9 +121,9 @@ void CLASS init_xtrans_block(struct xtrans_block* info, const struct xtrans_para
|
||||
info->cur_bit = 0;
|
||||
info->cur_pos = 0;
|
||||
info->cur_buf_offset = raw_offset;
|
||||
|
||||
for (int j = 0; j < 3; j++)
|
||||
for (int i=0; i<41; i++)
|
||||
{
|
||||
for (int i = 0; i < 41; i++) {
|
||||
info->grad_even[j][i].value1 = params->maxDiff;
|
||||
info->grad_even[j][i].value2 = 1;
|
||||
info->grad_odd[j][i].value1 = params->maxDiff;
|
||||
@@ -148,27 +147,28 @@ void CLASS copy_line_to_xtrans(struct xtrans_block* info, int cur_line, int cur_
|
||||
ushort* raw_block_data = raw_image + offset;
|
||||
int row_count = 0;
|
||||
|
||||
for(int i = 0; i<3; i++)
|
||||
{
|
||||
for (int i = 0; i < 3; i++) {
|
||||
lineBufR[i] = info->linebuf[_R2 + i] + 1;
|
||||
lineBufB[i] = info->linebuf[_B2 + i] + 1;
|
||||
}
|
||||
for(int i = 0; i<6; i++)
|
||||
lineBufG[i] = info->linebuf[_G2+i] + 1;
|
||||
|
||||
while (row_count < 6)
|
||||
{
|
||||
for (int i = 0; i < 6; i++) {
|
||||
lineBufG[i] = info->linebuf[_G2 + i] + 1;
|
||||
}
|
||||
|
||||
while (row_count < 6) {
|
||||
pixel_count = 0;
|
||||
while (pixel_count < cur_block_width)
|
||||
{
|
||||
switch (xtrans_abs[row_count][(pixel_count % 6)])
|
||||
{
|
||||
|
||||
while (pixel_count < cur_block_width) {
|
||||
switch (xtrans_abs[row_count][ (pixel_count % 6)]) {
|
||||
case 0: // red
|
||||
line_buf = lineBufR[row_count >> 1];
|
||||
break;
|
||||
|
||||
case 1: // green
|
||||
line_buf = lineBufG[row_count];
|
||||
break;
|
||||
|
||||
case 2: // blue
|
||||
line_buf = lineBufB[row_count >> 1];
|
||||
break;
|
||||
@@ -179,6 +179,7 @@ void CLASS copy_line_to_xtrans(struct xtrans_block* info, int cur_line, int cur_
|
||||
|
||||
++pixel_count;
|
||||
}
|
||||
|
||||
++row_count;
|
||||
raw_block_data += raw_width;
|
||||
}
|
||||
@@ -190,18 +191,21 @@ void CLASS fuji_zerobits(struct xtrans_block* info, int *count)
|
||||
{
|
||||
uchar zero = 0;
|
||||
*count = 0;
|
||||
while (zero == 0)
|
||||
{
|
||||
|
||||
while (zero == 0) {
|
||||
zero = (info->cur_buf[info->cur_pos] >> (7 - info->cur_bit)) & 1;
|
||||
info->cur_bit++;
|
||||
info->cur_bit &= 7;
|
||||
if (!info->cur_bit)
|
||||
{
|
||||
|
||||
if (!info->cur_bit) {
|
||||
++info->cur_pos;
|
||||
fuji_fill_buffer (info);
|
||||
}
|
||||
if (zero)
|
||||
|
||||
if (zero) {
|
||||
break;
|
||||
}
|
||||
|
||||
++*count;
|
||||
}
|
||||
}
|
||||
@@ -211,26 +215,27 @@ void CLASS fuji_read_code(struct xtrans_block* info, int *data, int bits_to_read
|
||||
uchar bits_left = bits_to_read;
|
||||
uchar bits_left_in_byte = 8 - (info->cur_bit & 7);
|
||||
*data = 0;
|
||||
if (!bits_to_read)
|
||||
|
||||
if (!bits_to_read) {
|
||||
return;
|
||||
if (bits_to_read >= bits_left_in_byte)
|
||||
{
|
||||
do
|
||||
{
|
||||
}
|
||||
|
||||
if (bits_to_read >= bits_left_in_byte) {
|
||||
do {
|
||||
*data <<= bits_left_in_byte;
|
||||
bits_left -= bits_left_in_byte;
|
||||
*data |= info->cur_buf[info->cur_pos] & ((1 << bits_left_in_byte) - 1);
|
||||
++info->cur_pos;
|
||||
fuji_fill_buffer (info);
|
||||
bits_left_in_byte = 8;
|
||||
} while (bits_left >= 8);
|
||||
}
|
||||
while (bits_left >= 8);
|
||||
}
|
||||
if (!bits_left)
|
||||
{
|
||||
|
||||
if (!bits_left) {
|
||||
info->cur_bit = (8 - (bits_left_in_byte & 7)) & 7;
|
||||
return;
|
||||
}
|
||||
|
||||
*data <<= bits_left;
|
||||
bits_left_in_byte -= bits_left;
|
||||
*data |= ((1 << bits_left) - 1) & ((unsigned)info->cur_buf[info->cur_pos] >> bits_left_in_byte);
|
||||
@@ -240,20 +245,17 @@ void CLASS fuji_read_code(struct xtrans_block* info, int *data, int bits_to_read
|
||||
int CLASS bitDiff (int value1, int value2)
|
||||
{
|
||||
int decBits = 0;
|
||||
|
||||
if ( value2 < value1 )
|
||||
while (decBits <= 12 &&
|
||||
(value2 << ++decBits)
|
||||
< value1)
|
||||
while (decBits <= 12 && (value2 << ++decBits) < value1)
|
||||
;
|
||||
|
||||
return decBits;
|
||||
}
|
||||
|
||||
#define _abs(x) (((int)(x) ^ ((int)(x) >> 31)) - ((int)(x) >> 31))
|
||||
|
||||
int CLASS fuji_decode_sample_even (struct xtrans_block* info, const struct xtrans_params * params, ushort* line_buf, int pos, struct int_pair* grads)
|
||||
{
|
||||
int interp_val = 0;
|
||||
//ushort decBits;
|
||||
int errcnt = 0;
|
||||
|
||||
int sample = 0, code = 0;
|
||||
@@ -266,61 +268,68 @@ int CLASS fuji_decode_sample_even(struct xtrans_block* info, const struct xtrans
|
||||
int grad, gradient, diffRcRb, diffRfRb, diffRdRb;
|
||||
|
||||
grad = fuji_quant_gradient (params, Rb - Rf, Rc - Rb);
|
||||
gradient = _abs(grad);
|
||||
diffRcRb = _abs(Rc - Rb);
|
||||
diffRfRb = _abs(Rf - Rb);
|
||||
diffRdRb = _abs(Rd - Rb);
|
||||
gradient = std::abs (grad);
|
||||
diffRcRb = std::abs (Rc - Rb);
|
||||
diffRfRb = std::abs (Rf - Rb);
|
||||
diffRdRb = std::abs (Rd - Rb);
|
||||
|
||||
if ( diffRcRb > diffRfRb && diffRcRb > diffRdRb )
|
||||
if ( diffRcRb > diffRfRb && diffRcRb > diffRdRb ) {
|
||||
interp_val = Rf + Rd + 2 * Rb;
|
||||
else if ( diffRdRb > diffRcRb && diffRdRb > diffRfRb )
|
||||
} else if ( diffRdRb > diffRcRb && diffRdRb > diffRfRb ) {
|
||||
interp_val = Rf + Rc + 2 * Rb;
|
||||
else
|
||||
} else {
|
||||
interp_val = Rd + Rc + 2 * Rb;
|
||||
}
|
||||
|
||||
|
||||
fuji_zerobits (info, &sample);
|
||||
|
||||
if (sample < params->max_bits - params->raw_bits - 1)
|
||||
{
|
||||
if (sample < params->max_bits - params->raw_bits - 1) {
|
||||
int decBits = bitDiff (grads[gradient].value1, grads[gradient].value2);
|
||||
fuji_read_code (info, &code, decBits);
|
||||
code += sample << decBits;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
fuji_read_code (info, &code, params->raw_bits);
|
||||
code++;
|
||||
}
|
||||
|
||||
if (code < 0 || code >= params->total_values)
|
||||
if (code < 0 || code >= params->total_values) {
|
||||
errcnt++;
|
||||
}
|
||||
|
||||
if (code & 1)
|
||||
if (code & 1) {
|
||||
code = -1 - code / 2;
|
||||
else
|
||||
} else {
|
||||
code /= 2;
|
||||
}
|
||||
|
||||
grads[gradient].value1 += _abs(code);
|
||||
if (grads[gradient].value2 == params->min_value )
|
||||
{
|
||||
grads[gradient].value1 += std::abs (code);
|
||||
|
||||
if (grads[gradient].value2 == params->min_value ) {
|
||||
grads[gradient].value1 >>= 1;
|
||||
grads[gradient].value2 >>= 1;
|
||||
}
|
||||
grads[gradient].value2++;
|
||||
if (grad < 0)
|
||||
interp_val = (interp_val >> 2) - code;
|
||||
else
|
||||
interp_val = (interp_val >> 2) + code;
|
||||
if ( interp_val < 0 )
|
||||
interp_val += params->total_values;
|
||||
else if (interp_val > params->q_point[4])
|
||||
interp_val -= params->total_values;
|
||||
|
||||
if ( interp_val >= 0 )
|
||||
line_buf_cur[0] = _min(interp_val, params->q_point[4]);
|
||||
else
|
||||
grads[gradient].value2++;
|
||||
|
||||
if (grad < 0) {
|
||||
interp_val = (interp_val >> 2) - code;
|
||||
} else {
|
||||
interp_val = (interp_val >> 2) + code;
|
||||
}
|
||||
|
||||
if ( interp_val < 0 ) {
|
||||
interp_val += params->total_values;
|
||||
} else if (interp_val > params->q_point[4]) {
|
||||
interp_val -= params->total_values;
|
||||
}
|
||||
|
||||
if ( interp_val >= 0 ) {
|
||||
line_buf_cur[0] = std::min (interp_val, params->q_point[4]);
|
||||
} else {
|
||||
line_buf_cur[0] = 0;
|
||||
}
|
||||
|
||||
return errcnt;
|
||||
}
|
||||
|
||||
@@ -340,55 +349,62 @@ int CLASS fuji_decode_sample_odd(struct xtrans_block* info, const struct xtrans_
|
||||
int grad, gradient;
|
||||
|
||||
grad = fuji_quant_gradient (params, Rb - Rc, Rc - Ra);
|
||||
gradient = _abs(grad);
|
||||
gradient = std::abs (grad);
|
||||
|
||||
if ((Rb > Rc && Rb > Rd) || (Rb < Rc && Rb < Rd))
|
||||
if ((Rb > Rc && Rb > Rd) || (Rb < Rc && Rb < Rd)) {
|
||||
interp_val = (Rg + Ra + 2 * Rb) >> 2;
|
||||
else
|
||||
} else {
|
||||
interp_val = (Ra + Rg) >> 1;
|
||||
}
|
||||
|
||||
fuji_zerobits (info, &sample);
|
||||
|
||||
if (sample < params->max_bits - params->raw_bits - 1)
|
||||
{
|
||||
if (sample < params->max_bits - params->raw_bits - 1) {
|
||||
int decBits = bitDiff (grads[gradient].value1, grads[gradient].value2);
|
||||
fuji_read_code (info, &code, decBits);
|
||||
code += sample << decBits;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
fuji_read_code (info, &code, params->raw_bits);
|
||||
code++;
|
||||
}
|
||||
|
||||
if (code < 0 || code >= params->total_values)
|
||||
if (code < 0 || code >= params->total_values) {
|
||||
errcnt++;
|
||||
}
|
||||
|
||||
if (code & 1)
|
||||
if (code & 1) {
|
||||
code = -1 - code / 2;
|
||||
else
|
||||
} else {
|
||||
code /= 2;
|
||||
}
|
||||
|
||||
grads[gradient].value1 += _abs(code);
|
||||
if (grads[gradient].value2 == params->min_value)
|
||||
{
|
||||
grads[gradient].value1 += std::abs (code);
|
||||
|
||||
if (grads[gradient].value2 == params->min_value) {
|
||||
grads[gradient].value1 >>= 1;
|
||||
grads[gradient].value2 >>= 1;
|
||||
}
|
||||
grads[gradient].value2++;
|
||||
if (grad < 0)
|
||||
interp_val -= code;
|
||||
else
|
||||
interp_val += code;
|
||||
if ( interp_val < 0 )
|
||||
interp_val += params->total_values;
|
||||
else if (interp_val > params->q_point[4])
|
||||
interp_val -= params->total_values;
|
||||
|
||||
if ( interp_val >= 0 )
|
||||
line_buf_cur[0] = _min(interp_val, params->q_point[4]);
|
||||
else
|
||||
grads[gradient].value2++;
|
||||
|
||||
if (grad < 0) {
|
||||
interp_val -= code;
|
||||
} else {
|
||||
interp_val += code;
|
||||
}
|
||||
|
||||
if ( interp_val < 0 ) {
|
||||
interp_val += params->total_values;
|
||||
} else if (interp_val > params->q_point[4]) {
|
||||
interp_val -= params->total_values;
|
||||
}
|
||||
|
||||
if ( interp_val >= 0 ) {
|
||||
line_buf_cur[0] = std::min(interp_val, params->q_point[4]);
|
||||
} else {
|
||||
line_buf_cur[0] = 0;
|
||||
}
|
||||
|
||||
return errcnt;
|
||||
}
|
||||
|
||||
@@ -399,21 +415,22 @@ void CLASS fuji_decode_interpolation_even(int line_width, ushort* line_buf, int
|
||||
int Rc = line_buf_cur[-3 - line_width];
|
||||
int Rd = line_buf_cur[-1 - line_width];
|
||||
int Rf = line_buf_cur[-4 - 2 * line_width];
|
||||
int diffRcRb = _abs(Rc - Rb);
|
||||
int diffRfRb = _abs(Rf - Rb);
|
||||
int diffRdRb = _abs(Rd - Rb);
|
||||
if ( diffRcRb > diffRfRb && diffRcRb > diffRdRb )
|
||||
int diffRcRb = std::abs (Rc - Rb);
|
||||
int diffRfRb = std::abs (Rf - Rb);
|
||||
int diffRdRb = std::abs (Rd - Rb);
|
||||
|
||||
if ( diffRcRb > diffRfRb && diffRcRb > diffRdRb ) {
|
||||
*line_buf_cur = (Rf + Rd + 2 * Rb) >> 2;
|
||||
else if ( diffRdRb > diffRcRb && diffRdRb > diffRfRb )
|
||||
} else if ( diffRdRb > diffRcRb && diffRdRb > diffRfRb ) {
|
||||
*line_buf_cur = (Rf + Rc + 2 * Rb) >> 2;
|
||||
else
|
||||
} else {
|
||||
*line_buf_cur = (Rd + Rc + 2 * Rb) >> 2;
|
||||
}
|
||||
}
|
||||
|
||||
void CLASS xtrans_extend_generic (ushort *linebuf[_ltotal], int line_width, int start, int end)
|
||||
{
|
||||
for(int i = start; i<= end; i++)
|
||||
{
|
||||
for (int i = start; i <= end; i++) {
|
||||
linebuf[i][0] = linebuf[i - 1][1];
|
||||
linebuf[i][line_width + 1] = linebuf[i - 1][line_width];
|
||||
}
|
||||
@@ -444,17 +461,15 @@ void CLASS xtrans_decode_block(struct xtrans_block* info, const struct xtrans_pa
|
||||
|
||||
const int line_width = params->line_width;
|
||||
|
||||
while (g_even_pos < line_width || g_odd_pos < line_width)
|
||||
{
|
||||
if (g_even_pos < line_width)
|
||||
{
|
||||
while (g_even_pos < line_width || g_odd_pos < line_width) {
|
||||
if (g_even_pos < line_width) {
|
||||
fuji_decode_interpolation_even (line_width, info->linebuf[_R2] + 1, r_even_pos);
|
||||
r_even_pos += 2;
|
||||
errcnt += fuji_decode_sample_even (info, params, info->linebuf[_G2] + 1, g_even_pos, info->grad_even[0]);
|
||||
g_even_pos += 2;
|
||||
}
|
||||
if (g_even_pos > 8)
|
||||
{
|
||||
|
||||
if (g_even_pos > 8) {
|
||||
errcnt += fuji_decode_sample_odd (info, params, info->linebuf[_R2] + 1, r_odd_pos, info->grad_odd[0]);
|
||||
r_odd_pos += 2;
|
||||
errcnt += fuji_decode_sample_odd (info, params, info->linebuf[_G2] + 1, g_odd_pos, info->grad_odd[0]);
|
||||
@@ -467,17 +482,15 @@ void CLASS xtrans_decode_block(struct xtrans_block* info, const struct xtrans_pa
|
||||
|
||||
g_even_pos = 0, g_odd_pos = 1;
|
||||
|
||||
while (g_even_pos < line_width || g_odd_pos < line_width)
|
||||
{
|
||||
if (g_even_pos < line_width)
|
||||
{
|
||||
while (g_even_pos < line_width || g_odd_pos < line_width) {
|
||||
if (g_even_pos < line_width) {
|
||||
errcnt += fuji_decode_sample_even (info, params, info->linebuf[_G3] + 1, g_even_pos, info->grad_even[1]);
|
||||
g_even_pos += 2;
|
||||
fuji_decode_interpolation_even (line_width, info->linebuf[_B2] + 1, b_even_pos);
|
||||
b_even_pos += 2;
|
||||
}
|
||||
if (g_even_pos > 8)
|
||||
{
|
||||
|
||||
if (g_even_pos > 8) {
|
||||
errcnt += fuji_decode_sample_odd (info, params, info->linebuf[_G3] + 1, g_odd_pos, info->grad_odd[1]);
|
||||
g_odd_pos += 2;
|
||||
errcnt += fuji_decode_sample_odd (info, params, info->linebuf[_B2] + 1, b_odd_pos, info->grad_odd[1]);
|
||||
@@ -491,20 +504,20 @@ void CLASS xtrans_decode_block(struct xtrans_block* info, const struct xtrans_pa
|
||||
r_even_pos = 0, r_odd_pos = 1;
|
||||
g_even_pos = 0, g_odd_pos = 1;
|
||||
|
||||
while (g_even_pos < line_width || g_odd_pos < line_width)
|
||||
{
|
||||
if (g_even_pos < line_width)
|
||||
{
|
||||
if (r_even_pos & 3)
|
||||
while (g_even_pos < line_width || g_odd_pos < line_width) {
|
||||
if (g_even_pos < line_width) {
|
||||
if (r_even_pos & 3) {
|
||||
errcnt += fuji_decode_sample_even (info, params, info->linebuf[_R3] + 1, r_even_pos, info->grad_even[2]);
|
||||
else
|
||||
} else {
|
||||
fuji_decode_interpolation_even (line_width, info->linebuf[_R3] + 1, r_even_pos);
|
||||
}
|
||||
|
||||
r_even_pos += 2;
|
||||
fuji_decode_interpolation_even (line_width, info->linebuf[_G4] + 1, g_even_pos);
|
||||
g_even_pos += 2;
|
||||
}
|
||||
if (g_even_pos > 8)
|
||||
{
|
||||
|
||||
if (g_even_pos > 8) {
|
||||
errcnt += fuji_decode_sample_odd (info, params, info->linebuf[_R3] + 1, r_odd_pos, info->grad_odd[2]);
|
||||
r_odd_pos += 2;
|
||||
errcnt += fuji_decode_sample_odd (info, params, info->linebuf[_G4] + 1, g_odd_pos, info->grad_odd[2]);
|
||||
@@ -518,20 +531,21 @@ void CLASS xtrans_decode_block(struct xtrans_block* info, const struct xtrans_pa
|
||||
g_even_pos = 0, g_odd_pos = 1;
|
||||
b_even_pos = 0, b_odd_pos = 1;
|
||||
|
||||
while (g_even_pos < line_width || g_odd_pos < line_width)
|
||||
{
|
||||
if (g_even_pos < line_width)
|
||||
{
|
||||
while (g_even_pos < line_width || g_odd_pos < line_width) {
|
||||
if (g_even_pos < line_width) {
|
||||
errcnt += fuji_decode_sample_even (info, params, info->linebuf[_G5] + 1, g_even_pos, info->grad_even[0]);
|
||||
g_even_pos += 2;
|
||||
if ((b_even_pos & 3) == 2)
|
||||
|
||||
if ((b_even_pos & 3) == 2) {
|
||||
fuji_decode_interpolation_even (line_width, info->linebuf[_B3] + 1, b_even_pos);
|
||||
else
|
||||
} else {
|
||||
errcnt += fuji_decode_sample_even (info, params, info->linebuf[_B3] + 1, b_even_pos, info->grad_even[0]);
|
||||
}
|
||||
|
||||
b_even_pos += 2;
|
||||
}
|
||||
if (g_even_pos > 8)
|
||||
{
|
||||
|
||||
if (g_even_pos > 8) {
|
||||
errcnt += fuji_decode_sample_odd (info, params, info->linebuf[_G5] + 1, g_odd_pos, info->grad_odd[0]);
|
||||
g_odd_pos += 2;
|
||||
errcnt += fuji_decode_sample_odd (info, params, info->linebuf[_B3] + 1, b_odd_pos, info->grad_odd[0]);
|
||||
@@ -545,20 +559,20 @@ void CLASS xtrans_decode_block(struct xtrans_block* info, const struct xtrans_pa
|
||||
r_even_pos = 0, r_odd_pos = 1;
|
||||
g_even_pos = 0, g_odd_pos = 1;
|
||||
|
||||
while (g_even_pos < line_width || g_odd_pos < line_width)
|
||||
{
|
||||
if (g_even_pos < line_width)
|
||||
{
|
||||
if ((r_even_pos & 3) == 2)
|
||||
while (g_even_pos < line_width || g_odd_pos < line_width) {
|
||||
if (g_even_pos < line_width) {
|
||||
if ((r_even_pos & 3) == 2) {
|
||||
fuji_decode_interpolation_even (line_width, info->linebuf[_R4] + 1, r_even_pos);
|
||||
else
|
||||
} else {
|
||||
errcnt += fuji_decode_sample_even (info, params, info->linebuf[_R4] + 1, r_even_pos, info->grad_even[1]);
|
||||
}
|
||||
|
||||
r_even_pos += 2;
|
||||
errcnt += fuji_decode_sample_even (info, params, info->linebuf[_G6] + 1, g_even_pos, info->grad_even[1]);
|
||||
g_even_pos += 2;
|
||||
}
|
||||
if (g_even_pos > 8)
|
||||
{
|
||||
|
||||
if (g_even_pos > 8) {
|
||||
errcnt += fuji_decode_sample_odd (info, params, info->linebuf[_R4] + 1, r_odd_pos, info->grad_odd[1]);
|
||||
r_odd_pos += 2;
|
||||
errcnt += fuji_decode_sample_odd (info, params, info->linebuf[_G6] + 1, g_odd_pos, info->grad_odd[1]);
|
||||
@@ -572,20 +586,21 @@ void CLASS xtrans_decode_block(struct xtrans_block* info, const struct xtrans_pa
|
||||
g_even_pos = 0, g_odd_pos = 1;
|
||||
b_even_pos = 0, b_odd_pos = 1;
|
||||
|
||||
while (g_even_pos < line_width || g_odd_pos < line_width)
|
||||
{
|
||||
if (g_even_pos < line_width)
|
||||
{
|
||||
while (g_even_pos < line_width || g_odd_pos < line_width) {
|
||||
if (g_even_pos < line_width) {
|
||||
fuji_decode_interpolation_even (line_width, info->linebuf[_G7] + 1, g_even_pos);
|
||||
g_even_pos += 2;
|
||||
if (b_even_pos & 3)
|
||||
|
||||
if (b_even_pos & 3) {
|
||||
errcnt += fuji_decode_sample_even (info, params, info->linebuf[_B4] + 1, b_even_pos, info->grad_even[2]);
|
||||
else
|
||||
} else {
|
||||
fuji_decode_interpolation_even (line_width, info->linebuf[_B4] + 1, b_even_pos);
|
||||
}
|
||||
|
||||
b_even_pos += 2;
|
||||
}
|
||||
if (g_even_pos > 8)
|
||||
{
|
||||
|
||||
if (g_even_pos > 8) {
|
||||
errcnt += fuji_decode_sample_odd (info, params, info->linebuf[_G7] + 1, g_odd_pos, info->grad_odd[2]);
|
||||
g_odd_pos += 2;
|
||||
errcnt += fuji_decode_sample_odd (info, params, info->linebuf[_B4] + 1, b_odd_pos, info->grad_odd[2]);
|
||||
@@ -596,9 +611,10 @@ void CLASS xtrans_decode_block(struct xtrans_block* info, const struct xtrans_pa
|
||||
xtrans_extend_green (info->linebuf, line_width);
|
||||
xtrans_extend_blue (info->linebuf, line_width);
|
||||
|
||||
if(errcnt)
|
||||
if (errcnt) {
|
||||
derror();
|
||||
}
|
||||
}
|
||||
|
||||
void CLASS xtrans_decode_strip (const struct xtrans_params* info_common, int cur_block, INT64 raw_offset, unsigned dsize)
|
||||
{
|
||||
@@ -610,27 +626,29 @@ void CLASS xtrans_decode_strip(const struct xtrans_params* info_common, int cur_
|
||||
line_size = sizeof (ushort) * (info_common->line_width + 2);
|
||||
|
||||
cur_block_width = fuji_block_width;
|
||||
if (cur_block+1 == fuji_total_blocks)
|
||||
cur_block_width = raw_width % fuji_block_width;
|
||||
|
||||
struct i_pair
|
||||
{
|
||||
if (cur_block + 1 == fuji_total_blocks) {
|
||||
cur_block_width = raw_width % fuji_block_width;
|
||||
}
|
||||
|
||||
struct i_pair {
|
||||
int a, b;
|
||||
};
|
||||
|
||||
const i_pair mtable[6] = { {_R0, _R3}, {_R1, _R4}, {_G0, _G6}, {_G1, _G7}, {_B0, _B3}, {_B1, _B4}},
|
||||
ztable[3] = {{_R2, 3}, {_G2, 6}, {_B2, 3}};
|
||||
for (cur_line = 0; cur_line < fuji_total_lines; cur_line++)
|
||||
{
|
||||
|
||||
for (cur_line = 0; cur_line < fuji_total_lines; cur_line++) {
|
||||
xtrans_decode_block (&info, info_common, cur_line);
|
||||
|
||||
// copy data from line buffers and advance
|
||||
for(int i=0; i < 6; i++)
|
||||
for (int i = 0; i < 6; i++) {
|
||||
memcpy (info.linebuf[mtable[i].a], info.linebuf[mtable[i].b], line_size);
|
||||
}
|
||||
|
||||
copy_line_to_xtrans (&info, cur_line, cur_block, cur_block_width);
|
||||
|
||||
for(int i=0; i < 3; i++)
|
||||
{
|
||||
for (int i = 0; i < 3; i++) {
|
||||
memset (info.linebuf[ztable[i].a], 0, ztable[i].b * line_size);
|
||||
info.linebuf[ztable[i].a][0] = info.linebuf[ztable[i].a - 1][1];
|
||||
info.linebuf[ztable[i].a][info_common->line_width + 1] = info.linebuf[ztable[i].a - 1][info_common->line_width];
|
||||
@@ -645,8 +663,11 @@ void CLASS xtrans_decode_strip(const struct xtrans_params* info_common, int cur_
|
||||
static unsigned sgetn (int n, uchar *s)
|
||||
{
|
||||
unsigned result = 0;
|
||||
while (n-- > 0)
|
||||
|
||||
while (n-- > 0) {
|
||||
result = (result << 8) | (*s++);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -668,8 +689,10 @@ void CLASS xtrans_compressed_load_raw()
|
||||
merror (raw_block_offsets, "xtrans_load_raw()");
|
||||
|
||||
raw_offset = sizeof (unsigned) * fuji_total_blocks;
|
||||
if (raw_offset & 0xC)
|
||||
|
||||
if (raw_offset & 0xC) {
|
||||
raw_offset += 0x10 - (raw_offset & 0xC);
|
||||
}
|
||||
|
||||
raw_offset += data_offset;
|
||||
|
||||
@@ -677,15 +700,16 @@ void CLASS xtrans_compressed_load_raw()
|
||||
fread (block_sizes, 1, sizeof (unsigned)*fuji_total_blocks, ifp);
|
||||
|
||||
raw_block_offsets[0] = raw_offset;
|
||||
|
||||
// calculating raw block offsets
|
||||
for (cur_block = 0; cur_block < fuji_total_blocks; cur_block++)
|
||||
{
|
||||
for (cur_block = 0; cur_block < fuji_total_blocks; cur_block++) {
|
||||
unsigned bsize = sgetn (4, (uchar *) (block_sizes + cur_block));
|
||||
block_sizes[cur_block] = bsize;
|
||||
}
|
||||
|
||||
for (cur_block = 1; cur_block < fuji_total_blocks; cur_block++)
|
||||
for (cur_block = 1; cur_block < fuji_total_blocks; cur_block++) {
|
||||
raw_block_offsets[cur_block] = raw_block_offsets[cur_block - 1] + block_sizes[cur_block - 1] ;
|
||||
}
|
||||
|
||||
xtrans_decode_loop (&common_info, fuji_total_blocks, raw_block_offsets, block_sizes);
|
||||
|
||||
@@ -696,12 +720,12 @@ void CLASS xtrans_compressed_load_raw()
|
||||
|
||||
void CLASS xtrans_decode_loop (const struct xtrans_params* common_info, int count, INT64* raw_block_offsets, unsigned *block_sizes)
|
||||
{
|
||||
int cur_block;
|
||||
|
||||
#ifdef _OPENMP
|
||||
#pragma omp parallel for private(cur_block)
|
||||
#pragma omp parallel for
|
||||
#endif
|
||||
for (cur_block = 0; cur_block < count ; cur_block++)
|
||||
{
|
||||
|
||||
for (int cur_block = 0; cur_block < count ; cur_block++) {
|
||||
xtrans_decode_strip (common_info, cur_block, raw_block_offsets[cur_block], block_sizes[cur_block]);
|
||||
}
|
||||
}
|
||||
@@ -763,6 +787,7 @@ void CLASS parse_xtrans_header()
|
||||
xtransCompressed = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// modify data
|
||||
fuji_total_lines = h_total_lines;
|
||||
fuji_total_blocks = h_blocks_in_row;
|
||||
|
Reference in New Issue
Block a user