forked from knarkowicz/IntegrateDFG
-
Notifications
You must be signed in to change notification settings - Fork 0
/
csv.cpp
31 lines (28 loc) · 819 Bytes
/
csv.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <stdio.h>
#include "csv.h"
void SaveCSV( char const* name, unsigned sampleNum )
{
FILE* f = fopen( name, "w" );
for ( unsigned i = 0; i < sampleNum; ++i )
{
float const sample = ( i + 0.5f ) / sampleNum;
fprintf( f, "%f%s", sample, i + 1 < sampleNum ? ", " : "" );
}
fclose( f );
}
void SaveCSV( char const* name, float* lutData, unsigned lutWidth, unsigned lutHeight, unsigned elemOffset )
{
FILE* f = fopen( name, "w" );
for ( unsigned y = 0; y < lutHeight; ++y )
{
for ( unsigned x = 0; x < lutWidth; ++x )
{
fprintf( f, "%f%s", lutData[ x * 4 + y * lutWidth * 4 + elemOffset ], x + 1 < lutWidth ? ", " : "" );
}
if ( y + 1 < lutHeight )
{
fputs( "\n", f );
}
}
fclose( f );
}