Scroom  0.14
OperationsCMYK16 Class Reference

#include <layeroperations.hh>

Inheritance diagram for OperationsCMYK16:
Inheritance graph
Collaboration diagram for OperationsCMYK16:
Collaboration graph

Public Member Functions

 OperationsCMYK16 ()
 
int getBpp () override
 
Scroom::Utils::Stuff cache (const ConstTile::Ptr &tile) override
 
void reduce (Tile::Ptr target, ConstTile::Ptr source, int x, int y) override
 
- Public Member Functions inherited from PipetteCommonOperationsCMYK
 PipetteCommonOperationsCMYK (int bps_)
 
PipetteLayerOperations::PipetteColor sumPixelValues (Scroom::Utils::Rectangle< int > area, const ConstTile::Ptr &tile) override
 
- Public Member Functions inherited from Scroom::Utils::Base
 Base ()=default
 
 Base (const Base &)=delete
 
 Base (Base &&)=delete
 
Baseoperator= (const Base &)=delete
 
Baseoperator= (Base &&)=delete
 
virtual ~Base ()=default
 
template<typename R >
boost::shared_ptr< R > shared_from_this ()
 
template<typename R >
boost::shared_ptr< R const > shared_from_this () const
 
- Public Member Functions inherited from CommonOperations
void initializeCairo (cairo_t *cr) override
 
void drawState (cairo_t *cr, TileState s, Scroom::Utils::Rectangle< double > viewArea) override
 
Scroom::Utils::Stuff cacheZoom (const ConstTile::Ptr &tile, int zoom, Scroom::Utils::Stuff &cache) override
 
void draw (cairo_t *cr, const ConstTile::Ptr &tile, Scroom::Utils::Rectangle< double > tileArea, Scroom::Utils::Rectangle< double > viewArea, int zoom, Scroom::Utils::Stuff cache) override
 

Static Public Member Functions

static Ptr create ()
 
- Static Public Member Functions inherited from CommonOperations
static void drawPixelValue (cairo_t *cr, int x, int y, int size, int value)
 
static void drawPixelValue (cairo_t *cr, int x, int y, int size, int value, Color const &bgColor)
 

Additional Inherited Members

- Public Types inherited from PipetteCommonOperationsCMYK
using Ptr = boost::shared_ptr< PipetteCommonOperationsCMYK >
 
- Public Types inherited from PipetteLayerOperations
using Ptr = boost::shared_ptr< PipetteLayerOperations >
 
using PipetteColor = std::vector< std::pair< std::string, double > >
 
- Public Types inherited from LayerOperations
using Ptr = boost::shared_ptr< LayerOperations >
 
- Protected Attributes inherited from PipetteCommonOperationsCMYK
int bps
 

Constructor & Destructor Documentation

◆ OperationsCMYK16()

OperationsCMYK16::OperationsCMYK16 ( )
127 {
128 }

Referenced by create().

Here is the caller graph for this function:

Member Function Documentation

◆ cache()

Scroom::Utils::Stuff OperationsCMYK16::cache ( const ConstTile::Ptr tile)
overridevirtual

Cache the given tile

Reimplemented from LayerOperations.

136 {
137  // Allocate the space for the cache - stride is the height of one row
138  const int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, tile->width);
139  boost::shared_ptr<uint8_t> const data = shared_malloc(static_cast<size_t>(stride * tile->height));
140 
141  // Row is a pointer to a row of pixels (destination)
142  auto* row = reinterpret_cast<uint32_t*>(data.get());
143  // Cur is a pointer to the start of the row in the tile (source)
144  const uint8_t* cur = tile->data.get();
145 
146  for(int i = 0; i < 2 * tile->height * tile->width; i += 2)
147  {
148  // Convert CMYK to ARGB, because cairo doesn't know how to render CMYK.
149  auto C_i = static_cast<uint8_t>(255 - ((cur[i]) >> 4) * 17); // 17 == 255/15
150  auto M_i = static_cast<uint8_t>(255 - ((cur[i] & 0x0F)) * 17);
151  auto Y_i = static_cast<uint8_t>(255 - ((cur[i + 1]) >> 4) * 17);
152  auto K_i = static_cast<uint8_t>(255 - ((cur[i + 1] & 0x0F)) * 17);
153 
154  uint32_t const R = static_cast<uint8_t>((C_i * K_i) / 255);
155  uint32_t const G = static_cast<uint8_t>((M_i * K_i) / 255);
156  uint32_t const B = static_cast<uint8_t>((Y_i * K_i) / 255);
157 
158  // Write 255 as alpha (fully opaque)
159  row[i / 2] = 255u << 24 | R << 16 | G << 8 | B;
160  }
161 
162  return Scroom::Bitmap::BitmapSurface::create(tile->width, tile->height, CAIRO_FORMAT_ARGB32, stride, data);
163 }
Here is the call graph for this function:

◆ create()

PipetteCommonOperationsCMYK::Ptr OperationsCMYK16::create ( )
static

Referenced by Scroom::TiledBitmap::CMYKBitmap().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getBpp()

int OperationsCMYK16::getBpp ( )
overridevirtual

Return the number of bits per pixel that the layer will use.

This number will be used to compute the amount of memory required to store one tile

Implements LayerOperations.

130 { return 16; }

◆ reduce()

void OperationsCMYK16::reduce ( Tile::Ptr  target,
ConstTile::Ptr  source,
int  x,
int  y 
)
overridevirtual

Reduce the source tile by a factor of 8

The target tile will contain data for 8*8 source tiles. Offsets x and y indicate which of those 64 source tiles is currently being processed

Parameters
targetTile that will contain the reduced bitmap
sourceTile that is to be reduced
xx-offset (0..7) of the source tile in the target tile
yy-offset (0..7) of the source tile in the target tile
Note
The target tile belongs to a different layer, and hence possibly has a different bpp than the current one, depending on the LayerSpec given to createTiledBitmap()

Implements LayerOperations.

166 {
167  // Reducing by a factor 8
168  const int sourceStride = 4 * source->width / 2; // stride in bytes
169  const byte* sourceBase = source->data.get();
170 
171  const int targetStride = 8 * target->width / 2; // stride in bytes
172  byte* targetBase = target->data.get() + (target->height * top_left_y + top_left_x) * targetStride / 8;
173 
174  for(int y = 0; y < source->height / 8; y++)
175  {
176  byte* targetPtr = targetBase;
177 
178  for(int x = 0; x < source->width / 8; x++)
179  {
180  // We want to store the average colour of the 8*8 pixel image
181  // with (x, y) as its top-left corner into targetPtr.
182  const byte* base = sourceBase + 4 * 4 * x; // start of the row
183  const byte* end = base + 8 * sourceStride; // end of the row
184 
185  int sum_c = 0;
186  int sum_m = 0;
187  int sum_y = 0;
188  int sum_k = 0;
189  for(const byte* row = base; row < end; row += sourceStride)
190  {
191  for(size_t current = 0; current < 8 * 2; current += 2)
192  {
193  sum_c += row[current] >> 4;
194  sum_m += row[current] & 15;
195  sum_y += row[current + 1] >> 4;
196  sum_k += row[current + 1] & 15;
197  }
198  }
199 
200  targetPtr[0] = static_cast<byte>(sum_c * 255 / (15 * 64));
201  targetPtr[1] = static_cast<byte>(sum_m * 255 / (15 * 64));
202  targetPtr[2] = static_cast<byte>(sum_y * 255 / (15 * 64));
203  targetPtr[3] = static_cast<byte>(sum_k * 255 / (15 * 64));
204 
205  targetPtr += 4;
206  }
207 
208  targetBase += targetStride;
209  sourceBase += sourceStride * 8;
210  }
211 }

The documentation for this class was generated from the following files:
Scroom::Bitmap::BitmapSurface::create
static Ptr create(int width, int height, cairo_format_t format)
Definition: bitmap-helpers.cc:13
PipetteCommonOperationsCMYK::Ptr
boost::shared_ptr< PipetteCommonOperationsCMYK > Ptr
Definition: layeroperations.hh:41
OperationsCMYK16::OperationsCMYK16
OperationsCMYK16()
Definition: cmyklayeroperations.cc:125
PipetteCommonOperationsCMYK::PipetteCommonOperationsCMYK
PipetteCommonOperationsCMYK(int bps_)
Definition: layeroperations.hh:44
current
static unsigned int current
Definition: measure-framerate-callbacks.cc:17
anonymous_namespace{cmyklayeroperations.cc}::shared_malloc
boost::shared_ptr< unsigned char > shared_malloc(size_t size)
Definition: cmyklayeroperations.cc:24
B
Definition: threadpool-tests.cc:53