当前位置: 首页>>代码示例>>C#>>正文


C# Tiff.GetField方法代码示例

本文整理汇总了C#中BitMiracle.LibTiff.Classic.Tiff.GetField方法的典型用法代码示例。如果您正苦于以下问题:C# Tiff.GetField方法的具体用法?C# Tiff.GetField怎么用?C# Tiff.GetField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BitMiracle.LibTiff.Classic.Tiff的用法示例。


在下文中一共展示了Tiff.GetField方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: tiffcvt

        public bool tiffcvt(Tiff inImage, Tiff outImage)
        {
            FieldValue[] result = inImage.GetField(TiffTag.IMAGEWIDTH);
            if (result == null)
                return false;
            int width = result[0].ToInt();

            result = inImage.GetField(TiffTag.IMAGELENGTH);
            if (result == null)
                return false;
            int height = result[0].ToInt();

            copyField(inImage, outImage, TiffTag.SUBFILETYPE);
            outImage.SetField(TiffTag.IMAGEWIDTH, width);
            outImage.SetField(TiffTag.IMAGELENGTH, height);
            outImage.SetField(TiffTag.BITSPERSAMPLE, 8);
            outImage.SetField(TiffTag.COMPRESSION, m_compression);
            outImage.SetField(TiffTag.PHOTOMETRIC, Photometric.RGB);

            copyField(inImage, outImage, TiffTag.FILLORDER);
            outImage.SetField(TiffTag.ORIENTATION, Orientation.TOPLEFT);

            if (m_noAlpha)
                outImage.SetField(TiffTag.SAMPLESPERPIXEL, 3);
            else
                outImage.SetField(TiffTag.SAMPLESPERPIXEL, 4);

            if (!m_noAlpha)
            {
                short[] v = new short[1];
                v[0] = (short)ExtraSample.ASSOCALPHA;
                outImage.SetField(TiffTag.EXTRASAMPLES, 1, v);
            }

            copyField(inImage, outImage, TiffTag.XRESOLUTION);
            copyField(inImage, outImage, TiffTag.YRESOLUTION);
            copyField(inImage, outImage, TiffTag.RESOLUTIONUNIT);
            outImage.SetField(TiffTag.PLANARCONFIG, PlanarConfig.CONTIG);

            if (!m_testFriendly)
                outImage.SetField(TiffTag.SOFTWARE, Tiff.GetVersion());

            copyField(inImage, outImage, TiffTag.DOCUMENTNAME);
            
            if (m_processByBlock && inImage.IsTiled())
                return cvt_by_tile(inImage, outImage, width, height);
            else if (m_processByBlock)
                return cvt_by_strip(inImage, outImage, width, height);

            return cvt_whole_image(inImage, outImage, width, height);
        }
开发者ID:XiBeichuan,项目名称:hydronumerics,代码行数:51,代码来源:Converter.cs

示例2: TiffGrid

    public TiffGrid(string FileName)
    {

      string fname = Path.GetFullPath(FileName);

      tiff = Tiff.Open(FileName, "r");
      var val = tiff.GetField((TiffTag)33922)[1].ToDoubleArray();
      XOrigin = val[3];
      YOrigin = val[4]; //Upper basegrid assumes Lower
      val = tiff.GetField((TiffTag)33550)[1].ToDoubleArray();
      GridSize = val[0];
      GridSize = val[1];
      NumberOfColumns = tiff.GetField(TiffTag.IMAGEWIDTH)[0].ToInt();
      NumberOfRows = tiff.GetField(TiffTag.IMAGELENGTH)[0].ToInt();
      scanline = new byte[tiff.ScanlineSize()];
      bits = tiff.ScanlineSize() / NumberOfColumns;
      ScanLineCache = new Dictionary<int, byte[]>();

      
    }
开发者ID:XiBeichuan,项目名称:hydronumerics,代码行数:20,代码来源:TiffGrid.cs

示例3: TiffGrid

        public TiffGrid(string FileName)
    {

      string fname = Path.GetFullPath(FileName);
      if (!File.Exists(fname))
        return;
        tiff = BitMiracle.LibTiff.Classic.Tiff.Open(FileName, "r");
      
      var val = tiff.GetField((TiffTag)33922)[1].ToDoubleArray();
      XOrigin = val[3];
      YOrigin = val[4]; //Upper basegrid assumes Lower
      val = tiff.GetField((TiffTag)33550)[1].ToDoubleArray();
      GridSize = val[0];
      GridSize = val[1];
      NumberOfColumns = tiff.GetField(TiffTag.IMAGEWIDTH)[0].ToInt();
      NumberOfRows = tiff.GetField(TiffTag.IMAGELENGTH)[0].ToInt();

      //Shift YOrigin to lower left
      YOrigin -= GridSize * NumberOfRows;
      scanline = new byte[tiff.ScanlineSize()];
      bits = scanline.Count() / NumberOfColumns;
      ScanLineCache = new Dictionary<int, byte[]>();
      
    }
开发者ID:JacobGudbjerg,项目名称:hydronumerics,代码行数:24,代码来源:TiffGrid.cs

示例4: PrintTagInfo

        private static void PrintTagInfo(Tiff tiff, TiffTag tiffTag)
        {
            try
            {
                var field = tiff.GetField(tiffTag);
                if (field != null)
                {
                    Console.WriteLine($"{tiffTag}");
                    for (int i = 0; i < field.Length; i++)
                    {
                        Console.WriteLine($"  [{i}] {field[i].Value}");
                        byte[] bytes = field[i].Value as byte[];
                        if (bytes != null)
                        {
                            Console.WriteLine($"    Length: {bytes.Length}");
                            if (bytes.Length % 8 == 0)
                            {
                                for (int k = 0; k < bytes.Length / 8; k++)
                                {
                                    Console.WriteLine($"      [{k}] {BitConverter.ToDouble(bytes, k * 8)}");
                                }
                            }

                            try
                            {
                                Console.WriteLine($"   > {System.Text.Encoding.ASCII.GetString(bytes).Trim()} < ");
                            }
                            catch (Exception ex)
                            {

                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"ERROR: {tiffTag}");
            }
        }
开发者ID:CatalystCode,项目名称:TerrainFlow-Web,代码行数:40,代码来源:GeoTiff.cs

示例5: read_tiff_init

        /*
        This function scans the input TIFF file for pages.  It attempts
        to determine which IFD's of the TIFF file contain image document
        pages.  For each, it gathers some information that has to do
        with the output of the PDF document as a whole.  
        */
        private void read_tiff_init(Tiff input)
        {
            short directorycount = input.NumberOfDirectories();
            m_tiff_pages = new T2P_PAGE [directorycount];
            for (int p = 0; p < directorycount; p++)
                m_tiff_pages[p] = new T2P_PAGE();

            FieldValue[] result = null;

            for (short i = 0; i < directorycount; i++)
            {
                int subfiletype = 0;

                if (!input.SetDirectory(i))
                {
                    Tiff.Error(Tiff2PdfConstants.TIFF2PDF_MODULE, 
                        "Can't set directory {0} of input file {1}", i, input.FileName());
                    return;
                }

                result = input.GetField(TiffTag.PAGENUMBER);
                if (result != null)
                {
                    short pagen = result[0].ToShort();
                    short paged = result[1].ToShort();

                    if ((pagen > paged) && (paged != 0))
                        m_tiff_pages[m_tiff_pagecount].page_number = paged;
                    else
                        m_tiff_pages[m_tiff_pagecount].page_number = pagen;
                }
                else
                {
                    result = input.GetField(TiffTag.SUBFILETYPE);
                    if (result != null)
                    {
                        subfiletype = result[0].ToInt();
                        if ((((FileType)subfiletype & FileType.PAGE) == 0) && (subfiletype != 0))
                            continue;
                    }
                    else
                    {
                        result = input.GetField(TiffTag.OSUBFILETYPE);
                        if (result != null)
                        {
                            subfiletype = result[0].ToInt();
                            if (((OFileType)subfiletype != OFileType.IMAGE) && ((OFileType)subfiletype != OFileType.PAGE) && (subfiletype != 0))
                                continue;
                        }
                    }

                    m_tiff_pages[m_tiff_pagecount].page_number = m_tiff_pagecount;
                }

                m_tiff_pages[m_tiff_pagecount].page_directory = i;

                if (input.IsTiled())
                    m_tiff_pages[m_tiff_pagecount].page_tilecount = input.NumberOfTiles();
                
                m_tiff_pagecount++;
            }

            IComparer myComparer = new cmp_t2p_page();
            Array.Sort(m_tiff_pages, myComparer);

            for (short i = 0; i < m_tiff_pagecount; i++)
            {
                m_pdf_xrefcount += 5;
                input.SetDirectory(m_tiff_pages[i].page_directory);

                result = input.GetField(TiffTag.PHOTOMETRIC);
                if ((result != null && ((Photometric)result[0].ToInt() == Photometric.PALETTE)) || input.GetField(TiffTag.INDEXED) != null)
                {
                    m_tiff_pages[i].page_extra++;
                    m_pdf_xrefcount++;
                }

                result = input.GetField(TiffTag.COMPRESSION);
                if (result != null)
                {
                    Compression xuint16 = (Compression)result[0].ToInt();
                    if ((xuint16 == Compression.DEFLATE || xuint16 == Compression.ADOBE_DEFLATE) 
                        && ((m_tiff_pages[i].page_tilecount != 0) || input.NumberOfStrips() == 1) 
                        && !m_pdf_nopassthrough)
                    {
                        if (m_pdf_minorversion < 2)
                            m_pdf_minorversion = 2;
                    }
                }

                result = input.GetField(TiffTag.TRANSFERFUNCTION);
                if (result != null)
                {
                    m_tiff_transferfunction[0] = result[0].GetBytes();
//.........这里部分代码省略.........
开发者ID:dronab,项目名称:libtiff.net,代码行数:101,代码来源:T2P.cs

示例6: ParseMetadata

        private FileMetadata ParseMetadata(string filename)
        {
            FileMetadata metadata = new FileMetadata();
            _tiff = Tiff.Open(filename, "r");

            metadata.Height = _tiff.GetField(TiffTag.IMAGELENGTH)[0].ToInt();
            metadata.Width = _tiff.GetField(TiffTag.IMAGEWIDTH)[0].ToInt();

            FieldValue[] modelPixelScaleTag = _tiff.GetField((TiffTag)33550);
            FieldValue[] modelTiepointTag = _tiff.GetField((TiffTag)33922);

            byte[] modelPixelScale = modelPixelScaleTag[1].GetBytes();
            metadata.PixelScaleX = BitConverter.ToDouble(modelPixelScale, 0);
            metadata.PixelScaleY = BitConverter.ToDouble(modelPixelScale, 8);

            // Ignores first set of model points (3 bytes) and assumes they are 0's...
            byte[] modelTransformation = modelTiepointTag[1].GetBytes();
            metadata.OriginLongitude = BitConverter.ToDouble(modelTransformation, 24);
            metadata.OriginLatitude = BitConverter.ToDouble(modelTransformation, 32);

            // Grab some raster metadata
            metadata.BitsPerSample = _tiff.GetField(TiffTag.BITSPERSAMPLE)[0].ToInt();

            // Add other information about the data
            metadata.SampleFormat = "Single";
            // TODO: Read this from tiff metadata or determine after parsing
            metadata.NoDataValue = "-10000";

            metadata.WorldUnits = "meter";

            return metadata;
        }
开发者ID:CatalystCode,项目名称:TerrainFlow-Web,代码行数:32,代码来源:GeoTiff.cs

示例7: pickFuncAndCopy

        /*
         * Select the appropriate copy function to use.
         */
        bool pickFuncAndCopy(Tiff inImage, Tiff outImage, short bitspersample, short samplesperpixel, int length, int width)
        {
            using (TextWriter stderr = Console.Error)
            {
                FieldValue[] result = inImage.GetField(TiffTag.PLANARCONFIG);
                PlanarConfig shortv = (PlanarConfig)result[0].ToShort();

                if (shortv != m_config && bitspersample != 8 && samplesperpixel > 1)
                {
                    stderr.Write("{0}: Cannot handle different planar configuration w/ bits/sample != 8\n", inImage.FileName());
                    return false;
                }

                result = inImage.GetField(TiffTag.IMAGEWIDTH);
                int w = result[0].ToInt();

                result = inImage.GetField(TiffTag.IMAGELENGTH);
                int l = result[0].ToInt();

                bool bychunk;
                if (!(outImage.IsTiled() || inImage.IsTiled()))
                {
                    result = inImage.GetField(TiffTag.ROWSPERSTRIP);
                    if (result != null)
                    {
                        int irps = result[0].ToInt();

                        /* if biased, force decoded copying to allow image subtraction */
                        bychunk = (m_bias == null) && (m_rowsperstrip == irps);
                    }
                    else
                        bychunk = false;
                }
                else
                {
                    /* either inImage or outImage is tiled */
                    if (m_bias != null)
                    {
                        stderr.Write("{0}: Cannot handle tiled configuration w/bias image\n", inImage.FileName());
                        return false;
                    }

                    if (outImage.IsTiled())
                    {
                        int tw;
                        result = inImage.GetField(TiffTag.TILEWIDTH);
                        if (result == null)
                            tw = w;
                        else
                            tw = result[0].ToInt();

                        int tl;
                        result = inImage.GetField(TiffTag.TILELENGTH);
                        if (result == null)
                            tl = l;
                        else
                            tl = result[0].ToInt();

                        bychunk = (tw == m_tilewidth && tl == m_tilelength);
                    }
                    else
                    {
                        /* outImage's not, so inImage must be tiled */
                        result = inImage.GetField(TiffTag.TILEWIDTH);
                        int tw = result[0].ToInt();

                        result = inImage.GetField(TiffTag.TILELENGTH);
                        int tl = result[0].ToInt();

                        bychunk = (tw == w && tl == m_rowsperstrip);
                    }
                }

                if (inImage.IsTiled())
                {
                    if (outImage.IsTiled())
                    {
                        /* Tiles -> Tiles */
                        if (shortv == PlanarConfig.CONTIG && m_config == PlanarConfig.CONTIG)
                            return cpContigTiles2ContigTiles(inImage, outImage, length, width, samplesperpixel);
                        else if (shortv == PlanarConfig.CONTIG && m_config == PlanarConfig.SEPARATE)
                            return cpContigTiles2SeparateTiles(inImage, outImage, length, width, samplesperpixel);
                        else if (shortv == PlanarConfig.SEPARATE && m_config == PlanarConfig.CONTIG)
                            return cpSeparateTiles2ContigTiles(inImage, outImage, length, width, samplesperpixel);
                        else if (shortv == PlanarConfig.SEPARATE && m_config == PlanarConfig.SEPARATE)
                            return cpSeparateTiles2SeparateTiles(inImage, outImage, length, width, samplesperpixel);
                    }
                    else
                    {
                        /* Tiles -> Strips */
                        if (shortv == PlanarConfig.CONTIG && m_config == PlanarConfig.CONTIG)
                            return cpContigTiles2ContigStrips(inImage, outImage, length, width, samplesperpixel);
                        else if (shortv == PlanarConfig.CONTIG && m_config == PlanarConfig.SEPARATE)
                            return cpContigTiles2SeparateStrips(inImage, outImage, length, width, samplesperpixel);
                        else if (shortv == PlanarConfig.SEPARATE && m_config == PlanarConfig.CONTIG)
                            return cpSeparateTiles2ContigStrips(inImage, outImage, length, width, samplesperpixel);
                        else if (shortv == PlanarConfig.SEPARATE && m_config == PlanarConfig.SEPARATE)
//.........这里部分代码省略.........
开发者ID:XiBeichuan,项目名称:hydronumerics,代码行数:101,代码来源:Copier.cs

示例8: copyTag

 private static void copyTag(Tiff inImage, Tiff outImage, TiffTag tag, short count, TiffType type)
 {
     FieldValue[] result = null;
     switch (type)
     {
         case TiffType.SHORT:
             result = inImage.GetField(tag);
             if (result != null)
             {
                 if (count == 1)
                     outImage.SetField(tag, result[0]);
                 else if (count == 2)
                     outImage.SetField(tag, result[0], result[1]);
                 else if (count == 4)
                     outImage.SetField(tag, result[0], result[1], result[2]);
                 else if (count == -1)
                     outImage.SetField(tag, result[0], result[1]);
             }
             break;
         case TiffType.LONG:
             result = inImage.GetField(tag);
             if (result != null)
                 outImage.SetField(tag, result[0]);
             break;
         case TiffType.RATIONAL:
             result = inImage.GetField(tag);
             if (result != null)
                 outImage.SetField(tag, result[0]);
             break;
         case TiffType.ASCII:
             result = inImage.GetField(tag);
             if (result != null)
                 outImage.SetField(tag, result[0]);
             break;
         case TiffType.DOUBLE:
             result = inImage.GetField(tag);
             if (result != null)
                 outImage.SetField(tag, result[0]);
             break;
         default:
             Tiff.Error(inImage.FileName(),
                 "Data type {0} is not supported, tag {1} skipped.", tag, type);
             break;
     }
 }
开发者ID:XiBeichuan,项目名称:hydronumerics,代码行数:45,代码来源:Copier.cs

示例9: writeBufferToContigTiles

        bool writeBufferToContigTiles(Tiff outImage, byte[] buf, int imagelength, int imagewidth, short spp)
        {
            byte[] obuf = new byte[outImage.TileSize()];

            FieldValue[] result = outImage.GetField(TiffTag.TILELENGTH);
            int tl = result[0].ToInt();

            result = outImage.GetField(TiffTag.TILEWIDTH);
            int tw = result[0].ToInt();

            int imagew = outImage.ScanlineSize();
            int tilew = outImage.TileRowSize();
            int iskew = imagew - tilew;

            int bufp = 0;

            for (int row = 0; row < imagelength; row += m_tilelength)
            {
                int nrow = (row + tl > imagelength) ? imagelength - row : tl;
                int colb = 0;

                for (int col = 0; col < imagewidth; col += tw)
                {
                    /*
                     * Tile is clipped horizontally.  Calculate
                     * visible portion and skewing factors.
                     */
                    if (colb + tilew > imagew)
                    {
                        int width = imagew - colb;
                        int oskew = tilew - width;
                        cpStripToTile(obuf, 0, buf, bufp + colb, nrow, width, oskew, oskew + iskew);
                    }
                    else
                        cpStripToTile(obuf, 0, buf, bufp + colb, nrow, tilew, 0, iskew);

                    if (outImage.WriteTile(obuf, col, row, 0, 0) < 0)
                    {
                        Tiff.Error(outImage.FileName(), "Error, can't write tile at {0} {1}", col, row);
                        return false;
                    }

                    colb += tilew;
                }

                bufp += nrow * imagew;
            }

            return true;
        }
开发者ID:XiBeichuan,项目名称:hydronumerics,代码行数:50,代码来源:Copier.cs

示例10: readContigTilesIntoBuffer

        bool readContigTilesIntoBuffer(Tiff inImage, byte[] buf, int imagelength, int imagewidth, short spp)
        {
            byte[] tilebuf = new byte[inImage.TileSize()];

            FieldValue[] result = inImage.GetField(TiffTag.TILEWIDTH);
            int tw = result[0].ToInt();

            result = inImage.GetField(TiffTag.TILELENGTH);
            int tl = result[0].ToInt();

            int imagew = inImage.ScanlineSize();
            int tilew = inImage.TileRowSize();
            int iskew = imagew - tilew;

            int bufp = 0;

            for (int row = 0; row < imagelength; row += tl)
            {
                int nrow = (row + tl > imagelength) ? imagelength - row : tl;
                int colb = 0;

                for (int col = 0; col < imagewidth; col += tw)
                {
                    if (inImage.ReadTile(tilebuf, 0, col, row, 0, 0) < 0 && !m_ignore)
                    {
                        Tiff.Error(inImage.FileName(), "Error, can't read tile at {0} {1}", col, row);
                        return false;
                    }

                    if (colb + tilew > imagew)
                    {
                        int width = imagew - colb;
                        int oskew = tilew - width;
                        cpStripToTile(buf, bufp + colb, tilebuf, 0, nrow, width, oskew + iskew, oskew);
                    }
                    else
                        cpStripToTile(buf, bufp + colb, tilebuf, 0, nrow, tilew, iskew, 0);

                    colb += tilew;
                }

                bufp += imagew * nrow;
            }

            return true;
        }
开发者ID:XiBeichuan,项目名称:hydronumerics,代码行数:46,代码来源:Copier.cs

示例11: cvt_by_tile

        static bool cvt_by_tile(Tiff inImage, Tiff outImage, int width, int height)
        {
            int tile_width = 0;
            int tile_height = 0;

            FieldValue[] result = inImage.GetField(TiffTag.TILEWIDTH);
            if (result != null)
            {
                tile_width = result[0].ToInt();

                result = inImage.GetField(TiffTag.TILELENGTH);
                if (result != null)
                    tile_height = result[0].ToInt();
            }

            if (result == null)
            {
                Tiff.Error(inImage.FileName(), "Source image not tiled");
                return false;
            }

            outImage.SetField(TiffTag.TILEWIDTH, tile_width);
            outImage.SetField(TiffTag.TILELENGTH, tile_height);

            // Allocate tile buffer
            int raster_size = multiply(tile_width, tile_height);
            int rasterByteSize = multiply(raster_size, sizeof(int));
            if (raster_size == 0 || rasterByteSize == 0)
            {
                Tiff.Error(inImage.FileName(),
                    "Can't allocate buffer for raster of size {0}x{1}", tile_width, tile_height);
                return false;
            }

            int[] raster = new int[raster_size];
            byte[] rasterBytes = new byte[rasterByteSize];

            // Allocate a scanline buffer for swapping during the vertical mirroring pass.
            // (Request can't overflow given prior checks.)
            int[] wrk_line = new int[tile_width];

            // Loop over the tiles.
            for (int row = 0; row < height; row += tile_height)
            {
                for (int col = 0; col < width; col += tile_width)
                {
                    // Read the tile into an RGBA array
                    if (!inImage.ReadRGBATile(col, row, raster))
                        return false;

                    // For some reason the ReadRGBATile() function chooses the lower left corner
                    // as the origin. Vertically mirror scanlines.
                    for (int i_row = 0; i_row < tile_height / 2; i_row++)
                    {
                        int topIndex = tile_width * i_row * sizeof(int);
                        int bottomIndex = tile_width * (tile_height - i_row - 1) * sizeof(int);

                        Buffer.BlockCopy(raster, topIndex, wrk_line, 0, tile_width * sizeof(int));
                        Buffer.BlockCopy(raster, bottomIndex, raster, topIndex, tile_width * sizeof(int));
                        Buffer.BlockCopy(wrk_line, 0, raster, bottomIndex, tile_width * sizeof(int));
                    }

                    // Write out the result in a tile.
                    int tile = outImage.ComputeTile(col, row, 0, 0);
                    Buffer.BlockCopy(raster, 0, rasterBytes, 0, rasterByteSize);
                    if (outImage.WriteEncodedTile(tile, rasterBytes, rasterByteSize) == -1)
                        return false;
                }
            }

            return true;
        }
开发者ID:XiBeichuan,项目名称:hydronumerics,代码行数:72,代码来源:Converter.cs

示例12: copyField

 private static void copyField(Tiff inImage, Tiff outImage, TiffTag tag)
 {
     FieldValue[] result = inImage.GetField(tag);
     if (result != null)
         outImage.SetField(tag, result[0]);
 }
开发者ID:XiBeichuan,项目名称:hydronumerics,代码行数:6,代码来源:Converter.cs

示例13: cvt_by_strip

        private bool cvt_by_strip(Tiff inImage, Tiff outImage, int width, int height)
        {
            FieldValue[] result = inImage.GetField(TiffTag.ROWSPERSTRIP);
            if (result == null)
            {
                Tiff.Error(inImage.FileName(), "Source image not in strips");
                return false;
            }

            m_rowsPerStrip = result[0].ToInt();
            outImage.SetField(TiffTag.ROWSPERSTRIP, m_rowsPerStrip);

            // Allocate strip buffer
            int raster_size = multiply(width, m_rowsPerStrip);
            int rasterByteSize = multiply(raster_size, sizeof(int));
            if (raster_size == 0 || rasterByteSize == 0)
            {
                Tiff.Error(inImage.FileName(),
                    "Can't allocate buffer for raster of size {0}x{1}", width, m_rowsPerStrip);
                return false;
            }

            int[] raster = new int[raster_size];
            byte[] rasterBytes = new byte[rasterByteSize];

            // Allocate a scanline buffer for swapping during the vertical mirroring pass.
            // (Request can't overflow given prior checks.)
            int[] wrk_line = new int[width];

            // Loop over the strips.
            for (int row = 0; row < height; row += m_rowsPerStrip)
            {
                // Read the strip into an RGBA array
                if (!inImage.ReadRGBAStrip(row, raster))
                    return false;

                // Figure out the number of scanlines actually in this strip.
                int rows_to_write;
                if (row + m_rowsPerStrip > height)
                    rows_to_write = height - row;
                else
                    rows_to_write = m_rowsPerStrip;

                // For some reason the TIFFReadRGBAStrip() function chooses the lower left corner
                // as the origin. Vertically mirror scanlines.
                for (int i_row = 0; i_row < rows_to_write / 2; i_row++)
                {
                    int topIndex = width * i_row * sizeof(int);
                    int bottomIndex = width * (rows_to_write - i_row - 1) * sizeof(int);

                    Buffer.BlockCopy(raster, topIndex, wrk_line, 0, width * sizeof(int));
                    Buffer.BlockCopy(raster, bottomIndex, raster, topIndex, width * sizeof(int));
                    Buffer.BlockCopy(wrk_line, 0, raster, bottomIndex, width * sizeof(int));
                }

                // Write out the result in a strip
                int bytesToWrite = rows_to_write * width * sizeof(int);
                Buffer.BlockCopy(raster, 0, rasterBytes, 0, bytesToWrite);
                if (outImage.WriteEncodedStrip(row / m_rowsPerStrip, rasterBytes, bytesToWrite) == -1)
                    return false;
            }

            return true;
        }
开发者ID:XiBeichuan,项目名称:hydronumerics,代码行数:64,代码来源:Converter.cs

示例14: read_tiff_data

        /*
        This function sets the input directory to the directory of a given
        page and determines information about the image.  It checks
        the image characteristics to determine if it is possible to convert
        the image data into a page of PDF output, setting values of the T2P
        struct for this page.  It determines what color space is used in
        the output PDF to represent the image.

        It determines if the image can be converted as raw data without
        requiring transcoding of the image data.
        */
        private void read_tiff_data(Tiff input)
        {
            m_pdf_transcode = t2p_transcode_t.T2P_TRANSCODE_ENCODE;
            m_pdf_sample = t2p_sample_t.T2P_SAMPLE_NOTHING;
            m_pdf_switchdecode = m_pdf_colorspace_invert;

            input.SetDirectory(m_tiff_pages[m_pdf_page].page_directory);

            FieldValue[] result = input.GetField(TiffTag.IMAGEWIDTH);
            m_tiff_width = result[0].ToInt();
            if (m_tiff_width == 0)
            {
                Tiff.Error(Tiff2PdfConstants.TIFF2PDF_MODULE, "No support for {0} with zero width", input.FileName());
                m_error = true;
                return;
            }

            result = input.GetField(TiffTag.IMAGELENGTH);
            m_tiff_length = result[0].ToInt();
            if (m_tiff_length == 0)
            {
                Tiff.Error(Tiff2PdfConstants.TIFF2PDF_MODULE, 
                    "No support for {0} with zero length", input.FileName());
                m_error = true;
                return;
            }

            result = input.GetField(TiffTag.COMPRESSION);
            if (result == null)
            {
                Tiff.Error(Tiff2PdfConstants.TIFF2PDF_MODULE, 
                    "No support for {0} with no compression tag", input.FileName());
                m_error = true;
                return;
            }
            else
                m_tiff_compression = (Compression)result[0].ToInt();

            if (!input.IsCodecConfigured(m_tiff_compression))
            {
                Tiff.Error(Tiff2PdfConstants.TIFF2PDF_MODULE, 
                    "No support for {0} with compression type {1}:  not configured", 
                    input.FileName(), m_tiff_compression);
                m_error = true;
                return;

            }

            result = input.GetFieldDefaulted(TiffTag.BITSPERSAMPLE);
            m_tiff_bitspersample = result[0].ToShort();

            switch (m_tiff_bitspersample)
            {
                case 1:
                case 2:
                case 4:
                case 8:
                    break;
                case 0:
                    Tiff.Warning(Tiff2PdfConstants.TIFF2PDF_MODULE, 
                        "Image {0} has 0 bits per sample, assuming 1", input.FileName());
                    m_tiff_bitspersample = 1;
                    break;
                default:
                    Tiff.Error(Tiff2PdfConstants.TIFF2PDF_MODULE, 
                        "No support for {0} with {1} bits per sample",
                        input.FileName(), m_tiff_bitspersample);
                    m_error = true;
                    return;
            }

            result = input.GetFieldDefaulted(TiffTag.SAMPLESPERPIXEL);
            m_tiff_samplesperpixel = result[0].ToShort();
            if (m_tiff_samplesperpixel > 4)
            {
                Tiff.Error(Tiff2PdfConstants.TIFF2PDF_MODULE, 
                    "No support for {0} with {1} samples per pixel", input.FileName(), m_tiff_samplesperpixel);
                m_error = true;
                return;
            }

            if (m_tiff_samplesperpixel == 0)
            {
                Tiff.Warning(Tiff2PdfConstants.TIFF2PDF_MODULE, 
                    "Image {0} has 0 samples per pixel, assuming 1", input.FileName());
                m_tiff_samplesperpixel = 1;
            }

            result = input.GetField(TiffTag.SAMPLEFORMAT);
//.........这里部分代码省略.........
开发者ID:dronab,项目名称:libtiff.net,代码行数:101,代码来源:T2P.cs

示例15: LoadTiff

        //Load tiff to display for the first time
        private bool LoadTiff(string tiffname)
        {
            int[] xyOffsets;
            using (image = Tiff.Open(tiffname, "r"))
            {
                if (image == null)
                {
                    MessageBox.Show("Could not open incoming image");
                    return false;
                }

                // Find the width and height of the image
                FieldValue[] value = image.GetField(TiffTag.TILEWIDTH);
                tileWidth = value[0].ToInt();

                value = image.GetField(TiffTag.TILELENGTH);
                tileHeight = value[0].ToInt();

                tileSize = tileHeight * tileWidth;

                // For the column and row calculations we round up
                // because .21 or .55 of a column/row is still another
                // tile even if it isn't a complete tile.

                //find the number of tile columns
                value = image.GetField(TiffTag.IMAGEWIDTH);
                imageWidth = value[0].ToInt();
                numOfColumns = imageWidth / tileWidth + 1;

                //find the number of tile rows
                value = image.GetField(TiffTag.IMAGELENGTH);
                imageHeight = value[0].ToInt();
                numOfRows = imageHeight / tileHeight + 1;

                //find the number of bands
                value = image.GetField(TiffTag.SAMPLESPERPIXEL);
                numOfBands = value[0].ToInt();
                MainParent.RadianceNumBandsTB.Text = numOfBands.ToString();

                xyOffsets = AnalyzeTiff();
                createBase(xyOffsets[0], xyOffsets[1]);
                checkPreviewState();
                this.Text = tiffname;
                return true;
            }
        }
开发者ID:stereoa,项目名称:condorsubmitgui,代码行数:47,代码来源:RadiancePreview.cs


注:本文中的BitMiracle.LibTiff.Classic.Tiff.GetField方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。