Esempio n. 1
0
 public static void Print(this Dictionary <object, object> dict, E_ColorType ecolor = E_ColorType.Init)
 {
     Darkfeast.Log("Print-dictCount " + dict.Count, E_ColorType.UI);
     foreach (var v in dict)
     {
         Darkfeast.Log("k " + v.Key + "  v " + v.Value, ecolor);
     }
     Darkfeast.Log("---------------------" + dict.Count, E_ColorType.Over);
 }
Esempio n. 2
0
 //打印列表内容
 public static void Print <T>(this List <T> list, E_ColorType ecolor = E_ColorType.Init)
 {
     Darkfeast.Log("Print-listCount " + list.Count, E_ColorType.UI);
     foreach (var v in list)
     {
         Darkfeast.Log(v, ecolor);
     }
     Darkfeast.Log("---------------------" + list.Count, E_ColorType.Over);
 }
Esempio n. 3
0
    //获取列表中的字符串并拼成一行
    public static string GetOneLine(this List <string> list, E_ColorType ecolor = E_ColorType.Init)
    {
        StringBuilder sb = new StringBuilder();

        foreach (var v in list)
        {
            sb.Append(v + "#");
        }
        return(sb.ToString(0, sb.Length - 1));
    }
Esempio n. 4
0
        private IhdrChunk ReadIhdrChunk(byte[] loadedDatastream)
        {
            int         width;
            int         height;
            E_BitDepth  bitDepth  = E_BitDepth.NO_DATA;
            E_ColorType colorType = E_ColorType.NO_DATA;
            int         compressionMetod;
            int         filter;
            E_Interlace interlace = E_Interlace.NO_DATA;

            byte[] ihdrPattern = new byte[] { 73, 72, 68, 82 };
            int    index       = FindChunkPosition(loadedDatastream, ihdrPattern) + ihdrPattern.Length;

            width  = calculateBytesArray(loadedDatastream, index, 4);
            height = calculateBytesArray(loadedDatastream, index + 4, 4);
            switch (calculateBytesArray(loadedDatastream, index + 8, 1))
            {
            case 1: bitDepth = E_BitDepth.One; break;

            case 2: bitDepth = E_BitDepth.Two; break;

            case 4: bitDepth = E_BitDepth.Four; break;

            case 8: bitDepth = E_BitDepth.Eight; break;

            case 16: bitDepth = E_BitDepth.Sixteen; break;
            }
            switch (calculateBytesArray(loadedDatastream, index + 9, 1))
            {
            case 0: colorType = E_ColorType.GRAYSCALE; break;

            case 2: colorType = E_ColorType.TRUECOLOR; break;

            case 3: colorType = E_ColorType.INDEXED; break;

            case 4: colorType = E_ColorType.GRAYSCALE_ALPHA; break;

            case 6: colorType = E_ColorType.TRUECOLOR_ALPHA; break;
            }
            compressionMetod = calculateBytesArray(loadedDatastream, index + 10, 1);
            filter           = calculateBytesArray(loadedDatastream, index + 11, 1);
            switch (calculateBytesArray(loadedDatastream, index + 12, 1))
            {
            case 0: interlace = E_Interlace.NO_INTERLACE; break;

            case 1: interlace = E_Interlace.ADAM7; break;
            }

            return(new IhdrChunk(width, height, bitDepth, colorType, compressionMetod, filter, interlace));
        }
Esempio n. 5
0
    public Color ColorTool(string colorCode = "#000000", E_ColorType colorType = E_ColorType.Dark)
    {
        Color currentColor = Color.white;

        switch (colorType)
        {
        case E_ColorType.ClickLight:
            //ColorUtility.TryParseHtmlString(dictColorClickLight[App.MgrData.GetTheme()], out currentColor);
            ColorUtility.TryParseHtmlString(colorCode, out currentColor);
            break;

        case E_ColorType.Glow:
            ColorUtility.TryParseHtmlString(colorCode, out currentColor);
            break;

        case E_ColorType.Dark:
            ColorUtility.TryParseHtmlString(colorCode, out currentColor);
            break;

        case E_ColorType.Combo:
            ColorUtility.TryParseHtmlString(colorCode, out currentColor);
            break;

        case E_ColorType.Idle:
            ColorUtility.TryParseHtmlString(colorCode, out currentColor);
            break;

        case E_ColorType.Trans:
            ColorUtility.TryParseHtmlString(colorCode, out currentColor);
            break;

        case E_ColorType.LightBg:
            ColorUtility.TryParseHtmlString(colorCode, out currentColor);
            break;

        case E_ColorType.SocketOut:
            ColorUtility.TryParseHtmlString(colorCode, out currentColor);
            break;

        case E_ColorType.SocketIn:
            ColorUtility.TryParseHtmlString(colorCode, out currentColor);
            break;

        default:
            break;
        }
        return(currentColor);
    }
Esempio n. 6
0
    public static void Log(object str, E_ColorType c = E_ColorType.Normal)
    {
        string formatStr = "";

        if (!DFConfig.Print)
        {
            return;
        }

        if (c == E_ColorType.Init)
        {
            formatStr = "<color=cyan>" + str + "</color>";
            Debug.Log(formatStr);
        }
        else if (c == E_ColorType.Normal)
        {
            formatStr = "<color=#00c0ff>" + str + "</color>";
            Debug.Log(formatStr);
        }
        else if (c == E_ColorType.UI)        //#00FF21a0
        {
            formatStr = "<color=#91EC17FF>>>>>>>> " + str + "  -----------------</color>";
            Debug.Log(formatStr);
        }
        else if (c == E_ColorType.Temp)
        {
            formatStr = "<color=magenta>>>>>>>> " + str + "  -----------------</color>";
            Debug.Log(formatStr);
        }
        else if (c == E_ColorType.Err)
        {
            formatStr = "<color=#FF0000FF>-----------" + str + "</color>";            //FF0000FF  C94A4AFF
            Debug.Log(formatStr);
        }
        else if (c == E_ColorType.Over)
        {
            formatStr = "<color=#FFA662FF> =====" + str + "=====</color>";
            Debug.Log(formatStr);             //2F5283FF
        }

        if (isRecord)
        {
            sb.Append(str + "\n");
        }
    }
Esempio n. 7
0
        private byte[] UnfilterImageDatastream(int scanlineLenght, IdatChunk idatChunk, IhdrChunk ihdrChunk)
        {
            //int datastreamLenght = chunkIhdr.height * chunkIhdr.width * scanlineLenght;
            byte[] datastreamIdat   = idatChunk.DatastreamBytes;
            int    datastreamLenght = datastreamIdat.Length;
            // Datastream after unfitering = size - amount of filter bytes
            int amountOfScanLines = ihdrChunk.Height;

            byte[] refilteredDatastream = new byte[datastreamLenght];

            // Lenght of the scanLine without filter byte
            int scanLineLenWithoutFilter = scanlineLenght - 1;

            // pixel size (in bytes)
            int pixelbytesLenght = 4;

            E_ColorType colorType = ihdrChunk.ColorType;

            if (colorType == E_ColorType.GRAYSCALE)
            {
                pixelbytesLenght = 1;
            }
            else if (colorType == E_ColorType.GRAYSCALE_ALPHA)
            {
                pixelbytesLenght = 2;
            }
            else if (colorType == E_ColorType.TRUECOLOR)
            {
                pixelbytesLenght = 3;
            }
            else if (colorType == E_ColorType.TRUECOLOR_ALPHA)
            {
                pixelbytesLenght = 4;
            }

            //Actual used scanLine and unfilteredScanLine
            byte[] tempScanline;          // Actual filtered scanline
            byte[] previousReconScanline; // Previous scanline which was reconstructed;
            byte[] unfilteredScanline = new byte[scanlineLenght - 1];

            for (int datastreamScanlineIter = 0; datastreamScanlineIter < amountOfScanLines; datastreamScanlineIter++)
            {
                int datastreamIter = (datastreamScanlineIter * (scanlineLenght));
                // Each iteration is on another scanline
                tempScanline = CutFromDatastream(datastreamIdat, datastreamIter, scanlineLenght);

                //Checking tempScanine FILTER TYPE:
                if (tempScanline[0] == 0)
                {
                    //  Console.WriteLine("--- Filter method 0: Non ---");
                    //NOTHING TO DO - FILTER 0
                    for (int scanLineIter = 1; scanLineIter < tempScanline.Length; scanLineIter++)
                    {
                        unfilteredScanline[scanLineIter - 1] = tempScanline[scanLineIter];
                    }
                }
                else if (tempScanline[0] == 1)
                {
                    //   Console.WriteLine("--- Filter method 1: Sub ---");

                    //Actual and previous used pixel (in bytes)
                    byte[] tempPixel   = new byte[pixelbytesLenght];
                    byte[] reconAPixel = new byte[pixelbytesLenght]; // recon(a) - pixel on the left to actual pixel (tempPiexl)
                    byte[] reconXPixel = new byte[pixelbytesLenght]; // recon(x) - reconstructed actual pixel;

                    // Pixel on the left from the first pixel in scanline stores 0 values
                    for (int k = 0; k < pixelbytesLenght; k++)
                    {
                        reconAPixel[k] = 0;
                    }

                    for (int scanLineIter = 1; scanLineIter < tempScanline.Length; scanLineIter += pixelbytesLenght)    // scanLineIter=1 becouse of filter byte
                    {
                        //Update pixel data
                        for (int k = 0; k < pixelbytesLenght; k++)
                        {
                            tempPixel[k] = tempScanline[scanLineIter + k];
                        }

                        for (int pixelIter = 0; pixelIter < pixelbytesLenght; pixelIter++)
                        {
                            reconXPixel[pixelIter] = (byte)(reconAPixel[pixelIter] + tempPixel[pixelIter]);
                            unfilteredScanline[scanLineIter + pixelIter - 1] = reconXPixel[pixelIter];
                            reconAPixel[pixelIter] = reconXPixel[pixelIter];
                        }
                    }
                }
                else if (tempScanline[0] == 2)
                {
                    //   Console.WriteLine("--- Filter method 2: Up ---");

                    //Actual and previous used pixel (in bytes)
                    byte[] tempPixel   = new byte[pixelbytesLenght];
                    byte[] reconBPixel = new byte[pixelbytesLenght]; // recon(b) - pixel above actual pixel (tempPiexl)


                    if (datastreamScanlineIter == 0)
                    {
                        previousReconScanline = new byte[scanlineLenght];
                    }
                    else
                    {
                        previousReconScanline = CutFromDatastream(refilteredDatastream, (datastreamIter - datastreamScanlineIter) - (scanlineLenght - 1), scanlineLenght - 1);
                    }

                    for (int scanLineIter = 1; scanLineIter < tempScanline.Length; scanLineIter += pixelbytesLenght)    // scanLineIter=1 becouse of filter byte
                    {
                        //Update pixel data
                        for (int k = 0; k < pixelbytesLenght; k++)
                        {
                            tempPixel[k] = tempScanline[scanLineIter + k];
                        }
                        for (int k = 0; k < pixelbytesLenght; k++)
                        {
                            reconBPixel[k] = previousReconScanline[scanLineIter - 1 + k];
                        }

                        for (int pixelIter = 0; pixelIter < pixelbytesLenght; pixelIter++)
                        {
                            unfilteredScanline[scanLineIter + pixelIter - 1] = (byte)(reconBPixel[pixelIter] + tempPixel[pixelIter]);
                        }
                    }
                }
                else if (tempScanline[0] == 3)
                {
                    //   Console.WriteLine("--- Filter method 3: Average ---");


                    byte[] tempPixel   = new byte[pixelbytesLenght]; //Actual and previous used pixel (in bytes)
                    byte[] reconBPixel = new byte[pixelbytesLenght]; // recon(b) - pixel above actual pixel (tempPiexl)
                    byte[] reconAPixel = new byte[pixelbytesLenght]; // recon(a) - pixel on the left to actual pixel (tempPiexl)
                    byte[] reconXPixel = new byte[pixelbytesLenght]; // recon(x) - reconstructed actual pixel;

                    if (datastreamScanlineIter == 0)
                    {
                        previousReconScanline = new byte[scanlineLenght]; // stores 0 if there is no previously reconstructed scanline
                    }
                    else
                    {
                        previousReconScanline = CutFromDatastream(refilteredDatastream, (datastreamIter - datastreamScanlineIter) - (scanlineLenght - 1), scanlineLenght - 1);
                    }

                    // Pixel on the left from the first pixel in scanline stores 0 values
                    for (int k = 0; k < pixelbytesLenght; k++)
                    {
                        reconAPixel[k] = 0;
                    }

                    for (int scanLineIter = 1; scanLineIter < tempScanline.Length; scanLineIter += pixelbytesLenght)    // scanLineIter=1 becouse of filter byte
                    {
                        //Update pixel data
                        for (int k = 0; k < pixelbytesLenght; k++)
                        {
                            tempPixel[k] = tempScanline[scanLineIter + k];
                        }
                        for (int k = 0; k < pixelbytesLenght; k++)
                        {
                            reconBPixel[k] = previousReconScanline[scanLineIter - 1 + k];
                        }

                        for (int pixelIter = 0; pixelIter < pixelbytesLenght; pixelIter++)
                        {
                            reconXPixel[pixelIter] = (byte)(tempPixel[pixelIter] + (reconBPixel[pixelIter] + reconAPixel[pixelIter]) / 2);
                            unfilteredScanline[scanLineIter + pixelIter - 1] = reconXPixel[pixelIter];
                            reconAPixel[pixelIter] = reconXPixel[pixelIter];
                        }
                    }
                }
                else if (tempScanline[0] == 4)
                {
                    //   Console.WriteLine("--- Filter method 4: PaethPredictor ---");

                    byte[] tempPixel    = new byte[pixelbytesLenght];
                    byte[] reconAPixel  = new byte[pixelbytesLenght]; // aPixel - pixel on the left to actual pixel
                    byte[] reconAPixel2 = new byte[pixelbytesLenght];
                    byte[] reconBPixel  = new byte[pixelbytesLenght]; // bPixel - pixel above actual pixel
                    byte[] reconCPixel  = new byte[pixelbytesLenght]; // cPixel - pixel on the left to bPixel pixel
                    byte[] reconXPixel  = new byte[pixelbytesLenght]; // recon(x) - reconstructed actual pixel;
                    byte[] reconPPixel  = new byte[pixelbytesLenght];

                    if (datastreamScanlineIter == 0)
                    {
                        previousReconScanline = new byte[scanlineLenght]; // stores 0 if there is no previously reconstructed scanline
                    }
                    else
                    {
                        previousReconScanline = CutFromDatastream(refilteredDatastream, (datastreamIter - datastreamScanlineIter) - (scanlineLenght - 1), scanlineLenght - 1);
                    }

                    for (int k = 0; k < pixelbytesLenght; k++)
                    {
                        // Pixel on the left from the first pixel in scanline stores 0 values
                        reconAPixel[k] = 0;
                        // Pixel on the above-left from the first pixel in scanline stores 0 values
                        reconCPixel[k] = 0;
                        // Pixel on the above from the first pixel in scanline stores 0 values
                        reconBPixel[k] = 0;
                    }

                    for (int scanLineIter = 1; scanLineIter < tempScanline.Length; scanLineIter += pixelbytesLenght)    // scanLineIter=1 becouse of filter byte
                    {
                        //Update pixel data
                        if (datastreamScanlineIter != 0)
                        {
                            for (int k = 0; k < pixelbytesLenght; k++)
                            {
                                reconBPixel[k] = previousReconScanline[scanLineIter - 1 + k];
                            }
                        }

                        if (scanLineIter != 1)
                        {
                            for (int k = 0; k < pixelbytesLenght; k++)
                            {
                                reconCPixel[k] = previousReconScanline[scanLineIter - 1 - pixelbytesLenght + k];
                            }
                        }

                        for (int k = 0; k < pixelbytesLenght; k++)
                        {
                            tempPixel[k]    = tempScanline[scanLineIter + k];
                            reconAPixel2[k] = reconAPixel[k];
                            reconXPixel[k]  = 0;
                            reconPPixel[k]  = 0;
                        }

                        for (int pixelIter = 0; pixelIter < pixelbytesLenght; pixelIter++)
                        {
                            int p, pa, pb, pc = 0;

                            p  = (reconAPixel2[pixelIter] + reconBPixel[pixelIter] - reconCPixel[pixelIter]);
                            pa = (Math.Abs(p - reconAPixel[pixelIter]));
                            pb = (Math.Abs(p - reconBPixel[pixelIter]));
                            pc = (Math.Abs(p - reconCPixel[pixelIter]));

                            if (pa <= pb && pa <= pc)
                            {
                                reconPPixel[pixelIter] = reconAPixel2[pixelIter];
                            }
                            else if (pb <= pc)
                            {
                                reconPPixel[pixelIter] = reconBPixel[pixelIter];
                            }
                            else
                            {
                                reconPPixel[pixelIter] = reconCPixel[pixelIter];
                            }

                            int x = (tempPixel[pixelIter] + reconPPixel[pixelIter]);
                            reconXPixel[pixelIter] = (byte)(tempPixel[pixelIter] + reconPPixel[pixelIter]);
                            unfilteredScanline[scanLineIter + pixelIter - 1] = reconXPixel[pixelIter];
                            reconAPixel[pixelIter] = reconXPixel[pixelIter];
                        }
                    }
                }
                else
                {
                    Console.WriteLine(" WRONG METHOD CODE !!!:  " + tempScanline[0] + "  Scanline: " + datastreamScanlineIter);
                    //NOTHING TO DO - FILTER 0
                    //for (int scanLineIter = 1; scanLineIter < tempScanline.Length; scanLineIter++)
                    //{
                    //    unfilteredScanline[scanLineIter - 1] = tempScanline[scanLineIter];
                    //}
                }

                // Fill refilteredDatastream with refiltered scanLine
                int refilteredDatastreamIter = datastreamScanlineIter * (scanlineLenght - 1);
                for (int k = 0; k < scanlineLenght - 1; k++) // k=1 becouse of filter byte
                {
                    refilteredDatastream[refilteredDatastreamIter + k] = unfilteredScanline[k];
                }
            }
            return(refilteredDatastream);
        }