35 #define YUVoffset4 8 // 2^3 36 #define YUVoffset6 32 // 2^5 37 #define YUVoffset8 128 // 2^7 38 #define YUVoffset16 32768 // 2^15 46 OSError GetLastPGFError() {
47 OSError tmp = _PGF_Error_;
48 _PGF_Error_ = NoError;
63 , m_favorSpeedOverSize(false)
64 , m_useOMPinEncoder(true)
65 , m_useOMPinDecoder(true)
66 , m_skipUserData(false)
68 , m_streamReinitialized(false)
195 if (!
m_channel[c]) ReturnWithError(InsufficientMemory);
198 for (UINT32 i=0; i < size; i++) {
201 if (count !=
DataTSize) ReturnWithError(MissingData);
309 if (bpc > 31) bpc = 31;
349 while (currentLevel > level) {
363 if (err != NoError) ReturnWithError(err);
388 #ifdef __PGFROISUPPORT__ 392 Read(rect, level, cb, data);
402 if ((*cb)(1.0,
true, data)) ReturnWithError(EscapePressed);
429 volatile OSError error = NoError;
430 #ifdef LIBPGF_USE_OPENMP 431 #pragma omp parallel for default(shared) 435 if (error == NoError) {
437 if (err != NoError) error = err;
441 if (error != NoError) ReturnWithError(error);
453 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
462 #ifdef __PGFROISUPPORT__ 479 Read(level, cb, data);
489 if (levelDiff <= 0) {
516 for (UINT32 tileY=0; tileY < nTiles; tileY++) {
517 for (UINT32 tileX=0; tileX < nTiles; tileX++) {
519 if (tileIndices.
IsInside(tileX, tileY)) {
532 volatile OSError error = NoError;
533 #ifdef LIBPGF_USE_OPENMP 534 #pragma omp parallel for default(shared) 538 if (error == NoError) {
540 if (err != NoError) error = err;
544 if (error != NoError) ReturnWithError(error);
556 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
583 else rect.
left -= dx;
584 if (rect.
top < dy) rect.
top = 0;
607 #endif // __PGFROISUPPORT__ 627 ASSERT(targetLen > 0);
638 ASSERT(len >= 0 && len <= targetLen);
662 ASSERT(targetLen > 0);
681 ASSERT(len >= 0 && len <= targetLen);
694 while(maxValue > 0) {
699 if (pot > bpc) pot = bpc;
700 if (pot > 31) pot = 31;
748 RgbToYuv(pitch, buff, bpp, channelMap, cb, data);
766 const int oddW = w%2;
773 for (
int i=0; i < h2; i++) {
774 for (
int j=0; j < w2; j++) {
776 buff[sampledPos] = (buff[loPos] + buff[loPos + 1] + buff[hiPos] + buff[hiPos + 1]) >> 2;
777 loPos += 2; hiPos += 2;
781 buff[sampledPos] = (buff[loPos] + buff[hiPos]) >> 1;
785 loPos += w; hiPos += w;
788 for (
int j=0; j < w2; j++) {
789 buff[sampledPos] = (buff[loPos] + buff[loPos+1]) >> 1;
790 loPos += 2; hiPos += 2;
794 buff[sampledPos] = buff[loPos];
812 while (s > maxThumbnailWidth) {
849 #ifdef __PGFROISUPPORT__ 887 if (userDataLength && userData) {
911 ReturnWithError(InsufficientMemory);
928 volatile OSError error = NoError;
930 #ifdef LIBPGF_USE_OPENMP 931 #pragma omp parallel for default(shared) 935 if (error == NoError) {
940 temp =
new(std::nothrow)
DataT[size];
946 error = InsufficientMemory;
949 if (error == NoError) {
956 #ifdef __PGFROISUPPORT__ 963 if (err != NoError) error = err;
967 error = InsufficientMemory;
972 if (error != NoError) {
977 ReturnWithError(error);
986 #ifdef __PGFROISUPPORT__ 1001 return (nBytes > 0) ? (UINT32)nBytes : 0;
1017 #ifdef __PGFROISUPPORT__ 1024 const UINT32 lastTile = nTiles - 1;
1028 ASSERT(nTiles == 1);
1032 for (UINT32 tileY=0; tileY < nTiles; tileY++) {
1033 for (UINT32 tileX=0; tileX < nTiles; tileX++) {
1037 if (i == lastChannel && tileY == lastTile && tileX == lastTile) {
1097 double percent = pow(0.25, levels);
1108 for (UINT32 i=0; i < size; i++) {
1110 stream->Write(&count, &
m_channel[c][i]);
1116 if ((*cb)(1,
true, data)) ReturnWithError(EscapePressed);
1131 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
1147 return nWrittenBytes;
1174 if (nWrittenBytes) *nWrittenBytes += nBytes;
1177 #ifdef __PGFROISUPPORT__ 1200 UINT32 nWrittenBytes = 0;
1224 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
1238 return nWrittenBytes;
1240 #endif // __PGFROISUPPORT__ 1293 if (iFirstColor + nColors >
ColorTableLen) ReturnWithError(ColorTableError);
1295 for (UINT32 i=iFirstColor, j=0; j < nColors; i++, j++) {
1307 if (iFirstColor + nColors >
ColorTableLen) ReturnWithError(ColorTableError);
1309 for (UINT32 i=iFirstColor, j=0; j < nColors; i++, j++) {
1331 void CPGFImage::RgbToYuv(
int pitch, UINT8* buff, BYTE bpp,
int channelMap[], CallbackPtr cb,
void *data ) THROW_ {
1333 int yPos = 0, cnt = 0;
1336 int defMap[] = { 0, 1, 2, 3, 4, 5, 6, 7 }; ASSERT(
sizeof(defMap)/
sizeof(defMap[0]) ==
MaxChannels);
1338 if (channelMap == NULL) channelMap = defMap;
1353 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
1357 for (UINT32 j=0; j < w2; j++) {
1360 for (UINT32 j=w2; j < w; j++) {
1390 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
1411 ASSERT(bpp%16 == 0);
1413 UINT16 *buff16 = (UINT16 *)buff;
1414 const int pitch16 = pitch/2;
1421 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
1428 m_channel[c][yPos] = (buff16[cnt + channelMap[c]] >> shift) - yuvOffset16;
1451 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
1457 b = buff[cnt + channelMap[0]];
1458 g = buff[cnt + channelMap[1]];
1459 r = buff[cnt + channelMap[2]];
1461 y[yPos] = ((b + (g << 1) + r) >> 2) -
YUVoffset8;
1475 ASSERT(bpp%16 == 0);
1477 UINT16 *buff16 = (UINT16 *)buff;
1478 const int pitch16 = pitch/2;
1490 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
1496 b = buff16[cnt + channelMap[0]] >> shift;
1497 g = buff16[cnt + channelMap[1]] >> shift;
1498 r = buff16[cnt + channelMap[2]] >> shift;
1500 y[yPos] = ((b + (g << 1) + r) >> 2) - yuvOffset16;
1526 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
1532 b = buff[cnt + channelMap[0]];
1533 g = buff[cnt + channelMap[1]];
1534 r = buff[cnt + channelMap[2]];
1536 y[yPos] = ((b + (g << 1) + r) >> 2) -
YUVoffset8;
1539 a[yPos++] = buff[cnt + channelMap[3]] -
YUVoffset8;
1550 ASSERT(bpp%16 == 0);
1552 UINT16 *buff16 = (UINT16 *)buff;
1553 const int pitch16 = pitch/2;
1566 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
1572 b = buff16[cnt + channelMap[0]] >> shift;
1573 g = buff16[cnt + channelMap[1]] >> shift;
1574 r = buff16[cnt + channelMap[2]] >> shift;
1576 y[yPos] = ((b + (g << 1) + r) >> 2) - yuvOffset16;
1579 a[yPos++] = (buff16[cnt + channelMap[3]] >> shift) - yuvOffset16;
1586 #ifdef __PGF32SUPPORT__ 1596 UINT32 *buff32 = (UINT32 *)buff;
1597 const int pitch32 = pitch/4;
1603 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
1608 y[yPos++] = (buff32[w] >> shift) - yuvOffset31;
1625 UINT8 rgb = 0, b, g, r;
1629 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
1639 g = (rgb & 0xF0) >> 4;
1645 b = (rgb & 0xF0) >> 4;
1649 r = (rgb & 0xF0) >> 4;
1654 y[yPos] = ((b + (g << 1) + r) >> 2) -
YUVoffset4;
1673 UINT16 *buff16 = (UINT16 *)buff;
1674 UINT16 rgb, b, g, r;
1675 const int pitch16 = pitch/2;
1679 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
1684 r = (rgb & 0xF800) >> 10;
1685 g = (rgb & 0x07E0) >> 5;
1686 b = (rgb & 0x001F) << 1;
1688 y[yPos] = ((b + (g << 1) + r) >> 2) -
YUVoffset6;
1720 void CPGFImage::GetBitmap(
int pitch, UINT8* buff, BYTE bpp,
int channelMap[] , CallbackPtr cb ,
void *data )
const THROW_ {
1724 UINT8* targetBuff = 0;
1725 UINT8* buffStart = 0;
1726 int targetPitch = 0;
1728 #ifdef __PGFROISUPPORT__ 1738 targetPitch = pitch;
1743 buff = buffStart =
new(std::nothrow) UINT8[pitch*h];
1744 if (!buff) ReturnWithError(InsufficientMemory);
1748 const bool wOdd = (1 == w%2);
1750 const double dP = 1.0/h;
1751 int defMap[] = { 0, 1, 2, 3, 4, 5, 6, 7 }; ASSERT(
sizeof(defMap)/
sizeof(defMap[0]) ==
MaxChannels);
1752 if (channelMap == NULL) channelMap = defMap;
1753 int sampledPos = 0, yPos = 0;
1765 const UINT32 w2 = (w + 7)/8;
1768 for (i=0; i < h; i++) {
1770 for (j=0; j < w2; j++) {
1790 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
1806 for (i=0; i < h; i++) {
1808 for (j=0; j < w; j++) {
1819 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
1834 UINT16 *buff16 = (UINT16 *)buff;
1835 int pitch16 = pitch/2;
1838 for (i=0; i < h; i++) {
1840 for (j=0; j < w; j++) {
1842 buff16[cnt + channelMap[c]] =
Clamp16((
m_channel[c][yPos] + yuvOffset16) << shift);
1851 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
1859 for (i=0; i < h; i++) {
1861 for (j=0; j < w; j++) {
1863 buff[cnt + channelMap[c]] =
Clamp8((
m_channel[c][yPos] + yuvOffset16) >> shift);
1872 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
1888 UINT8 *buffg = &buff[channelMap[1]],
1889 *buffr = &buff[channelMap[2]],
1890 *buffb = &buff[channelMap[0]];
1892 int cnt, channels = bpp/8;
1894 for (i=0; i < h; i++) {
1895 if (i%2) sampledPos -= (w + 1)/2;
1897 for (j=0; j < w; j++) {
1899 uAvg = u[sampledPos];
1900 vAvg = v[sampledPos];
1903 buffr[cnt] =
Clamp8(uAvg + g);
1904 buffb[cnt] =
Clamp8(vAvg + g);
1907 if (j%2) sampledPos++;
1912 if (wOdd) sampledPos++;
1915 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
1919 for (i=0; i < h; i++) {
1921 for (j = 0; j < w; j++) {
1926 buffr[cnt] =
Clamp8(uAvg + g);
1927 buffb[cnt] =
Clamp8(vAvg + g);
1937 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
1956 if (bpp >= 48 && bpp%16 == 0) {
1958 UINT16 *buff16 = (UINT16 *)buff;
1959 int pitch16 = pitch/2;
1962 for (i=0; i < h; i++) {
1963 if (i%2) sampledPos -= (w + 1)/2;
1965 for (j=0; j < w; j++) {
1968 uAvg = u[sampledPos];
1969 vAvg = v[sampledPos];
1975 g = y[yPos] + yuvOffset16 - ((uAvg + vAvg ) >> 2);
1976 buff16[cnt + channelMap[1]] =
Clamp16(g << shift);
1977 buff16[cnt + channelMap[2]] =
Clamp16((uAvg + g) << shift);
1978 buff16[cnt + channelMap[0]] =
Clamp16((vAvg + g) << shift);
1981 if (j%2) sampledPos++;
1984 if (wOdd) sampledPos++;
1988 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
1996 for (i=0; i < h; i++) {
1997 if (i%2) sampledPos -= (w + 1)/2;
1999 for (j=0; j < w; j++) {
2002 uAvg = u[sampledPos];
2003 vAvg = v[sampledPos];
2009 g = y[yPos] + yuvOffset16 - ((uAvg + vAvg ) >> 2);
2010 buff[cnt + channelMap[1]] =
Clamp8(g >> shift);
2011 buff[cnt + channelMap[2]] =
Clamp8((uAvg + g) >> shift);
2012 buff[cnt + channelMap[0]] =
Clamp8((vAvg + g) >> shift);
2015 if (j%2) sampledPos++;
2018 if (wOdd) sampledPos++;
2022 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
2039 for (i=0; i < h; i++) {
2040 if (i%2) sampledPos -= (w + 1)/2;
2042 for (j=0; j < w; j++) {
2045 uAvg = a[sampledPos];
2046 vAvg = b[sampledPos];
2056 if (j%2) sampledPos++;
2059 if (wOdd) sampledPos++;
2063 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
2082 UINT16 *buff16 = (UINT16 *)buff;
2083 int pitch16 = pitch/2;
2086 for (i=0; i < h; i++) {
2087 if (i%2) sampledPos -= (w + 1)/2;
2089 for (j=0; j < w; j++) {
2092 uAvg = a[sampledPos];
2093 vAvg = b[sampledPos];
2098 buff16[cnt + channelMap[0]] =
Clamp16((l[yPos] + yuvOffset16) << shift);
2099 buff16[cnt + channelMap[1]] =
Clamp16((uAvg + yuvOffset16) << shift);
2100 buff16[cnt + channelMap[2]] =
Clamp16((vAvg + yuvOffset16) << shift);
2103 if (j%2) sampledPos++;
2106 if (wOdd) sampledPos++;
2110 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
2118 for (i=0; i < h; i++) {
2119 if (i%2) sampledPos -= (w + 1)/2;
2121 for (j=0; j < w; j++) {
2124 uAvg = a[sampledPos];
2125 vAvg = b[sampledPos];
2130 buff[cnt + channelMap[0]] =
Clamp8((l[yPos] + yuvOffset16) >> shift);
2131 buff[cnt + channelMap[1]] =
Clamp8((uAvg + yuvOffset16) >> shift);
2132 buff[cnt + channelMap[2]] =
Clamp8((vAvg + yuvOffset16) >> shift);
2135 if (j%2) sampledPos++;
2138 if (wOdd) sampledPos++;
2142 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
2162 for (i=0; i < h; i++) {
2163 if (i%2) sampledPos -= (w + 1)/2;
2165 for (j=0; j < w; j++) {
2168 uAvg = u[sampledPos];
2169 vAvg = v[sampledPos];
2177 buff[cnt + channelMap[1]] = g =
Clamp8(y[yPos] +
YUVoffset8 - ((uAvg + vAvg ) >> 2));
2178 buff[cnt + channelMap[2]] =
Clamp8(uAvg + g);
2179 buff[cnt + channelMap[0]] =
Clamp8(vAvg + g);
2180 buff[cnt + channelMap[3]] = aAvg;
2183 if (j%2) sampledPos++;
2186 if (wOdd) sampledPos++;
2190 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
2211 UINT16 *buff16 = (UINT16 *)buff;
2212 int pitch16 = pitch/2;
2215 for (i=0; i < h; i++) {
2216 if (i%2) sampledPos -= (w + 1)/2;
2218 for (j=0; j < w; j++) {
2221 uAvg = u[sampledPos];
2222 vAvg = v[sampledPos];
2223 aAvg = a[sampledPos] + yuvOffset16;
2227 aAvg = a[yPos] + yuvOffset16;
2230 g = y[yPos] + yuvOffset16 - ((uAvg + vAvg ) >> 2);
2231 buff16[cnt + channelMap[1]] =
Clamp16(g << shift);
2232 buff16[cnt + channelMap[2]] =
Clamp16((uAvg + g) << shift);
2233 buff16[cnt + channelMap[0]] =
Clamp16((vAvg + g) << shift);
2234 buff16[cnt + channelMap[3]] =
Clamp16(aAvg << shift);
2237 if (j%2) sampledPos++;
2240 if (wOdd) sampledPos++;
2244 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
2252 for (i=0; i < h; i++) {
2253 if (i%2) sampledPos -= (w + 1)/2;
2255 for (j=0; j < w; j++) {
2258 uAvg = u[sampledPos];
2259 vAvg = v[sampledPos];
2260 aAvg = a[sampledPos] + yuvOffset16;
2264 aAvg = a[yPos] + yuvOffset16;
2267 g = y[yPos] + yuvOffset16 - ((uAvg + vAvg ) >> 2);
2268 buff[cnt + channelMap[1]] =
Clamp8(g >> shift);
2269 buff[cnt + channelMap[2]] =
Clamp8((uAvg + g) >> shift);
2270 buff[cnt + channelMap[0]] =
Clamp8((vAvg + g) >> shift);
2271 buff[cnt + channelMap[3]] =
Clamp8(aAvg >> shift);
2274 if (j%2) sampledPos++;
2277 if (wOdd) sampledPos++;
2281 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
2287 #ifdef __PGF32SUPPORT__ 2299 UINT32 *buff32 = (UINT32 *)buff;
2300 int pitch32 = pitch/4;
2302 for (i=0; i < h; i++) {
2303 for (j=0; j < w; j++) {
2304 buff32[j] =
Clamp31((y[yPos++] + yuvOffset31) << shift);
2310 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
2313 }
else if (bpp == 16) {
2315 UINT16 *buff16 = (UINT16 *)buff;
2316 int pitch16 = pitch/2;
2318 if (usedBits < 16) {
2319 const int shift = 16 - usedBits;
2320 for (i=0; i < h; i++) {
2321 for (j=0; j < w; j++) {
2322 buff16[j] =
Clamp16((y[yPos++] + yuvOffset31) << shift);
2328 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
2332 const int shift =
__max(0, usedBits - 16);
2333 for (i=0; i < h; i++) {
2334 for (j=0; j < w; j++) {
2335 buff16[j] =
Clamp16((y[yPos++] + yuvOffset31) >> shift);
2341 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
2349 for (i=0; i < h; i++) {
2350 for (j=0; j < w; j++) {
2351 buff[j] =
Clamp8((y[yPos++] + yuvOffset31) >> shift);
2357 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
2377 for (i=0; i < h; i++) {
2379 for (j=0; j < w; j++) {
2385 buff[cnt] = UINT8(
Clamp4(vAvg + yval) | (yval << 4));
2387 buff[cnt] =
Clamp4(uAvg + yval);
2389 buff[cnt] |=
Clamp4(vAvg + yval) << 4;
2391 buff[cnt] = UINT8(yval | (
Clamp4(uAvg + yval) << 4));
2399 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
2415 UINT16 *buff16 = (UINT16 *)buff;
2416 int pitch16 = pitch/2;
2418 for (i=0; i < h; i++) {
2419 for (j=0; j < w; j++) {
2424 buff16[j] = (yval << 5) | ((Clamp6(uAvg + yval) >> 1) << 11) | (
Clamp6(vAvg + yval) >> 1);
2430 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
2439 #ifdef __PGFROISUPPORT__ 2444 buff = buffStart + (levelRoi.
top - roi.
top)*pitch + (levelRoi.
left - roi.
left)*bypp;
2445 w = levelRoi.
Width()*bypp;
2448 for (i=0; i < h; i++) {
2449 for (j=0; j < w; j++) {
2450 targetBuff[j] = buff[j];
2452 targetBuff += targetPitch;
2459 delete[] buffStart; buffStart = 0;
2482 const bool wOdd = (1 == w%2);
2483 const int dataBits =
DataTSize*8; ASSERT(dataBits == 16 || dataBits == 32);
2486 const double dP = 1.0/h;
2488 int defMap[] = { 0, 1, 2, 3, 4, 5, 6, 7 }; ASSERT(
sizeof(defMap)/
sizeof(defMap[0]) ==
MaxChannels);
2489 if (channelMap == NULL) channelMap = defMap;
2490 int sampledPos = 0, yPos = 0;
2496 ASSERT(bpp%dataBits == 0);
2503 for (i=0; i < h; i++) {
2504 if (i%2) sampledPos -= (w + 1)/2;
2506 for (j=0; j < w; j++) {
2509 uAvg = u[sampledPos];
2510 vAvg = v[sampledPos];
2515 buff[cnt + channelMap[0]] = y[yPos];
2516 buff[cnt + channelMap[1]] = uAvg;
2517 buff[cnt + channelMap[2]] = vAvg;
2520 if (j%2) sampledPos++;
2523 if (wOdd) sampledPos++;
2527 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
2532 ASSERT(bpp%dataBits == 0);
2541 for (i=0; i < h; i++) {
2542 if (i%2) sampledPos -= (w + 1)/2;
2544 for (j=0; j < w; j++) {
2547 uAvg = u[sampledPos];
2548 vAvg = v[sampledPos];
2549 aAvg =
Clamp8(a[sampledPos] + yuvOffset);
2553 aAvg =
Clamp8(a[yPos] + yuvOffset);
2556 buff[cnt + channelMap[0]] = y[yPos];
2557 buff[cnt + channelMap[1]] = uAvg;
2558 buff[cnt + channelMap[2]] = vAvg;
2559 buff[cnt + channelMap[3]] = aAvg;
2562 if (j%2) sampledPos++;
2565 if (wOdd) sampledPos++;
2569 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
2592 const int dataBits =
DataTSize*8; ASSERT(dataBits == 16 || dataBits == 32);
2596 int yPos = 0, cnt = 0;
2598 int defMap[] = { 0, 1, 2, 3, 4, 5, 6, 7 }; ASSERT(
sizeof(defMap)/
sizeof(defMap[0]) ==
MaxChannels);
2600 if (channelMap == NULL) channelMap = defMap;
2603 ASSERT(bpp%dataBits == 0);
2612 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
2618 y[yPos] = buff[cnt + channelMap[0]];
2619 u[yPos] = buff[cnt + channelMap[1]];
2620 v[yPos] = buff[cnt + channelMap[2]];
2627 ASSERT(bpp%dataBits == 0);
2637 if ((*cb)(percent,
true, data)) ReturnWithError(EscapePressed);
2643 y[yPos] = buff[cnt + channelMap[0]];
2644 u[yPos] = buff[cnt + channelMap[1]];
2645 v[yPos] = buff[cnt + channelMap[2]];
2646 a[yPos] = buff[cnt + channelMap[3]] - yuvOffset;
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.
#define PGFVersion
current standard version
void Dequantize(int quantParam)
UINT32 AlignWordPos(UINT32 pos)
#define MaxChannels
maximum number of (color) channels
static BYTE CurrentVersion(BYTE version=PGFVersion)
Return version.
Abstract stream base class.
void DecodeInterleaved(CWaveletTransform *wtChannel, int level, int quantParam) THROW_
UINT32 ReadEncodedData(int level, UINT8 *target, UINT32 targetLen) const THROW_
BYTE UsedBitsPerChannel() const
bool m_skipUserData
skip user data (metadata) during open
void ImportYUV(int pitch, DataT *buff, BYTE bpp, int channelMap[]=NULL, CallbackPtr cb=NULL, void *data=NULL) THROW_
UINT32 ReadEncodedData(UINT8 *target, UINT32 len) const THROW_
void ExtractTile(CEncoder &encoder, bool tile=false, UINT32 tileX=0, UINT32 tileY=0) THROW_
void RgbToYuv(int pitch, UINT8 *rgbBuff, BYTE bpp, int channelMap[], CallbackPtr cb, void *data) THROW_
void Write(CPGFStream *stream, UINT32 *nWrittenBytes=NULL, CallbackPtr cb=NULL, void *data=NULL) THROW_
CDecoder * m_decoder
PGF decoder.
void Open(CPGFStream *stream) THROW_
UINT32 GetEncodedLevelLength(int level) const
PGFHeader m_header
PGF file header.
bool m_streamReinitialized
stream has been reinitialized
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.
UINT32 WriteLevelLength(UINT32 *&levelLength) THROW_
UINT32 GetEncodedHeaderLength() const
void GetBitmap(int pitch, UINT8 *buff, BYTE bpp, int channelMap[]=NULL, CallbackPtr cb=NULL, void *data=NULL) const THROW_
void SetStreamPosToData() THROW_
Reset stream position to beginning of data block.
void SetROI(PGFRect rect)
const RGBQUAD * GetColorTable() const
#define PGFMagic
PGF identification.
const UINT8 * GetUserData(UINT32 &size) const
void GetYUV(int pitch, DataT *buff, BYTE bpp, int channelMap[]=NULL, CallbackPtr cb=NULL, void *data=NULL) const THROW_
#define Version6
new HeaderSize: 32 bits instead of 16 bits
UINT16 Clamp6(DataT v) const
#define ColorTableLen
size of color lookup table (clut)
#define MaxLevel
maximum number of transform levels
ProgressMode m_progressMode
progress mode used in Read and Write; PM_Relative is default mode
CWaveletTransform * m_wtChannel[MaxChannels]
wavelet transformed color channels
void Read(int level=0, CallbackPtr cb=NULL, void *data=NULL) THROW_
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
UINT32 ReadEncodedHeader(UINT8 *target, UINT32 targetLen) const THROW_
bool m_downsample
chrominance channels are downsampled
#define DownsampleThreshold
if quality is larger than this threshold than downsampling is used
UINT32 UpdatePostHeaderSize() THROW_
UINT32 * m_levelLength
length of each level in bytes; first level starts immediately after this array
UINT32 m_width[MaxChannels]
width of each channel at current level
#define Version2
data structure PGFHeader of major version 2
UINT32 UpdateLevelLength() THROW_
CPGFImage()
Standard constructor: It is used to create a PGF instance for opening and reading.
void SetColorTable(UINT32 iFirstColor, UINT32 nColors, const RGBQUAD *prgbColors) THROW_
void ImportBitmap(int pitch, UINT8 *buff, BYTE bpp, int channelMap[]=NULL, CallbackPtr cb=NULL, void *data=NULL) THROW_
bool ROIisSupported() const
#define MaxQuality
maximum quality
void Reconstruct(int level=0) THROW_
bool m_useOMPinEncoder
use Open MP in encoder
INT64 ComputeHeaderLength() const
virtual ~CPGFImage()
Destructor: Destroy internal data structures.
UINT8 Clamp8(DataT v) const
UINT8 Clamp4(DataT v) const
void FavorSpeedOverSize()
Encoder favors speed over compression size.
UINT32 GetEncodedHeaderLength() const
double m_percent
progress [0..1]
static UINT32 LevelWidth(UINT32 width, int level)
void SetMaxValue(UINT32 maxValue)
UINT32 WriteHeader(CPGFStream *stream) THROW_
RefreshCB m_cb
pointer to refresh callback procedure
static bool ImportIsSupported(BYTE mode)
void PlaceTile(CDecoder &decoder, int quantParam, bool tile=false, UINT32 tileX=0, UINT32 tileY=0) THROW_
void Skip(UINT64 offset) THROW_
CEncoder * m_encoder
PGF encoder.
bool IsInside(UINT32 x, UINT32 y) const
INT64 ComputeOffset() const
void ResetStreamPos() THROW_
Reset stream position to start of PGF pre-header.
void Downsample(int nChannel)
UINT32 WriteImage(CPGFStream *stream, CallbackPtr cb=NULL, void *data=NULL) THROW_
int m_currentLevel
transform level of current image
#define Version5
new coding scheme since major version 5
void SetHeader(const PGFHeader &header, BYTE flags=0, UINT8 *userData=0, UINT32 userDataLength=0) THROW_
UINT32 m_height[MaxChannels]
height of each channel at current level
void SetStreamPosToStart() THROW_
Reset stream position to beginning of PGF pre-header.
PGFRect m_roi
region of interest
void UpdatePostHeaderSize(PGFPreHeader preHeader) THROW_
void SetEncodedLevel(int currentLevel)
static UINT32 LevelHeight(UINT32 height, int level)