Scroom 0.14-49-gb7ae7a6d
Loading...
Searching...
No Matches
OperationsCMYK4 Class Reference

#include <layeroperations.hh>

Inheritance diagram for OperationsCMYK4:
Inheritance graph
Collaboration diagram for OperationsCMYK4:
Collaboration graph

Public Member Functions

 OperationsCMYK4 ()
 
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 >
std::shared_ptr< R > shared_from_this ()
 
template<typename R >
std::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 = std::shared_ptr< PipetteCommonOperationsCMYK >
 
- Public Types inherited from PipetteLayerOperations
using Ptr = std::shared_ptr< PipetteLayerOperations >
 
using PipetteColor = std::vector< std::pair< std::string, double > >
 
- Public Types inherited from LayerOperations
using Ptr = std::shared_ptr< LayerOperations >
 
- Protected Attributes inherited from PipetteCommonOperationsCMYK
int bps
 

Constructor & Destructor Documentation

◆ OperationsCMYK4()

OperationsCMYK4::OperationsCMYK4 ( )
303{
304}
Definition layeroperations.hh:38

Referenced by create().

Here is the caller graph for this function:

Member Function Documentation

◆ cache()

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

Cache the given tile

Reimplemented from LayerOperations.

316{
317 // Allocate the space for the cache - stride is the height of one row
318 const int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, tile->width);
319 std::shared_ptr<uint8_t> const data = Scroom::Utils::shared_malloc(static_cast<size_t>(stride * tile->height));
320
321 // Row is a pointer to a row of pixels (destination)
322 auto* row = reinterpret_cast<uint32_t*>(data.get());
323 // Cur is a pointer to the start of the row in the tile (source)
324 const uint8_t* cur = tile->data.get();
325
326 // assume stride = tile->width * 4
327 for(int i = 0; i < tile->height * tile->width; i++)
328 {
329 // Convert CMYK to ARGB, because cairo doesn't know how to render CMYK.
330 uint8_t C_i;
331
332 uint8_t M_i;
333
334 uint8_t Y_i;
335
336 uint8_t K_i;
337 if((i & 1) == 0)
338 { // even pixels -> top half of byte
339 C_i = static_cast<uint8_t>(((cur[i / 2]) >> 7) - 1); // 0 -> 255 (= -1), 1 -> 0
340 M_i = static_cast<uint8_t>(((cur[i / 2] & 0x40) >> 6) - 1);
341 Y_i = static_cast<uint8_t>(((cur[i / 2] & 0x20) >> 5) - 1);
342 K_i = static_cast<uint8_t>(((cur[i / 2] & 0x10) >> 4) - 1);
343 }
344 else
345 { // odd pixels -> lower half of the byte
346 C_i = static_cast<uint8_t>(((cur[i / 2] & 0x08) >> 3) - 1); // 0 -> 255 (= -1), 1 -> 0
347 M_i = static_cast<uint8_t>(((cur[i / 2] & 0x04) >> 2) - 1);
348 Y_i = static_cast<uint8_t>(((cur[i / 2] & 0x02) >> 1) - 1);
349 K_i = static_cast<uint8_t>(((cur[i / 2] & 0x01)) - 1);
350 }
351
352 uint32_t const R = static_cast<uint8_t>((C_i * K_i) / 255);
353 uint32_t const G = static_cast<uint8_t>((M_i * K_i) / 255);
354 uint32_t const B = static_cast<uint8_t>((Y_i * K_i) / 255);
355
356 // Write 255 as alpha (fully opaque)
357 row[i] = 255u << 24 | R << 16 | G << 8 | B;
358 }
359
360 return Scroom::Bitmap::BitmapSurface::create(tile->width, tile->height, CAIRO_FORMAT_ARGB32, stride, data);
361}
uint8_t data
Definition blob-tests.cc:36
Definition threadpool-tests.cc:55
static Ptr create(int width, int height, cairo_format_t format)
Definition bitmap-helpers.cc:13
std::shared_ptr< unsigned char > shared_malloc(size_t size)
Definition utilities.hh:123
Here is the call graph for this function:

◆ create()

PipetteCommonOperationsCMYK::Ptr OperationsCMYK4::create ( )
static
OperationsCMYK4()
Definition cmyklayeroperations.cc:301
std::shared_ptr< PipetteCommonOperationsCMYK > Ptr
Definition layeroperations.hh:43

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

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

◆ getBpp()

int OperationsCMYK4::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.

307{
308 // CMYK has 4 channels -> 4 samples per pixel.
309 return 4;
310}

◆ reduce()

void OperationsCMYK4::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.

364{
365 // Reducing by a factor 8
366 const int sourceStride = source->width / 2; // stride in bytes
367 const byte* sourceBase = source->data.get();
368
369 const int targetStride = 8 * target->width / 2; // stride in bytes
370 byte* targetBase = target->data.get() + (target->height * top_left_y + top_left_x) * targetStride / 8;
371
372 for(int y = 0; y < source->height / 8; y++)
373 {
374 for(int x = 0; x < source->width / 8; x++)
375 {
376 // We want to store the average colour of the 8*8 pixel image
377 // with (x, y) as its top-left corner into targetPtr.
378 const byte* base = sourceBase + 4 * x; // start of the row
379 const byte* end = base + 8 * sourceStride; // end of the row
380
381 int sum_c = 0;
382 int sum_m = 0;
383 int sum_y = 0;
384 int sum_k = 0;
385 for(const byte* row = base; row < end; row += sourceStride)
386 {
387 for(size_t current = 0; current < 4; current++)
388 {
389 sum_c += ((row[current] >> 7) & 1) + ((row[current] >> 3) & 1);
390 sum_m += ((row[current] >> 6) & 1) + ((row[current] >> 2) & 1);
391 sum_y += ((row[current] >> 5) & 1) + ((row[current] >> 1) & 1);
392 sum_k += ((row[current] >> 4) & 1) + ((row[current] >> 0) & 1);
393 }
394 }
395
396 targetBase[4 * x] = static_cast<uint8_t>(sum_c * 255 / 64);
397 targetBase[4 * x + 1] = static_cast<uint8_t>(sum_m * 255 / 64);
398 targetBase[4 * x + 2] = static_cast<uint8_t>(sum_y * 255 / 64);
399 targetBase[4 * x + 3] = static_cast<uint8_t>(sum_k * 255 / 64);
400 }
401
402 targetBase += targetStride;
403 sourceBase += sourceStride * 8;
404 }
405}
static unsigned int current
Definition measure-framerate-callbacks.cc:15

The documentation for this class was generated from the following files: