28 #include "rawdata.hpp"
29 #include "olympusdecompressor.hpp"
30 #include "bititerator.hpp"
35 static void decompressOlympus(
const uint8_t* buffer,
size_t size, uint16_t* data16,
36 uint32_t w, uint32_t h);
39 static void decompressOlympus(
const uint8_t* buffer,
size_t size, uint16_t* data16,
40 uint32_t w, uint32_t h)
42 int nbits, sign, low, high, n;
46 int acarry[2][3], pred, diff;
53 for (
int i = 0; i < 4096; i++) {
55 for (high = 0; high < 12; high++) {
56 if ((b >> (11 - high)) & 1) {
65 BitIterator bits(buffer, size - 7);
67 for (uint32_t y = 0; y < h; y++) {
68 memset(acarry, 0,
sizeof acarry);
70 uint16_t* dest = &data16[(y * pitch)/2];
71 for (uint32_t x = 0; x < w / 2; x++) {
73 for (
int p = 0; p < 2; p++) {
74 int i = 2 * (acarry[p][2] < 3);
75 for (nbits = 2 + i; (uint16_t)acarry[p][0] >> (nbits + i); nbits++) {
78 uint32_t b = bits.peek(15);
79 sign = (b >> 14) * -1;
81 high = bittable[b & 4095];
83 bits.skip(std::min(12 + 3, high + 1 + 3));
86 high = bits.get(16 - nbits) >> 1;
89 acarry[p][0] = (high << nbits) | bits.get(nbits);
90 diff = (acarry[p][0] ^ sign) + acarry[p][1];
91 acarry[p][1] = (diff * 3 + acarry[p][1]) >> 5;
92 acarry[p][2] = acarry[p][0] > 16 ? 0 : acarry[p][2] + 1;
94 if (y < 2 || col < 2) {
95 if (y < 2 && col < 2) {
102 pred = dest[-pitch + (int)(col + p)];
105 dest[col + p] = pred + ((diff << 2) | low);
107 wo[p] = dest[col + p];
110 n = dest[-pitch + (int)(col + p)];
111 if (((wo[p] < nw[p]) & (nw[p] < n)) | ((n < nw[p]) & (nw[p] < wo[p]))) {
112 if (abs(wo[p] - nw[p]) > 32 || abs(n - nw[p]) > 32) {
113 pred = wo[p] + n - nw[p];
115 pred = (wo[p] + n) >> 1;
118 pred = abs(wo[p] - nw[p]) > abs(n - nw[p]) ? wo[p] : n;
121 dest[col + p] = pred + ((diff << 2) | low);
123 wo[p] = dest[col + p];
133 RawDataPtr output(
new RawData);
135 output->allocData(m_w * m_h * 2);
136 decompressOlympus(m_buffer, m_size, (uint16_t*)output->data(), m_w, m_h);
140 output->setWhiteLevel((1 << 12) - 1);
virtual RawDataPtr decompress() override
Represent camera raw data.
Global namespace for libopenraw.