Merge pull request #5464 from Beep6581/hasselblad_load_review

Improve readability of hasselblad_load_raw() code, #5434
This commit is contained in:
Ingo Weyrich 2019-09-23 14:23:15 +02:00 committed by GitHub
commit eae86cbd35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2418,58 +2418,77 @@ void CLASS hasselblad_correct()
void CLASS hasselblad_load_raw() void CLASS hasselblad_load_raw()
{ {
struct jhead jh; struct jhead jh;
int shot, row, col, *back[5], len[2], diff[12], pred, sh, f, s, c; int *back[5], diff[12];
unsigned upix, urow, ucol;
ushort *ip;
if (!ljpeg_start (&jh, 0)) return; if (!ljpeg_start (&jh, 0)) {
return;
}
order = 0x4949; order = 0x4949;
ph1_bithuff_t ph1_bithuff(this, ifp, order); ph1_bithuff_t ph1_bithuff(this, ifp, order);
hb_bits(-1); hb_bits(-1);
back[4] = (int *) calloc (raw_width, 3*sizeof **back); back[4] = (int *) calloc(raw_width, 3 * sizeof **back);
merror (back[4], "hasselblad_load_raw()"); merror(back[4], "hasselblad_load_raw()");
FORC3 back[c] = back[4] + c*raw_width; for (int c = 0; c < 3; ++c) {
cblack[6] >>= sh = tiff_samples > 1; back[c] = back[4] + c * raw_width;
shot = LIM(shot_select, 1, tiff_samples) - 1; }
for (row=0; row < raw_height; row++) { const int sh = tiff_samples > 1;
FORC4 back[(c+3) & 3] = back[c]; cblack[6] >>= sh;
for (col=0; col < raw_width; col+=2) { const int shot = LIM(shot_select, 1, tiff_samples) - 1;
for (s=0; s < tiff_samples*2; s+=2) { for (int row = 0; row < raw_height; ++row) {
FORC(2) len[c] = ph1_huff(jh.huff[0]); for (int c = 0; c < 4; ++c) {
FORC(2) { back[(c + 3) & 3] = back[c];
diff[s+c] = hb_bits(len[c]); }
if ((diff[s+c] & (1 << (len[c]-1))) == 0) for (int col = 0; col < raw_width; col += 2) {
diff[s+c] -= (1 << len[c]) - 1; for (int s = 0; s < tiff_samples * 2; s += 2) {
if (diff[s+c] == 65535) diff[s+c] = -32768; const int len[2]= {
ph1_huff(jh.huff[0]),
ph1_huff(jh.huff[0])
};
for (int c = 0; c < 2; ++c) {
diff[s + c] = hb_bits(len[c]);
if ((diff[s + c] & (1 << (len[c] - 1))) == 0) {
diff[s + c] -= (1 << len[c]) - 1;
}
if (diff[s + c] == 65535) {
diff[s + c] = -32768;
} }
} }
for (s=col; s < col+2; s++) { }
for (int s = col; s < col + 2; ++s) {
int pred;
if (col) {
pred = back[2][s - 2];
if (row > 1 && jh.psv == 11) {
pred += back[0][s] / 2 - back[0][s - 2] / 2;
}
} else {
pred = 0x8000 + load_flags; pred = 0x8000 + load_flags;
if (col) pred = back[2][s-2];
if (col && row > 1) switch (jh.psv) {
case 11: pred += back[0][s]/2 - back[0][s-2]/2; break;
} }
f = (row & 1)*3 ^ ((col+s) & 1); for (int c = 0; c < tiff_samples; ++c) {
FORC (tiff_samples) { pred += diff[(s & 1) * tiff_samples + c];
pred += diff[(s & 1)*tiff_samples+c]; const unsigned upix = pred >> sh & 0xffff;
upix = pred >> sh & 0xffff; if (raw_image && c == shot) {
if (raw_image && c == shot) RAW(row, s) = upix;
RAW(row,s) = upix; }
if (image) { if (image) {
urow = row-top_margin + (c & 1); const int f = (row & 1) * 3 ^ ((col + s) & 1);
ucol = col-left_margin - ((c >> 1) & 1); const unsigned urow = row - top_margin + (c & 1);
ip = &image[urow*width+ucol][f]; const unsigned ucol = col - left_margin - ((c >> 1) & 1);
if (urow < height && ucol < width) ushort* const ip = &image[urow * width + ucol][f];
if (urow < height && ucol < width) {
*ip = c < 4 ? upix : (*ip + upix) >> 1; *ip = c < 4 ? upix : (*ip + upix) >> 1;
} }
} }
}
back[2][s] = pred; back[2][s] = pred;
} }
} }
} }
free (back[4]); free(back[4]);
ljpeg_end (&jh); ljpeg_end(&jh);
if (image) mix_green = 1; if (image) {
mix_green = 1;
}
} }
void CLASS leaf_hdr_load_raw() void CLASS leaf_hdr_load_raw()