File: ppeffect_temperature.cpp

package info (click to toggle)
photoprint 0.4.1-3
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 10,568 kB
  • ctags: 4,517
  • sloc: cpp: 46,643; sh: 10,360; ansic: 4,755; makefile: 543; sed: 16
file content (110 lines) | stat: -rw-r--r-- 2,282 bytes parent folder | download | duplicates (3)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include <iostream>
#include <stdlib.h>
#include <string.h>

#include <gdk-pixbuf/gdk-pixdata.h>

#include "imagesource_cms.h"
#include "layout.h"

#include "ppeffect_temperature.h"
#include "ppeffect_temperature_icon.cpp"

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "gettext.h"
#define _(x) gettext(x)
#define N_(x) gettext_noop(x)


const char *PPEffect_Temperature::ID="Temperature";
const char *PPEffect_Temperature::GetID()
{
	return(ID);
}

const char *PPEffect_Temperature::Name=N_("Warm/Cool");
const char *PPEffect_Temperature::GetName()
{
	return(gettext(Name));
}


PPEffect_Temperature::PPEffect_Temperature(PPEffectHeader &header,int priority,enum PPEFFECT_STAGE stage)
	:	PPEffect(header,priority,stage), tempchange(0), transform(NULL)
{
}


PPEffect_Temperature::~PPEffect_Temperature()
{
	if(transform)
		delete transform;
}


PPEffect_Temperature *PPEffect_Temperature::Clone(PPEffectHeader &head)
{
	PPEffect_Temperature *result=new PPEffect_Temperature(head,priority,stage);
	result->SetTempChange(GetTempChange());
	return(result);
}


void PPEffect_Temperature::MakeTransform(IS_TYPE type)
{
	CMSRGBGamma RGBGamma(2.2,2.2,2.2);
	CMSGamma GreyGamma(2.2);
	CMSWhitePoint srcwp(6500+tempchange);
	CMSWhitePoint dstwp(6500);
	CMSProfile *source;
	switch(STRIP_ALPHA(type))
	{
		case IS_TYPE_RGB:
			source=new CMSProfile(CMSPrimaries_Rec709,RGBGamma,srcwp);
			break;
		case IS_TYPE_GREY:
			source=new CMSProfile(GreyGamma,srcwp);
			break;
		default:
			throw "Only RGB and Greyscale images are currently supported";
	}
	if(!source)
		throw "Can't create source profile";

	CMSProfile dest(CMSPrimaries_Rec709,RGBGamma,dstwp);
	transform=new CMSTransform(source,&dest,LCMSWRAPPER_INTENT_ABSOLUTE_COLORIMETRIC);
	delete source;
}


ImageSource *PPEffect_Temperature::Apply(ImageSource *source)
{
	if(!transform)
		MakeTransform(source->type);

	if(transform->GetInputColourSpace()!=STRIP_ALPHA(source->type))
	{
		delete transform;
		transform=NULL;
		MakeTransform(source->type);
	}
	return(new ImageSource_CMS(source,transform));
}


void PPEffect_Temperature::SetTempChange(int tempchange)
{
	if(transform)
		delete transform;
	transform=NULL;
	this->tempchange=tempchange;
}


int PPEffect_Temperature::GetTempChange()
{
	return (tempchange);
}