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;
1789void 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__
1809 w = levelRoi.
Width();
1811 roiOffsetX = levelRoi.
left - roi.
left;
1812 roiOffsetY = levelRoi.
top - roi.
top;
1813 yOffset = roiOffsetX + roiOffsetY*yw;
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);