36 #define YUVoffset4 8 // 2^3 37 #define YUVoffset6 32 // 2^5 38 #define YUVoffset8 128 // 2^7 39 #define YUVoffset16 32768 // 2^15 47 OSError GetLastPGFError() {
48 OSError tmp = _PGF_Error_;
49 _PGF_Error_ = NoError;
56 struct DebugBGRImage {
57 int width, height, pitch;
76 #ifdef __PGFROISUPPORT__ 205 if (!
m_channel[c]) ReturnWithError(InsufficientMemory);
208 for (UINT32 i=0; i < size; i++) {
211 if (count !=
DataTSize) ReturnWithError(MissingData);
322 if (bpc > 31) bpc = 31;
360 #ifdef __PGFROISUPPORT__ 367 while (currentLevel > level) {
381 if (err != NoError) ReturnWithError(err);
406 #ifdef __PGFROISUPPORT__ 410 Read(rect, level, cb, data);
420 if ((*cb)(1.0,
true, data)) ReturnWithError(EscapePressed);
449 volatile OSError error = NoError;
450 #ifdef LIBPGF_USE_OPENMP 451 #pragma omp parallel for default(shared) 455 if (error == NoError) {
457 if (err != NoError) error = err;
461 if (error != NoError) ReturnWithError(error);
473 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
479 #ifdef __PGFROISUPPORT__ 496 Read(level, cb, data);
510 if (levelDiff <= 0) {
533 for (UINT32 tileY=0; tileY < nTiles; tileY++) {
534 for (UINT32 tileX=0; tileX < nTiles; tileX++) {
549 volatile OSError error = NoError;
550 #ifdef LIBPGF_USE_OPENMP 551 #pragma omp parallel for default(shared) 555 if (error == NoError) {
557 if (err != NoError) error = err;
561 if (error != NoError) ReturnWithError(error);
573 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
591 return PGFRect(rLeft, rTop, rRight - rLeft, rBottom - rTop);
606 ASSERT(roi.Width() ==
m_width[c]);
607 ASSERT(roi.Height() ==
m_height[c]);
642 #endif // __PGFROISUPPORT__ 662 ASSERT(targetLen > 0);
673 ASSERT(len >= 0 && len <= targetLen);
710 ASSERT(targetLen > 0);
729 ASSERT(len >= 0 && len <= targetLen);
742 while(maxValue > 0) {
747 if (pot > bpc) pot = bpc;
748 if (pot > 31) pot = 31;
797 RgbToYuv(pitch, buff, bpp, channelMap, cb, data);
816 const int oddW = w%2;
823 for (
int i=0; i < h2; i++) {
824 for (
int j=0; j < w2; j++) {
826 buff[sampledPos] = (buff[loPos] + buff[loPos + 1] + buff[hiPos] + buff[hiPos + 1]) >> 2;
827 loPos += 2; hiPos += 2;
831 buff[sampledPos] = (buff[loPos] + buff[hiPos]) >> 1;
835 loPos += w; hiPos += w;
838 for (
int j=0; j < w2; j++) {
839 buff[sampledPos] = (buff[loPos] + buff[loPos+1]) >> 1;
840 loPos += 2; hiPos += 2;
844 buff[sampledPos] = buff[loPos];
862 while (s > maxThumbnailWidth) {
900 #ifdef __PGFROISUPPORT__ 941 if (userDataLength && userData) {
966 ReturnWithError(InsufficientMemory);
984 volatile OSError error = NoError;
986 #ifdef LIBPGF_USE_OPENMP 987 #pragma omp parallel for default(shared) 990 DataT *temp =
nullptr;
991 if (error == NoError) {
996 temp =
new(std::nothrow)
DataT[size];
1002 error = InsufficientMemory;
1005 if (error == NoError) {
1012 #ifdef __PGFROISUPPORT__ 1019 if (err != NoError) error = err;
1023 error = InsufficientMemory;
1028 if (error != NoError) {
1033 ReturnWithError(error);
1042 #ifdef __PGFROISUPPORT__ 1057 return (nBytes > 0) ? (UINT32)nBytes : 0;
1073 #ifdef __PGFROISUPPORT__ 1080 const UINT32 lastTile = nTiles - 1;
1084 ASSERT(nTiles == 1);
1088 for (UINT32 tileY=0; tileY < nTiles; tileY++) {
1089 for (UINT32 tileX=0; tileX < nTiles; tileX++) {
1094 if (i == lastChannel && tileY == lastTile && tileX == lastTile) {
1155 double percent = pow(0.25, levels);
1166 for (UINT32 i=0; i < size; i++) {
1174 if ((*cb)(1,
true, data)) ReturnWithError(EscapePressed);
1189 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
1205 return nWrittenBytes;
1232 if (nWrittenBytes) *nWrittenBytes += nBytes;
1235 #ifdef __PGFROISUPPORT__ 1258 UINT32 nWrittenBytes = 0;
1282 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
1296 return nWrittenBytes;
1298 #endif // __PGFROISUPPORT__ 1351 if (iFirstColor + nColors >
ColorTableLen) ReturnWithError(ColorTableError);
1353 for (UINT32 i=iFirstColor, j=0; j < nColors; i++, j++) {
1365 if (iFirstColor + nColors >
ColorTableLen) ReturnWithError(ColorTableError);
1367 for (UINT32 i=iFirstColor, j=0; j < nColors; i++, j++) {
1391 UINT32 yPos = 0, cnt = 0;
1394 int defMap[] = { 0, 1, 2, 3, 4, 5, 6, 7 }; ASSERT(
sizeof(defMap)/
sizeof(defMap[0]) ==
MaxChannels);
1396 if (channelMap ==
nullptr) channelMap = defMap;
1412 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
1416 for (UINT32 j = 0; j < w2; j++) {
1417 UINT8
byte = buff[j];
1418 for (
int k = 0; k < 8; k++) {
1419 UINT8 bit = (
byte & 0x80) >> 7;
1420 if (cnt < w) y[yPos++] = bit;
1459 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
1480 ASSERT(bpp%16 == 0);
1482 UINT16 *buff16 = (UINT16 *)buff;
1483 const int pitch16 = pitch/2;
1490 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
1497 m_channel[c][yPos] = (buff16[cnt + channelMap[c]] >> shift) - yuvOffset16;
1520 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
1526 b = buff[cnt + channelMap[0]];
1527 g = buff[cnt + channelMap[1]];
1528 r = buff[cnt + channelMap[2]];
1530 y[yPos] = ((b + (g << 1) + r) >> 2) -
YUVoffset8;
1544 ASSERT(bpp%16 == 0);
1546 UINT16 *buff16 = (UINT16 *)buff;
1547 const int pitch16 = pitch/2;
1559 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
1565 b = buff16[cnt + channelMap[0]] >> shift;
1566 g = buff16[cnt + channelMap[1]] >> shift;
1567 r = buff16[cnt + channelMap[2]] >> shift;
1569 y[yPos] = ((b + (g << 1) + r) >> 2) - yuvOffset16;
1595 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
1601 b = buff[cnt + channelMap[0]];
1602 g = buff[cnt + channelMap[1]];
1603 r = buff[cnt + channelMap[2]];
1605 y[yPos] = ((b + (g << 1) + r) >> 2) -
YUVoffset8;
1608 a[yPos++] = buff[cnt + channelMap[3]] -
YUVoffset8;
1619 ASSERT(bpp%16 == 0);
1621 UINT16 *buff16 = (UINT16 *)buff;
1622 const int pitch16 = pitch/2;
1635 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
1641 b = buff16[cnt + channelMap[0]] >> shift;
1642 g = buff16[cnt + channelMap[1]] >> shift;
1643 r = buff16[cnt + channelMap[2]] >> shift;
1645 y[yPos] = ((b + (g << 1) + r) >> 2) - yuvOffset16;
1648 a[yPos++] = (buff16[cnt + channelMap[3]] >> shift) - yuvOffset16;
1655 #ifdef __PGF32SUPPORT__ 1665 UINT32 *buff32 = (UINT32 *)buff;
1666 const int pitch32 = pitch/4;
1672 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
1677 y[yPos++] = (buff32[w] >> shift) - yuvOffset31;
1694 UINT8 rgb = 0, b, g, r;
1698 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
1708 g = (rgb & 0xF0) >> 4;
1714 b = (rgb & 0xF0) >> 4;
1718 r = (rgb & 0xF0) >> 4;
1723 y[yPos] = ((b + (g << 1) + r) >> 2) -
YUVoffset4;
1742 UINT16 *buff16 = (UINT16 *)buff;
1743 UINT16 rgb, b, g, r;
1744 const int pitch16 = pitch/2;
1748 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
1753 r = (rgb & 0xF800) >> 10;
1754 g = (rgb & 0x07E0) >> 5;
1755 b = (rgb & 0x001F) << 1;
1757 y[yPos] = ((b + (g << 1) + r) >> 2) -
YUVoffset6;
1789 void CPGFImage::GetBitmap(
int pitch, UINT8* buff, BYTE bpp,
int channelMap[] , CallbackPtr cb ,
void *data )
const {
1795 UINT32 roiOffsetX = 0;
1796 UINT32 roiOffsetY = 0;
1800 #ifdef __PGFROISUPPORT__ 1804 ASSERT(roi.
left <= levelRoi.left && levelRoi.right <= roi.
right);
1805 ASSERT(roi.
top <= levelRoi.top && levelRoi.bottom <= roi.
bottom);
1807 if (
ROIisSupported() && (levelRoi.Width() < w || levelRoi.Height() < h)) {
1809 w = levelRoi.Width();
1810 h = levelRoi.Height();
1811 roiOffsetX = levelRoi.left - roi.
left;
1812 roiOffsetY = levelRoi.top - roi.
top;
1813 yOffset = roiOffsetX + roiOffsetY*yw;
1817 uOffset = levelRoi.left/2 - downsampledRoi.
left + (levelRoi.top/2 - downsampledRoi.
top)*
m_width[1];
1824 const double dP = 1.0/h;
1825 int defMap[] = { 0, 1, 2, 3, 4, 5, 6, 7 }; ASSERT(
sizeof(defMap)/
sizeof(defMap[0]) ==
MaxChannels);
1826 if (channelMap ==
nullptr) channelMap = defMap;
1838 const UINT32 w2 = (w + 7)/8;
1844 for (i = 0; i < h; i++) {
1846 for (j = 0; j < w2; j++) {
1848 for (
int k = 0; k < 8; k++) {
1852 bit = y[yOffset + cnt] & 1;
1864 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
1871 yOffset = roiOffsetX/8 + roiOffsetY*yw;
1872 for (i = 0; i < h; i++) {
1873 for (j = 0; j < w2; j++) {
1881 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
1898 for (i=0; i < h; i++) {
1899 UINT32 yPos = yOffset;
1901 for (j=0; j < w; j++) {
1913 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
1924 UINT32 cnt, channels;
1928 UINT16 *buff16 = (UINT16 *)buff;
1929 int pitch16 = pitch/2;
1932 for (i=0; i < h; i++) {
1933 UINT32 yPos = yOffset;
1935 for (j=0; j < w; j++) {
1937 buff16[cnt + channelMap[c]] =
Clamp16((
m_channel[c][yPos] + yuvOffset16) << shift);
1947 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
1955 for (i=0; i < h; i++) {
1956 UINT32 yPos = yOffset;
1958 for (j=0; j < w; j++) {
1960 buff[cnt + channelMap[c]] =
Clamp8((
m_channel[c][yPos] + yuvOffset16) >> shift);
1970 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
1986 UINT8 *buffg = &buff[channelMap[1]],
1987 *buffr = &buff[channelMap[2]],
1988 *buffb = &buff[channelMap[0]];
1990 UINT32 cnt, channels = bpp/8;
1993 for (i=0; i < h; i++) {
1994 UINT32 uPos = uOffset;
1995 UINT32 yPos = yOffset;
1997 for (j=0; j < w; j++) {
2003 buffr[cnt] =
Clamp8(uAvg + g);
2004 buffb[cnt] =
Clamp8(vAvg + g);
2009 if (i & 1) uOffset += uw;
2017 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
2022 for (i=0; i < h; i++) {
2024 UINT32 yPos = yOffset;
2025 for (j = 0; j < w; j++) {
2030 buffr[cnt] =
Clamp8(uAvg + g);
2031 buffb[cnt] =
Clamp8(vAvg + g);
2042 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
2058 UINT32 cnt, channels;
2061 if (bpp >= 48 && bpp%16 == 0) {
2063 UINT16 *buff16 = (UINT16 *)buff;
2064 int pitch16 = pitch/2;
2067 for (i=0; i < h; i++) {
2068 UINT32 uPos = uOffset;
2069 UINT32 yPos = yOffset;
2071 for (j=0; j < w; j++) {
2075 g = y[yPos] + yuvOffset16 - ((uAvg + vAvg ) >> 2);
2076 buff16[cnt + channelMap[1]] =
Clamp16(g << shift);
2077 buff16[cnt + channelMap[2]] =
Clamp16((uAvg + g) << shift);
2078 buff16[cnt + channelMap[0]] =
Clamp16((vAvg + g) << shift);
2089 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
2097 for (i=0; i < h; i++) {
2098 UINT32 uPos = uOffset;
2099 UINT32 yPos = yOffset;
2101 for (j=0; j < w; j++) {
2105 g = y[yPos] + yuvOffset16 - ((uAvg + vAvg ) >> 2);
2106 buff[cnt + channelMap[1]] =
Clamp8(g >> shift);
2107 buff[cnt + channelMap[2]] =
Clamp8((uAvg + g) >> shift);
2108 buff[cnt + channelMap[0]] =
Clamp8((vAvg + g) >> shift);
2119 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
2136 for (i=0; i < h; i++) {
2137 UINT32 uPos = uOffset;
2138 UINT32 yPos = yOffset;
2140 for (j=0; j < w; j++) {
2156 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
2171 UINT32 cnt, channels;
2175 UINT16 *buff16 = (UINT16 *)buff;
2176 int pitch16 = pitch/2;
2179 for (i=0; i < h; i++) {
2180 UINT32 uPos = uOffset;
2181 UINT32 yPos = yOffset;
2183 for (j=0; j < w; j++) {
2186 buff16[cnt + channelMap[0]] =
Clamp16((l[yPos] + yuvOffset16) << shift);
2187 buff16[cnt + channelMap[1]] =
Clamp16((uAvg + yuvOffset16) << shift);
2188 buff16[cnt + channelMap[2]] =
Clamp16((vAvg + yuvOffset16) << shift);
2199 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
2207 for (i=0; i < h; i++) {
2208 UINT32 uPos = uOffset;
2209 UINT32 yPos = yOffset;
2211 for (j=0; j < w; j++) {
2214 buff[cnt + channelMap[0]] =
Clamp8((l[yPos] + yuvOffset16) >> shift);
2215 buff[cnt + channelMap[1]] =
Clamp8((uAvg + yuvOffset16) >> shift);
2216 buff[cnt + channelMap[2]] =
Clamp8((vAvg + yuvOffset16) >> shift);
2227 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
2247 for (i=0; i < h; i++) {
2248 UINT32 uPos = uOffset;
2249 UINT32 yPos = yOffset;
2251 for (j=0; j < w; j++) {
2256 buff[cnt + channelMap[1]] = g =
Clamp8(y[yPos] +
YUVoffset8 - ((uAvg + vAvg ) >> 2));
2257 buff[cnt + channelMap[2]] =
Clamp8(uAvg + g);
2258 buff[cnt + channelMap[0]] =
Clamp8(vAvg + g);
2259 buff[cnt + channelMap[3]] = aAvg;
2270 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
2287 UINT32 cnt, channels;
2291 UINT16 *buff16 = (UINT16 *)buff;
2292 int pitch16 = pitch/2;
2295 for (i=0; i < h; i++) {
2296 UINT32 uPos = uOffset;
2297 UINT32 yPos = yOffset;
2299 for (j=0; j < w; j++) {
2302 aAvg = a[uPos] + yuvOffset16;
2304 g = y[yPos] + yuvOffset16 - ((uAvg + vAvg ) >> 2);
2305 buff16[cnt + channelMap[1]] =
Clamp16(g << shift);
2306 buff16[cnt + channelMap[2]] =
Clamp16((uAvg + g) << shift);
2307 buff16[cnt + channelMap[0]] =
Clamp16((vAvg + g) << shift);
2308 buff16[cnt + channelMap[3]] =
Clamp16(aAvg << shift);
2319 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
2327 for (i=0; i < h; i++) {
2328 UINT32 uPos = uOffset;
2329 UINT32 yPos = yOffset;
2331 for (j=0; j < w; j++) {
2334 aAvg = a[uPos] + yuvOffset16;
2336 g = y[yPos] + yuvOffset16 - ((uAvg + vAvg ) >> 2);
2337 buff[cnt + channelMap[1]] =
Clamp8(g >> shift);
2338 buff[cnt + channelMap[2]] =
Clamp8((uAvg + g) >> shift);
2339 buff[cnt + channelMap[0]] =
Clamp8((vAvg + g) >> shift);
2340 buff[cnt + channelMap[3]] =
Clamp8(aAvg >> shift);
2351 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
2357 #ifdef __PGF32SUPPORT__ 2368 UINT32 *buff32 = (UINT32 *)buff;
2369 int pitch32 = pitch/4;
2371 for (i=0; i < h; i++) {
2372 UINT32 yPos = yOffset;
2373 for (j = 0; j < w; j++) {
2374 buff32[j] =
Clamp31((y[yPos++] + yuvOffset31) << shift);
2381 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
2384 }
else if (bpp == 16) {
2386 UINT16 *buff16 = (UINT16 *)buff;
2387 int pitch16 = pitch/2;
2389 if (usedBits < 16) {
2390 const int shift = 16 - usedBits;
2391 for (i=0; i < h; i++) {
2392 UINT32 yPos = yOffset;
2393 for (j = 0; j < w; j++) {
2394 buff16[j] =
Clamp16((y[yPos++] + yuvOffset31) << shift);
2401 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
2405 const int shift =
__max(0, usedBits - 16);
2406 for (i=0; i < h; i++) {
2407 UINT32 yPos = yOffset;
2408 for (j = 0; j < w; j++) {
2409 buff16[j] =
Clamp16((y[yPos++] + yuvOffset31) >> shift);
2416 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
2424 for (i=0; i < h; i++) {
2425 UINT32 yPos = yOffset;
2426 for (j = 0; j < w; j++) {
2427 buff[j] =
Clamp8((y[yPos++] + yuvOffset31) >> shift);
2434 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
2454 for (i=0; i < h; i++) {
2455 UINT32 yPos = yOffset;
2457 for (j=0; j < w; j++) {
2463 buff[cnt] = UINT8(
Clamp4(vAvg + yval) | (yval << 4));
2465 buff[cnt] =
Clamp4(uAvg + yval);
2467 buff[cnt] |=
Clamp4(vAvg + yval) << 4;
2469 buff[cnt] = UINT8(yval | (
Clamp4(uAvg + yval) << 4));
2479 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
2495 UINT16 *buff16 = (UINT16 *)buff;
2496 int pitch16 = pitch/2;
2498 for (i=0; i < h; i++) {
2499 UINT32 yPos = yOffset;
2500 for (j = 0; j < w; j++) {
2505 buff16[j] = (yval << 5) | ((
Clamp6(uAvg + yval) >> 1) << 11) | (
Clamp6(vAvg + yval) >> 1);
2512 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
2524 roiimage.height = h;
2526 roiimage.pitch = pitch;
2527 roiimage.data = buff;
2529 roiimage.pitch = -pitch;
2530 roiimage.data = buff + (h - 1)*pitch;
2554 const bool wOdd = (1 == w%2);
2555 const int dataBits =
DataTSize*8; ASSERT(dataBits == 16 || dataBits == 32);
2558 const double dP = 1.0/h;
2560 int defMap[] = { 0, 1, 2, 3, 4, 5, 6, 7 }; ASSERT(
sizeof(defMap)/
sizeof(defMap[0]) ==
MaxChannels);
2561 if (channelMap ==
nullptr) channelMap = defMap;
2562 int sampledPos = 0, yPos = 0;
2568 ASSERT(bpp%dataBits == 0);
2575 for (i=0; i < h; i++) {
2576 if (i%2) sampledPos -= (w + 1)/2;
2578 for (j=0; j < w; j++) {
2581 uAvg = u[sampledPos];
2582 vAvg = v[sampledPos];
2587 buff[cnt + channelMap[0]] = y[yPos];
2588 buff[cnt + channelMap[1]] = uAvg;
2589 buff[cnt + channelMap[2]] = vAvg;
2592 if (j%2) sampledPos++;
2595 if (wOdd) sampledPos++;
2599 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
2604 ASSERT(bpp%dataBits == 0);
2613 for (i=0; i < h; i++) {
2614 if (i%2) sampledPos -= (w + 1)/2;
2616 for (j=0; j < w; j++) {
2619 uAvg = u[sampledPos];
2620 vAvg = v[sampledPos];
2621 aAvg =
Clamp8(a[sampledPos] + yuvOffset);
2625 aAvg =
Clamp8(a[yPos] + yuvOffset);
2628 buff[cnt + channelMap[0]] = y[yPos];
2629 buff[cnt + channelMap[1]] = uAvg;
2630 buff[cnt + channelMap[2]] = vAvg;
2631 buff[cnt + channelMap[3]] = aAvg;
2634 if (j%2) sampledPos++;
2637 if (wOdd) sampledPos++;
2641 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
2664 const int dataBits =
DataTSize*8; ASSERT(dataBits == 16 || dataBits == 32);
2668 int yPos = 0, cnt = 0;
2670 int defMap[] = { 0, 1, 2, 3, 4, 5, 6, 7 }; ASSERT(
sizeof(defMap)/
sizeof(defMap[0]) ==
MaxChannels);
2672 if (channelMap ==
nullptr) channelMap = defMap;
2675 ASSERT(bpp%dataBits == 0);
2684 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
2690 y[yPos] = buff[cnt + channelMap[0]];
2691 u[yPos] = buff[cnt + channelMap[1]];
2692 v[yPos] = buff[cnt + channelMap[2]];
2699 ASSERT(bpp%dataBits == 0);
2709 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
2715 y[yPos] = buff[cnt + channelMap[0]];
2716 u[yPos] = buff[cnt + channelMap[1]];
2717 v[yPos] = buff[cnt + channelMap[2]];
2718 a[yPos] = buff[cnt + channelMap[3]] - yuvOffset;
void Open(CPGFStream *stream)
void SetColorTable(UINT32 iFirstColor, UINT32 nColors, const RGBQUAD *prgbColors)
virtual void Read(int *count, void *buffer)=0
void Read(int level=0, CallbackPtr cb=nullptr, void *data=nullptr)
bool m_favorSpeedOverSize
favor encoding speed over compression ratio
UINT64 m_userDataPos
stream position of user data
bool m_useOMPinDecoder
use Open MP in decoder
UINT8 version
PGF version.
UINT32 ReadEncodedHeader(UINT8 *target, UINT32 targetLen) const
#define PGFVersion
current standard version
void GetYUV(int pitch, DataT *buff, BYTE bpp, int channelMap[]=nullptr, CallbackPtr cb=nullptr, void *data=nullptr) const
void Dequantize(int quantParam)
const UINT8 * GetUserData(UINT32 &cachedSize, UINT32 *pTotalSize=nullptr) const
virtual void Write(int *count, void *buffer)=0
#define MaxChannels
maximum number of (color) channels
Abstract stream base class.
BYTE UsedBitsPerChannel() const
void GetBitmap(int pitch, UINT8 *buff, BYTE bpp, int channelMap[]=nullptr, CallbackPtr cb=nullptr, void *data=nullptr) const
void ExtractTile(CEncoder &encoder, bool tile=false, UINT32 tileX=0, UINT32 tileY=0)
UINT32 ReadEncodedData(int level, UINT8 *target, UINT32 targetLen) const
CDecoder * m_decoder
PGF decoder.
UINT32 GetEncodedLevelLength(int level) const
void ImportYUV(int pitch, DataT *buff, BYTE bpp, int channelMap[]=nullptr, CallbackPtr cb=nullptr, void *data=nullptr)
PGFHeader m_header
PGF file header.
bool m_streamReinitialized
stream has been reinitialized
void DecodeInterleaved(CWaveletTransform *wtChannel, int level, int quantParam)
BYTE m_quant
quantization parameter
void * m_cbArg
refresh callback argument
DataT * m_channel[MaxChannels]
untransformed channels in YUV format
PGFPreHeader m_preHeader
PGF pre-header.
void SetStreamPosToData()
Resets stream position to beginning of data block.
UINT32 GetEncodedHeaderLength() const
static UINT32 LevelSizeL(UINT32 size, int level)
UINT32 WriteLevelLength(UINT32 *&levelLength)
void SetROI(PGFRect rect)
const RGBQUAD * GetColorTable() const
#define PGFMagic
PGF identification.
PGFRect GetAlignedROI(int c=0) const
UINT32 WriteImage(CPGFStream *stream, CallbackPtr cb=nullptr, void *data=nullptr)
#define Version6
hSize in PGFPreHeader uses 32 bits instead of 16 bits
static BYTE CodecMajorVersion(BYTE version=PGFVersion)
Return major version.
UINT16 Clamp6(DataT v) const
#define ColorTableLen
size of color lookup table (clut)
#define MaxLevel
maximum number of transform levels
void UpdatePostHeaderSize(PGFPreHeader preHeader)
ProgressMode m_progressMode
progress mode used in Read and Write; PM_Relative is default mode
CWaveletTransform * m_wtChannel[MaxChannels]
wavelet transformed color channels
void PlaceTile(CDecoder &decoder, int quantParam, bool tile=false, UINT32 tileX=0, UINT32 tileY=0)
char magic[3]
PGF identification = "PGF".
PGFPostHeader m_postHeader
PGF post-header.
UINT32 Clamp31(DataT v) const
UINT16 Clamp16(DataT v) const
INT64 ComputeBufferLength() const
bool m_downsample
chrominance channels are downsampled
#define DownsampleThreshold
if quality is larger than this threshold than downsampling is used
UINT32 * m_levelLength
length of each level in bytes; first level starts immediately after this array
UINT32 WriteHeader(CPGFStream *stream)
UINT32 m_width[MaxChannels]
width of each channel at current level
#define Version2
data structure PGFHeader of major version 2
CPGFImage()
Standard constructor.
void SetStreamPosToStart()
Resets stream position to beginning of PGF pre-header.
void SetHeader(const PGFHeader &header, BYTE flags=0, const UINT8 *userData=0, UINT32 userDataLength=0)
bool ROIisSupported() const
#define MaxQuality
maximum quality
bool m_useOMPinEncoder
use Open MP in encoder
INT64 ComputeHeaderLength() const
virtual ~CPGFImage()
Destructor.
UINT32 UpdateLevelLength()
void Reconstruct(int level=0)
UINT8 Clamp8(DataT v) const
UINT8 Clamp4(DataT v) const
UINT32 ReadEncodedData(UINT8 *target, UINT32 len) const
void FavorSpeedOverSize()
Encoder favors speed over compression size.
UINT32 GetEncodedHeaderLength() const
UINT32 m_userDataPolicy
user data (metadata) policy during open
double m_percent
progress [0..1]
#define Version7
Codec major and minor version number stored in PGFHeader.
void RgbToYuv(int pitch, UINT8 *rgbBuff, BYTE bpp, int channelMap[], CallbackPtr cb, void *data)
void ImportBitmap(int pitch, UINT8 *buff, BYTE bpp, int channelMap[]=nullptr, CallbackPtr cb=nullptr, void *data=nullptr)
void ResetStreamPos(bool startOfData)
void SetMaxValue(UINT32 maxValue)
RefreshCB m_cb
pointer to refresh callback procedure
static bool ImportIsSupported(BYTE mode)
CEncoder * m_encoder
PGF encoder.
void SetStreamPosToStart()
Resets stream position to beginning of PGF pre-header.
INT64 ComputeOffset() const
void Downsample(int nChannel)
int m_currentLevel
transform level of current image
PGFRect ComputeLevelROI() const
void Write(CPGFStream *stream, UINT32 *nWrittenBytes=nullptr, CallbackPtr cb=nullptr, void *data=nullptr)
version number stored in header since major version 7
#define Version5
new coding scheme since major version 5
UINT32 m_height[MaxChannels]
height of each channel at current level
UINT32 UpdatePostHeaderSize()
PGFRect m_roi
region of interest
void SetEncodedLevel(int currentLevel)