コード例 #1
0
        /// <summary>
        /// Add the next RGB image
        /// </summary>
        /// <param name="data">Image data</param>
        /// <param name="allInfo">TIFF info</param>
        public void addRGBplane(byte[][] data, TiffInfoCollection allInfo)
        {
            System.IO.Stream stream = writer.BaseStream;

            allInfo.add(new TiffInfo(TiffInfoCollection.PhotometricInterpretation, "", (ushort)2));
            allInfo.add(new TiffInfo(TiffInfoCollection.XResolution, "", (uint)1, (uint)1));
            allInfo.add(new TiffInfo(TiffInfoCollection.YResolution, "", (uint)1, (uint)1));
            allInfo.add(new TiffInfo(TiffInfoCollection.ResolutionUnit, "", (ushort)1));
            allInfo.forceAdd(new TiffInfo(TiffInfoCollection.SamplesPerPixel, "", (ushort)3));

            allInfo.forceAdd(new TiffInfo(TiffInfoCollection.PlanarConfiguration, "", (ushort)1));
            MyTiffCompression.setCompressionTag(allInfo, CompressMethod, CompressLevel);
            MyTiffCompression.setHorizontalDifferencing(allInfo, HorizontalDifferencing);

            ushort[] nbits = new ushort[] { (ushort)8, (ushort)8, (ushort)8 };
            allInfo.forceAdd(new TiffInfo(TiffInfoCollection.BitsPerSample, "Bits per Sample", nbits));

            uint width, height;

            allInfo.getImageSize(out width, out height);
            uint colorBytes        = width * height;
            uint totOrigByteCounts = colorBytes * 3;

            allInfo.forceAdd(new TiffInfo(TiffInfoCollection.StripOffsets, "strip Offsets", toWordBoundary()));
            allInfo.forceAdd(new TiffInfo(TiffInfoCollection.StripByteCounts, "strip Byte Counts", totOrigByteCounts));

            allInfo.forceAdd(new TiffInfo(TiffInfoCollection.RowsPerStrip, "Rows per strip", height));

            int[] missing = allInfo.missingInfoRGB();
            if (missing.Length > 0)
            {
                String msg = "Missing tags: ";
                for (int i = 0; i < missing.Length; i++)
                {
                    msg += missing[i] + " ";
                }
                throw new WriteFileException(msg);
            }

            if (BufferSize < MIN_BUFFER_SIZE)
            {
                BufferSize = MIN_BUFFER_SIZE;
            }
            writeRGBImageDataStrips(new byte[1][][] { data }, totOrigByteCounts, width, height, allInfo);

            finalizeImageWriting(allInfo, new TiffStruct());
        }
コード例 #2
0
ファイル: TiffStruct.cs プロジェクト: rfimor/TiffCSharp
        internal virtual TiffInfoCollection toInfoCollection()
        {
            TiffInfoCollection col = new TiffInfoCollection();

            for (int i = 0; i < dirArray.Length; i++)
            {
                col.add(new TiffInfo(dirArray[i].Tag, "", dirArray[i].Data));
            }

            return(col);
        }
コード例 #3
0
        /// <summary>
        /// Add the next palette color image
        /// </summary>
        /// <param name="data">Image data</param>
        /// <param name="allInfo">Tiff info</param>
        public void addPaletteColorPlane(Array data, TiffInfoCollection allInfo)
        {
            System.IO.Stream stream = writer.BaseStream;

            allInfo.forceAdd(new TiffInfo(TiffInfoCollection.PhotometricInterpretation, "", (ushort)3));
            allInfo.add(new TiffInfo(TiffInfoCollection.XResolution, "", (uint)1, (uint)1));
            allInfo.add(new TiffInfo(TiffInfoCollection.YResolution, "", (uint)1, (uint)1));
            allInfo.add(new TiffInfo(TiffInfoCollection.ResolutionUnit, "", (ushort)1));
            allInfo.forceAdd(new TiffInfo(TiffInfoCollection.SamplesPerPixel, "", (ushort)1));
            MyTiffCompression.setCompressionTag(allInfo, CompressMethod, CompressLevel);
            MyTiffCompression.setHorizontalDifferencing(allInfo, HorizontalDifferencing);

            uint nBits = 0;

            ushort[][] data16bit = null;
            byte[][]   data8bit  = null;
            float[][]  dataFloat = null;
            uint[][]   data32bit = null;
            dealWithBits(data, allInfo, out nBits, out data16bit, out data8bit, out data32bit, out dataFloat);

            Array info = allInfo.getOneInfoData(TiffInfoCollection.ColorMap);

            if (info == null)
            {
                throw new WriteFileException("Invalid colormap.");
            }

            uint width, height;

            allInfo.getImageSize(out width, out height);
            uint byteCounts = width * height * nBits / 8;

            allInfo.forceAdd(new TiffInfo(TiffInfoCollection.StripOffsets, "strip Offsets", toWordBoundary()));
            allInfo.forceAdd(new TiffInfo(TiffInfoCollection.StripByteCounts, "strip Byte Counts", byteCounts));

            allInfo.forceAdd(new TiffInfo(TiffInfoCollection.RowsPerStrip, "Rows per strip", height));

            int[] missing = allInfo.missingInfoPaletteColor();
            if (missing.Length > 0)
            {
                String msg = "Missing tags: ";
                for (int i = 0; i < missing.Length; i++)
                {
                    msg += missing[i] + " ";
                }
                throw new WriteFileException(msg);
            }

            if (nBits == 8)
            {
                writeGrayScaleImageDataStrips(data8bit, byteCounts, width, height, allInfo);
            }
            else if (nBits == 16)
            {
                writeGrayScaleImageDataStrips(data16bit, byteCounts, width, height, allInfo);
            }
            else if (dataFloat != null)
            {
                writeGrayScaleImageDataStrips(dataFloat, byteCounts, width, height, allInfo);
            }
            else
            {
                writeGrayScaleImageDataStrips(data32bit, byteCounts, width, height, allInfo);
            }

            finalizeImageWriting(allInfo, new TiffStruct());
        }