Esempio n. 1
0
    private void RemoveLine()
    {
        ImageLine line = lines[lines.Count - 1];

        lines.Remove(line);
        Destroy(line.gameObject);
    }
Esempio n. 2
0
        public static void tile(String orig, String dest, int factor)
        {
            if (orig.Equals(dest))
            {
                throw new PngjException("input and output file cannot coincide");
            }
            if (factor < 2 || factor > 100)
            {
                throw new PngjException("bad factor ");
            }
            PngReader pngr = FileHelper.CreatePngReader(orig);
            var       x    = pngr.ImgInfo;
            PngWriter pngw = FileHelper.CreatePngWriter(dest, pngr.ImgInfo, true);

            pngr.SetUnpackedMode(true);    // we dont want to do the unpacking ourselves, we want a sample per array element
            pngw.SetUseUnPackedMode(true); // not really necesary here, as we pass the ImageLine, but anyway...
            pngw.CopyChunksFirst(pngr, ChunkCopyBehaviour.COPY_ALL_SAFE);
            for (int row = 0; row < pngr.ImgInfo.Rows; row++)
            {
                ImageLine l1 = pngr.ReadRowInt(row);
                mirrorLineInt(pngr.ImgInfo, l1.Scanline);
                pngw.WriteRow(l1, row);
            }
            pngw.CopyChunksLast(pngr, ChunkCopyBehaviour.COPY_ALL_SAFE);
            pngw.End();
        }
        public static void testWrite(string src, string target)
        {
            // for writing is not necesary to register
            DummyClass c = new DummyClass();

            c.name = "Hernán";
            c.age  = 45;

            PngReader pngr = FileHelper.CreatePngReader(src);
            PngWriter pngw = FileHelper.CreatePngWriter(target, pngr.ImgInfo, true);

            pngw.CopyChunksFirst(pngr, ChunkCopyBehaviour.COPY_ALL_SAFE);
            PngChunkSERI mychunk = new PngChunkSERI(pngw.ImgInfo);

            mychunk.SetObj(c);
            mychunk.Priority = true; // if we want it to be written as soon as possible
            pngw.GetChunksList().Queue(mychunk);
            for (int row = 0; row < pngr.ImgInfo.Rows; row++)
            {
                ImageLine l1 = pngr.ReadRow(row);
                pngw.WriteRow(l1, row);
            }
            pngw.CopyChunksLast(pngr, ChunkCopyBehaviour.COPY_ALL);
            pngr.End();
            pngw.End();
            Console.Out.WriteLine("Done. Writen : " + target);
        }
Esempio n. 4
0
    public static void WriteToFile(int imageWidth, int imageHeight, Color32[] pixels, String filename, bool hasAlpha)
    {
        ImageInfo imageInfo = new ImageInfo(imageWidth, imageHeight, 8, hasAlpha); // 8 bits per channel, with alpha
        // open image for writing
        PngWriter pngWriter = FileHelper.CreatePngWriter(filename, imageInfo, false);

        // add some optional metadata (chunks)
        pngWriter.GetMetadata().SetDpi(70.0);
        pngWriter.GetMetadata().SetTimeNow(0); // 0 seconds fron now = now

        ImageLine iline = new ImageLine(imageInfo);

        for (int row = 0; row < imageHeight; row++)
        {
            var bottomRow = (imageHeight - 1) - row;
            for (int col = 0; col < imageWidth; col++)
            {
                var pixel = pixels[col + (bottomRow * imageWidth)];
                if (hasAlpha)
                {
                    ImageLineHelper.SetPixel(iline, col, pixel.r, pixel.g, pixel.b, pixel.a);
                }
                else
                {
                    ImageLineHelper.SetPixel(iline, col, pixel.r, pixel.g, pixel.b);
                }
            }
            pngWriter.WriteRow(iline, row);
        }
        pngWriter.End();
    }
        public static void doit(String orig)
        {
            string copy = TestsHelper.addSuffixToName(orig, "_tc");

            PngReader pngr = FileHelper.CreatePngReader(orig);

            if (!pngr.ImgInfo.Indexed)
            {
                throw new Exception("Not indexed image");
            }
            PngChunkPLTE plte  = pngr.GetMetadata().GetPLTE();
            PngChunkTRNS trns  = pngr.GetMetadata().GetTRNS(); // transparency metadata, can be null
            bool         alpha = trns != null;
            ImageInfo    im2   = new ImageInfo(pngr.ImgInfo.Cols, pngr.ImgInfo.Rows, 8, alpha);
            PngWriter    pngw  = FileHelper.CreatePngWriter(copy, im2, true);

            pngw.CopyChunksFirst(pngr, ChunkCopyBehaviour.COPY_ALL_SAFE);
            int[] buf = null;
            for (int row = 0; row < pngr.ImgInfo.Rows; row++)
            {
                ImageLine line = pngr.ReadRowInt(row);
                buf = ImageLineHelper.Palette2rgb(line, plte, trns, buf);
                pngw.WriteRowInt(buf, row);
            }
            pngw.CopyChunksLast(pngr, ChunkCopyBehaviour.COPY_ALL_SAFE);
            pngr.End();
            pngw.End();
            Console.WriteLine("True color: " + copy);
        }
Esempio n. 6
0
 public Pngw(string filn, int cols, int rows)
 {
     pngw  = FileHelper.CreatePngWriter(filn, new ImageInfo(cols, rows, 8, false), true);
     icol  = 0;
     irow  = 0;
     iline = new ImageLine(pngw.ImgInfo);
 }
        static void Process8BitIndexedRow(ImageLine line, Chunks.PngChunkPLTE plte, Color[] pixels)
        {
            int       row      = line.ImageRow;
            ImageInfo imgInfo  = line.ImgInfo;
            int       numRows  = imgInfo.Rows;
            int       numCols  = imgInfo.Cols;
            int       bitDepth = imgInfo.BitDepth;
            int       channels = imgInfo.Channels;      // int channels = 3;
            float     max      = GetBitDepthMaxValue(bitDepth);

            if (line.SampleType == ImageLine.ESampleType.BYTE)
            {
                byte[] scanline = line.ScanlineB;
                for (int col = 0; col < numCols; col++)
                {
                    int       index = scanline[col] & 0xFF;
                    RGB <int> rgb   = plte.GetEntryRgb(index, col * channels);
                    pixels[IndexPngToTexture(row, col, numRows, numCols)] = RGB.ToColor(rgb, max);
                }
            }
            else
            {
                int[] scanline = line.Scanline;
                for (int col = 0; col < numCols; col++)
                {
                    int       index = scanline[col];
                    RGB <int> rgb   = plte.GetEntryRgb(index, col * channels);
                    pixels[IndexPngToTexture(row, col, numRows, numCols)] = RGB.ToColor(rgb, max);
                }
            }
        }
        static void Process4BitRow(ImageLine imageLine, Color[] pixels)
        {
            int       row      = imageLine.ImageRow;
            ImageInfo imgInfo  = imageLine.ImgInfo;
            int       numRows  = imgInfo.Rows;
            int       numCols  = imgInfo.Cols;
            float     max      = GetBitDepthMaxValue(4);
            var       scanline = imageLine.ScanlineB;

            for (int col = 0; col < numCols / 2; col++)
            {
                byte  B        = scanline[col];
                int   hiNybble = (B & 0xF0) >> 4;               //Left hand nybble
                int   loNyblle = (B & 0x0F);                    //Right hand nybble
                float val1     = (float)hiNybble / max;
                float val2     = (float)loNyblle / max;
                Color color_1  = new Color {
                    r = val1,
                    g = val1,
                    b = val1,
                    a = val1
                };
                Color color_2 = new Color {
                    r = val2,
                    g = val2,
                    b = val2,
                    a = val2
                };
                pixels[IndexPngToTexture(row, col * 2 + 0, numRows, numCols)] = color_1;
                pixels[IndexPngToTexture(row, col * 2 + 1, numRows, numCols)] = color_2;
            }
        }
Esempio n. 9
0
        public void LoadFromP8PNG(Stream stream)
        {
            PngReader reader = new PngReader(stream);

            if (!validatePNG(reader.ImgInfo))
            {
                throw new BadImageFormatException("Bad Cart");
            }

            int offset = 0;

            for (int row = 0; row < reader.ImgInfo.Rows && offset < CART_SIZE; row++)
            {
                ImageLine line = reader.ReadRowInt(row);
                for (int col = 0; col < line.ImgInfo.Cols && offset < CART_SIZE; col++)
                {
                    rom[offset] = decodeBytes(line.Scanline, col * 4);
                    offset     += 1;
                }
            }

            Version = rom[0x8000];
            Build   = (rom[0x8001] << 24) + (rom[0x8002] << 16) + (rom[0x8003] << 8) + rom[0x8004];

            /*
             * Debug.Log(rom[0]);
             * Debug.Log(rom[1]);
             * Debug.Log(rom[2]);
             * Debug.Log(rom[3]);
             */
            reader.End();
        }
Esempio n. 10
0
    private void UpdateLineRenderers()
    {
        // Update ImageLines.
        //lineRenderer.SetNumPoints(numPoints);
        //for (int i=0; i<numPoints; i++) {
        //	lineRenderer.SetPoint (i, points[i]);
        //}
        // Add missing ImageLines!
        for (int i = imgLines.Count; i < numLines; i++)
        {
            ImageLine newObj = Instantiate(ResourcesHandler.Instance.ImageLine).GetComponent <ImageLine>();
            newObj.Initialize(this.transform);
            newObj.SetAnchors(Vector2.zero, Vector2.zero); // bottom-left anchor.
            newObj.SetColor(beamLineColor);
            newObj.SetThickness(beamLineThickness);
            imgLines.Add(newObj);
        }
        // Update all ImageLines!
        for (int i = 0; i < imgLines.Count; i++)
        {
            bool isVisible = i < numLines;
            imgLines[i].IsVisible = isVisible;
            imgLines[i].SetStartAndEndPos(lines[i]);
        }

        // Position the ps_endSparks!
        Line endLine = lines[numLines - 1];

        ps_endSparks.transform.localPosition = endLine.end;
        float endSparksRot = endLine.GetAngleDeg();        // -LineUtils.GetAngle_Degrees (lineRenderer.GetPoint(numPoints-1), lineRenderer.GetPoint(numPoints-2));

        ps_endSparks.transform.localEulerAngles = new Vector3(ps_endSparks.transform.localEulerAngles.x, ps_endSparks.transform.localEulerAngles.y, endSparksRot);
    }
Esempio n. 11
0
        public void BuildPngImageLine(int lineNumber, ImageLine iLine)
        {
            DPoint c = new DPoint(0, _yVals[lineNumber]);

            for (int xPtr = 0; xPtr < CanvasSize.Width; xPtr++)
            {
                c.X = _xVals[xPtr];

                DPoint z              = new DPoint(0, 0);
                int    cnt            = 0;
                double escapeVelocity = _mPointWork.Iterate(c, z, ref cnt, done: out bool notUsed);

                int[] cComps;
                if (cnt == MapInfo.MaxIterations)
                {
                    cComps = ColorMap.HighColorEntry.StartColor.ColorComps;
                }
                else
                {
                    cComps = ColorMap.GetColor(cnt, escapeVelocity);
                }

                ImageLineHelper.SetPixel(iLine, xPtr, cComps[0], cComps[1], cComps[2]);
            }
        }
        /// <summary> Writes 16-bit grayscale image </summary>
        public static async Task WriteGrayscaleAsync
        (
            ushort[] pixels,
            int width,
            int height,
            bool alpha,
            string filePath
        )
        {
            try {
                var imageInfo = new ImageInfo(
                    width,
                    height,
                    16,
                    alpha,
                    true,
                    false                    //not implemented here yet
                    );
                await Task.Run(() => {
                    // open image for writing:
                    PngWriter writer = FileHelper.CreatePngWriter(filePath, imageInfo, true);

                    // add some optional metadata (chunks)
                    var meta = writer.GetMetadata();
                    meta.SetTimeNow(0);                      // 0 seconds fron now = now

                    int numRows  = imageInfo.Rows;
                    int numCols  = imageInfo.Cols;
                    int channels = imageInfo.Channels;
                    for (int row = 0; row < numRows; row++)
                    {
                        //fill line:
                        int[] ints = new int[imageInfo.SamplesPerRow];
                        if (alpha == false)
                        {
                            for (int col = 0; col < numCols; col++)
                            {
                                ushort R = pixels[IndexPngToTexture(row, col, numRows, numCols)];
                                ImageLineHelper.SetPixel(ints, R, col, channels);
                            }
                        }
                        else
                        {
                            for (int col = 0; col < numCols; col++)
                            {
                                ushort A = pixels[IndexPngToTexture(row, col, numRows, numCols)];
                                ImageLineHelper.SetPixel(ints, A, col, channels);
                            }
                        }

                        //write line:
                        ImageLine imageline = new ImageLine(imageInfo, ImageLine.ESampleType.INT, false, ints, null, row);
                        writer.WriteRow(imageline, row);
                    }
                    writer.End();
                });
            }
            catch (System.Exception ex) { Debug.LogException(ex); await Task.CompletedTask; }             //kills debugger execution loop on exception
            finally { await Task.CompletedTask; }
        }
Esempio n. 13
0
        /// <summary>
        /// Saves the PNGFile to disk.
        /// </summary>
        /// <param name="path">Output path for the PNGFile.</param>
        public void SaveAs(string path)
        {
            PngReader reader = FileHelper.CreatePngReader(originalFile);
            PngWriter writer = FileHelper.CreatePngWriter(path, reader.ImgInfo, true);

            writer.CopyChunksFirst(reader, ChunkCopyBehaviour.COPY_ALL_SAFE);

            for (var x = 0; x < reader.ImgInfo.Rows; x++)
            {
                ImageLine line = reader.ReadRowByte(x);
                for (var y = 0; y < line.ScanlineB.Length; y += reader.ImgInfo.BytesPixel)
                {
                    line.ScanlineB[y]     = lines[x][y / reader.ImgInfo.BytesPixel].Red;
                    line.ScanlineB[y + 1] = lines[x][(y + 1) / reader.ImgInfo.BytesPixel].Green;
                    line.ScanlineB[y + 2] = lines[x][(y + 2) / reader.ImgInfo.BytesPixel].Blue;
                    if (reader.ImgInfo.Alpha)
                    {
                        line.ScanlineB[y + 3] = lines[x][(y + 3) / reader.ImgInfo.BytesPixel].Alpha;
                    }
                }
                writer.WriteRow(line, x);
            }
            writer.CopyChunksLast(reader, ChunkCopyBehaviour.COPY_ALL_SAFE);
            writer.End();
            reader.End();
        }
        public static void SetPixel(ImageLine line, int column, int r, int g, int b, int a)
        {
            int offset = column * line.channels;

            if (line.IsInt())
            {
                var scanline = line.Scanline;
                scanline[offset++] = r;
                scanline[offset++] = g;
                scanline[offset]   = b;
                if (line.ImgInfo.Alpha)
                {
                    scanline[offset + 1] = a;
                }
            }
            else
            {
                var scanline = line.ScanlineB;
                scanline[offset++] = (byte)r;
                scanline[offset++] = (byte)g;
                scanline[offset]   = (byte)b;
                if (line.ImgInfo.Alpha)
                {
                    scanline[offset + 1] = (byte)a;
                }
            }
        }
Esempio n. 15
0
        private void GenerateImage(string name, float[] data, int colors, int w, int h)
        {
            var imageInfo = new ImageInfo(w, h, 8, false);
            var png       = FileHelper.CreatePngWriter(Path.Combine(Helpers.TempDir, name), imageInfo, true);

            for (int y = 0; y < h; y++)
            {
                var line = new ImageLine(imageInfo);
                for (int x = 0; x < w; x++)
                {
                    if (colors == 1)
                    {
                        var r = (int)(255f * data[x + y * w]);
                        ImageLineHelper.SetPixel(line, x, r, r, r);
                    }
                    else
                    {
                        var r = (int)(255f * data[(x + y * w) * 3 + 0]);
                        var g = (int)(255f * data[(x + y * w) * 3 + 1]);
                        var b = (int)(255f * data[(x + y * w) * 3 + 2]);
                        ImageLineHelper.SetPixel(line, x, r, g, b);
                    }
                }
                png.WriteRow(line, y);
            }
            png.End();
        }
Esempio n. 16
0
        public static bool WritePixelImageAsPng(Stream s, IPixelImage img, Action <int> reportProgress, Func <bool> shouldCancel)
        {
            var imgInfo = new ImageInfo(img.Width, img.Height, 8, true);

            var writer = new PngWriter(s, imgInfo);

            for (var y = 0; y < img.Height; y++)
            {
                if (shouldCancel())
                {
                    return(false);
                }

                var line = new ImageLine(imgInfo);
                for (var x = 0; x < img.Width; x++)
                {
                    var c      = img.GetPixel(x, y);
                    var offset = x * 4;
                    line.Scanline[offset]     = c.R;
                    line.Scanline[offset + 1] = c.G;
                    line.Scanline[offset + 2] = c.B;
                    line.Scanline[offset + 3] = c.A;
                }

                writer.WriteRow(line, y);

                reportProgress((y * 100) / img.Height);
            }

            writer.End();

            return(true);
        }
Esempio n. 17
0
 public static void BuildBlankPngImageLineSegment(int pixPtr, int len, ImageLine iLine)
 {
     for (int xPtr = 0; xPtr < len; xPtr++)
     {
         ImageLineHelper.SetPixel(iLine, pixPtr++, 255, 255, 255);
     }
 }
Esempio n. 18
0
        public static void Create(string filename, int cols, int rows)
        {
            ImageInfo imi = new ImageInfo(cols, rows, 8, false); // 8 bits per channel, no alpha
            // open image for writing
            PngWriter png = FileHelper.CreatePngWriter(filename, imi, true);

            // add some optional metadata (chunks)
            png.GetMetadata().SetDpi(100.0);
            png.GetMetadata().SetTimeNow(0); // 0 seconds fron now = now
            png.GetMetadata().SetText(PngChunkTextVar.KEY_Title, "Just a text image");
            PngChunk chunk = png.GetMetadata().SetText("my key", "my text .. bla bla");

            chunk.Priority = true; // this chunk will be written as soon as possible
            ImageLine iline = new ImageLine(imi);

            for (int col = 0; col < imi.Cols; col++)   // this line will be written to all rows
            {
                int r = 255;
                int g = 127;
                int b = 255 * col / imi.Cols;
                ImageLineHelper.SetPixel(iline, col, r, g, b);  // orange-ish gradient
            }
            for (int row = 0; row < png.ImgInfo.Rows; row++)
            {
                png.WriteRow(iline, row);
            }
            png.End();
        }
Esempio n. 19
0
        public static void addMetadata(String origFilename, Dictionary <string, string> data)
        {
            String    destFilename = "tmp.png";
            PngReader pngr         = FileHelper.CreatePngReader(origFilename);                     // or you can use the constructor
            PngWriter pngw         = FileHelper.CreatePngWriter(destFilename, pngr.ImgInfo, true); // idem
            //Console.WriteLine(pngr.ToString()); // just information
            int chunkBehav = ChunkCopyBehaviour.COPY_ALL_SAFE;                                     // tell to copy all 'safe' chunks

            pngw.CopyChunksFirst(pngr, chunkBehav);                                                // copy some metadata from reader
            foreach (string key in data.Keys)
            {
                PngChunk chunk = pngw.GetMetadata().SetText(key, data[key]);
                chunk.Priority = true;
            }

            int channels = pngr.ImgInfo.Channels;

            if (channels < 3)
            {
                throw new Exception("This example works only with RGB/RGBA images");
            }
            for (int row = 0; row < pngr.ImgInfo.Rows; row++)
            {
                ImageLine l1 = pngr.ReadRowInt(row);     // format: RGBRGB... or RGBARGBA...
                pngw.WriteRow(l1, row);
            }
            pngw.CopyChunksLast(pngr, chunkBehav); // metadata after the image pixels? can happen
            pngw.End();                            // dont forget this
            pngr.End();
            File.Delete(origFilename);
            File.Move(destFilename, origFilename);
        }
Esempio n. 20
0
        private static void additionalTestInterlaced(string orig, string origni)
        {
            // tests also read/write in packed format
            PngReader pngr = FileHelper.CreatePngReader(orig);
            string    copy = TestsHelper.addSuffixToName(orig, "_icopy");

            pngr.SetUnpackedMode(false);
            PngWriter pngw = FileHelper.CreatePngWriter(copy, pngr.ImgInfo, true);

            pngw.CopyChunksFirst(pngr, ChunkCopyBehaviour.COPY_ALL);
            pngw.SetUseUnPackedMode(false);
            Random random  = new Random();
            bool   useByte = random.NextDouble() > 0.5 && pngr.ImgInfo.BitDepth < 16;

            for (int row = 0; row < pngr.ImgInfo.Rows; row++)
            {
                if (useByte)
                {
                    ImageLine line = pngr.ReadRowByte(row);
                    pngw.WriteRow(line, row);
                }
                else
                {
                    ImageLine line = pngr.ReadRowInt(row);
                    pngw.WriteRow(line, row);
                }
            }
            pngr.End();
            pngw.End();
            TestsHelper.testEqual(copy, origni);
            System.IO.File.Delete(copy);
        }
Esempio n. 21
0
        static void mirrorLine(ImageLine imline)   // unpacked line !
        {
            if (!imline.SamplesUnpacked)
            {
                throw new PngjException("this requires unpacked lines");
            }
            int channels = imline.ImgInfo.Channels;

            for (int c1 = 0, c2 = imline.ImgInfo.Cols - 1; c1 < c2; c1++, c2--)
            {
                for (int i = 0; i < channels; i++)
                {
                    int s1 = c1 * channels + i; // sample left
                    int s2 = c2 * channels + i; // sample right
                    if (imline.SampleType == ImageLine.ESampleType.INT)
                    {
                        int aux = imline.Scanline[s1]; // swap
                        imline.Scanline[s1] = imline.Scanline[s2];
                        imline.Scanline[s2] = aux;
                    }
                    else
                    {
                        byte auxb = imline.ScanlineB[s1]; // swap
                        imline.ScanlineB[s1] = imline.ScanlineB[s2];
                        imline.ScanlineB[s2] = auxb;
                    }
                }
            }
        }
Esempio n. 22
0
        public static string createWaves(String suffix, double scale, ImageInfo imi)
        {
            string f = getTmpFile(suffix);
            // open image for writing to a output stream
            PngWriter png = FileHelper.CreatePngWriter(f, imi, true);

            png.GetMetadata().SetText("key1", "val1");
            ImageLine iline = new ImageLine(imi, ImageLine.ESampleType.BYTE, true);

            for (int row = 0; row < png.ImgInfo.Rows; row++)
            {
                for (int x = 0; x < imi.Cols; x++)
                {
                    int r = (int)((Math.Sin((row + x) * 0.073 * scale) + 1) * 128);
                    int g = (int)((Math.Sin((row + x * 0.22) * 0.08 * scale) + 1) * 128);
                    int b = (int)((Math.Sin((row * 0.52 - x * 0.2) * 0.21 * scale) + 1) * 128);
                    iline.ScanlineB[x * imi.Channels]     = (byte)r;
                    iline.ScanlineB[x * imi.Channels + 1] = (byte)g;
                    iline.ScanlineB[x * imi.Channels + 2] = (byte)b;
                    if (imi.Channels == 4)
                    {
                        iline.ScanlineB[x * imi.Channels + 3] = (byte)((b + g) / 2);
                    }
                }
                png.WriteRow(iline, row);
            }
            png.End();
            return(f);
        }
Esempio n. 23
0
        public static void DecreaseRed(String origFilename, String destFilename)
        {
            if (origFilename.Equals(destFilename))
            {
                throw new PngjException("input and output file cannot coincide");
            }
            PngReader pngr = FileHelper.CreatePngReader(origFilename);
            PngWriter pngw = FileHelper.CreatePngWriter(destFilename, pngr.ImgInfo, true);

            Console.WriteLine(pngr.ToString());
            int chunkBehav = ChunkCopyBehaviour.COPY_ALL_SAFE; // copy all 'safe' chunks

            // this can copy some metadata from reader
            pngw.CopyChunksFirst(pngr, chunkBehav);
            int channels = pngr.ImgInfo.Channels;

            if (channels < 3)
            {
                throw new Exception("This method is for RGB/RGBA images");
            }
            for (int row = 0; row < pngr.ImgInfo.Rows; row++)
            {
                ImageLine l1 = pngr.ReadRow(row);
                for (int j = 0; j < pngr.ImgInfo.Cols; j++)
                {
                    l1.Scanline[j * channels] /= 2;
                }
                pngw.WriteRow(l1, row);
            }
            // just in case some new metadata has been read after the image
            pngw.CopyChunksLast(pngr, chunkBehav);
            pngw.End();
        }
Esempio n. 24
0
        public static ImageLine generateNoiseLine(ImageInfo imi)   // byte format!
        {
            ImageLine line = new ImageLine(imi, ImageLine.ESampleType.BYTE, true);
            Random    r    = new Random();

            r.NextBytes(line.ScanlineB);
            return(line);
        }
Esempio n. 25
0
        static void testmirror(string orig, string origni, string truecolor)
        {
            string mirror = TestsHelper.addSuffixToName(orig, "_mirror");
            string recov  = TestsHelper.addSuffixToName(orig, "_recov");
            long   crc0   = 0;
            bool   interlaced;
            bool   palete;

            {
                PngReader pngr = FileHelper.CreatePngReader(orig);
                palete = pngr.ImgInfo.Indexed;
                PngHelperInternal.InitCrcForTests(pngr);
                pngr.SetUnpackedMode(true);
                interlaced = pngr.IsInterlaced();
                PngWriter pngw = FileHelper.CreatePngWriter(mirror, pngr.ImgInfo, true);
                pngw.SetFilterType(FilterType.FILTER_CYCLIC); // just to test all filters
                pngw.CopyChunksFirst(pngr, ChunkCopyBehaviour.COPY_ALL);
                pngw.SetUseUnPackedMode(true);
                for (int row = 0; row < pngr.ImgInfo.Rows; row++)
                {
                    ImageLine line = pngr.ReadRowInt(row);
                    mirrorLine(line);
                    pngw.WriteRow(line, row);
                }
                pngr.End();
                crc0 = PngHelperInternal.GetCrctestVal(pngr);
                pngw.CopyChunksFirst(pngr, ChunkCopyBehaviour.COPY_ALL);
                pngw.End();
            }
            // mirror again, now with BYTE (if depth<16) and loading all rows
            {
                PngReader pngr2 = FileHelper.CreatePngReader(mirror);
                pngr2.SetUnpackedMode(true);
                PngWriter pngw = FileHelper.CreatePngWriter(recov, pngr2.ImgInfo, true);
                pngw.SetFilterType(FilterType.FILTER_AGGRESSIVE);
                pngw.CopyChunksFirst(pngr2, ChunkCopyBehaviour.COPY_ALL);
                pngw.SetUseUnPackedMode(true);
                ImageLines lines = pngr2.ImgInfo.BitDepth < 16 ? pngr2.ReadRowsByte() : pngr2
                                   .ReadRowsInt();
                for (int row = 0; row < pngr2.ImgInfo.Rows; row++)
                {
                    ImageLine line = lines.GetImageLineAtMatrixRow(row);
                    mirrorLine(line);
                    pngw.WriteRow(line, row);
                }
                pngr2.End();
                pngw.End();
            }
            // now check
            if (orig[11] != 'i')
            {
                TestsHelper.testCrcEquals(recov, crc0);
            }
            //if (interlaced)
            //    additionalTestInterlaced(orig, origni);
            //if (palete && System.IO.File.Exists(truecolor))
            //    additionalTestPalette(orig, truecolor);
        }
Esempio n. 26
0
        static async Task FillLine
        (
            Texture2D texture,
            ImageLine line,
            ImageInfo info,
            int row
        )
        {
            int  numCols   = info.Cols;
            int  numRows   = info.Rows;
            int  bitDepth  = info.BitDepth;
            bool alpha     = info.Alpha;
            bool greyscale = info.Greyscale;

            //fill line:
            Color[] pixels = texture.GetPixels(0, row, numCols, 1);
            if (greyscale == false)
            {
                if (alpha)
                {
                    for (int col = 0; col < numCols; col++)
                    {
                        RGBA rgba = ToRGBA(pixels[col], bitDepth);
                        ImageLineHelper.SetPixel(line, col, rgba.r, rgba.g, rgba.b, rgba.a);
                    }
                }
                else
                {
                    for (int col = 0; col < numCols; col++)
                    {
                        RGB rgb = ToRGB(pixels[col], bitDepth);
                        ImageLineHelper.SetPixel(line, col, rgb.r, rgb.g, rgb.b);
                    }
                }
            }
            else
            {
                if (alpha == false)
                {
                    for (int col = 0; col < numCols; col++)
                    {
                        int r = ToInt(pixels[col].r, bitDepth);
                        ImageLineHelper.SetPixel(line, col, r);
                    }
                }
                else
                {
                    for (int col = 0; col < numCols; col++)
                    {
                        int a = ToInt(pixels[col].a, bitDepth);
                        ImageLineHelper.SetPixel(line, col, a);
                    }
                }
            }

            await Task.CompletedTask;
        }
Esempio n. 27
0
        public void AddImage(ImageLine i)
        {
            Images.Add(i);

            if (!Categories.Contains(i.Category))
            {
                Categories.Add(i.Category);
            }
        }
Esempio n. 28
0
        public static void endFileTmp(PngWriter png)
        {
            ImageLine imline = new ImageLine(png.ImgInfo);

            for (int i = 0; i < png.ImgInfo.Rows; i++)
            {
                png.WriteRow(imline, i);
            }
            png.End();
        }
Esempio n. 29
0
        public PngImage(string path, int width, int height)
        {
            Path         = path;
            OutputStream = File.Open(Path, FileMode.CreateNew, FileAccess.Write, FileShare.Read);

            imi       = new ImageInfo(width, height, 8, false); // 8 bits per channel, no alpha
            png       = new PngWriter(OutputStream, imi, path);
            ImageLine = new ImageLine(imi);
            curRow    = 0;
        }
Esempio n. 30
0
        public ImageLine GetImageLineAtMatrixRow(int mrow)
        {
            if (mrow < 0 || mrow > Nrows)
            {
                throw new PngjException("Bad row " + mrow.ToString() + ". Should be positive and less than " + Nrows.ToString());
            }
            ImageLine obj = (sampleType == ImageLine.ESampleType.INT) ? new ImageLine(ImgInfo, sampleType, SamplesUnpacked, Scanlines[mrow], null) : new ImageLine(ImgInfo, sampleType, SamplesUnpacked, null, ScanlinesB[mrow]);

            obj.Rown = MatrixRowToImageRow(mrow);
            return(obj);
        }