Gazebo Rendering

API Reference

6.7.0
gz/rendering/PixelBuffer.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2026 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 #ifndef GZ_RENDERING_PIXELBUFFER_HH_
18 #define GZ_RENDERING_PIXELBUFFER_HH_
19 
20 #include <cstddef>
21 
22 #include "gz/rendering/config.hh"
23 #include "gz/rendering/Export.hh"
25 
26 namespace ignition
27 {
28  namespace rendering
29  {
30  inline namespace IGNITION_RENDERING_VERSION_NAMESPACE {
31  //
32  class Image;
33 
48  class IGNITION_RENDERING_VISIBLE PixelBuffer
49  {
56  public: PixelBuffer(unsigned int _width, unsigned int _height,
57  PixelFormat _format, void *_data, std::size_t _size);
58 
62  public: explicit PixelBuffer(Image &_image);
63 
66  public: PixelBuffer(const PixelBuffer &_other) = default;
67 
69  public: PixelBuffer &operator=(const PixelBuffer &) = delete;
70 
72  public: PixelBuffer &operator=(PixelBuffer &&) = delete;
73 
75  public: ~PixelBuffer() = default;
76 
79  public: unsigned int Width() const;
80 
83  public: unsigned int Height() const;
84 
87  public: PixelFormat Format() const;
88 
91  public: std::size_t Size() const;
92 
95  public: std::size_t MemorySize() const;
96 
100  public: bool Valid() const;
101 
106  public: unsigned char *Data() const;
107 
109  private: const unsigned int width;
110 
112  private: const unsigned int height;
113 
115  private: const PixelFormat format;
116 
118  private: unsigned char *const data;
119 
121  private: const std::size_t size;
122  };
123  }
124  }
125 }
126 #endif
Encapsulates a raw image buffer and relevant properties.
Definition: gz/rendering/Image.hh:40
Non owning, writable view of a caller owned pixel buffer.
Definition: gz/rendering/PixelBuffer.hh:49
~PixelBuffer()=default
Destructor. Does not free the buffer.
unsigned int Width() const
Get the width in pixels.
bool Valid() const
Check that the buffer can hold a frame: the pointer is not null and Size() is at least MemorySize().
PixelBuffer(const PixelBuffer &_other)=default
Copy constructor. Copies of a view share the same buffer.
std::size_t MemorySize() const
Get the number of bytes Width x Height pixels of Format need.
PixelBuffer & operator=(PixelBuffer &&)=delete
Views cannot be rebound.
PixelBuffer(unsigned int _width, unsigned int _height, PixelFormat _format, void *_data, std::size_t _size)
Describe a caller owned buffer.
unsigned char * Data() const
Get a pointer to the first byte of the buffer. The pointer is writable even through a const view: thi...
std::size_t Size() const
Get the size of the buffer in bytes, as given by the caller.
unsigned int Height() const
Get the height in pixels.
PixelBuffer & operator=(const PixelBuffer &)=delete
Views cannot be rebound.
PixelFormat Format() const
Get the pixel format.
PixelBuffer(Image &_image)
View the storage of an existing image. The view is only valid while the image, or a copy of it,...
PixelFormat
Image pixel format types.
Definition: gz/rendering/PixelFormat.hh:33