Ejemplo n.º 1
0
        }        //end CopyAsGray

        public bool SaveSeq(string sSetFileBase, string sSetFileExt)
        {
            bool bGood = true;

            //try { //first write debug file
            sFileExt          = sSetFileExt;
            sPathFileBaseName = sSetFileBase;
            //	RString.StringToFile(sSetFileBase+".txt", RString.ToString(true)); }
            //catch (Exception exn) {
            //	RReporting.ShowExn(exn,anim SaveSeq","saving dump"); }
            try {
                for (long lFrameSave = 0; lFrameSave < lFrames; lFrameSave++)
                {
                    if (!SaveSeqFrame(lFrameSave))
                    {
                        bGood = false;
                        RReporting.ShowError("Couldn't Save " + PathFileOfSeqFrame(sSetFileBase, sSetFileExt, lFrameNow, iSeqDigitsMin), "SaveSeq");
                    }
                }
            } catch (Exception exn) { RReporting.ShowExn(exn, "SaveSeq"); }
            return(bGood);
        }        //SaveSeq
Ejemplo n.º 2
0
        }        //end Shade

        public bool ShadeAlpha(ref byte[] byarrDest, int iDestByte, int iValue)
        {
            bool bGood = true;

            try {
                if (iBytesPP >= 4)
                {
                    if (by2dGrad[iValue][3] == 0)                    //transparent
                    {
                    }
                    else if (by2dGrad[iValue][3] == 255)
                    {
                        byarrDest[iDestByte] = by2dGrad[iValue][0];
                        iDestByte++;
                        byarrDest[iDestByte] = by2dGrad[iValue][1];
                        iDestByte++;
                        byarrDest[iDestByte] = by2dGrad[iValue][2];
                    }
                    else                      //else blend alpha
                    {
                        byarrDest[iDestByte] = RMath.Approach(byarrDest[iDestByte], by2dGrad[iValue][0], (float)by2dGrad[iValue][3] / 255.0f);
                        iDestByte++;
                        byarrDest[iDestByte] = RMath.Approach(byarrDest[iDestByte], by2dGrad[iValue][1], (float)by2dGrad[iValue][3] / 255.0f);
                        iDestByte++;
                        byarrDest[iDestByte] = RMath.Approach(byarrDest[iDestByte], by2dGrad[iValue][2], (float)by2dGrad[iValue][3] / 255.0f);
                    }
                }
                else
                {
                    RReporting.ShowErr("Incorrect gradient bit depth (need 4 for ShadeAlpha)", "", String.Format("RGradient ShadeAlpha(...){{GradientBitDepth:{0}}}", (iBytesPP * 8)));
                }
            }
            catch (Exception exn) {
                bGood = false;
                RReporting.ShowExn(exn, "shading", "RImage ShadeAlpha(byte array location) {iDestByte:" + iDestByte.ToString() + "; iValue:" + iValue.ToString() + "; by2dGrad.Length:" + by2dGrad.Length.ToString() + "}");
            }
            return(bGood);
        }        //end ShadeAlpha
Ejemplo n.º 3
0
		}//end ForceSet(...,...,string)
		public bool ForceSetByRef(int iInternalIndex, string sName, byte[] byarrToReference) {
			bool bGood=true;
			try {
				if (iInternalIndex>=MAXIMUM) {
					IncreaseMaxToFuzzy(iInternalIndex+1);
				}
				if (iInternalIndex>iCount) {//but CAN be created at iCount!!!!
					bGood=false;
					RReporting.ShowErr("variables.ForceSetByRef(...,"+sName+",...)","Index "+iInternalIndex.ToString()+" is beyond "+iCount.ToString()+" currently used slots and cannot be set or created.");
				}
				else if (iInternalIndex>=0) { //else if everything is okay, set it
					//if (sName.Length>0) {
						//DONT check//if (byarrToReference.Length>0) {
						if (varr[iInternalIndex]==null) varr[iInternalIndex]=new Variable(sName,byarrToReference);
						else varr[iInternalIndex].byarrVal=byarrToReference;
						varr[iInternalIndex].iType=Variable.TypeBinary;
						if (iInternalIndex==iCount) iCount++;
						//}
						//else {
						//	bGood=false;
						//	RReporting.ShowErr("variables.ForceCreate","Value is blank.");
						//}
					//}
					//else {
					//	bGood=false;
					//	RReporting.ShowErr("Name is blank.","variables ForceSet");
					//}
				}
				else {
					bGood=false;
					RReporting.ShowErr("variables ForceSetByRef","Index "+iInternalIndex.ToString()+" is not valid");
				}
			}
			catch (Exception exn) {
				RReporting.ShowExn(exn,"ForceSetByRef("+((sName==null)?"null":"\"sName\","),((byarrToReference==null)?"null":"\"val\")"));
			}
			return bGood;
		}//end ForceSetByRef(...,...,byarrToReference)
Ejemplo n.º 4
0
        public bool SaveSeq(string sFileBaseName, string sFileExt, int iGlyphType)
        {
            RReporting.sLastFile = sFileBaseName + "*." + sFileExt;
            bool bGood = false;

            try {
                bGood = animarrGlyphType[iGlyphType].SaveSeq(sFileBaseName, sFileExt);
            }
            catch (Exception exn) {
                RReporting.ShowExn(exn, "accessing font glyph type while saving", "RFont SaveSeq {sFileBaseName:" + sFileBaseName + "; sFileExt:" + sFileExt + "; GlyphType:" + GlyphTypeToString(iGlyphType) + "}");
                bGood = false;
            }
            if (!bGood)
            {
                try {
                    RReporting.ShowErr("Failed to save " + sFileExt + " files with names starting on " + sFileBaseName + " " + animarrGlyphType[iGlyphType].ToString(true), "", "SaveSeq");
                }
                catch (Exception exn2) {
                    RReporting.ShowExn(exn2, "accessing font glyph type while saving error data", "RFont SaveSeq(" + sFileBaseName + "," + sFileExt + "," + iGlyphType.ToString() + "){sFileBaseName:" + sFileBaseName + "; sFileExt:" + sFileExt + "; GlyphType:" + GlyphTypeToString(iGlyphType) + "}");
                }
            }
            return(bGood);
        }        //end SaveSeq
Ejemplo n.º 5
0
		}//end GetOrCreate(float,...
		public bool GetOrCreate(ref double val, string sName) {
			bool bGood=true;
			int iAt=IndexOf(sName);
			bool bFound=(iAt>=0);
			//float valTemp;
			try {
				if (bFound) {
					//if (!
					varr[iAt].Get(out val);
					//) val=0.0;
					//val=valTemp;
				}
				else {
					ForceSet(iCount,sName,val.ToString());
					//if (bSaveEveryChange) Save();
				}
			}
			catch (Exception exn) {
				bGood=false;
				RReporting.ShowExn(exn,"variables.GetOrCreate(double,...)");
			}
			return bGood;
		}//end GetOrCreate(double,...
Ejemplo n.º 6
0
        public bool LoadInternalBitmap(string sFile)
        {
            bool bGood = true;

            try {
                if (bmpLoaded != null)
                {
                    bmpLoaded.Dispose();
                }
            }
            catch (Exception exn) {
                RReporting.ShowExn(exn, "LoadInternalBitmap(\"" + sFile + "\")", "disposing previous frame image");
            }
            try {
                bmpLoaded = new Bitmap(sFile);
                bGood     = CopyFrameFromInternalBitmap();
            }
            catch (Exception exn) {
                RReporting.ShowExn(exn, "LoadInternalBitmap(\"" + sFile + "\")", "working with file type or location");
                bGood = false;
            }
            return(bGood);
        }
Ejemplo n.º 7
0
        public static string PathFileOfSeqFrame(string sFileBaseName1, string sSetFileExt, long lFrameTarget, int iDigitsMin)
        {
            string sReturn = "";

            try {
                sReturn = sFileBaseName1;
                if (iDigitsMin > 0)
                {
                    long lDivisor  = RMath.SafeE10L((int)(iDigitsMin - 1));               //returns long since implied base is 10L
                    long lDestruct = lFrameTarget;
                    while (lDivisor > 0)
                    {
                        long lResult = lDestruct / lDivisor;
                        sReturn   += lResult.ToString();
                        lDestruct -= lResult * lDivisor;
                        if (lDivisor == 1)
                        {
                            lDivisor = 0;
                        }
                        else
                        {
                            lDivisor /= 10;
                        }
                    }
                }
                else
                {
                    sReturn += lFrameTarget.ToString();
                }
                sReturn += "." + sSetFileExt;
            }
            catch (Exception exn) {
                RReporting.ShowExn(exn, "PathFileOfSeqFrame");
                sReturn = "";
            }
            return(sReturn);
        }        //end PathFileOfSeqFrame
Ejemplo n.º 8
0
        public bool From(ref Pixel32Struct pxUpper, ref Pixel32Struct pxLower)
        {
            bool bGood = false;

            try {
                FPx fpxUpper = new FPx();
                FPx fpxLower = new FPx();
                fpxUpper.B = (float)pxUpper.B;
                fpxUpper.G = (float)pxUpper.G;
                fpxUpper.R = (float)pxUpper.R;
                fpxUpper.A = (float)pxUpper.A;
                fpxLower.B = (float)pxLower.B;
                fpxLower.G = (float)pxLower.G;
                fpxLower.R = (float)pxLower.R;
                fpxLower.A = (float)pxLower.A;
                float fGrad = (int)iGrad;
                int   iVal  = 0;
                float fVal;
                float fOpacity;
                //needs to be float in case gradient is longer than 256!!!
                for (fVal = 0; fVal < fGrad; fVal += 1.0f, iVal++)
                {
                    fOpacity          = fVal / 255.0f;
                    by2dGrad[iVal][0] = (byte)(((fpxUpper.B - fpxLower.B) * fOpacity + fpxLower.B) + .5f);
                    by2dGrad[iVal][1] = (byte)(((fpxUpper.G - fpxLower.G) * fOpacity + fpxLower.G) + .5f);
                    by2dGrad[iVal][2] = (byte)(((fpxUpper.R - fpxLower.R) * fOpacity + fpxLower.R) + .5f);
                    by2dGrad[iVal][3] = (byte)(((fpxUpper.A - fpxLower.A) * fOpacity + fpxLower.A) + .5f);
                }
                //bGood=ByteArrayFromPixArray();
            }
            catch (Exception exn) {
                RReporting.ShowExn(exn, "changing gradient values", "RImage From(Pixel32Struct)");
                bGood = false;
            }
            return(bGood);
        }        //end From(Pixel32Struct,Pixel32Struct)
Ejemplo n.º 9
0
 public bool Push(string sAdd)
 {
     //if (!IsFull) {
     try {
         if (NewIndex >= Maximum)
         {
             SetFuzzyMaximumByLocation(NewIndex);
         }
         sarr[NewIndex] = sAdd;
         iCount++;
         //sLogLine="debug enq iCount="+iCount.ToString();
     }
     catch (Exception e) {
         RReporting.ShowExn(e, "accessing StringStack array", "StringStack Push(" + ((sAdd == null)?"null string":"non-null") + "){at:" + NewIndex.ToString() + "}");
         return(false);
     }
     return(true);
     //}
     //else {
     //	if (sAdd==null) sAdd="";
     //	RReporting.ShowErr("StringStack is full, can't push","","StringStack Push("+((sAdd==null)?"null string":"non-null")+"){count:"+iCount.ToString()+"}");
     //	return false;
     //}
 }
Ejemplo n.º 10
0
        }        //end static constructor

        #endregion constructors
        //public static byte SafeIndex(byte[][] arr2dX, int iDim1, int iDim2) {
        //	byte byReturn=0;
        //	return byReturn;
        //}
        public static byte Descramble(byte Src_Value, uint Src_OriginalIndex)
        {
            try {
                if (by2dUnFibo != null)
                {
                    if (by2dUnFibo[Src_Value] != null)
                    {
                        return(by2dUnFibo[Src_Value][Src_OriginalIndex % 256]);
                    }
                    else
                    {
                        Console.Error.WriteLine("Descramble array was not sized correctly");
                    }
                }
                else
                {
                    Console.Error.WriteLine("Descramble array not present");
                }
            }
            catch (Exception exn) {
                RReporting.ShowExn(exn, String.Format("accessing Descramble array at [{0}][{1}]", Src_Value, Src_OriginalIndex % 256), "Descramble");
            }
            return(0);
        }
Ejemplo n.º 11
0
        }        //end Fill4ByteChunksByUnitCount

        public static unsafe void Fill4ByteChunksByUnitCount(ref byte[] destination, ref byte[] src, int iDestByte, int iSrcByte, int iCount_BytesDivBy4)
        {
            try
            {
                fixed(byte *lpDest = destination, lpSrc = src)                //keeps GC at bay
                {
                    byte *lpDestNow = lpDest;
                    byte *lpSrcNow  = lpSrc;

                    lpDestNow += iDestByte;
                    lpSrcNow  += iSrcByte;
                    for (int i = 0; i < iCount_BytesDivBy4; i++)
                    {
                        *((uint *)lpDestNow) = *((uint *)lpSrcNow); //64bit chunks
                        lpDestNow           += 3;                   //do NOT do lpSrcNow+=8;
                    }
                }
            }
            catch (Exception e) {
                RReporting.ShowExn(e, "Memory Fill4ByteChunksByUnitCount");
                return;
            }
            return;
        }        //end Fill4ByteChunksByUnitCount
Ejemplo n.º 12
0
        }        //end CopyFastVoid

        ///<summary>
        ///Fills iCount_BytesDivBy8 8-byte units with data from src which must be 8-bytes
        /// long or larger
        ///src: first 8 bytes will be looped and written onto destination
        ///</summary>
        private static unsafe void Fill8ByteChunksByUnitCount(ref byte[] destination, ref byte[] src, int iDestByte, int iSrcByte, int iCount_BytesDivBy8)
        {
            try
            {
                fixed(byte *lpDest = destination, lpSrc = src)                //keeps GC at bay
                {
                    byte *lpDestNow = lpDest;
                    byte *lpSrcNow  = lpSrc;

                    lpDestNow += iDestByte;
                    lpSrcNow  += iSrcByte;
                    for (int i = 0; i < iCount_BytesDivBy8; i++)
                    {
                        *((ulong *)lpDestNow) = *((ulong *)lpSrcNow); //64bit chunks
                        lpDestNow            += 8;                    //do NOT do lpSrcNow+=8;
                    }
                }
            }
            catch (Exception e) {
                RReporting.ShowExn(e, "Memory Fill8ByteChunksByUnitCount(array,array,iDest,iSource,count)");
                return;
            }
            return;
        }        //end Fill8ByteChunksByUnitCount
Ejemplo n.º 13
0
        public Effect Copy()
        {
            Effect fxReturn = null;

            try {
                fxReturn = new Effect();
                //fxReturn.varsFX=varsFX.Copy(); //TODO: re-implement this
                fxReturn.bitsAttrib   = bitsAttrib;
                fxReturn.iEffect      = iEffect;
                fxReturn.iDest        = iDest;
                fxReturn.iTypeDest    = iTypeDest;
                fxReturn.iOverlay     = iOverlay;
                fxReturn.iTypeOverlay = iTypeOverlay;
                fxReturn.iMask        = iMask;
                fxReturn.iTypeMask    = iTypeMask;
                fxReturn.lStartFrame  = lStartFrame;
                fxReturn.lFrames      = lFrames;
                fxReturn.sScript      = sScript;
            }
            catch (Exception exn) {
                RReporting.ShowExn(exn, "Effect Copy");
            }
            return(fxReturn);
        }        //end Copy
Ejemplo n.º 14
0
        //public bool FromFrames(byte[][] by2dFrames, long lFrames, int iChannels, int iWidthNow, int iHeightNow) {
        //}
        public bool GotoFrame(long lFrameX)
        {
            //refers to a file if a file is used.\
            bool bGood = true;

            try {
                if (lFramesCached == lFrames)
                {
                    gbFrame   = gbarrAnim[lFrameX];
                    lFrameNow = lFrameX;
                }
                else                                                                                         //if ((sPathFile!=null) && (sPathFile.Length>0)) {
                {
                    RReporting.ShowErr("GotoFrame of non-cached sequence is not available in this version"); //debug NYI
                    //image.SelectActiveFrame(image.FrameDimensionsList[lFrameX], (int)lFrameX);
                    //debug NYI load from file
                }
            }
            catch (Exception exn) {
                RReporting.ShowExn(exn, "GotoFrame");
                bGood = false;
            }
            return(bGood);
        }        //end GotoFrame
Ejemplo n.º 15
0
        ///<summary>
        ///Primary Set overload (all overloads call this)
        ///</summary>
        public unsafe bool SetArgb(byte a, byte r, byte g, byte b)
        {
            try {
                //bool bMake=false;
                //if (data32==null) {data32=new byte[4]; bMake=true; }
                //else if ( data32[0]!=b
                //	||data32[1]!=g
                //	||data32[2]!=r
                //	||data32[3]!=a
                //	) {
                //	bMake=true;
                //}
                //if (bMake) {
                data32[0]         = b;
                data32[1]         = g;
                data32[2]         = r;
                data32[3]         = a;
                data24Copied48[0] = b; data24Copied48[1] = g; data24Copied48[2] = r;
                data24Copied48[3] = b; data24Copied48[4] = g; data24Copied48[5] = r;
                //if (data32Copied64==null) data32Copied64=new byte[8];
                fixed(byte *lp64 = data32Copied64, lp32 = data32)
                {
                    byte *lp64Now = lp64;

                    *((UInt32 *)lp64Now) = *((UInt32 *)lp32);
                    lp64Now += 4;
                    *((UInt32 *)lp64Now) = *((UInt32 *)lp32);
                }
                //}
            }
            catch (Exception exn) {
                RReporting.ShowExn(exn, "", "RBrush SetArgb(a,r,g,b)");
                return(false);
            }
            return(true);
        }        //end SetArgb (primary overload)
Ejemplo n.º 16
0
        }        //end FromImageValue

        public bool FromImage(string sFile, int iCharWidth, int iCharHeight, int iRows, int iColumns)
        {
            bool  bGood = false;
            RAnim animNormal;

            RReporting.sLastFile = sFile;          //TODO: implement this EVERYWHERE
            try {
                animNormal = new RAnim();
                bGood      = Init();
                if (bGood)
                {
                    bGood = animNormal.SplitFromImage32(sFile, iCharWidth, iCharHeight, iRows, iColumns);
                    //animNormal.SaveSeq("etc/test/0.debug-glyph", "png");
                    //RImage.OverlayToBigNoClipRaw(ref riTarget, ref ipAt, ref animNormal.riFrame.byarrData, iCharWidth, iCharHeight, 4);
                    if (bGood)
                    {
                        Normal     = animNormal;
                        Bold       = Normal.Copy();
                        Italic     = Normal.Copy();
                        BoldItalic = Normal.Copy();
                        //TODO: finish modifying the Glyph Types -- italics using image manip
                    }
                    //else RReporting.ShowErr("RFont failed to split image","","RFont FromImage");//already shown by anim
                    //ShowAsciiTable();
                    //Console.Error.WriteLine("Normal.ToString(true):"+Normal.ToString(true));
                }
                else
                {
                    RReporting.ShowErr("Couldn't initialize font glyph graphics buffer", "initializing font graphics", "RFont FromImage");
                }
            }
            catch (Exception exn) {
                RReporting.ShowExn(exn, "initializing font graphics", "RFont FromImage");
            }
            return(bGood);
        }        //end FromImage
Ejemplo n.º 17
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)
Ejemplo n.º 18
0
        public bool NeedsToBreakBeforeWordBreaker(string sText, int iCursor, int xPixel, IRect rectDest, int iGlyphType)
        {
            bool bReturn = false;

            try {
                if (rectDest != null)
                {
                    if (sText != null && iCursor >= 0 && iCursor < sText.Length)
                    {
                        int zone_Right = rectDest.X + rectDest.Width;
                        while (!RString.IsWordBreaker(sText[iCursor]))                           //while (!RString.IsSpacing(sText[iCursor])) {
                        {
                            xPixel += WidthOf(sText[iCursor], iGlyphType);
                            if (xPixel >= zone_Right)
                            {
                                bReturn = true;
                                break;
                            }
                            iCursor++;
                        }
                    }
                }
                else
                {
                    RReporting.ShowErr("Cannot check line breaking using null rect.", "", "NeedsToBreakBeforeWordBreaker");
                }
            }
            catch (Exception exn) {
                RReporting.ShowExn(exn, "checking for line break", String.Format("NeedsToBreakBeforeWordBreaker {{{0}{1}{2}rectDest:{3}}}",
                                                                                 RReporting.DebugStyle("sText", sText, false, true),
                                                                                 RReporting.DebugStyle("iCursor", iCursor, true),
                                                                                 RReporting.DebugStyle("xPixel", xPixel, true),
                                                                                 IRect.ToString(rectDest)));
            }
            return(bReturn);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Set by 6-character (rgb), 8-character (rgba), or 3-character (rgb) hex string (may start with # or 0x, x and hex chars are case-insensitive).
        /// </summary>
        /// <param name="sHexCode"></param>
        /// <returns></returns>
        public bool SetRgb(string sHexCode)
        {
            bool bGood = true;

            try {
                sHexCode = sHexCode.ToUpper();
                if (sHexCode.StartsWith("#"))
                {
                    sHexCode = sHexCode.Substring(1);
                }
                else if (sHexCode.StartsWith("0X"))
                {
                    sHexCode = sHexCode.Substring(2);
                }
                if (sHexCode.Length < 6)
                {
                    if (sHexCode.Length == 3)
                    {
                        if (!SetRgba(RConvert.ToByte(RConvert.HexNibbleToInt(sHexCode[0]) << 4),                      //*17
                                     RConvert.ToByte(RConvert.HexNibbleToInt(sHexCode[1]) << 4),                      //*17
                                     RConvert.ToByte(RConvert.HexNibbleToInt(sHexCode[2]) << 4),                      //*17
                                     255
                                     ))
                        {
                            bGood = false;
                        }
                    }
                    else
                    {
                        RReporting.ShowErr("This hex color code in the file is not complete", "", "RBrush SetRgb(" + sHexCode + ")");
                        bGood = false;
                    }
                }
                else
                {
                    if (sHexCode.Length >= 8)
                    {
                        if (!SetRgba(RConvert.HexToByte(sHexCode.Substring(0, 2)),
                                     RConvert.HexToByte(sHexCode.Substring(2, 2)),
                                     RConvert.HexToByte(sHexCode.Substring(4, 2)),
                                     RConvert.HexToByte(sHexCode.Substring(6, 2))
                                     ))
                        {
                            bGood = false;
                        }
                    }
                    else
                    {
                        if (!SetRgba(RConvert.HexToByte(sHexCode.Substring(0, 2)),
                                     RConvert.HexToByte(sHexCode.Substring(2, 2)),
                                     RConvert.HexToByte(sHexCode.Substring(4, 2)), 255))
                        {
                            bGood = false;
                        }
                    }
                }
            }
            catch (Exception exn) {
                RReporting.ShowExn(exn, "interpreting the specified hex color code", "RBrush SetRgb(" + sHexCode + ")");
                bGood = false;
            }
            return(bGood);
        }        //end SetRgb(Hex)
Ejemplo n.º 20
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="sText">Time length formatted as [D]:[H]:[M]:[S.MS], [D]:[H]:[M]:[S]:[F], [H]:[M]:[S];[F], [S.MS], [F],
		/// numbers in arbitrary order but labeled as 0d0h0m0s0ms0f or where
		/// items in brackets are not in brackets but are instead numbers, and where [D] (days) and anything
		/// else to the left of [S] is optional.</param>
		/// <returns>Seconds, or if fails, returns decimal.MinValue instead.</returns>
		public static decimal SecondsFromDHMSF(string sText, decimal dFrameRate, uint FrameRate_override) {
			decimal dReturn=0.0M;
			bool bGood=false;
			RReporting.sParticiple="trimming DHMSF timecode string";
			try {
				darrToSecondMultiplier[TimeType_Frame]=1.0M/dFrameRate;
				darrFromSecondDivisor[TimeType_Frame]=dFrameRate;
				if (sText==null) sText="";
				if (sText.Length>0) {
					//int iMSTotal=0;
					//string[] sarrNum=new String[sText.Length];
					//string[] sarrType=new String[sText.Length];
					//for (int iNow=0; iNow<sText.Length; iNow++) {
					//	sarrNum[iNow]="";
					//	sarrType[iNow]="";
					//}
					int iFirst=0;
					int iLast=sText.Length-1;
					while (RString.IsWhiteSpace(sText[iFirst])) {
						iFirst++;
					}
					while (RString.IsWhiteSpace(sText[iLast])) {
						iLast--;
					}
					if (iFirst>0||(iLast!=(sText.Length-1))) {
						if (iLast>=iFirst) {
							sText=RString.SafeSubstringByInclusiveEnder(sText,iFirst,iLast);
						}
						else sText="";
					}
					int iNums=0;
					RReporting.sParticiple="checking DHMSF timecode string";
					int iDigits=0;
					int iLastDecimal=-1;
					int iLastColon=-1;
					for (int i=0; i<sText.Length; i++) {
						if (RString.IsDigit(sText[i])) iDigits++;
						else if (sText[i]=='.') iLastDecimal=i;
						else if (sText[i]==':') iLastColon=i;
					}
					bool bHasDecimalInLastSegment=iLastDecimal>iLastColon;
					int TimeType_Now=TimeType_Frame; //since SMTPE timecode is [hh]:[mm]:[ss]:[ff] (vegas is [hh]:[mm]:[ss];[ff])
					if (bHasDecimalInLastSegment) {
						TimeType_Now=TimeType_Second;//to account timecode with decimal seconds e.g. [hh]:[mm]:[ss].[_ms]
					}
					int iChar=sText.Length-1;
					bGood=true;
					int ParsingWhat=Parsing_Delimiter;
					int SegmentNow_EndBefore=iChar+1;
					if (RString.IsDigit(sText[iChar])) ParsingWhat=Parsing_Number; //ok to use iChar since this whole process only happens if sText.Length>0
					while (iChar>=-1) {
						if (ParsingWhat==Parsing_Space) {
							if (iChar==-1) {
								//do nothing
							}
							else if (!RString.IsWhiteSpace(sText[iChar])) {
								SegmentNow_EndBefore=iChar+1;//+1 since NOT whitespace
								if (RString.IsDigit(sText[iChar])||(sText[iChar]=='.')) {
									ParsingWhat=Parsing_Number;
									//sarrNum[iNums]+=sText.Substring(iChar,1);
								}
								else {
									ParsingWhat=Parsing_Delimiter;
								}
							}
						}
						else if (ParsingWhat==Parsing_Delimiter) {
							if (iChar<0) {
								RReporting.SourceErr("Warning: unknown text found at start of time string","",sText);
							}
							else if (RString.IsDigit(sText[iChar])||(sText[iChar]=='.')||(RString.IsWhiteSpace(sText[iChar]))) {
								int TimeType_Temp=-1;
								//if (sText[iChar]=='.') {
								//HANDLED BELOW (TimeType_Now decremented twice)
								//	TimeType_Temp=TimeType_Second 
								//}
								//else {
								if (SegmentNow_EndBefore-(iChar+1) == 1) TimeType_Temp=TimeDelimiterToTimeType(sText[iChar+1]); //+1 since [iChar] is NOT delimiter
								else TimeType_Temp=TimeDelimiterToTimeType(RString.SafeSubstringByExclusiveEnder(sText,iChar+1,SegmentNow_EndBefore)); //+1 since [iChar] is NOT delimiter
								//}
								if (TimeType_Temp<0) {//assume generic delimiter //if (sText[iChar]==":"||sText[iChar]==";") {
									if (carrTimeType[TimeType_Now]=='.') TimeType_Now--;//skip f if on ms
									TimeType_Now--;
								}
								else TimeType_Now=TimeType_Temp;
								
								SegmentNow_EndBefore=iChar+1;//+1 since sText[iChar] is NOT delimiter
								if (RString.IsWhiteSpace(sText[iChar])) {
									ParsingWhat=Parsing_Space;
								}
								else {//digit or '.'
									ParsingWhat=Parsing_Number;
								}
								//sarrNum[iNums]+=sText.Substring(iChar,1);
							}
						}
						else if (ParsingWhat==Parsing_Number) {
							if (  iChar<0  ||  ( !RString.IsDigit(sText[iChar]) && !(sText[iChar]=='.') )  ) {
								if (IsValidTimeType(TimeType_Now)) {
									//Each hour is 108000 non-drop frames (30 * 60 * 60) or 107892 drop frames (drop 108 frames). In real time,
									//each hour is 107892.108 frames.
									//Each "deci-minute" is 18000 non-drop frames (30 * 60 * 10) or 17982 drop frames (drop 18 frames, or 2 frames
									//for nine out of every ten minutes). In real time, 10 minutes is 17982.018 frames.
									//Each "single-minute" is 1800 non-drop frames (30 * 60) or 1798 drop frames (drop 2 frames for every minute, or
									//0 frames when multiplying by 0). In real time, a minute is 1798.202 frames.
									//Each second is 30 frames (both timebases), or 29.970 frames real-time.
									if (TimeType_Now==TimeType_Frame) {
										
									}
									else dReturn+=RConvert.ToDecimal( RString.SafeSubstringByExclusiveEnder(sText,iChar+1,SegmentNow_EndBefore) ) * darrToSecondMultiplier[TimeType_Now]; //+1 since [iChar] is NOT digit
								}
								if (!(iChar<0)) {
									SegmentNow_EndBefore=iChar+1;//+1 since [iChar] is NOT part of number
									if (RString.IsWhiteSpace(sText[iChar])) {
										ParsingWhat=Parsing_Space;
									}
									else {
										ParsingWhat=Parsing_Delimiter;
									}
								}//if not out of range
							}
							//else if (sText[iChar]=='.' && TimeType_Now==TimeType_Millisecond) TimeType_Now=TimeType_Second
						}
						else { //ParsingWhat does not have valid opcode
							bGood=false;
							RReporting.ShowErr("DHMSF Parsing Corruption");
						}
						iChar--;
					}//end while iChar>=-1
				}//end if sText.Length>0
				else {
					bGood=true; //good since it is ok to be blank
					dReturn=0.0M;
				}
			}
			catch (Exception e) {
				bGood=false;
				RReporting.ShowExn(e);
			}
			if (!bGood) dReturn=decimal.MinValue;
			return dReturn;
		}//end From(sDHMSF)
Ejemplo n.º 21
0
        public bool FromFixedHeightStaggered(string sFile, int iCharHeight)          //this is named FromFixedHeightStaggered while the function it called anim.SplitFromFixedHeightStaggered
        {
            RReporting.sLastFile = sFile + "...";
            bool  bGood      = false;
            RAnim animNormal = null;

            bGood = Init();
            try {
                if (!sFile.EndsWith(".png"))
                {
                    animNormal = new RAnim();
                    RImage riNormal = new RImage();
                    RReporting.sLastFile = sFile + ".png";
                    if (!riNormal.Load(sFile + ".png", 4))                    //assumes 32-bit is needed
                    {
                        RReporting.ShowErr("Cannot load font file", "", "RAnim FromFixedHeightStaggered(\"" + RString.SafeString(sFile) + ".png\")");
                    }
                    RReporting.sParticiple = "splitting normal font image";
                    bGood = animNormal.SplitFromFixedHeightStaggered(riNormal, iCharHeight);
                    if (bGood)
                    {
                        Normal = animNormal;
                        bGood  = Normal != null;
                        if (Normal == null)
                        {
                            RReporting.ShowErr("failed to load normal font though split image returned true", "checking loaded normal font", "rfont_bgra32 FromFixedHeightStaggered");
                        }
                        if (File.Exists(sFile + "-bold.png"))
                        {
                            RReporting.sLastFile = sFile + "-bold.png";
                            if (animarrGlyphType[RFont.GlyphTypeBold] == null)
                            {
                                Bold = new RAnim();
                            }
                            RImage riBold = new RImage();
                            RReporting.sParticiple = "loading bold font image";
                            riBold.Load(sFile + "-bold.png", 4);                         //assumes 32-bit is needed
                            if (!Bold.SplitFromFixedHeightStaggered(riBold, iCharHeight))
                            {
                                RReporting.sParticiple = "falling back to generated bold font";
                                bGood = false;
                                RReporting.ShowErr("Could not split image to bold font frames", "separating bold font frames", "rfont_bgra32 FromFixedHeightStaggered");
                                Bold = animNormal.Copy();
                                //TODO: embolden font manually
                            }
                        }
                        else
                        {
                            RReporting.sParticiple = "getting bold font image from normal";
                            Bold = animNormal.Copy();
                            if (Bold != null)
                            {
                                //TODO: embolden font manually
                            }
                            else
                            {
                                bGood = false;
                                RReporting.ShowErr("Could not copy font frames", "copying font frames to bold font frames", "rfont_bgra32 FromFixedHeightStaggered");
                            }
                        }
                        RReporting.sParticiple = "getting italic font image from normal";
                        Italic = Normal.Copy();
                        if (Italic != null)
                        {
                            //TODO: italicize font manually
                        }
                        else
                        {
                            bGood = false;
                            RReporting.ShowErr("Could not copy font frames", "copying font frames to italic font frames", "rfont_bgra32 FromFixedHeightStaggered");
                        }
                        RReporting.sParticiple = "getting bold italic font image from bold";
                        BoldItalic             = Bold.Copy();
                        if (BoldItalic != null)
                        {
                            //TODO: italicize bold font manually
                        }
                        else
                        {
                            bGood = false;
                            RReporting.ShowErr("Could not copy font frames", "copying font frames to bold italic font frames", "rfont_bgra32 FromFixedHeightStaggered");
                        }
                        CalculateSpacing(GlyphTypeNormal);
                    }
                    else
                    {
                        RReporting.ShowErr("Could not split image to font frames", "separating font frames", "rfont_bgra32 FromFixedHeightStaggered");
                    }
                }
                else
                {
                    bGood = false;
                    RReporting.ShowErr("Font file base name must not end with extension--must have assumed png extension.", "checking raster font file", "rfont_bgra32 FromFixedHeightStaggered");
                }
            }
            catch (Exception exn) {
                bGood = false;
                RReporting.ShowExn(exn, "Splitting Proportional Font Glyphs", "FromFixedHeightStaggered(" + sFile + "," + iCharHeight.ToString() + ")");
            }
            if (this.animarrGlyphType != null)
            {
                for (int i = 0; i < RFont.iGlyphTypes; i++)
                {
                    if (animarrGlyphType[i] == null)
                    {
                        RReporting.ShowErr("Null glyph type " + RFont.GlyphTypeToString(i), "getting glyphs from images", "FromFixedHeightStaggered(sFile=" + RReporting.StringMessage(sFile, true) + ",iCharHeight=" + iCharHeight + ")");
                    }
                    else if (!animarrGlyphType[i].FrameIsCached(0))
                    {
                        RReporting.ShowErr("First glyph is null in glyph type " + RFont.GlyphTypeToString(i), "getting glyphs from images", "FromFixedHeightStaggered(sFile=" + RReporting.StringMessage(sFile, true) + ",iCharHeight=" + iCharHeight + ")");
                    }
                }
            }
            else
            {
                RReporting.ShowErr("Null glyph type array", "getting glyphs from images", "FromFixedHeightStaggered(sFile=" + RReporting.StringMessage(sFile, true) + ",iCharHeight=" + iCharHeight + ")");
            }
            return(bGood);
        }        //end FromFixedHeightStaggered
Ejemplo n.º 22
0
        }        //end From(Pixel32Struct,Pixel32Struct)

        public bool From(int[] iarrPosition, Pixel32Struct[] pxarrColor)
        {
            bool   bGood = false;
            string sVerb = "getting maximum";

            try {
                if (iarrPosition.Length > 0)
                {
                    if (iarrPosition.Length == pxarrColor.Length)
                    {
                        int iPositions   = iarrPosition.Length;
                        int iMaxPosition = 0;
                        int iNow;
                        for (iNow = 0; iNow < iarrPosition.Length; iNow++)
                        {
                            if (iarrPosition[iNow] > iMaxPosition)
                            {
                                iMaxPosition = iarrPosition[iNow];
                            }
                        }
                        int iShades = iMaxPosition + 1;
                        if (iShades < 256)
                        {
                            iShades = 256;
                        }
                        sVerb    = "creating [" + iShades.ToString() + "] shades";
                        by2dGrad = new byte[iShades][];
                        sVerb    = "setting [" + iShades.ToString() + "] shades";
                        for (iNow = 0; iNow < iShades; iNow++)
                        {
                            by2dGrad[iNow] = new byte[iBytesPP];
                            for (int iChan = 0; iChan < iBytesPP; iChan++)
                            {
                                by2dGrad[iNow][iChan] = 0;
                            }
                        }
                        //do the last position so overlap is not needed in the calculations in the for loop:
                        sVerb = "setting top color [shade " + (iPositions - 1).ToString() + "]";
                        if (iBytesPP == 1)
                        {
                            by2dGrad[iPositions][0] = pxarrColor[iPositions - 1].A;
                        }
                        else
                        {
                            by2dGrad[iMaxPosition][0] = pxarrColor[iPositions - 1].B;
                            by2dGrad[iMaxPosition][1] = pxarrColor[iPositions - 1].G;
                            by2dGrad[iMaxPosition][2] = pxarrColor[iPositions - 1].R;
                            if (iBytesPP > 3)
                            {
                                by2dGrad[iMaxPosition][3] = pxarrColor[iPositions - 1].A;
                            }
                        }
                        float fNextness;
                        for (int iPositionIndex = 0; iPositionIndex < iPositions - 1; iPositionIndex++)
                        {
                            sVerb = "setting position " + iPositionIndex.ToString();
                            if (iarrPosition[iPositionIndex + 1] > iarrPosition[iPositionIndex])
                            {
                                for (int iGradNow = iarrPosition[iPositionIndex]; iGradNow < iarrPosition[iPositionIndex + 1]; iGradNow++)
                                {
                                    sVerb     = "setting shade " + iGradNow.ToString() + " at position " + iPositionIndex.ToString();
                                    fNextness = (float)((double)(iGradNow - iarrPosition[iPositionIndex]) / (double)(iarrPosition[iPositionIndex + 1] - iarrPosition[iPositionIndex]));
                                    //debug performance--the next lines can use an alpha lookup table (fNextness*255)!
                                    by2dGrad[iGradNow][0] = RMath.Approach(pxarrColor[iPositionIndex].B, pxarrColor[iPositionIndex + 1].B, fNextness);
                                    by2dGrad[iGradNow][1] = RMath.Approach(pxarrColor[iPositionIndex].G, pxarrColor[iPositionIndex + 1].G, fNextness);
                                    by2dGrad[iGradNow][2] = RMath.Approach(pxarrColor[iPositionIndex].R, pxarrColor[iPositionIndex + 1].R, fNextness);
                                    by2dGrad[iGradNow][3] = RMath.Approach(pxarrColor[iPositionIndex].A, pxarrColor[iPositionIndex + 1].A, fNextness);
                                }
                            }
                            else
                            {
                                RReporting.ShowErr("Couldn't arrange RGradient position list", "", "RGradient From(int array, Pixel32Struct array)");
                            }
                        }
                    }
                    else
                    {
                        RReporting.ShowErr("RGradient position and color lists' sizes do not match", "", "RGradient From(int array, Pixel32Struct array)");
                    }
                }
                else
                {
                    RReporting.ShowErr("RGradient positions are inaccessible", "", "RGradient From(int array, Pixel32Struct array)");
                }
                bGood = true;
            }
            catch (Exception exn) {
                bGood = false;
                RReporting.ShowExn(exn, "calculating gradient from colors at given positions (" + sVerb + ")", "RGradient From(int array, Pixel32Struct array)");
            }
            return(bGood);
        }        //end From(int[],Pixel32Struct[])
Ejemplo n.º 23
0
        public bool ReadLine(out string sLine, string sText, ref int iMoveMe, IRect rectDest, int iGlyphType)
        {
            bool HasALine   = false;
            bool bBreakable = false;
            int  iSkipper   = 0;
            int  iStartLine = iMoveMe;

            try {
                int iStart     = iMoveMe;
                int xPixel     = rectDest.X;
                int zone_Right = rectDest.Right;
                if (iMoveMe + 1 < sText.Length)
                {
                    HasALine = true;
                }
                while (iMoveMe + 1 < sText.Length)
                {
                    //string sTemp=SafeSubstring(sText,iMoveMe,Environment.NewLine.Length);
                    if (RString.CompareAt(sText, Environment.NewLine, iMoveMe))
                    {
                        bBreakable = true;
                        iSkipper   = Environment.NewLine.Length;
                        break;
                    }
                    else if (RString.CompareAt(sText, '\n', iMoveMe))
                    {
                        bBreakable = true;
                        iSkipper   = 1;
                        break;
                    }
                    else if (RString.CompareAt(sText, '\r', iMoveMe))
                    {
                        bBreakable = true;
                        iSkipper   = 1;
                        break;
                    }
                    else if (xPixel + WidthOf(sText[iMoveMe], iGlyphType) >= zone_Right)
                    {
                        int  iLastBreaker    = iMoveMe;
                        bool bVisibleBreaker = false;
                        bool bTest           = RString.PreviousWordBreakerExceptNewLine(sText, ref iLastBreaker, out bVisibleBreaker);
                        if (iLastBreaker > iStartLine)
                        {
                            if (bVisibleBreaker)
                            {
                                iSkipper = 0;                 //says not to skip any characters
                                iMoveMe  = iLastBreaker + 1;  //includes it in the substring
                            }
                            else                              //else invisible, so skip it
                            {
                                iSkipper = 1;                 //says to skip it after substring is taken
                                iMoveMe  = iLastBreaker;      //excludes it from the substring
                            }
                        }
                        else                          //else no breaker
                        {
                            iSkipper = 0;
                        }
                        //NOTE: debug non-compliance: bBreakable and break allow non-html-style forced breakage if no breaker before wrap (when "else" case above occurs)
                        bBreakable = true;                      //says to not skip to end of sText
                        break;
                    }
                    //else if (NeedsToBreakBeforeWordBreaker(sText, iMoveMe+1, xPixel, rectDest, iGlyphType) && RString.IsWordBreakerExceptNewLine(sText,iMoveMe)) {
                    //	bBreakable=true;
                    //	iSkipper=1;
                    //	bTypeableNewLine=true;
                    //	break;
                    //}
                    else
                    {
                        xPixel += WidthOf(sText[iMoveMe], iGlyphType);
                        iMoveMe++;
                    }
                }
                if (!bBreakable)
                {
                    iMoveMe = sText.Length;
                }
                sLine = RString.SafeSubstring(sText, iStart, iMoveMe - iStart);
                if (bBreakable)
                {
                    iMoveMe += iSkipper;
                }
            }
            catch (Exception exn) {
                sLine = "";
                RReporting.ShowExn(exn, "RFont ReadLine");
            }
            return(HasALine);
        }
Ejemplo n.º 24
0
        }                                                                                                     //end RenderLine

        public bool Render(ref RImage riDest, IRect rectDest, string sText, int iGlyphType, int LineBreaking) //formerly typefast
        //TODO: really, this should return a rect (e.g. html-style stretching of container)
        {
            bool bGood = true;
            //IPoint ipDestNow;
            //IPoint ipDestLine;
            bool bSpacing;

            try {
                //ipDestNow=new IPoint();
                //ipDestNow.X=rectDest.X;
                //ipDestNow.Y=rectDest.Y;
                //ipDestLine.Set(ipDestNow);
                int    zone_Bottom = rectDest.Bottom;
                string sLine;
                int    iCursor     = 0;
                int    yDest       = rectDest.Y;
                int    iLineHeight = GlyphHeight(iGlyphType);
                int    iLine       = 0;
                //RImage.rpaintFore.SetRgb(0,0,0);
                //riDest.DrawRectCropped(rectDest);
                //string sDebugReadLineFile="0.debug-Typing.txt";//debug only
                //bool bDebug=!File.Exists(sDebugReadLineFile);
                CalculateSpacing(iGlyphType);
                if (LineBreaking == LineBreakingOnlyWhenEndOfTextLine)
                {
                    while (RenderLine(ref riDest, rectDest.X, yDest, sText, iGlyphType, ref iCursor, false))
                    {
                        yDest += iLineHeight;
                        if (yDest + iLineHeight >= zone_Bottom)
                        {
                            break;                                                        //+iLineHeight skips croppable chars
                        }
                        iLine++;
                    }
                }
                else if (LineBreaking == LineBreakingFast)
                {
                    while (RenderLine(ref riDest, rectDest.X, yDest, sText, iGlyphType, ref iCursor, true))
                    {
                        yDest += iLineHeight;
                        if (yDest + iLineHeight >= zone_Bottom)
                        {
                            break;                                                        //+iLineHeight skips croppable chars
                        }
                        iLine++;
                    }
                }
                else                  //assume LineBreakingSlowAccurate
                {
                    while (ReadLine(out sLine, sText, ref iCursor, rectDest, iGlyphType))
                    {
                        if (yDest < zone_Bottom)
                        {
                            TypeOnOneLine(ref riDest, rectDest.X, yDest, sLine, iGlyphType);
                        }
                        else
                        {
                            break;
                        }
                        yDest += iLineHeight;                      //+iLineHeight skips croppable chars
                        iLine++;
                    }
                }
            }
            catch (Exception exn) {
                RReporting.ShowExn(exn, "", "Render(...,\"" + RString.ElipsisIfOver(sText, 10) + "\")");
                bGood = false;
            }
            return(bGood);
        }
Ejemplo n.º 25
0
 public bool Render(ref RImage riDest, IZone zoneDest, string sText)
 {
     try { zoneDest.CopyTo(ref rectDefault); }
     catch (Exception exn) { RReporting.ShowExn(exn, "accessing destination text zone", "RFont Render"); riDest.ToRect(ref rectDefault); }
     return(Render(ref riDest, rectDefault, sText, GlyphTypeNormal));
 }
Ejemplo n.º 26
0
// 		public bool Render(GBuffer gbDest, IRect rectDest) {
// 			bool bGood=true;
// 			IRect rectShrinking=gbDest.ToRect();
// 			//int iBlobSizeNow=8;
// 			int iBlobSizeNow=1;
// 			int iShrinkBy=gbDest.Height/8;
// 			while (iBlobSizeNow>0) {
// 				if (!Render(gbDest,rectDest,rectShrinking,iBlobSizeNow)) bGood=false;
// 				if (iBlobSizeNow==1) iBlobSizeNow=0;
// 				else {
// 					iBlobSizeNow/=2;
// 					//rectShrinking.Shrink(iShrinkBy);//commented for debug only
// 				}
// 			}
// 			return bGood;
// 		}
		public bool Render(GBuffer gbDest, IRect rectDest) {//, DPoint pPixelOrigin, double rPixelsPerUnit, double rSeed) {
			bool bGood=true;
			try {
				ResetPasses();//fixes iDetailRadius etc
				//int xDest=rectDest.Left;
				//int yDest=rectDest.Top;
				int xEnder=rectDest.X+rectDest.Width;
				int yEnder=rectDest.Y+rectDest.Height;
				
				//double rInverseScale=1.0/rPixelsPerUnit;
				FRACTALREAL rUnitsPerPixel=fr1/rPixelsPerUnit;
				xSrcStart=-((FRACTALREAL)xCenterAtPixel*rUnitsPerPixel);//rInverseScale
				ySrc=-((FRACTALREAL)yCenterAtPixel*rUnitsPerPixel);//rInverseScale
				int iHalfW=gbFractal.Width/2;
				int iHalfH=gbFractal.Height/2;
				//int iBlobIncrement=gbFractal.Height/8;
				//if (iBlobIncrement<1) iBlobIncrement=1;
				FRACTALREAL rFractalness=fr0;
// 			int xBlobPrev=-1;
// 			int yBlobPrev=-1;
// 			int xBlob;
// 			int yBlob;
// 			bool bBlobStartX=false;
// 			bool bBlobStartY=false;
				xDest=rectDest.X;
				yDest=rectDest.Y;
				//int zone_Right=rectCropFractal.Right;
				//int zone_Bottom=rectCropFractal.Bottom;
				//int iBlobSize=(int)RMath.Dist((double)iHalfW,(double)iHalfH,(double)xDest,(double)yDest)/iBlobIncrement;
				//int iBlobSize=(int)(  (1.0-(RMath.Dist((double)iHalfW,(double)iHalfH,(double)xDest,(double)yDest)/(double)iHalfW)) * (double)iBlobIncrement  );
				//iBlobSize=8;//debug only
				for (yDest=rectDest.Y; yDest<yEnder; yDest++) {
					xSrc=xSrcStart;
					//yBlob=yDest/iBlobSize;
					//bBlobStartY=yBlobPrev!=yBlob;
					//yBlobPrev=yBlob;
					for (xDest=rectDest.X; xDest<xEnder; xDest++) {
						///NOTE: Hsv is NOT H<360 it is H<1.0
						//iBlobSize=(int)(  (1.0-(RMath.Dist((double)iHalfW,(double)iHalfH,(double)xDest,(double)yDest)/(double)iHalfW)) * (double)iBlobIncrement  );
						//iBlobSize=8;//debug only
						//if (iBlobSize<1) iBlobSize=1;
						//xBlob=xDest/iBlobSize;
						//bBlobStartX=xBlobPrev!=xBlob;//&&yBlobPrev!=yBlob;
						//xBlobPrev=xBlob;
						//this.SetPixelHsva(xDest,yDest,RMath.SafeAngle360(RMath.THETAOFXY_RAD(xSrc,ySrc))/360.0f,1.0,1.0,1.0);
						//double rFractalness=RMath.SafeAngle360(
						//	(double)FractalResultMandelbrot(xSrc,ySrc,rSeed) 
						//	);
						//int iFractalResult=FractalResultMandelbrot((float)xSrc,(float)ySrc);//TODO: use rSeed
						//byte byFractalResult=(byte)(iFractalResult%255);
						//double rFractalness=(double)byFractalResult/255.0;
						//float rFractalness=(float)(Fractal.FractalResultMandelbrot((float)xSrc,(float)ySrc)%255)/255.0f;
						//double rFractalness=(double)(FractalResultMandelbrot((double)xSrc,(double)ySrc)%255)/255.0;
						//if (iBlobSize==1||(bBlobStartX||bBlobStartY))
						//if (bBlobStartX||bBlobStartY)
						//rFractalness=fr_1;
						//if (xDest>rectCropFractal.X&&xDest<zone_Right&&yDest<zone_Bottom&&yDest>=rectCropFractal.Y) {
							//if (xDest%iBlobSize==0&&yDest%iBlobSize==0)
							//double rFractalness=(double)(ResultMandelbrot(xSrc,ySrc,(double)rSeed)%256)/255.0;
							rFractalness=(FRACTALREAL)(ResultMandelbrot((FRACTALREAL)xSrc,(FRACTALREAL)ySrc,rSeed)%256)/fr255;
						//}
						//if (rFractalness!=fr_1) {//bBlobStartX||bBlobStartY) {
							//if (iBlobSize>1) {
							//	try {
							//		if (xDest>=0&&yDest>=0&&xDest+iBlobSize<=gbFractal.Width&&yDest+iBlobSize<=gbFractal.Height) {
							//			GBuffer.SetBrushHsva(rFractalness,1.0,rFractalness,1.0);
							//			if (!gbFractal.DrawRectFilledSafe(xDest,yDest,iBlobSize,iBlobSize)) {
							//				RReporting.Warning("Skipped fractal blob.","{location:"+IPoint.Description(xDest,yDest)+"; size:"+IPoint.Description(iBlobSize,iBlobSize)+"}");
							//			}
							//		}
							//	}
							//	catch {RReporting.Warning("Failed to render fractal blob.","{location:"+IPoint.Description(xDest,yDest)+"}");}
							//}
							//else {
								gbFractal.SetPixelHsva(xDest,yDest,rFractalness,1.0,rFractalness,1.0);
							//}
						//}
						xSrc+=rUnitsPerPixel;
					}
					ySrc+=rUnitsPerPixel;
				}
				//GBuffer.SetBrushRgb(255,0,0);
				//gbFractal.DrawRectFilledSafe(0,0,64,64);
				//gbFractal.DrawRectFilledSafe(gbFractal.Width-64,gbFractal.Height-64,64,64);
				//if (!gbDest.DrawSmallerWithoutCropElseCancel(rectDest.X,rectDest.Y,gbFractal)) bGood=false;
				if (!gbDest.Draw(rectDest,gbFractal,rectSrcDefault)) bGood=false;
				//if (!GBuffer.Render(gbDest,rectDest,gbFractal,rectCropFractal,GBuffer.DrawModeCopyAlpha)) bGood=false;
				if (bGood) iFramesRendered++;
			}
			catch (Exception exn) {	
				RReporting.ShowExn(exn,"Fractal Render");
			}
			return bGood;
		}//end Render
Ejemplo n.º 27
0
		public bool RenderIncrement(GBuffer gbDest, IRect rectDest) {
			bool bGood=true;
			try {
				gbFractal.SetPixelArgb(400,300, 255,255,0,0);//debug only
				if (!FinishedRenderingAll()) {
					iTickStartPrev=iTickStart;
					iTickStart=PlatformNow.TickCount;
					if (iTickStartPrev!=-1) {//&&iTickStart!=-1) {
						iTicksPerFrame=iTickStart-iTickStartPrev;
						//if (iTicksPerFrame>iMaxUsableTicksPerFrame_ElseIgnoreFrameRate) {
							//TODO: fix this: //FRACTALREAL rPerformanceScaler=(FRACTALREAL)iMaxUsableTicksPerFrame_ElseIgnoreFrameRate/(FRACTALREAL)iTicksPerFrame;
							//TODO: fix this: iMaxPPF=(int)((FRACTALREAL)iMaxPPF*rPerformanceScaler);
							if (iMaxPPF<1) iMaxPPF=1;
						//}
					}
					int iPixelRel=0;
					while (iPixelRel<iMaxPPF&&iPixelsRendered<gbFractal.iPixelsTotal) {
						//xSrc+=rPassUnitsPerChunk;
						if (xDest>=gbFractal.Width) {
							xDest=0;
							yDest+=iPassPixelsPerChunk;
							xSrc=xSrcStart;
							//ySrc+=rPassUnitsPerChunk;
						}
						xSrc=XPixelToUnitLocation(xDest);
						ySrc=YPixelToUnitLocation(yDest);
						
						if (yDest<gbFractal.Height) {
							//gbFractal.SetPixelRgb(xDest,yDest, 255,0,0);//debug only
	
							//float rFractalness=(float)(ResultMandelbrot((float)xSrc,(float)ySrc)%255)/255.0f;
							//TODO: finish this--use rSeed
							//double rFractalness=(double)(ResultMandelbrot((double)xSrc,(double)ySrc)%255)/255.0;
							
							//if (RMath.Dist(RMath.IRound(gbFractal.Width/2),RMath.IRound(gbFractal.Height/2),xDest,yDest)<iDetailRadius) {
							if (iPass==1||RMath.Dist((double)(gbFractal.Width/2.0),(double)(gbFractal.Height/2.0),(double)xDest,(double)yDest)<(double)iDetailRadius) {
								FRACTALREAL rFractalness=(FRACTALREAL)(ResultMandelbrot((FRACTALREAL)xSrc,(FRACTALREAL)ySrc)%255)/fr255;
								if (iPassPixelsPerChunk>1) {
									GBuffer.SetBrushHsva(rFractalness,1.0,rFractalness,1.0);
									gbFractal.DrawRectCroppedFilled(xDest,yDest,iPassPixelsPerChunk,iPassPixelsPerChunk);
								}
								else gbFractal.SetPixelHsva(xDest,yDest,rFractalness,1.0,rFractalness,1.0);
								//xSrc+=rPassUnitsPerChunk;
							}
							
							iPixelsRendered++;
							iPixelRel++;
						}//end if yDest<gbFractal.Height
						else break;//finished rendering frame
						xDest+=iPassPixelsPerChunk;
					}//end while iPixelRel<iMaxPPF
					
					//TODO: finish this
					if (FinishedRenderingFrame()) {
						iPass++;//must be incremented BEFORE ResetLocations (before OnSetPass)
						ResetLocations();//DOES OnStartPass
						iFramesRendered++;
					}
				}//end if !FinishedRenderingAll
				//gbFractal.SetPixelArgb(400,300, 255,0,255,0);//debug only
				if (!gbDest.Draw(rectDest,gbFractal)) {
					bGood=false;
					RReporting.Warning("Couldn't draw Fractal buffer to destination.","{gbFractal:"+GBuffer.VariableMessage(gbFractal)+"; gbDest:"+GBuffer.VariableMessage(gbDest)+"; rectDest:"+rectDest.Description()+"}");
				}
			}
			catch (Exception exn) {
				bGood=false;
				RReporting.ShowExn(exn,"Fractal RenderIncrement","rendering fractal increment");
			}
			return bGood;
		}//end RenderIncrement
Ejemplo n.º 28
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)
Ejemplo n.º 29
0
        public bool Shade(ref PixelYhsa 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 PixelYhsa();
                }
                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 pxDest.From(pxarrStep[iTop]);//debug only
                    //else if (rSrcZeroTo1>=(REAL)1.0) pxDest.From(pxarrStep[iTop]);
                    else
                    {
                        int  iLower = 0;
                        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[iLower]);
                                }
                                else
                                {
                                    //use the alpha formula: (src-dest)*fAlphaRatio+dest
                                    pxDest.Y = (pxDest.Y - pxarrStep[iLower].Y) * ratio + pxDest.Y;
                                    pxDest.H = (pxDest.H - pxarrStep[iLower].H) * ratio + pxDest.H;
                                    pxDest.S = (pxDest.S - pxarrStep[iLower].S) * ratio + pxDest.S;
                                    pxDest.A = (pxDest.A - pxarrStep[iLower].A) * ratio + pxDest.A;
                                }
                                bFound = true;
                            }
                        }
                        if (!bFound)
                        {
                            pxDest.From(pxarrStep[STEPS - 1]);
                        }
                    }            //else shade rationally
                }                //end if steps are initialized
                else
                {
                    pxDest.Set(0, 0, 0, 0);
                }
            }
            catch (Exception exn) {
                RReporting.ShowExn(exn, "Gradient Shade(YHSA)");
            }
            if (bWasNull)
            {
                RReporting.ShowErr("Null dest pixel", "Gradient Shade(YHSA)");
            }
            return(bFound); //TODO: is this right?
        }                   //end Shade(YHSA,REAL)
Ejemplo n.º 30
0
        public bool From(ref PixelYhsa pxUpper, ref PixelYhsa pxLower)
        {
            bool bGood = false;

            try {
                //PixelYhsa pxUpperNow=new PixelYhsa(pxUpper);
                //PixelYhsa pxLowerNow=new PixelYhsa(pxLower);
                try {
                    STEPS = 2;
                }
                catch (Exception exn) {
                    bGood = false;
                    RReporting.ShowExn(exn, "Gradient.From(YHSA,YHSA)", "setting steps to " + STEPS.ToString());
                }
                if (pxarrStep == null)
                {
                    bGood = false;
                    RReporting.ShowErr("Gradient step array is still null!", "Gradient From(YHSA,YHSA)");
                }
                else if (pxarrStep[0] == null)
                {
                    bGood = false;
                    RReporting.ShowErr("Gradient step first index is still null!", "Gradient From(YHSA,YHSA)");
                }
                try {
                    pxarrStep[0].Y = pxarrStep[0].Y;
                }
                catch (Exception exn) {
                    bGood = false;
                    RReporting.ShowExn(exn, "Gradient.From(YHSA,YHSA)", "accessing pixel step array");
                }
                try {
                    pxarrStep[0].Y = pxLower.Y;
                    pxarrStep[0].H = pxLower.H;
                    pxarrStep[0].S = pxLower.S;
                    pxarrStep[0].A = pxLower.A;
                }
                catch (Exception exn) {
                    bGood = false;
                    RReporting.ShowExn(exn, "Gradient.From(YHSA,YHSA)", "copying lower pixel values");
                }
                try {
                    pxarrStep[1].Y = pxUpper.Y;
                    pxarrStep[1].H = pxUpper.H;
                    pxarrStep[1].S = pxUpper.S;
                    pxarrStep[1].A = pxUpper.A;
                }
                catch (Exception exn) {
                    bGood = false;
                    RReporting.ShowExn(exn, "Gradient.From(YHSA,YHSA)", "copying upper pixel values");
                }
                try {
                    rarrStep[0] = (REAL)0.0;
                    rarrStep[1] = (REAL)1.0;
                }
                catch (Exception exn) {
                    bGood = false;
                    RReporting.ShowExn(exn, "Gradient.From(YHSA,YHSA)", "setting step values");
                }
                bGood = true;
            }
            catch (Exception exn) {
                bGood = false;
                RReporting.ShowExn(exn, "Gradient.From(YHSA,YHSA)", "copying values");
            }
            return(bGood);
        }        //end From(YHSA,YHSA)