2 * Color Correction Plugin (YUV Version) 0.01
4 * Copyright (c) 2005 Peter Schlaile
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.
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.
22 char name[]= "Color Correction";
25 { NUMSLI|FLO, "St Y:", 0.0, -1.0, 1.0, "Setup Y"},
26 { NUMSLI|FLO, "Gn Y:", 1.0, 0.0, 10.0,"Gain Y"},
27 { NUMSLI|FLO, "Ga Y:", 1.0, 0.0, 10.0, "Gamma Y"},
29 { NUMSLI|FLO, "Lo S:", 1.0, 0.0, 10.0,"Saturation Shadows"},
30 { NUMSLI|FLO, "Md S:", 1.0, 0.0, 10.0,"Saturation Midtones"},
31 { NUMSLI|FLO, "Hi S:", 1.0, 0.0, 10.0,"Saturation Highlights"},
33 { NUMSLI|FLO, "MA S:", 1.0, 0.0, 10.0,"Master Saturation"},
34 { NUMSLI|FLO, "Lo T:", 0.25, 0.0, 1.0,
35 "Saturation Shadow Thres"},
36 { NUMSLI|FLO, "Hi T:", 0.75, 0.0, 1.0,
37 "Saturation Highlights Thres"},
38 { TOG|INT, "Debug", 0.0, 0.0, 1.0,
39 "Show curves as overlay"},
59 void plugin_seq_doit(Cast *, float, float, int, int, ImBuf *, ImBuf *, ImBuf *, ImBuf *);
61 int plugin_seq_getversion(void) { return B_PLUGIN_VERSION;}
62 void plugin_but_changed(int but) {}
65 void plugin_getinfo(PluginInfo *info)
68 info->nvars= sizeof(varstr)/sizeof(VarStruct);
73 info->init= plugin_init;
74 info->seq_doit= (SeqDoit) plugin_seq_doit;
75 info->callback= plugin_but_changed;
78 static void rgb_to_yuv(float rgb[3], float yuv[3])
80 yuv[0]= 0.299*rgb[0] + 0.587*rgb[1] + 0.114*rgb[2];
81 yuv[1]= 0.492*(rgb[2] - yuv[0]);
82 yuv[2]= 0.877*(rgb[0] - yuv[0]);
89 static void yuv_to_rgb(float yuv[3], float rgb[3])
94 rgb[0] = yuv[2]/0.877 + yuv[0];
95 rgb[2] = yuv[1]/0.492 + yuv[0];
96 rgb[1] = (yuv[0] - 0.299*rgb[0] - 0.114*rgb[2]) / 0.587;
117 void plugin_seq_doit(Cast *cast, float facf0, float facf1, int width,
118 int height, ImBuf *ibuf1, ImBuf *ibuf2, ImBuf *out, ImBuf *use) {
119 char *dest, *src1, *src2;
123 float gamma_table[256];
125 float *destf = out->rect_float;
130 dest= (char *) out->rect;
131 src1= (char *) ibuf1->rect;
132 src1f= ibuf1->rect_float;
134 for (y = 0; y < 256; y++) {
135 float v = 1.0 * y / 255;
138 v = pow(v, cast->gamma_y);
141 } else if (v < 0.0) {
144 gamma_table[y] = v * 255;
147 for (y = 0; y < 256; y++) {
149 v *= cast->master_sat;
150 if (y < cast->lo_thres * 255) {
151 v *= cast->sat_shadows;
152 } else if (y > cast->hi_thres * 255) {
153 v *= cast->sat_highlights;
155 v *= cast->sat_midtones;
161 for (y = 0; y < height; y++) {
162 for (x = 0; x < width; x++) {
164 if (out->rect_float) {
165 rgb[0]= (float)src1f[0]/255.0;
166 rgb[1]= (float)src1f[1]/255.0;
167 rgb[2]= (float)src1f[2]/255.0;
169 rgb[0]= (float)src1[0]/255.0;
170 rgb[1]= (float)src1[1]/255.0;
171 rgb[2]= (float)src1[2]/255.0;
173 rgb_to_yuv(rgb, yuv);
175 yuv[0] = gamma_table[(int) (yuv[0] * 255.0)] / 255.0;
176 fac = uv_table[(int) (255.0 * yuv[0])];
178 yuv[1] = yuv[1] * fac;
179 yuv[2] = yuv[2] * fac;
192 yuv_to_rgb(yuv, rgb);
194 if (out->rect_float) {
201 *dest++ = rgb[0]*255.0;
202 *dest++ = rgb[1]*255.0;
203 *dest++ = rgb[2]*255.0;
211 dest= (char *) out->rect;
212 for (c = 0; c < 10; c++) {
214 for (y = 0; y < 256; y++) {
215 char val = gamma_table[y];
216 while (x < y * width / 255) {
225 for (c = 0; c < 10; c++) {
227 for (y = 0; y < 256; y++) {
228 char val = uv_table[y] * 255.0/10.0;
229 while (x < y * width / 255) {