Esempio n. 1
0
        public Gradient(ref PixelYhs pxUpper, ref PixelYhs pxLower)
        {
            bool bGood = true;

            try {
                if (pxUpper == null || pxLower == null)
                {
                    if (pxUpper == null)
                    {
                        RReporting.ShowErr("pxUpper is null", "Gradient(YHS,YHS)", "creating gradient");
                    }
                    else if (pxLower == null)
                    {
                        RReporting.ShowErr("pxUpper is null", "Gradient(YHS,YHS)", "creating gradient");
                    }
                }
                else
                {
                    From(ref pxUpper, ref pxLower);
                }
            }
            catch (Exception exn) {
                RReporting.ShowExn(exn, "Gradient(YHS,YHS)", "initializing");
            }
        }
Esempio n. 2
0
        }        //end From(YHSA,YHSA)

        public bool From(ref PixelYhs pxUpper, ref PixelYhs pxLower)
        {
            bool bGood = false;

            try {
                STEPS          = 2;
                pxarrStep[0].Y = pxLower.Y;
                pxarrStep[0].H = pxLower.H;
                pxarrStep[0].S = pxLower.S;
                pxarrStep[0].A = (REAL)1.0;
                pxarrStep[1].Y = pxUpper.Y;
                pxarrStep[1].H = pxUpper.H;
                pxarrStep[1].S = pxUpper.S;
                pxarrStep[1].A = (REAL)1.0;
                rarrStep[0]    = (REAL)0.0;
                rarrStep[1]    = (REAL)1.0;
                bGood          = true;
            }
            catch (Exception exn) {
                RReporting.ShowExn(exn, "Gradient.From(YHS,YHS)");
                bGood = false;
            }
            return(bGood);
        }        //end From(YHS,YHS)
Esempio n. 3
0
        public bool Shade(ref PixelYhs pxDest, REAL rSrcZeroTo1)
        {
            //TODO:? return top or bottom if out of range
            bool bFound   = false;
            bool bWasNull = false;

            try {
                if (pxDest == null)
                {
                    bWasNull = true;
                    pxDest   = new PixelYhs();
                }
                if (STEPS > 0)
                {
                    if (rSrcZeroTo1 <= (REAL)0.0)
                    {
                        pxDest.From(pxarrStep[0]);
                    }
                    //else if (rSrcZeroTo1==(REAL)1.0) pxDest.From(pxarrStep[STEPS-1]);//unnecessary since !bFound is checked below
                    else
                    {
                        int iLower = 0;                      //this is actually found in the iUpper "for" statement below!
                        //for (int iNow=iTop; iTop>=0; iTop--) {
                        //	if (rSrcZeroTo1>=rarrStep[iNow]) {
                        //		iLower=iNow;
                        //		break;
                        //	}
                        //}
                        REAL ratio;
                        for (int iUpper = 1; iUpper < STEPS; iUpper++, iLower++)
                        {
                            //start at 1 since the first "Top" is 1
                            if (rSrcZeroTo1 <= rarrStep[iUpper])
                            {
                                //the ratio formula: (abs-min)/(max-min)
                                ratio = (rSrcZeroTo1 - rarrStep[iLower]) / (rarrStep[iUpper] - rarrStep[iLower]);
                                if (ratio <= RMath.r0)
                                {
                                    pxDest.From(pxarrStep[iLower]);
                                }
                                else if (ratio >= RMath.r1)
                                {
                                    pxDest.From(pxarrStep[iUpper]);
                                }
                                else
                                {
                                    //use the alpha formula even though non-alpha: (src-dest)*fAlphaRatio+dest
                                    //-(overlays the "top" over the "bottom" based on the "topness" ("ratio")
                                    pxDest.Y = (pxarrStep[iUpper].Y - pxarrStep[iLower].Y) * ratio + pxarrStep[iLower].Y;
                                    pxDest.H = (pxarrStep[iUpper].H - pxarrStep[iLower].H) * ratio + pxarrStep[iLower].H;
                                    pxDest.S = (pxarrStep[iUpper].S - pxarrStep[iLower].S) * ratio + pxarrStep[iLower].S;
                                }
                                bFound = true;
                                break;
                            }
                        }
                        if (!bFound)
                        {
                            pxDest.From(pxarrStep[STEPS - 1]);
                        }
                    }
                }                //end if steps are initialized
                else
                {
                    pxDest.Set(0, 0, 0);
                }
            }
            catch (Exception exn) {
                RReporting.ShowExn(exn, "Gradient Shade(YHS)");
            }
            if (bWasNull)
            {
                RReporting.ShowErr("Null dest pixel", "Gradient Shade(YHS)");
            }
            return(bFound); //TODO: is this right?
        }                   //end Shade(YHS,REAL)
Esempio n. 4
0
        }                   //end Shade(YHSA,REAL)

        public bool Shade(ref PixelYhs pxDest, PixelYhs pxAssumeGrayAndUseY)
        {
            return(Shade(ref pxDest, pxAssumeGrayAndUseY.Y));
        }