~ubuntu-branches/ubuntu/gutsy/blender/gutsy-security

« back to all changes in this revision

Viewing changes to release/plugins/sequence/gamma.c

  • Committer: Bazaar Package Importer
  • Author(s): Lukas Fittl
  • Date: 2006-09-20 01:57:27 UTC
  • mfrom: (1.2.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20060920015727-gmoqlxwstx9wwqs3
Tags: 2.42a-1ubuntu1
* Merge from Debian unstable (Closes: Malone #55903). Remaining changes:
  - debian/genpot: Add python scripts from Lee June <blender@eyou.com> to
    generate a reasonable PO template from the sources. Since gettext is used
    in a highly nonstandard way, xgettext does not work for this job.
  - debian/rules: Call the scripts, generate po/blender.pot, and clean it up
    in the clean target.
  - Add a proper header to the generated PO template.
* debian/control: Build depend on libavformat-dev >= 3:0.cvs20060823-3.1,
  otherwise this package will FTBFS

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Gamma Correction Plugin (RGB Version) 0.01
 
3
 *
 
4
 * Copyright (c) 2005 Peter Schlaile
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; either version 2 of the License, or
 
9
 * (at your option) any later version.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 */
 
17
 
 
18
#include "math.h"
 
19
#include "plugin.h"
 
20
#include <stdio.h>
 
21
 
 
22
char name[]= "Gamma Correction";
 
23
 
 
24
VarStruct varstr[]= {
 
25
        { NUMSLI|FLO, "St M:", 0.0,     -1.0,   1.0, "Setup Main"}, 
 
26
        { NUMSLI|FLO, "Gn M:",  1.0,    0.0,    10.0,"Gain Main"},
 
27
        { NUMSLI|FLO, "Ga M:", 1.0,     0.0,    10.0, "Gamma Main"},
 
28
 
 
29
        { NUMSLI|FLO, "St R:", 0.0,     -1.0,   1.0, "Setup Red"}, 
 
30
        { NUMSLI|FLO, "Gn R:",  1.0,    0.0,    10.0,"Gain Red"},
 
31
        { NUMSLI|FLO, "Ga R:", 1.0,     0.0,    10.0, "Gamma Red"},
 
32
 
 
33
        { NUMSLI|FLO, "St G:", 0.0,     -1.0,   1.0, "Setup Green"}, 
 
34
        { NUMSLI|FLO, "Gn G:",  1.0,    0.0,    10.0,"Gain Green"},
 
35
        { NUMSLI|FLO, "Ga G:", 1.0,     0.0,    10.0, "Gamma Green"},
 
36
 
 
37
        { NUMSLI|FLO, "St B:", 0.0,     -1.0,   1.0, "Setup Blue"}, 
 
38
        { NUMSLI|FLO, "Gn B:",  1.0,    0.0,    10.0,"Gain Blue"},
 
39
        { NUMSLI|FLO, "Ga B:", 1.0,     0.0,    10.0, "Gamma Blue"},
 
40
};
 
41
 
 
42
typedef struct Cast {
 
43
        float setup_m;
 
44
        float gain_m;
 
45
        float gamma_m;
 
46
 
 
47
        float setup_r;
 
48
        float gain_r;
 
49
        float gamma_r;
 
50
 
 
51
        float setup_g;
 
52
        float gain_g;
 
53
        float gamma_g;
 
54
 
 
55
        float setup_b;
 
56
        float gain_b;
 
57
        float gamma_b;
 
58
} Cast;
 
59
 
 
60
float cfra;
 
61
 
 
62
void plugin_seq_doit(Cast *, float, float, int, int, ImBuf *, ImBuf *, ImBuf *, ImBuf *);
 
63
 
 
64
int plugin_seq_getversion(void) { return B_PLUGIN_VERSION;}
 
65
void plugin_but_changed(int but) {}
 
66
void plugin_init() {}
 
67
 
 
68
void plugin_getinfo(PluginInfo *info) {
 
69
        info->name= name;
 
70
        info->nvars= sizeof(varstr)/sizeof(VarStruct);
 
71
        info->cfra= &cfra;
 
72
 
 
73
        info->varstr= varstr;
 
74
 
 
75
        info->init= plugin_init;
 
76
        info->seq_doit= (SeqDoit) plugin_seq_doit;
 
77
        info->callback= plugin_but_changed;
 
78
}
 
79
 
 
80
static void make_gamma_table(float setup, float gain, float gamma,
 
81
                             unsigned char * table)
 
82
{
 
83
        int y;
 
84
 
 
85
        for (y = 0; y < 256; y++) {
 
86
                float v = 1.0 * y / 255;
 
87
                v += setup;
 
88
                v *= gain;
 
89
                v = pow(v, gamma);
 
90
                if ( v > 1.0) {
 
91
                        v = 1.0;
 
92
                } else if (v < 0.0) {
 
93
                        v = 0.0;
 
94
                }
 
95
                table[y] = v * 255;
 
96
        }
 
97
 
 
98
}
 
99
 
 
100
void plugin_seq_doit(Cast *cast, float facf0, float facf1, int width, 
 
101
        int height, ImBuf *ibuf1, ImBuf *ibuf2, ImBuf *out, ImBuf *use) {
 
102
        unsigned char *dest, *src1, *src2;
 
103
        int x, y, c;
 
104
        unsigned char gamma_table_m[256];
 
105
        unsigned char gamma_table_r[256];
 
106
        unsigned char gamma_table_g[256];
 
107
        unsigned char gamma_table_b[256];
 
108
        
 
109
        if (!ibuf1) return;
 
110
 
 
111
        dest= (unsigned char *) out->rect;
 
112
        src1= (unsigned char *) ibuf1->rect;
 
113
 
 
114
        make_gamma_table(cast->setup_m, cast->gain_m, cast->gamma_m,
 
115
                         gamma_table_m);
 
116
        make_gamma_table(cast->setup_r, cast->gain_r, cast->gamma_r,
 
117
                         gamma_table_r);
 
118
        make_gamma_table(cast->setup_g, cast->gain_g, cast->gamma_g,
 
119
                         gamma_table_g);
 
120
        make_gamma_table(cast->setup_b, cast->gain_b, cast->gamma_b,
 
121
                         gamma_table_b);
 
122
 
 
123
        for (y = 0; y < height; y++) {
 
124
                for (x = 0; x < width; x++) {
 
125
                        *dest++ = gamma_table_r[gamma_table_m[*src1++]];
 
126
                        *dest++ = gamma_table_g[gamma_table_m[*src1++]];
 
127
                        *dest++ = gamma_table_b[gamma_table_m[*src1++]];
 
128
                        dest++; src1++;
 
129
                }
 
130
        }
 
131
}