| #pragma once |
| |
| #ifndef RUNSMAP_H |
| #define RUNSMAP_H |
| |
| #include "traster.h" |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| class RunsMap final : public TRasterT<TPixelGR8> { |
| public: |
| RunsMap(int lx, int ly) : TRasterT<TPixelGR8>(lx, ly) { clear(); } |
| |
| const UCHAR &runHeader(int x, int y) const { return pixels(y)[x].value; } |
| UCHAR &runHeader(int x, int y) { return pixels(y)[x].value; } |
| |
| TUINT32 runLength(const TPixelGR8 *run, bool reversed = false) const; |
| TUINT32 runLength(int x, int y, bool reversed = false) const { |
| return runLength(pixels(y) + x, reversed); |
| } |
| |
| public: |
| void setRunLength(TPixelGR8 *run, TUINT32 length); |
| void setRunLength(int x, int y, TUINT32 length) { |
| setRunLength(pixels(y) + x, length); |
| } |
| }; |
| |
| |
| |
| #ifdef _WIN32 |
| template class DV_EXPORT_API TSmartPointerT<RunsMap>; |
| #endif |
| |
| class RunsMapP final : public TSmartPointerT<RunsMap> { |
| public: |
| RunsMapP() {} |
| RunsMapP(int lx, int ly) : TSmartPointerT<RunsMap>(new RunsMap(lx, ly)) {} |
| RunsMapP(const TDimension &d) |
| : TSmartPointerT<RunsMap>(new RunsMap(d.lx, d.ly)) {} |
| }; |
| |
| |
| |
| template <typename Pixel, typename PixelSelector> |
| void buildRunsMap(RunsMapP &runsMap, const TRasterPT<Pixel> &ras, |
| const PixelSelector &selector) { |
| |
| int y, ly = ras->getLy(); |
| for (y = 0; y < ly; ++y) { |
| Pixel *lineStart = (Pixel *)ras->pixels(y), |
| *lineEnd = lineStart + ras->getLx(); |
| |
| Pixel *pix, *runStart; |
| typename PixelSelector::value_type colorIndex; |
| for (pix = runStart = lineStart, colorIndex = selector.value(*pix); |
| pix < lineEnd; ++pix) |
| if (selector.value(*pix) != colorIndex) { |
| runsMap->setRunLength(runStart - lineStart, y, pix - runStart); |
| runStart = pix; |
| colorIndex = selector.value(*pix); |
| } |
| runsMap->setRunLength(runStart - lineStart, y, pix - runStart); |
| } |
| } |
| |
| #endif |