ogre_tile.cpp
Go to the documentation of this file.
1 /* Copyright 2014 Gareth Cross, 2018-2019 TomTom N.V.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7 http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License. */
14 
15 #include "ogre_tile.h"
16 
17 #include <string>
18 
19 namespace
20 {
24 QImage convertImage(QImage image)
25 {
26  return image.convertToFormat(QImage::Format_RGB888).mirrored();
27 }
28 
32 std::string uniqueTextureName()
33 {
34  static int count = 0;
35  ++count;
36  return "satellite_texture_" + std::to_string(count);
37 }
38 
42 Ogre::TexturePtr textureFromImage(QImage image)
43 {
44  Ogre::DataStreamPtr data_stream;
45  data_stream.bind(new Ogre::MemoryDataStream((void*)image.constBits(), image.byteCount()));
46 
47  Ogre::String const res_group = Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME;
48 
49  Ogre::TextureManager& texture_manager = Ogre::TextureManager::getSingleton();
50 
51  // swap byte order when going from QImage to Ogre
52  return texture_manager.loadRawData(uniqueTextureName(), res_group, data_stream, image.width(), image.height(),
53  Ogre::PF_B8G8R8, Ogre::TEX_TYPE_2D, 0);
54 }
55 } // namespace
56 
57 OgreTile::OgreTile(QImage image_) : texture(textureFromImage(convertImage(std::move(image_))))
58 {
59 }
OgreTile(QImage image_)
Definition: ogre_tile.cpp:57


rviz_satellite
Author(s): Gareth Cross , Andre Schröder
autogenerated on Thu May 4 2023 02:31:43