KiCad PCB EDA Suite
Loading...
Searching...
No Matches
buffers_debug.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2016 Mario Luzeiro <[email protected]>
5 * Copyright (C) 2016-2024 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program 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 this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
30#include "buffers_debug.h"
31#include <wx/image.h> // Used for save an image to disk
32
38static void dbg_save_rgb_buffer( const wxString& aFileName, unsigned char *aRGBpixelBuffer,
39 unsigned int aXSize, unsigned int aYSize )
40{
41 wxImage image( aXSize, aYSize );
42 image.SetData( aRGBpixelBuffer );
43 image = image.Mirror( false );
44 image.SaveFile( aFileName + wxT( ".png" ), wxBITMAP_TYPE_PNG );
45 image.Destroy();
46}
47
48
49static void dbg_save_rgb_a_buffer( const wxString& aFileName, unsigned char* aRGBpixelBuffer,
50 unsigned char* aAlphaBuffer, unsigned int aXSize,
51 unsigned int aYSize )
52{
53 wxImage image( aXSize, aYSize );
54 image.SetData( aRGBpixelBuffer );
55 image.SetAlpha( aAlphaBuffer );
56 image = image.Mirror( false );
57 image.SaveFile( aFileName + wxT( ".png" ), wxBITMAP_TYPE_PNG );
58 image.Destroy();
59}
60
61
62void DBG_SaveBuffer( const wxString& aFileName, const unsigned char *aInBuffer,
63 unsigned int aXSize, unsigned int aYSize )
64{
65 const unsigned int wxh = aXSize * aYSize;
66
67 unsigned char *pixelbuffer = (unsigned char*) malloc( wxh * 3 );
68
69 for( unsigned int i = 0; i < wxh; ++i )
70 {
71 unsigned char v = aInBuffer[i];
72
73 // Set RGB value with all same values intensities
74 pixelbuffer[i * 3 + 0] = v;
75 pixelbuffer[i * 3 + 1] = v;
76 pixelbuffer[i * 3 + 2] = v;
77 }
78
79 dbg_save_rgb_buffer( aFileName, pixelbuffer, aXSize, aYSize );
80}
81
82
83void DBG_SaveBuffer( const wxString& aFileName, const float *aInBuffer,
84 unsigned int aXSize, unsigned int aYSize )
85{
86 const unsigned int wxh = aXSize * aYSize;
87
88 unsigned char *pixelbuffer = (unsigned char*) malloc( wxh * 3 );
89
90 for( unsigned int i = 0; i < wxh; ++i )
91 {
92 const unsigned char v = (unsigned char)glm::min( (int)(aInBuffer[i] * 255.0f), 255 );
93
94 // Set RGB value with all same values intensities
95 pixelbuffer[i * 3 + 0] = v;
96 pixelbuffer[i * 3 + 1] = v;
97 pixelbuffer[i * 3 + 2] = v;
98 }
99
100 dbg_save_rgb_buffer( aFileName, pixelbuffer, aXSize, aYSize );
101}
102
103
104void DBG_SaveBuffer( const wxString& aFileName, const SFVEC3F *aInBuffer,
105 unsigned int aXSize, unsigned int aYSize )
106{
107 const unsigned int wxh = aXSize * aYSize;
108
109 unsigned char *pixelbuffer = (unsigned char*) malloc( wxh * 3 );
110
111 for( unsigned int i = 0; i < wxh; ++i )
112 {
113 const SFVEC3F &v = aInBuffer[i];
114 const unsigned int ix3 = i * 3;
115
116 // Set RGB value with all same values intensities
117 pixelbuffer[ix3 + 0] = (unsigned char) glm::min( (int) ( v.r * 255.0f ), 255 );
118 pixelbuffer[ix3 + 1] = (unsigned char) glm::min( (int) ( v.g * 255.0f ), 255 );
119 pixelbuffer[ix3 + 2] = (unsigned char) glm::min( (int) ( v.b * 255.0f ), 255 );
120 }
121
122 dbg_save_rgb_buffer( aFileName, pixelbuffer, aXSize, aYSize );
123}
124
125
126void DBG_SaveBuffer( const wxString& aFileName, const SFVEC4F *aInBuffer,
127 unsigned int aXSize, unsigned int aYSize )
128{
129 const unsigned int wxh = aXSize * aYSize;
130
131 unsigned char *pixelbuffer = (unsigned char*) malloc( wxh * 4 );
132 unsigned char *alphabuffer = (unsigned char*) malloc( wxh );
133
134 for( unsigned int i = 0; i < wxh; ++i )
135 {
136 const SFVEC4F &v = aInBuffer[i];
137 const unsigned int ix3 = i * 3;
138
139 // Set RGB value with all same values intensities
140 pixelbuffer[ix3 + 0] = (unsigned char) glm::min( (int) ( v.r * 255.0f ), 255 );
141 pixelbuffer[ix3 + 1] = (unsigned char) glm::min( (int) ( v.g * 255.0f ), 255 );
142 pixelbuffer[ix3 + 2] = (unsigned char) glm::min( (int) ( v.b * 255.0f ), 255 );
143
144 alphabuffer[i] = (unsigned char) glm::min( (int) ( v.a * 255.0f ), 255 );
145 }
146
147 dbg_save_rgb_a_buffer( aFileName, pixelbuffer, alphabuffer, aXSize, aYSize );
148}
149
150
151void DBG_SaveNormalsBuffer( const wxString& aFileName, const SFVEC3F *aInNormalsBuffer,
152 unsigned int aXSize, unsigned int aYSize )
153{
154 const unsigned int wxh = aXSize * aYSize;
155
156 unsigned char *pixelbuffer = (unsigned char*) malloc( wxh * 3 );
157
158 for( unsigned int i = 0; i < wxh; ++i )
159 {
160 const SFVEC3F &v = aInNormalsBuffer[i];
161 const unsigned int ix3 = i * 3;
162
163 // Set RGB value with all same values intensities
164 pixelbuffer[ix3 + 0] = (unsigned char) glm::min( (int) ( ( v.r + 1.0f ) * 127.0f ), 255 );
165 pixelbuffer[ix3 + 1] = (unsigned char) glm::min( (int) ( ( v.g + 1.0f ) * 127.0f ), 255 );
166 pixelbuffer[ix3 + 2] = (unsigned char) glm::min( (int) ( ( v.b + 1.0f ) * 127.0f ), 255 );
167 }
168
169 dbg_save_rgb_buffer( aFileName, pixelbuffer, aXSize, aYSize );
170}
void DBG_SaveBuffer(const wxString &aFileName, const unsigned char *aInBuffer, unsigned int aXSize, unsigned int aYSize)
static void dbg_save_rgb_a_buffer(const wxString &aFileName, unsigned char *aRGBpixelBuffer, unsigned char *aAlphaBuffer, unsigned int aXSize, unsigned int aYSize)
static void dbg_save_rgb_buffer(const wxString &aFileName, unsigned char *aRGBpixelBuffer, unsigned int aXSize, unsigned int aYSize)
void DBG_SaveNormalsBuffer(const wxString &aFileName, const SFVEC3F *aInNormalsBuffer, unsigned int aXSize, unsigned int aYSize)
glm::vec3 SFVEC3F
Definition: xv3d_types.h:44
glm::vec4 SFVEC4F
Definition: xv3d_types.h:46