"Fossies" - the Fresh Open Source Software Archive

Member "darktable-3.6.1/src/external/rawspeed/src/librawspeed/decompressors/AbstractDngDecompressor.h" (9 Sep 2021, 4823 Bytes) of package /linux/misc/darktable-3.6.1.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "AbstractDngDecompressor.h" see the Fossies "Dox" file reference documentation.

    1 /*
    2     RawSpeed - RAW file decoder.
    3 
    4     Copyright (C) 2009-2014 Klaus Post
    5     Copyright (C) 2017-2018 Roman Lebeedv
    6 
    7     This library is free software; you can redistribute it and/or
    8     modify it under the terms of the GNU Lesser General Public
    9     License as published by the Free Software Foundation; either
   10     version 2 of the License, or (at your option) any later version.
   11 
   12     This library is distributed in the hope that it will be useful,
   13     but WITHOUT ANY WARRANTY; without even the implied warranty of
   14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   15     Lesser General Public License for more details.
   16 
   17     You should have received a copy of the GNU Lesser General Public
   18     License along with this library; if not, write to the Free Software
   19     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
   20 */
   21 
   22 #pragma once
   23 
   24 #include "common/Common.h"                      // for roundUpDivision
   25 #include "common/Point.h"                       // for iPoint2D
   26 #include "common/RawImage.h"                    // for RawImage
   27 #include "decompressors/AbstractDecompressor.h" // for AbstractDecompressor
   28 #include "io/ByteStream.h"                      // for ByteStream
   29 #include <cassert>                              // for assert
   30 #include <cstdint>                              // for uint32_t
   31 #include <utility>                              // for move
   32 #include <vector>                               // for vector
   33 
   34 namespace rawspeed {
   35 
   36 struct DngTilingDescription final {
   37   // The dimensions of the whole image.
   38   const iPoint2D& dim;
   39 
   40   // How many horizontal pixels does one tile represent?
   41   const uint32_t tileW;
   42 
   43   // How many vertical pixels does one tile represent?
   44   const uint32_t tileH;
   45 
   46   // How many tiles per row is there?
   47   const uint32_t tilesX;
   48 
   49   // How many rows is there?
   50   const uint32_t tilesY;
   51 
   52   // How many tiles are there total?
   53   const unsigned numTiles;
   54 
   55   DngTilingDescription(const iPoint2D& dim_, uint32_t tileW_, uint32_t tileH_)
   56       : dim(dim_), tileW(tileW_), tileH(tileH_),
   57         tilesX(roundUpDivision(dim.x, tileW)),
   58         tilesY(roundUpDivision(dim.y, tileH)), numTiles(tilesX * tilesY) {
   59     assert(dim.area() > 0);
   60     assert(tileW > 0);
   61     assert(tileH > 0);
   62     assert(tilesX > 0);
   63     assert(tilesY > 0);
   64     assert(tileW * tilesX >= static_cast<unsigned>(dim.x));
   65     assert(tileH * tilesY >= static_cast<unsigned>(dim.y));
   66     assert(tileW * (tilesX - 1) < static_cast<unsigned>(dim.x));
   67     assert(tileH * (tilesY - 1) < static_cast<unsigned>(dim.y));
   68     assert(numTiles > 0);
   69   }
   70 };
   71 
   72 struct DngSliceElement final {
   73   const DngTilingDescription& dsc;
   74 
   75   // Which slice is this?
   76   const unsigned n;
   77 
   78   // The actual data of the tile.
   79   const ByteStream bs;
   80 
   81   // Which tile is this?
   82   const unsigned column;
   83   const unsigned row;
   84 
   85   const bool lastColumn;
   86   const bool lastRow;
   87 
   88   // Where does it start?
   89   const unsigned offX;
   90   const unsigned offY;
   91 
   92   // What's it's actual size?
   93   const unsigned width;
   94   const unsigned height;
   95 
   96   DngSliceElement(const DngTilingDescription& dsc_, unsigned n_, ByteStream bs_)
   97       : dsc(dsc_), n(n_), bs(std::move(bs_)), column(n % dsc.tilesX),
   98         row(n / dsc.tilesX), lastColumn((column + 1) == dsc.tilesX),
   99         lastRow((row + 1) == dsc.tilesY), offX(dsc.tileW * column),
  100         offY(dsc.tileH * row),
  101         width(!lastColumn ? dsc.tileW : dsc.dim.x - offX),
  102         height(!lastRow ? dsc.tileH : dsc.dim.y - offY) {
  103     assert(n < dsc.numTiles);
  104     assert(bs.getRemainSize() > 0);
  105     assert(column < dsc.tilesX);
  106     assert(row < dsc.tilesY);
  107     assert(offX < static_cast<unsigned>(dsc.dim.x));
  108     assert(offY < static_cast<unsigned>(dsc.dim.y));
  109     assert(width > 0);
  110     assert(height > 0);
  111     assert(offX + width <= static_cast<unsigned>(dsc.dim.x));
  112     assert(offY + height <= static_cast<unsigned>(dsc.dim.y));
  113     assert(!lastColumn || (offX + width == static_cast<unsigned>(dsc.dim.x)));
  114     assert(!lastRow || (offY + height == static_cast<unsigned>(dsc.dim.y)));
  115   }
  116 };
  117 
  118 class AbstractDngDecompressor final : public AbstractDecompressor {
  119   RawImage mRaw;
  120 
  121   template <int compression> void decompressThread() const noexcept;
  122 
  123   void decompressThread() const noexcept;
  124 
  125 public:
  126   AbstractDngDecompressor(const RawImage& img, DngTilingDescription dsc_,
  127                           int compression_, bool mFixLjpeg_, uint32_t mBps_,
  128                           uint32_t mPredictor_)
  129       : mRaw(img), dsc(dsc_), compression(compression_), mFixLjpeg(mFixLjpeg_),
  130         mBps(mBps_), mPredictor(mPredictor_) {}
  131 
  132   void decompress() const;
  133 
  134   const DngTilingDescription dsc;
  135 
  136   std::vector<DngSliceElement> slices;
  137 
  138   const int compression;
  139   const bool mFixLjpeg = false;
  140   const uint32_t mBps;
  141   const uint32_t mPredictor;
  142 };
  143 
  144 } // namespace rawspeed