| 80 | } |
| 81 | |
| 82 | uint32_t GetNeighborAvgColor(const Pixmap& pixmap, int xOrig, int yOrig) { |
| 83 | unsigned r = 0; |
| 84 | unsigned g = 0; |
| 85 | unsigned b = 0; |
| 86 | unsigned n = 0; |
| 87 | // Clamp the range to the edge of the bitmap. |
| 88 | int ymin = std::max(0, yOrig - 1); |
| 89 | int ymax = std::min(yOrig + 1, pixmap.height() - 1); |
| 90 | int xmin = std::max(0, xOrig - 1); |
| 91 | int xmax = std::min(xOrig + 1, pixmap.width() - 1); |
| 92 | |
| 93 | const auto pixelPointer = reinterpret_cast<const uint8_t*>(pixmap.pixels()); |
| 94 | auto rowBytes = pixmap.rowBytes(); |
| 95 | for (int y = ymin; y <= ymax; ++y) { |
| 96 | auto scanline = |
| 97 | reinterpret_cast<const uint32_t*>(pixelPointer + (static_cast<size_t>(y) * rowBytes)); |
| 98 | for (int x = xmin; x <= xmax; ++x) { |
| 99 | uint32_t color = *scanline++; |
| 100 | if (color != 0x00000000) { |
| 101 | r += (((color) >> 16) & 0xFF); |
| 102 | g += (((color) >> 8) & 0xFF); |
| 103 | b += (((color) >> 0) & 0xFF); |
| 104 | n++; |
| 105 | } |
| 106 | } |
| 107 | } |
| 108 | if (n > 0) { |
| 109 | auto avgR = static_cast<uint8_t>(r / n); |
| 110 | auto avgG = static_cast<uint8_t>(g / n); |
| 111 | auto avgB = static_cast<uint8_t>(b / n); |
| 112 | return ((static_cast<uint32_t>(avgR) << 16) | (static_cast<uint32_t>(avgG) << 8) | |
| 113 | static_cast<uint32_t>(avgB) << 0); |
| 114 | } |
| 115 | return 0x00000000; |
| 116 | } |
| 117 | |
| 118 | bool DoJpeg(std::shared_ptr<Data> data, YUVColorSpace /*imageColorSpace*/, PDFDocumentImpl* doc, |
| 119 | ISize size, PDFIndirectReference ref) { |
no test coverage detected