Beatmup
tools.h
Go to the documentation of this file.
1 /*
2  Beatmup image and signal processing library
3  Copyright (C) 2019, lnstadrum
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #pragma once
20 #include "abstract_bitmap.h"
21 #include "internal_bitmap.h"
22 #include "../geometry.h"
23 #include "pixel_arithmetic.h"
24 
25 namespace Beatmup {
26  /**
27  Set of handy operations with images
28  */
29  namespace BitmapTools {
30  /**
31  Makes a copy of a bitmap.
32  The copy is done in an AbstractTask run in the default thread pool of the context the bitmap is attached to.
33  \param[in] bitmap The bitmap to copy
34  */
36 
37  /**
38  Makes a copy of a bitmap converting the data to a given pixel format.
39  The copy is done in an AbstractTask run in the default thread pool of the context the bitmap is attached to.
40  \param[in] bitmap The bitmap to copy
41  \param[in] pixelFormat Pixel format of the copy
42  */
44 
45  /**
46  Makes a copy of a bitmap for a given Context converting the data to a given pixel format.
47  Can be used to exchange image content between different instances of Context.
48  The copy is done in an AbstractTask run in the default thread pool of the source bitmap context.
49  \param[in] bitmap The bitmap to copy
50  \param[in] context The Context instance the copy is associated with
51  \param[in] pixelFormat Pixel format of the copy
52  */
54 
55  /**
56  Renders a chessboard image.
57  \param[in] context A Context instance
58  \param[in] width Width in pixels of the resulting bitmap
59  \param[in] height Height in pixels of the resulting bitmap
60  \param[in] cellSize Size of a single chessboard cell in pixels
61  \param[in] pixelFormat Pixel format of the resulting bitmap
62  */
63  InternalBitmap* chessboard(Context& context, int width, int height, int cellSize, PixelFormat pixelFormat = BinaryMask);
64 
65  /**
66  Replaces a rectangular area in a bitmap by random noise.
67  \param[in] bitmap The bitmap
68  \param[in] area The area in pixels to process
69  */
71 
72  /**
73  Fills a given bitmap with random noise.
74  \param[in] bitmap The bitmap to fill
75  */
77 
78  /**
79  Makes a bitmap area opaque.
80  Applies for bitmaps having the alpha channel (of QuadByte and QuadFloat pixel formats). Bitmaps of other
81  pixel formats remain unchanged.
82  \param[in] bitmap The bitmap
83  \param[in] area The area in pixels to process
84  */
86 
87  /**
88  Inverses colors of an image in a pixelwise fashion.
89  \param[in] input The input image. Its content unchanged.
90  \param[in] output The output image.
91  */
92  void invert(AbstractBitmap& input, AbstractBitmap& output);
93 
94  /**
95  Goes through a bitmap in scanline order (left to right, top to bottom) until a pixel of a given color is met.
96  \param[in] source The bitmap to scan
97  \param[in] val The color value to look for
98  \param[in] startFrom Starting pixel position
99  \return the next closest position of the searched value (in scanline order) or (-1,-1) if not found.
100  */
101  IntPoint scanlineSearch(AbstractBitmap& source, pixint4 val, const IntPoint& startFrom);
102  IntPoint scanlineSearch(AbstractBitmap& source, pixfloat4 val, const IntPoint& startFrom);
103  }
104 }
A very basic class for any image.
Basic class: task and memory management, any kind of static data.
Definition: context.h:59
Bitmap whose memory is managed by the Beatmup engine.
IntPoint scanlineSearch(AbstractBitmap &source, pixint4 val, const IntPoint &startFrom)
Goes through a bitmap in scanline order (left to right, top to bottom) until a pixel of a given color...
Definition: tools.cpp:195
void invert(AbstractBitmap &input, AbstractBitmap &output)
Inverses colors of an image in a pixelwise fashion.
Definition: tools.cpp:155
InternalBitmap * makeCopy(AbstractBitmap &bitmap)
Makes a copy of a bitmap.
Definition: tools.cpp:72
void noise(AbstractBitmap &bitmap, IntRectangle area)
Replaces a rectangular area in a bitmap by random noise.
Definition: tools.cpp:100
InternalBitmap * chessboard(Context &context, int width, int height, int cellSize, PixelFormat pixelFormat=BinaryMask)
Renders a chessboard image.
Definition: tools.cpp:91
void makeOpaque(AbstractBitmap &bitmap, IntRectangle area)
Makes a bitmap area opaque.
Definition: tools.cpp:131
@ BinaryMask
1 bit per pixel
4-channel floating point arithmetic
4-channel integer arithmetic
jlong jint jint jint jint pixelFormat
jlong jint width
jlong jint jint height
return(jlong) new Beatmup jlong jstring jint val
Beatmup::InternalBitmap * bitmap