MeshLib Documentation
Loading...
Searching...
No Matches
MRImage.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRColor.h"
4#include "MRVector2.h"
5#include "MRHeapBytes.h"
6#include <cassert>
7#include <vector>
8
9namespace MR
10{
11
14struct Image
15{
16 std::vector<Color> pixels;
17 Vector2i resolution;
18
20 [[nodiscard]] Color& operator[]( const Vector2i & p );
21 [[nodiscard]] Color operator[]( const Vector2i & p ) const;
22
24 [[nodiscard]] size_t heapBytes() const { return MR::heapBytes( pixels ); }
25
28 [[nodiscard]] MRMESH_API Color sampleDiscrete( const UVCoord & pos ) const;
29
32 [[nodiscard]] MRMESH_API Color sampleBilinear( const UVCoord & pos ) const;
33
36 [[nodiscard]] Color sample( FilterType filter, const UVCoord & pos ) const
37 { return filter == FilterType::Discrete ? sampleDiscrete( pos ) : sampleBilinear( pos ); }
38};
39
40inline Color& Image::operator[]( const Vector2i & p )
41{
42 assert( p.x >= 0 && p.x < resolution.x );
43 assert( p.y >= 0 && p.y < resolution.y );
44 return pixels[p.x + p.y * resolution.x];
45}
46
47inline Color Image::operator[]( const Vector2i & p ) const
48{
49 assert( p.x >= 0 && p.x < resolution.x );
50 assert( p.y >= 0 && p.y < resolution.y );
51 return pixels[p.x + p.y * resolution.x];
52}
53
54} //namespace MR
#define MRMESH_API
Definition MRMesh/MRMeshFwd.h:46
size_t heapBytes(const std::vector< T > &vec)
returns the amount of memory given vector occupies on heap
Definition MRHeapBytes.h:15
Definition MRCameraOrientationPlugin.h:8
FilterType
Definition MRMesh/MRMeshFwd.h:579
Vector2f UVCoord
Definition MRMesh/MRMeshFwd.h:380
Definition MRColor.h:9
Definition MRImage.h:15
MRMESH_API Color sampleBilinear(const UVCoord &pos) const
Vector2i resolution
Definition MRImage.h:17
Color & operator[](const Vector2i &p)
fetches some texture element specified by integer coordinates
Definition MRImage.h:40
MRMESH_API Color sampleDiscrete(const UVCoord &pos) const
std::vector< Color > pixels
Definition MRImage.h:16
size_t heapBytes() const
returns the amount of memory this object occupies on heap
Definition MRImage.h:24
Color sample(FilterType filter, const UVCoord &pos) const
Definition MRImage.h:36