Blue Brain BioExplorer
FrameBuffer.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2024, EPFL/Blue Brain Project
3  *
4  * The Blue Brain BioExplorer is a tool for scientists to extract and analyse
5  * scientific data from visualization
6  *
7  * This file is part of Blue Brain BioExplorer <https://github.com/BlueBrain/BioExplorer>
8  *
9  * This library is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU Lesser General Public License version 3.0 as published
11  * by the Free Software Foundation.
12  *
13  * This library is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this library; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22 
23 #include "FrameBuffer.h"
24 
25 namespace core
26 {
27 FrameBuffer::FrameBuffer(const std::string& name, const Vector2ui& frameSize, const FrameBufferFormat frameBufferFormat)
28  : _name(name)
29  , _frameSize(frameSize)
30  , _frameBufferFormat(frameBufferFormat)
31 {
32 }
33 
35 {
36  switch (_frameBufferFormat)
37  {
41  return 4;
43  return 3;
44  default:
45  return 0;
46  }
47 }
48 
50 {
51  map();
52  const auto colorBuffer = getColorBuffer();
53  const auto& size = getSize();
54 
55  freeimage::ImagePtr image(FreeImage_ConvertFromRawBits(const_cast<uint8_t*>(colorBuffer), size.x, size.y,
56  getColorDepth() * size.x, 8 * getColorDepth(), 0xFF0000,
57  0x00FF00, 0x0000FF, false));
58 
59  unmap();
60 
61 #if FREEIMAGE_COLORORDER == FREEIMAGE_COLORORDER_BGR
62  freeimage::SwapRedBlue32(image.get());
63 #endif
64  return image;
65 }
66 } // namespace core
virtual PLATFORM_API const uint8_t * getColorBuffer() const =0
Get the Color Buffer object.
PLATFORM_API FrameBuffer(const std::string &name, const Vector2ui &frameSize, FrameBufferFormat frameBufferFormat)
FrameBuffer constructor.
Definition: FrameBuffer.cpp:27
virtual PLATFORM_API void map()=0
Map the buffer for reading with get*Buffer().
FrameBufferFormat _frameBufferFormat
Definition: FrameBuffer.h:209
PLATFORM_API size_t getColorDepth() const
Get the Color Depth object.
Definition: FrameBuffer.cpp:34
PLATFORM_API freeimage::ImagePtr getImage()
Get the Image object.
Definition: FrameBuffer.cpp:49
virtual PLATFORM_API Vector2ui getSize() const
Get the Size object.
Definition: FrameBuffer.h:97
virtual PLATFORM_API void unmap()=0
Unmap the buffer for reading with get*Buffer().
std::unique_ptr< FIBITMAP, ImageDeleter > ImagePtr
Definition: ImageUtils.h:49
bool SwapRedBlue32(FIBITMAP *freeImage)
Definition: ImageUtils.cpp:40
FrameBufferFormat
Definition: Types.h:205
glm::vec< 2, uint32_t > Vector2ui
Definition: MathTypes.h:133