AImageView#
Non-owning read-only image representation of some format.
Header: | #include <AUI/Image/AImageView.h> |
CMake: | aui_link(my_target PUBLIC aui::image) |
Public Methods#
buffer#
AByteBufferView AImageView::buffer()
- Returns
- Raw image pixel data.
bytesPerPixel#
- Returns
- Bytes per pixel.
cropped#
AImage AImageView::cropped(glm::uvec2 position, glm::uvec2 size)
Crops the image, creating new image with the same format.
- Arguments
position
offsetsize
size of new image
data#
Shortcut to buffer().data().
format#
APixelFormat AImageView::format()
- Returns
- Image pixel format.
get#
Retrieves pixel color data.
- Arguments
position
position- Returns
- color of specified pixel
This is a universal function that basically allows you to don't care about underlying image format representation. For performance critical code you may want to use visit method.
Specifying position out of image range causes assertion fail in debug or undefined behaviour.
Examples#
examples/app/game_of_life/src/main.cpp
Game of Life - Game of Life implementation that uses advanced large dynamic data rendering techniques such as ITexture, AImage to be GPU friendly. The computation is performed in AThreadPool.
mFrame = AThreadPool::global() * [&] {
for (int y = 0; y < mSize.y; ++y) {
for (int x = 0; x < mSize.x; ++x) {
glm::ivec2 i { x, y };
get(mNextPopulation, i) = [&] {
auto around = cellsAround(i);
switch (around) {
default:
return CellState::DEAD;
case 2:
examples/app/minesweeper/src/Style.cpp
Minesweeper Game - Minesweeper game implementation driven by ass.
}
void setupConnections(AView* view, const _<AAssHelper>& helper) override {
IAssSubSelector::setupConnections(view, helper);
view->customCssPropertyChanged.clearAllOutgoingConnectionsWith(helper.get());
AObject::connect(view->customCssPropertyChanged, AUI_SLOT(helper)::onInvalidateStateAss);
}
};
/// [CellSelector]
height#
- Returns
- Image height.
Examples#
examples/app/game_of_life/src/main.cpp
Game of Life - Game of Life implementation that uses advanced large dynamic data rendering techniques such as ITexture, AImage to be GPU friendly. The computation is performed in AThreadPool.
mTexture = AWindow::current()->getRenderingContext()->renderer().getNewTexture();
}
CellsImage image(mCells->size());
for (unsigned y = 0; y < image.height(); ++y) {
for (unsigned x = 0; x < image.width(); ++x) {
image.set(
{ x, y },
AFormattedColorConverter(
(*mCells)[glm::ivec2(x, y)] == CellState::ALIVE
rawDataAt#
Retrieves reference to raw data at specified position.
- Arguments
position
position- Returns
- reference to raw pixel data
Specifying position out of image range causes assertion fail in debug or undefined behaviour.
size#
- Returns
- Image size.
Examples#
examples/app/fractal/src/FractalView.cpp
Fractal Example - Fractal viewer application demonstrating usage of custom shaders.
mTexture->bind();
context.render.rectangle(ACustomShaderBrush {}, { 0, 0 }, getSize());
}
void FractalView::setSize(glm::ivec2 size) {
AView::setSize(size);
mShader.use();
mShader.set(UNIFORM_RATIO, mAspectRatio = float(size.x) / float(size.y));
}
examples/app/game_of_life/src/main.cpp
Game of Life - Game of Life implementation that uses advanced large dynamic data rendering techniques such as ITexture, AImage to be GPU friendly. The computation is performed in AThreadPool.
using CellsImage = AFormattedImage<APixelFormat::RGBA_BYTE>;
class Cells : public AObject {
public:
Cells(glm::ivec2 size) {
mSize = size;
for (auto s : { &mStorage, &mNextPopulation }) {
s->resize(size.x * size.y);
}
examples/7guis/cells/src/Spreadsheet.h
7GUIs Cells - Spreadsheet processor (Excel).
examples/7guis/cells/src/main.cpp
7GUIs Cells - Spreadsheet processor (Excel).
examples/7guis/cells/src/Functions.cpp
7GUIs Cells - Spreadsheet processor (Excel).
return double(accumulator);
} },
{ "IF",
[](Ctx ctx) {
if (ctx.args.size() != 3) {
throw AException("ARG");
}
auto condition = std::get_if<double>(&ctx.args[0]);
if (condition == nullptr) {
throw AException("ARG0");
width#
- Returns
- Image width.
Examples#
examples/app/game_of_life/src/main.cpp
Game of Life - Game of Life implementation that uses advanced large dynamic data rendering techniques such as ITexture, AImage to be GPU friendly. The computation is performed in AThreadPool.
}
CellsImage image(mCells->size());
for (unsigned y = 0; y < image.height(); ++y) {
for (unsigned x = 0; x < image.width(); ++x) {
image.set(
{ x, y },
AFormattedColorConverter(
(*mCells)[glm::ivec2(x, y)] == CellState::ALIVE
? AColor::WHITE