Geometrize 1.0
C++ library for geometrizing images into geometric primitives
commonutil.h
Go to the documentation of this file.
1#pragma once
2
3#include <algorithm>
4#include <cstdint>
5#include <tuple>
6#include <vector>
7
8#include "bitmap/rgba.h"
9
10namespace geometrize
11{
12class Bitmap;
13class Scanline;
14struct ImageRunnerShapeBoundsOptions;
15}
16
17namespace geometrize
18{
19
20namespace commonutil
21{
22
27void seedRandomGenerator(std::uint32_t seed);
28
36std::int32_t randomRange(std::int32_t min, std::int32_t max);
37
45template<typename T> T clamp(const T& value, const T& lower, const T& upper)
46{
47 return (std::max)(lower, (std::min)(value, upper));
48}
49
56
64bool scanlinesContainTransparentPixels(const std::vector<geometrize::Scanline>& scanlines, const geometrize::Bitmap& image, int minAlpha);
65
72std::tuple<std::int32_t, std::int32_t, std::int32_t, std::int32_t> mapShapeBoundsToImage(const geometrize::ImageRunnerShapeBoundsOptions& options, const geometrize::Bitmap& image);
73
74}
75
76}
The Bitmap class is a helper class for working with bitmap data.
Definition: bitmap.h:16
std::int32_t randomRange(const std::int32_t min, const std::int32_t max)
randomRange Returns a random integer in the range, inclusive. Uses thread-local random number generat...
Definition: commonutil.cpp:29
void seedRandomGenerator(const std::uint32_t seed)
seedRandomGenerator Seeds the (thread-local) random number generators.
Definition: commonutil.cpp:24
T clamp(const T &value, const T &lower, const T &upper)
clamp Clamps a value within a range.
Definition: commonutil.h:45
geometrize::rgba getAverageImageColor(const geometrize::Bitmap &image)
getAverageImageColor Computes the average RGB color of the pixels in the bitmap.
Definition: commonutil.cpp:35
bool scanlinesContainTransparentPixels(const std::vector< geometrize::Scanline > &scanlines, const geometrize::Bitmap &image, int minAlpha)
scanlinesContainTransparentPixels Returns true if the scanlines contain transparent pixels in the giv...
Definition: commonutil.cpp:62
std::tuple< std::int32_t, std::int32_t, std::int32_t, std::int32_t > mapShapeBoundsToImage(const geometrize::ImageRunnerShapeBoundsOptions &options, const geometrize::Bitmap &image)
mapShapeBoundsToImage Maps the given shape bound percentages to the given image, returning a bounding...
Definition: commonutil.cpp:75
Definition: bitmap.cpp:8
The ImageRunnerShapeBoundsOptions struct encapsulates options for where shapes may be drawn within th...
Definition: imagerunneroptions.h:15
The rgba struct is a helper for manipulating RGBA8888 color data.
Definition: rgba.h:13