~ubuntu-branches/ubuntu/karmic/photoprint/karmic

« back to all changes in this revision

Viewing changes to effects/ppeffect_temperature.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Milan Zamazal
  • Date: 2007-05-01 16:32:13 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070501163213-ni1933khtg9fdvn5
Tags: 0.3.5-2
Move to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <iostream>
 
2
#include <stdlib.h>
 
3
#include <string.h>
 
4
 
 
5
#include <gdk-pixbuf/gdk-pixdata.h>
 
6
 
 
7
#include "../imagesource/imagesource_cms.h"
 
8
#include "../layout.h"
 
9
 
 
10
#include "ppeffect_temperature.h"
 
11
#include "ppeffect_temperature_icon.cpp"
 
12
 
 
13
PPEffect_Temperature::PPEffect_Temperature(PPEffectHeader &header,enum PPEFFECT_STAGE stage)
 
14
        :       PPEffect(header,stage), tempchange(0), transform(NULL)
 
15
{
 
16
}
 
17
 
 
18
 
 
19
PPEffect_Temperature::~PPEffect_Temperature()
 
20
{
 
21
        if(transform)
 
22
                delete transform;
 
23
}
 
24
 
 
25
 
 
26
void PPEffect_Temperature::MakeTransform(IS_TYPE type)
 
27
{
 
28
        CMSRGBGamma RGBGamma(2.2,2.2,2.2);
 
29
        CMSGamma GreyGamma(2.2);
 
30
        CMSWhitePoint srcwp(6500+tempchange);
 
31
        CMSWhitePoint dstwp(6500);
 
32
        CMSProfile *source;
 
33
        switch(STRIP_ALPHA(type))
 
34
        {
 
35
                case IS_TYPE_RGB:
 
36
                        source=new CMSProfile(CMSPrimaries_Rec709,RGBGamma,srcwp);
 
37
                        break;
 
38
                case IS_TYPE_GREY:
 
39
                        source=new CMSProfile(GreyGamma,srcwp);
 
40
                        break;
 
41
                default:
 
42
                        throw "Only RGB and Greyscale images are currently supported";
 
43
        }
 
44
        if(!source)
 
45
                throw "Can't create source profile";
 
46
 
 
47
        CMSProfile dest(CMSPrimaries_Rec709,RGBGamma,dstwp);
 
48
        transform=new CMSTransform(source,&dest,LCMSWRAPPER_INTENT_ABSOLUTE_COLORIMETRIC);
 
49
        delete source;
 
50
}
 
51
 
 
52
 
 
53
ImageSource *PPEffect_Temperature::Apply(ImageSource *source)
 
54
{
 
55
        if(!transform)
 
56
                MakeTransform(source->type);
 
57
 
 
58
        if(transform->GetInputColourSpace()!=STRIP_ALPHA(source->type))
 
59
        {
 
60
                delete transform;
 
61
                transform=NULL;
 
62
                MakeTransform(source->type);
 
63
        }
 
64
        return(new ImageSource_CMS(source,transform));
 
65
}
 
66
 
 
67
 
 
68
void PPEffect_Temperature::SetTempChange(int tempchange)
 
69
{
 
70
        if(transform)
 
71
                delete transform;
 
72
        transform=NULL;
 
73
        this->tempchange=tempchange;
 
74
}
 
75
 
 
76
 
 
77
GdkPixbuf *PPEffect_Temperature::icon=NULL;
 
78
 
 
79
GdkPixbuf *PPEffect_Temperature::GetIcon_static()
 
80
{
 
81
        if(icon)
 
82
                return(icon);
 
83
        GdkPixdata pd;
 
84
        GError *err;
 
85
 
 
86
        if(!gdk_pixdata_deserialize(&pd,sizeof(PPEffect_Temperature_Icon),PPEffect_Temperature_Icon,&err))
 
87
                throw(err->message);
 
88
 
 
89
        if(!(icon=gdk_pixbuf_from_pixdata(&pd,false,&err)))
 
90
                throw(err->message);
 
91
 
 
92
        return(icon);
 
93
}