예제 #1
0
        private static void additionalTestPalette(string orig, string truecolor)
        {
            // covnert to true color 8 bits and check equality
            PngReader    pngr  = FileHelper.CreatePngReader(orig);
            PngChunkPLTE plte  = pngr.GetMetadata().GetPLTE();
            PngChunkTRNS trns  = pngr.GetMetadata().GetTRNS();
            string       copy  = TestsHelper.addSuffixToName(orig, "_tccopy");
            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);
            }
            pngr.End();
            pngw.End();
            TestsHelper.testEqual(copy, truecolor);
            System.IO.File.Delete(copy);
        }
예제 #2
0
        /// <summary>
        /// Writes a new file with several text chunks, reads it back and compares
        /// </summary>

        public static void test()
        {
            Dictionary <string, string> texts = new Dictionary <String, String>();

            texts.Add("key1", "val");
            texts.Add("empty1", "");
            texts.Add("unicode1", "Hernán");
            texts.Add("zero1", "Hola\0chau");
            texts.Add("key2", "val");
            texts.Add("empty2", "");
            texts.Add("unicode2", "Hernán");
            texts.Add("zero2", "Hola\0chau");
            texts.Add("key3", "val");
            texts.Add("empty3", "");
            texts.Add("unicode3", "Hernán");
            texts.Add("zero3", "Hola\0chau");
            texts.Add("nolatin1", "Hernán\u1230");
            String    suffix = "text";
            PngWriter png    = TestsHelper.prepareFileTmp(suffix);

            png.GetMetadata().SetText("key1", texts["key1"], false, false);
            png.GetMetadata().SetText("key2", texts["key2"], true, false);
            png.GetMetadata().SetText("key3", texts["key3"], true, true);
            png.GetMetadata().SetText("empty1", texts["empty1"], false, false);
            png.GetMetadata().SetText("empty2", texts["empty2"], true, false);
            png.GetMetadata().SetText("empty3", texts["empty3"], true, true);
            png.GetMetadata().SetText("unicode1", texts["unicode1"], false, false);
            png.GetMetadata().SetText("unicode2", texts["unicode2"], true, false);
            png.GetMetadata().SetText("unicode3", texts["unicode3"], true, true);
            png.GetMetadata().SetText("nolatin1", texts["nolatin1"], false, false);
            png.GetMetadata().SetText("zero1", texts["zero1"], false, false);
            png.GetMetadata().SetText("zero2", texts["zero2"], true, false);
            png.GetMetadata().SetText("zero3", texts["zero3"], true, true);
            TestsHelper.endFileTmp(png);
            PngReader pngr = TestsHelper.getReaderTmp(suffix);

            pngr.ReadSkippingAllRows();
            int ok = 0;

            foreach (PngChunk c in pngr.GetChunksList().GetChunks())
            {
                if (!ChunkHelper.IsText(c))
                {
                    continue;
                }
                ok++;
                PngChunkTextVar ct  = (PngChunkTextVar)c;
                String          key = ct.GetKey();
                String          val = ct.GetVal();
                Console.WriteLine(c.Id + " chunk. Key:" + key + " val='" + val + "'");
                if (!val.Equals(texts[key]))
                {
                    Console.WriteLine("ERROR: expected '" + texts[key] + "' got '" + val
                                      + "' key=" + key + " id=" + c.Id);
                }
            }
            if (ok != texts.Keys.Count)
            {
                throw new Exception("number of text chunks does not coincide");
            }
            Console.WriteLine("done");
        }
예제 #3
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 (!interlaced)
            {
                TestsHelper.testCrcEquals(recov, crc0);
            }
            else
            {
                TestsHelper.testEqual(recov, origni);
            }
            if (interlaced)
            {
                additionalTestInterlaced(orig, origni);
            }
            if (palete && System.IO.File.Exists(truecolor))
            {
                additionalTestPalette(orig, truecolor);
            }
        }