00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef RU_PixelFunctions_h
00021 #define RU_PixelFunctions_h
00022
00023 #include "RU_API.h"
00024 #include <UT/UT_Math.h>
00025 #include <UT/UT_Matrix4.h>
00026 #include <PXL/PXL_Lookup.h>
00027 #include <CL/CL_Clip.h>
00028 #include "RU_PixelFunction.h"
00029
00030 class RE_OGLComputeGPU;
00031
00032
00033
00034
00035 class RU_API RU_AddFunc : public RU_PixelFunction
00036 {
00037 public:
00038 RU_AddFunc(float addend) : myAddend(addend) {}
00039 protected:
00040 static float add(RU_PixelFunction *pf, float val, int)
00041 { return val +((RU_AddFunc*)pf)->myAddend; }
00042
00043 virtual RUPixelFunc getPixelFunction() const { return add; }
00044 virtual void getPixelShader(UT_String &frag_shader);
00045
00046 float myAddend;
00047 };
00048
00049
00050 class RU_API RU_MultFunc : public RU_PixelFunction
00051 {
00052 public:
00053 RU_MultFunc(float fact) : myFactor(fact) {}
00054 protected:
00055 static float mult(RU_PixelFunction *pf, float val, int)
00056 { return val * ((RU_MultFunc*)pf)->myFactor; }
00057
00058 virtual RUPixelFunc getPixelFunction() const { return mult; }
00059 virtual void getPixelShader(UT_String &frag_shader);
00060
00061 float myFactor;
00062 };
00063
00064 class RU_API RU_MAddFunc : public RU_PixelFunction
00065 {
00066 public:
00067 RU_MAddFunc(float fact, float add);
00068 RU_MAddFunc(float fact[4], float add[4]);
00069
00070 protected:
00071 static float madd(RU_PixelFunction *pf, float val, int comp)
00072 { return val * ((RU_MAddFunc*)pf)->myFactor[comp]
00073 + ((RU_MAddFunc*)pf)->myAddend[comp]; }
00074
00075 virtual RUPixelFunc getPixelFunction() const { return madd; }
00076 virtual void getPixelShader(UT_String &frag_shader);
00077
00078 virtual bool eachComponentDifferent() const { return myCompSep; }
00079
00080 bool myCompSep;
00081 float myFactor[4], myAddend[4];
00082 };
00083
00084 class RU_API RU_ScaleFunc : public RU_PixelFunction
00085 {
00086 public:
00087 RU_ScaleFunc(float scale, float pivot)
00088 : myScale(scale), myPivot(pivot) {}
00089
00090 protected:
00091 static float scale(RU_PixelFunction *pf, float val, int )
00092 { return (val - ((RU_ScaleFunc*)pf)->myPivot)
00093 * ((RU_ScaleFunc*)pf)->myScale
00094 + ((RU_ScaleFunc*)pf)->myPivot; }
00095
00096 virtual RUPixelFunc getPixelFunction() const { return scale; }
00097 virtual void getPixelShader(UT_String &frag_shader);
00098
00099 float myScale, myPivot;
00100 };
00101
00102
00103 class RU_API RU_GammaFunc : public RU_PixelFunction
00104 {
00105 public:
00106 RU_GammaFunc(float g) : myCompSep(false)
00107 { float ig = 1.0f / g; myInvGamma[0] = myInvGamma[1] =
00108 myInvGamma[2] = myInvGamma[3] = ig; }
00109
00110 RU_GammaFunc(float r, float g, float b, float w)
00111 : myCompSep(true)
00112 { myInvGamma[0] = 1.0f / r; myInvGamma[1] = 1.0f / g;
00113 myInvGamma[2] = 1.0f/ b; myInvGamma[3] = 1.0f / w; }
00114 protected:
00115 static float gamma(RU_PixelFunction *pf, float val, int);
00116 static float gamma(float val, float g);
00117
00118 virtual bool eachComponentDifferent() const { return myCompSep; }
00119 virtual RUPixelFunc getPixelFunction() const { return gamma; }
00120 virtual void getPixelShader(UT_String &frag_shader);
00121
00122 float myInvGamma[4];
00123 bool myCompSep;
00124 };
00125
00126
00127 class RU_API RU_LimitFunc : public RU_PixelFunction
00128 {
00129 public:
00130
00131 RU_LimitFunc(bool lower, float lval, bool upper, float uval, bool clamp)
00132 : myLClip(lower),
00133 myUClip(upper),
00134 myClamp(clamp),
00135 myLLimit(lval),
00136 myULimit(uval) {}
00137
00138 protected:
00139 static float limit(RU_PixelFunction *pf, float val, int);
00140
00141 virtual RUPixelFunc getPixelFunction() const { return limit; }
00142 virtual void getPixelShader(UT_String &frag_shader);
00143
00144 unsigned char myLClip:1,
00145 myUClip:1,
00146 myClamp:1;
00147 float myLLimit, myULimit;
00148 };
00149
00150
00151 class RU_API RU_QuantizeFunc : public RU_PixelFunction
00152 {
00153 public:
00154 RU_QuantizeFunc(float step, float offset)
00155 : myStep(step), myOffset(offset) {}
00156
00157 protected:
00158 static float quantize(RU_PixelFunction *pf, float val, int);
00159 virtual RUPixelFunc getPixelFunction() const { return quantize; }
00160 virtual void getPixelShader(UT_String &frag_shader);
00161
00162 float myStep, myOffset;
00163 };
00164
00165
00166
00167
00168 class RU_API RU_NTSCLuminanceFunc : public RU_PixelFunction
00169 {
00170 public:
00171 RU_NTSCLuminanceFunc() {}
00172
00173 protected:
00174 static void luminance(RU_PixelFunction *f, float **vals,
00175 const bool *scope);
00176
00177 virtual bool needAllComponents() const { return true; }
00178 virtual RUVectorFunc getVectorFunction() const { return luminance; }
00179 virtual void getPixelShader(UT_String &frag_shader);
00180 };
00181
00182 class RU_API RU_LuminanceFunc : public RU_PixelFunction
00183 {
00184 public:
00185 RU_LuminanceFunc() {}
00186
00187 protected:
00188 static void luminance(RU_PixelFunction *f, float **vals,
00189 const bool *scope);
00190
00191 virtual bool needAllComponents() const { return true; }
00192 virtual RUVectorFunc getVectorFunction() const { return luminance; }
00193 virtual void getPixelShader(UT_String &frag_shader);
00194 };
00195
00196
00197 class RU_API RU_HueFunc : public RU_PixelFunction
00198 {
00199 public:
00200 RU_HueFunc() {}
00201
00202 protected:
00203 static void hue(RU_PixelFunction *f, float **vals,
00204 const bool *scope);
00205
00206 virtual bool needAllComponents() const { return true; }
00207 virtual RUVectorFunc getVectorFunction() const { return hue; }
00208 virtual void getPixelShader(UT_String &frag_shader);
00209
00210 };
00211
00212
00213 class RU_API RU_SaturationFunc : public RU_PixelFunction
00214 {
00215 public:
00216 RU_SaturationFunc() {}
00217
00218 protected:
00219 static void saturation(RU_PixelFunction *f, float **vals,
00220 const bool *scope);
00221
00222 virtual bool needAllComponents() const { return true; }
00223 virtual RUVectorFunc getVectorFunction() const { return saturation; }
00224 virtual void getPixelShader(UT_String &frag_shader);
00225 };
00226
00227
00228 class RU_API RU_MaxFunc : public RU_PixelFunction
00229 {
00230 public:
00231 RU_MaxFunc() {}
00232
00233 protected:
00234 static void maxfunc(RU_PixelFunction *f, float **vals,
00235 const bool *scope);
00236
00237 virtual bool needAllComponents() const { return true; }
00238 virtual RUVectorFunc getVectorFunction() const { return maxfunc; }
00239 virtual void getPixelShader(UT_String &frag_shader);
00240 };
00241
00242
00243 class RU_API RU_MinFunc : public RU_PixelFunction
00244 {
00245 public:
00246 RU_MinFunc() {}
00247
00248 protected:
00249 static void minfunc(RU_PixelFunction *f, float **vals,
00250 const bool *scope);
00251
00252 virtual bool needAllComponents() const { return true; }
00253 virtual RUVectorFunc getVectorFunction() const { return minfunc; }
00254 virtual void getPixelShader(UT_String &frag_shader);
00255 };
00256
00257
00258 class RU_API RU_AverageFunc : public RU_PixelFunction
00259 {
00260 public:
00261 RU_AverageFunc() {}
00262
00263 protected:
00264 static void average(RU_PixelFunction *f, float **vals,
00265 const bool *scope);
00266
00267 virtual bool needAllComponents() const { return true; }
00268 virtual RUVectorFunc getVectorFunction() const { return average; }
00269 virtual void getPixelShader(UT_String &frag_shader);
00270 };
00271
00272
00273 class RU_API RU_LengthFunc : public RU_PixelFunction
00274 {
00275 public:
00276 RU_LengthFunc() {}
00277
00278 protected:
00279 static void length(RU_PixelFunction *f, float **vals,
00280 const bool *scope);
00281
00282 virtual bool needAllComponents() const { return true; }
00283 virtual RUVectorFunc getVectorFunction() const { return length; }
00284 virtual void getPixelShader(UT_String &frag_shader);
00285 };
00286
00287 class RU_API RU_ComponentFunc : public RU_PixelFunction
00288 {
00289 public:
00290 RU_ComponentFunc(int comp) : myComponent(comp) {}
00291
00292 protected:
00293 static void component(RU_PixelFunction *f, float **vals,
00294 const bool *scope);
00295
00296 virtual bool needAllComponents() const { return true; }
00297 virtual RUVectorFunc getVectorFunction() const { return component; }
00298 virtual void getPixelShader(UT_String &frag_shader);
00299
00300 int myComponent;
00301 };
00302
00303
00304 class RU_API RU_NormalizeFunc : public RU_PixelFunction
00305 {
00306 public:
00307 RU_NormalizeFunc() {}
00308
00309 protected:
00310 static void normalize(RU_PixelFunction *f, float **vals,
00311 const bool *scope);
00312
00313 virtual bool needAllComponents() const { return true; }
00314 virtual RUVectorFunc getVectorFunction() const { return normalize; }
00315 virtual void getPixelShader(UT_String &frag_shader);
00316 };
00317
00318 class RU_API RU_HSVConvertFunc : public RU_PixelFunction
00319 {
00320 public:
00321 enum RU_HSVConvertOp {
00322 CONVERT_TO_HSV,
00323 CONVERT_TO_RGB,
00324 ADJUST_HSV
00325 };
00326
00327 RU_HSVConvertFunc(RU_HSVConvertOp op, float hues = 0.0f,
00328 float *sat = 0, float *val = 0, bool maintain_lum = true)
00329 : myHSVOp(op),
00330 myHueShift(hues),
00331 mySatScale(sat?sat[0]:1.0f),
00332 mySatShift(sat?sat[1]:0.0f),
00333 myValueScale(val?val[0]:1.0f),
00334 myValueShift(val?val[1]:0.0f),
00335 myMaintainLum(maintain_lum) {}
00336
00337 protected:
00338 static void toHSV(RU_PixelFunction *f, float **vals,
00339 const bool *scope);
00340 static void fromHSV(RU_PixelFunction *f, float **vals,
00341 const bool *scope);
00342 static void adjustHSV(RU_PixelFunction *f, float **vals,
00343 const bool *scope);
00344
00345 virtual bool needAllComponents() const { return true; }
00346 virtual RUVectorFunc getVectorFunction() const
00347 { if(myHSVOp==CONVERT_TO_HSV) return toHSV;
00348 if(myHSVOp==CONVERT_TO_RGB) return fromHSV;
00349 return adjustHSV; }
00350 virtual void getPixelShader(UT_String &frag_shader);
00351
00352 RU_HSVConvertOp myHSVOp;
00353 float myHueShift;
00354 float mySatScale, mySatShift;
00355 float myValueScale, myValueShift;
00356 bool myMaintainLum;
00357 };
00358
00359 class RU_API RU_VectorFunc : public RU_PixelFunction
00360 {
00361 public:
00362 RU_VectorFunc(const UT_Matrix4 &matrix) : myMatrix(matrix) {}
00363
00364 protected:
00365 static void matrixmult(RU_PixelFunction *f, float **vals,
00366 const bool *scope);
00367
00368 virtual bool needAllComponents() const { return true; }
00369 virtual RUVectorFunc getVectorFunction() const { return matrixmult; }
00370 virtual void getPixelShader(UT_String &frag_shader);
00371
00372 UT_Matrix4 myMatrix;
00373 };
00374
00375
00376 class RU_API RU_LookupClipFunc : public RU_PixelFunction
00377 {
00378 public:
00379 RU_LookupClipFunc(const CL_Clip *clip) : myClip(clip) {}
00380 protected:
00381 static float lookup(RU_PixelFunction *pf, float val, int);
00382 static void vlookup(RU_PixelFunction *f, float **vals,
00383 const bool *scope);
00384
00385 virtual bool needAllComponents() const
00386 { return myClip->getNumTracks() > 1; }
00387 virtual RUVectorFunc getVectorFunction() const { return vlookup; }
00388 virtual RUPixelFunc getPixelFunction() const { return lookup; }
00389 virtual void getPixelShader(UT_String &frag_shader);
00390
00391 const CL_Clip *myClip;
00392 };
00393
00394 class RU_API RU_LookupTableFunc : public RU_PixelFunction
00395 {
00396 public:
00397 RU_LookupTableFunc(PXL_Lookup *table) : myTable(table) {}
00398
00399 virtual ~RU_LookupTableFunc() { delete myTable; }
00400
00401 protected:
00402 static float lookup(RU_PixelFunction *pf, float val, int);
00403 static void vlookup(RU_PixelFunction *f, float **vals,
00404 const bool *scope);
00405
00406 virtual bool eachComponentDifferent() const { return myTable->getNumChannels() > 1; }
00407 virtual bool needAllComponents() const
00408 { return myTable->is3DLUT(); }
00409
00410 virtual RUPixelFunc getPixelFunction() const { return lookup; }
00411 virtual RUVectorFunc getVectorFunction() const { return vlookup; }
00412
00413 PXL_Lookup *myTable;
00414 };
00415
00416
00417
00418
00419 class RU_API RU_AbsFunc : public RU_PixelFunction
00420 {
00421 public:
00422 RU_AbsFunc() {}
00423 protected:
00424 static float absolute(RU_PixelFunction *pf, float val, int);
00425 virtual RUPixelFunc getPixelFunction() const { return absolute; }
00426 virtual void getPixelShader(UT_String &frag_shader);
00427 };
00428
00429 class RU_API RU_SignFunc : public RU_PixelFunction
00430 {
00431 public:
00432 RU_SignFunc() {}
00433 protected:
00434 static float sign(RU_PixelFunction *pf, float val, int);
00435 virtual RUPixelFunc getPixelFunction() const { return sign; }
00436 virtual void getPixelShader(UT_String &frag_shader);
00437 };
00438
00439 class RU_API RU_PowerFunc : public RU_PixelFunction
00440 {
00441 public:
00442 RU_PowerFunc(float exponent) : myExponent(exponent) {}
00443 protected:
00444 static float power(RU_PixelFunction *pf, float val, int);
00445 virtual RUPixelFunc getPixelFunction() const { return power; }
00446 virtual void getPixelShader(UT_String &frag_shader);
00447 float myExponent;
00448 };
00449
00450 class RU_API RU_RaiseFunc : public RU_PixelFunction
00451 {
00452 public:
00453 RU_RaiseFunc(float base) : myBase(base) {}
00454 protected:
00455 static float raise(RU_PixelFunction *pf, float val, int);
00456 virtual RUPixelFunc getPixelFunction() const { return raise; }
00457 virtual void getPixelShader(UT_String &frag_shader);
00458 float myBase;
00459 };
00460
00461 class RU_API RU_LogFunc : public RU_PixelFunction
00462 {
00463 public:
00464 RU_LogFunc(float base, bool replace, float value);
00465 protected:
00466 static float logarithm(RU_PixelFunction *pf, float val, int);
00467 virtual RUPixelFunc getPixelFunction() const { return logarithm; }
00468 virtual void getPixelShader(UT_String &frag_shader);
00469 float myBase;
00470 bool myDoReplace;
00471 float myValue;
00472 };
00473
00474 class RU_API RU_SinFunc : public RU_PixelFunction
00475 {
00476 public:
00477 RU_SinFunc(float scale, float shift) : myScale(scale), myShift(shift) {}
00478 protected:
00479 static float sinfunc(RU_PixelFunction *pf, float val, int);
00480 virtual RUPixelFunc getPixelFunction() const { return sinfunc; }
00481 virtual void getPixelShader(UT_String &frag_shader);
00482 float myScale;
00483 float myShift;
00484 };
00485
00486 class RU_API RU_SinhFunc : public RU_PixelFunction
00487 {
00488 public:
00489 RU_SinhFunc(float scale) : myScale(scale) {}
00490 protected:
00491 static float sinhfunc(RU_PixelFunction *pf, float val, int);
00492 virtual RUPixelFunc getPixelFunction() const { return sinhfunc; }
00493 virtual void getPixelShader(UT_String &frag_shader);
00494 float myScale;
00495 };
00496
00497 class RU_API RU_CoshFunc : public RU_PixelFunction
00498 {
00499 public:
00500 RU_CoshFunc(float scale) : myScale(scale) {}
00501 protected:
00502 static float coshfunc(RU_PixelFunction *pf, float val, int);
00503 virtual RUPixelFunc getPixelFunction() const { return coshfunc; }
00504 virtual void getPixelShader(UT_String &frag_shader);
00505 float myScale;
00506 };
00507
00508 class RU_API RU_TanFunc : public RU_PixelFunction
00509 {
00510 public:
00511 RU_TanFunc(float scale, bool rep, float v)
00512 : myScale(scale), myDoReplace(rep), myValue(v) {}
00513 protected:
00514 static float tanfunc(RU_PixelFunction *pf, float val, int);
00515 virtual RUPixelFunc getPixelFunction() const { return tanfunc; }
00516 virtual void getPixelShader(UT_String &frag_shader);
00517 float myScale;
00518 bool myDoReplace;
00519 float myValue;
00520 };
00521
00522 class RU_API RU_TanhFunc : public RU_PixelFunction
00523 {
00524 public:
00525 RU_TanhFunc(float scale) : myScale(scale) {}
00526 protected:
00527 static float tanhfunc(RU_PixelFunction *pf, float val, int);
00528 virtual RUPixelFunc getPixelFunction() const { return tanhfunc; }
00529 virtual void getPixelShader(UT_String &frag_shader);
00530 float myScale;
00531 };
00532
00533 class RU_API RU_AtanFunc : public RU_PixelFunction
00534 {
00535 public:
00536 RU_AtanFunc(float scale) : myScale(scale) {}
00537 protected:
00538 static float atanfunc(RU_PixelFunction *pf, float val, int);
00539 virtual RUPixelFunc getPixelFunction() const { return atanfunc; }
00540 virtual void getPixelShader(UT_String &frag_shader);
00541 float myScale;
00542 };
00543
00544 class RU_API RU_AsinFunc : public RU_PixelFunction
00545 {
00546 public:
00547 RU_AsinFunc(float scale, bool rep, float v)
00548 : myScale(scale), myDoReplace(rep), myValue(v) {}
00549 protected:
00550 static float asinfunc(RU_PixelFunction *pf, float val, int);
00551 virtual RUPixelFunc getPixelFunction() const { return asinfunc; }
00552 virtual void getPixelShader(UT_String &frag_shader);
00553 float myScale;
00554 bool myDoReplace;
00555 float myValue;
00556 };
00557
00558 class RU_API RU_AcosFunc : public RU_PixelFunction
00559 {
00560 public:
00561 RU_AcosFunc(float scale, bool rep, float v)
00562 : myScale(scale), myDoReplace(rep), myValue(v) {}
00563 protected:
00564 static float acosfunc(RU_PixelFunction *pf, float val, int);
00565 virtual RUPixelFunc getPixelFunction() const { return acosfunc; }
00566 virtual void getPixelShader(UT_String &frag_shader);
00567 float myScale;
00568 bool myDoReplace;
00569 float myValue;
00570 };
00571
00572 class RU_API RU_NegateFunc : public RU_PixelFunction
00573 {
00574 public:
00575 RU_NegateFunc() {}
00576 protected:
00577 static float negate(RU_PixelFunction *pf, float val, int);
00578 virtual RUPixelFunc getPixelFunction() const { return negate; }
00579 virtual void getPixelShader(UT_String &frag_shader);
00580 };
00581
00582 class RU_API RU_InvertFunc : public RU_PixelFunction
00583 {
00584 public:
00585 RU_InvertFunc(bool rep, float v) : myDoReplace(rep), myValue(v) {}
00586 protected:
00587 static float invert(RU_PixelFunction *pf, float val, int);
00588 virtual RUPixelFunc getPixelFunction() const { return invert; }
00589 virtual void getPixelShader(UT_String &frag_shader);
00590 bool myDoReplace;
00591 float myValue;
00592 };
00593
00594 class RU_API RU_FloorFunc : public RU_PixelFunction
00595 {
00596 public:
00597 RU_FloorFunc() {}
00598 protected:
00599 static float floorfunc(RU_PixelFunction *pf, float val, int);
00600 virtual RUPixelFunc getPixelFunction() const { return floorfunc; }
00601 virtual void getPixelShader(UT_String &frag_shader);
00602 };
00603
00604 class RU_API RU_CeilFunc : public RU_PixelFunction
00605 {
00606 public:
00607 RU_CeilFunc() {}
00608 protected:
00609 static float ceilfunc(RU_PixelFunction *pf, float val, int);
00610 virtual RUPixelFunc getPixelFunction() const { return ceilfunc; }
00611 virtual void getPixelShader(UT_String &frag_shader);
00612 };
00613
00614 class RU_API RU_RoundFunc : public RU_PixelFunction
00615 {
00616 public:
00617 RU_RoundFunc() {}
00618 protected:
00619 static float roundfunc(RU_PixelFunction *pf, float val, int);
00620 virtual RUPixelFunc getPixelFunction() const { return roundfunc; }
00621 virtual void getPixelShader(UT_String &frag_shader);
00622 };
00623
00624 class RU_API RU_LevelsFunc : public RU_GammaFunc
00625 {
00626 public:
00627
00628
00629
00630
00631
00632 RU_LevelsFunc(float effect,
00633 float global_in_range_min, float global_in_range_max,
00634 float global_out_range_min, float global_out_range_max,
00635 float global_gamma,
00636 float comp_in_range_min[4], float comp_in_range_max[4],
00637 float comp_out_range_min[4], float comp_out_range_max[4],
00638 float comp_gamma[4]);
00639
00640 RU_LevelsFunc(float effect,
00641 float global_in_range_min, float global_in_range_max,
00642 float global_out_range_min, float global_out_range_max,
00643 float global_gamma,
00644 float comp_in_range_min, float comp_in_range_max,
00645 float comp_out_range_min, float comp_out_range_max,
00646 float comp_gamma);
00647
00648 protected:
00649
00650 static float fastLevels(RU_PixelFunction *pf, float val, int);
00651
00652
00653 static float safeLevels(RU_PixelFunction *pf, float val, int);
00654 float safeLevels(float val, int);
00655
00656 static void colourMap(float const effect,
00657 const float from_min, const float from_max,
00658 const float to_min, const float to_max,
00659 float& factor, float& addend);
00660
00661
00662 virtual RUPixelFunc getPixelFunction() const { return myLevelsFunc; }
00663 virtual void getPixelShader(UT_String &frag_shader);
00664
00665 float myGlobalGamma;
00666
00667
00668 float myGlobalFactor;
00669 float myGlobalAddend;
00670 float myFactor[4];
00671 float myAddend[4];
00672
00673
00674 float myGlobalInRangeMin;
00675 float myGlobalInRangeMax;
00676 float myGlobalOutRangeMin;
00677 float myGlobalOutRangeMax;
00678 float myCompInRangeMin[4];
00679 float myCompInRangeMax[4];
00680 float myCompOutRangeMin[4];
00681 float myCompOutRangeMax[4];
00682
00683 RUPixelFunc myLevelsFunc;
00684 };
00685
00686 #endif