Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
imagemap.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
/*
5 * Authors: see git history
6 *
7 * Copyright (C) 2018 Authors
8 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
9 */
10#ifndef INKSCAPE_TRACE_IMAGEMAP_H
11#define INKSCAPE_TRACE_IMAGEMAP_H
12
13#include <vector>
14#include <array>
15
16namespace Inkscape {
17namespace Trace {
18
19template <typename T>
20struct MapBase
21{
22 int width;
23 int height;
24 std::vector<T> pixels;
25
27 : width(width)
28 , height(height)
29 , pixels(width * height) {}
30
31 int offset(int x, int y) const { return x + y * width; }
32 T *row(int y) { return pixels.data() + y * width; }
33 T const *row(int y) const { return pixels.data() + y * width; }
34 void setPixel(int x, int y, T val) { pixels[offset(x, y)] = val; }
35 T getPixel(int x, int y) const { return pixels[offset(x, y)]; }
36};
37
38/*
39 * GrayMap
40 */
41
42struct GrayMap
43 : MapBase<unsigned long>
44{
45 static unsigned long constexpr BLACK = 0;
46 static unsigned long constexpr WHITE = 255 * 3;
47
48 GrayMap(int width, int height);
49
50 bool writePPM(char const *fileName);
51};
52
53/*
54 * RgbMap
55 */
56
57struct RGB
58{
59 unsigned char r;
60 unsigned char g;
61 unsigned char b;
62};
63
64struct RgbMap
65 : MapBase<RGB>
66{
67 RgbMap(int width, int height);
68
69 bool writePPM(char const *fileName);
70};
71
72/*
73 * IndexedMap
74 */
75
77 : MapBase<unsigned>
78{
79 IndexedMap(int width, int height);
80
81 RGB getPixelValue(int x, int y) const { return clut[getPixel(x, y) % clut.size()]; }
82 bool writePPM(char const *fileName);
83
85 std::array<RGB, 256> clut;
86};
87
88} // namespace Trace
89} // namespace Inkscape
90
91#endif // INKSCAPE_TRACE_IMAGEMAP_H
double offset
Helper class to stream background task notifications as a series of messages.
static unsigned long constexpr WHITE
Definition imagemap.h:46
bool writePPM(char const *fileName)
Definition imagemap.cpp:25
static unsigned long constexpr BLACK
Definition imagemap.h:45
RGB getPixelValue(int x, int y) const
Definition imagemap.h:81
bool writePPM(char const *fileName)
Definition imagemap.cpp:100
std::array< RGB, 256 > clut
Color look-up table.
Definition imagemap.h:85
T const * row(int y) const
Definition imagemap.h:33
T getPixel(int x, int y) const
Definition imagemap.h:35
void setPixel(int x, int y, T val)
Definition imagemap.h:34
int offset(int x, int y) const
Definition imagemap.h:31
MapBase(int width, int height)
Definition imagemap.h:26
std::vector< T > pixels
Definition imagemap.h:24
unsigned char g
Definition imagemap.h:60
unsigned char b
Definition imagemap.h:61
unsigned char r
Definition imagemap.h:59
bool writePPM(char const *fileName)
Definition imagemap.cpp:62