KiCad PCB EDA Suite
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 <mrluzeiro@ua.pt>
5  * Copyright (C) 1992-2016 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 
42 static void dbg_save_rgb_buffer( wxString aFileName,
43  unsigned char *aRGBpixelBuffer,
44  unsigned int aXSize,
45  unsigned int aYSize )
46 {
47  wxImage image( aXSize, aYSize );
48  image.SetData( aRGBpixelBuffer );
49  image = image.Mirror( false );
50  image.SaveFile( aFileName + ".png", wxBITMAP_TYPE_PNG );
51  image.Destroy();
52 }
53 
54 
55 void DBG_SaveBuffer( wxString aFileName,
56  const unsigned char *aInBuffer,
57  unsigned int aXSize,
58  unsigned int aYSize )
59 {
60  const unsigned int wxh = aXSize * aYSize;
61 
62  unsigned char *pixelbuffer = (unsigned char*) malloc( wxh * 3 );
63 
64  for( unsigned int i = 0; i < wxh; ++i )
65  {
66  unsigned char v = aInBuffer[i];
67 
68  // Set RGB value with all same values intensities
69  pixelbuffer[i * 3 + 0] = v;
70  pixelbuffer[i * 3 + 1] = v;
71  pixelbuffer[i * 3 + 2] = v;
72  }
73 
74  dbg_save_rgb_buffer( aFileName, pixelbuffer, aXSize, aYSize );
75 }
76 
77 
78 void DBG_SaveBuffer( wxString aFileName,
79  const float *aInBuffer,
80  unsigned int aXSize,
81  unsigned int aYSize )
82 {
83  const unsigned int wxh = aXSize * aYSize;
84 
85  unsigned char *pixelbuffer = (unsigned char*) malloc( wxh * 3 );
86 
87  for( unsigned int i = 0; i < wxh; ++i )
88  {
89  const unsigned char v = (unsigned char)glm::min( (int)(aInBuffer[i] * 255.0f),
90  255 );
91 
92  // Set RGB value with all same values intensities
93  pixelbuffer[i * 3 + 0] = v;
94  pixelbuffer[i * 3 + 1] = v;
95  pixelbuffer[i * 3 + 2] = v;
96  }
97 
98  dbg_save_rgb_buffer( aFileName, pixelbuffer, aXSize, aYSize );
99 }
100 
101 
102 void DBG_SaveBuffer( wxString aFileName,
103  const SFVEC3F *aInBuffer,
104  unsigned int aXSize,
105  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 
126 void DBG_SaveNormalsBuffer( wxString aFileName,
127  const SFVEC3F *aInNormalsBuffer,
128  unsigned int aXSize,
129  unsigned int aYSize )
130 {
131  const unsigned int wxh = aXSize * aYSize;
132 
133  unsigned char *pixelbuffer = (unsigned char*) malloc( wxh * 3 );
134 
135  for( unsigned int i = 0; i < wxh; ++i )
136  {
137  const SFVEC3F &v = aInNormalsBuffer[i];
138  const unsigned int ix3 = i * 3;
139 
140  // Set RGB value with all same values intensities
141  pixelbuffer[ix3 + 0] = (unsigned char)glm::min( (int)((v.r + 1.0f) * 127.0f), 255 );
142  pixelbuffer[ix3 + 1] = (unsigned char)glm::min( (int)((v.g + 1.0f) * 127.0f), 255 );
143  pixelbuffer[ix3 + 2] = (unsigned char)glm::min( (int)((v.b + 1.0f) * 127.0f), 255 );
144  }
145 
146  dbg_save_rgb_buffer( aFileName, pixelbuffer, aXSize, aYSize );
147 }
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47
static void dbg_save_rgb_buffer(wxString aFileName, unsigned char *aRGBpixelBuffer, unsigned int aXSize, unsigned int aYSize)
dbg_save_rgb_buffer
void DBG_SaveNormalsBuffer(wxString aFileName, const SFVEC3F *aInNormalsBuffer, unsigned int aXSize, unsigned int aYSize)
void DBG_SaveBuffer(wxString aFileName, const unsigned char *aInBuffer, unsigned int aXSize, unsigned int aYSize)
#define min(a, b)
Definition: auxiliary.h:85