File: interpolate.c

package info (click to toggle)
oolite 1.77.1-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 41,264 kB
  • ctags: 5,362
  • sloc: objc: 132,090; ansic: 10,457; python: 2,225; sh: 1,325; makefile: 332; perl: 259; xml: 125; php: 5
file content (39 lines) | stat: -rw-r--r-- 876 bytes parent folder | download
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
32
33
34
35
36
37
38
39
#include "FPMImageOperations.h"
#include "FPMPNG.h"
#include <assert.h>


enum
{
	kOutWidth = 173,
	kOutHeight = 219
};


#define kWorkingSpace kFPMGammaLinear


int main (int argc, const char * argv[])
{
	FPMInit();
	
	assert(argc > 1);
	FloatPixMapRef source = FPMCreateWithPNG(argv[1], kWorkingSpace, NULL);
	FloatPixMapRef target = FPMCreateC(kOutWidth, kOutHeight);
	
	float xscale = (float)FPMGetWidth(source) / (float)kOutWidth;
	float yscale = (float)FPMGetHeight(source) / (float)kOutHeight;
	
	FPM_FOR_EACH_PIXEL(target, true)
	{
		float fx = ((float)x) * xscale;
		float fy = ((float)y) * yscale;
		
	//	printf("(%i, %i) -> (%g, %g)\n", x, y, fx, fy);
		
		*pixel = FPMSampleCubic(source, fx, fy, kFPMWrapClamp, kFPMWrapClamp);
	}
	FPM_END_FOR_EACH_PIXEL
	
	FPMWritePNG(target, "/tmp/fpm-sample-test.png", kFPMWritePNGDither, kWorkingSpace, kFPMGammaSRGB, NULL);
}