Rigs of Rods 2023.09
Soft-body Physics Simulation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
AdvancedScreen.h
Go to the documentation of this file.
1/*
2 This source file is part of Rigs of Rods
3 Copyright 2005-2012 Pierre-Michel Ricordel
4 Copyright 2007-2012 Thomas Fischer
5
6 For more information, see http://www.rigsofrods.org/
7
8 Rigs of Rods is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License version 3, as
10 published by the Free Software Foundation.
11
12 Rigs of Rods is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
19*/
20
21// create by thomas fischer, 6th of februray 2011
22
23#pragma once
24
25#include "Application.h"
26
27#include <thread>
28
29#define SET_BIT(var, pos) ((var) |= (1<<(pos)))
30#define CLEAR_BIT(var, pos) ((var) &= ~(1<<(pos)))
31#define SET_LSB(var) ((var) |= 1)
32#define CLEAR_LSB(var) ((var) &= ~1)
33#define CHECK_BIT(var,pos) ((var) & (1<<(pos)))
34
35void save(Ogre::uchar* data, Ogre::uchar* databuf, int mWidth, int mHeight, Ogre::PixelFormat pf, Ogre::String filename)
36{
37 Ogre::Image img;
38 img.loadDynamicImage(data, mWidth, mHeight, 1, pf, false, 1, 0);
39 img.save(filename);
40
41 OGRE_FREE(data, Ogre::MEMCATEGORY_RENDERSYS);
42 OGRE_FREE(databuf, Ogre::MEMCATEGORY_RENDERSYS);
43}
44
45// this only works with lossless image compression (png)
46
48{
49public:
50
51 AdvancedScreen(Ogre::RenderWindow* win, Ogre::String filename) :
52 win(win)
54 {
55 }
56
58 {
59 }
60
61 void addData(Ogre::String name, Ogre::String value)
62 {
63 if (value.empty())
64 return;
65 map[name] = value;
66 }
67
68 void write()
69 {
70 // please do not misinterpret this feature
71 // its used in the forums like an EXTIF data to display things beside the screenshots
72 int mWidth = win->getWidth();
73 int mHeight = win->getHeight();
74
75 // grab the image data
76 Ogre::PixelFormat pf = Ogre::PF_B8G8R8; //win->suggestPixelFormat();
77 long isize = mWidth * mHeight * (long)Ogre::PixelUtil::getNumElemBytes(pf);
78 Ogre::uchar* data = OGRE_ALLOC_T(Ogre::uchar, isize, Ogre::MEMCATEGORY_RENDERSYS);
79 Ogre::PixelBox pb(mWidth, mHeight, 1, pf, data);
80 win->copyContentsToMemory(pb);
81
82 // now do the fancy stuff ;)
83
84 // 0. allocate enough buffer
85 Ogre::uchar* databuf = OGRE_ALLOC_T(Ogre::uchar, 32768, Ogre::MEMCATEGORY_RENDERSYS);
86 char* ptr = (char *)databuf;
87 // header
88 long dsize = 0;
89 int w = sprintf(ptr, "RORED\n");
90 ptr += w;
91 dsize += w;
92
93 // 1. convert the std::map to something properly
94 for (std::map<Ogre::String, Ogre::String>::iterator it = map.begin(); it != map.end(); it++)
95 {
96 int w2 = sprintf(ptr, "%s:%s\n", it->first.c_str(), it->second.c_str());
97 ptr += w2;
98 dsize += w2;
99 }
100
101 // now buffer ready, put it into the image
102 Ogre::uchar* ptri = data;
103 // set data pointer to the start again
104 ptr = (char *)databuf;
105 int bc = 7;
106 for (long b = 0; b < isize && b < dsize * 8 + 40; b++ , ptri++) // 40 = 5 zero bytes
107 {
108 if (CHECK_BIT(*ptr, bc))
109 SET_LSB(*ptri);
110 else
111 CLEAR_LSB(*ptri);
112 bc--;
113 if (bc < 0)
114 {
115 bc = 7;
116 ptr++;
117 }
118 }
119
120 std::thread(save, data, databuf, mWidth, mHeight, pf, filename).detach();
121 }
122
123protected:
124
125 Ogre::RenderWindow* win;
126 Ogre::String filename;
127 std::map<Ogre::String, Ogre::String> map;
128};
#define SET_LSB(var)
#define CHECK_BIT(var, pos)
#define CLEAR_LSB(var)
void save(Ogre::uchar *data, Ogre::uchar *databuf, int mWidth, int mHeight, Ogre::PixelFormat pf, Ogre::String filename)
Central state/object manager and communications hub.
void addData(Ogre::String name, Ogre::String value)
Ogre::RenderWindow * win
std::map< Ogre::String, Ogre::String > map
Ogre::String filename
AdvancedScreen(Ogre::RenderWindow *win, Ogre::String filename)