Exemplo n.º 1
0
        static void PrintGeoTags(GTIF gt, GTIFPrintMethod print, object aux)
        {
            TIFF tif = gt.gt_tif;

            if (tif == null)
            {
                return;
            }

            object data;
            int    count;

            if (gt.gt_methods.get(tif, (ushort)GTIFF_TIEPOINTS, out count, out data))
            {
                PrintTag((int)GTIFF_TIEPOINTS, count / 3, (double[])data, 3, print, aux);
            }

            if (gt.gt_methods.get(tif, (ushort)GTIFF_PIXELSCALE, out count, out data))
            {
                PrintTag((int)GTIFF_PIXELSCALE, count / 3, (double[])data, 3, print, aux);
            }

            if (gt.gt_methods.get(tif, (ushort)GTIFF_TRANSMATRIX, out count, out data))
            {
                PrintTag((int)GTIFF_TRANSMATRIX, count / 4, (double[])data, 4, print, aux);
            }
        }
Exemplo n.º 2
0
        //*********************************************************************
        //
        //							Public Routines
        //
        //*********************************************************************

        // Given an open TIFF file, look for GTIF keys and values and return GTIF structure.
        //
        // This function creates a GeoTIFF information interpretation handle
        // (GTIF) based on a passed in TIFF handle originally from
        // XTIFFOpen().
        //
        // The returned GTIF handle can be used to read or write GeoTIFF tags
        // using the various GTIF functions. The handle should be destroyed using
        // GTIFFree() before the file is closed with TIFFClose().
        //
        // If the file accessed has no GeoTIFF keys, an valid (but empty) GTIF is
        // still returned. GTIFNew() is used both for existing files being read, and
        // for new TIFF files that will have GeoTIFF tags written to them.

        public static GTIF GTIFNew(TIFF tif)
        {
            TIFFMethod default_methods = new TIFFMethod();

            _GTIFSetDefaultTIFF(default_methods);

            return(GTIFNewWithMethods(tif, default_methods));
        }
Exemplo n.º 3
0
 private void сохранитьВTiffToolStripMenuItem_Click(object sender, EventArgs e)
 {
     this.saveFileDialog1.AddExtension = true;
     this.saveFileDialog1.DefaultExt   = "tif";
     this.saveFileDialog1.Filter       = "Image Files (*.tif)|*.tif";
     if (this.saveFileDialog1.ShowDialog() == DialogResult.OK)
     {
         List <ExtendedBitmap> movie =
             getExtendedMovieFromWorkCells(sortSelectedCells(this.workDataGridView.SelectedCells));
         TIFF.ConvertBitmapsToTiff(movie, this.saveFileDialog1.FileName);
     }
 }
Exemplo n.º 4
0
        // This is the callback procedure, and is
        // called by the DefaultDirectory method
        // every time a new TIFF directory is opened.
        static void XTIFFDefaultDirectory(TIFF tif)
        {
            // set up our own defaults
            XTIFFLocalDefaultDirectory(tif);

            // Since an XTIFF client module may have overridden
            // the default directory method, we call it now to
            // allow it to set up the rest of its own methods.
            if (_ParentExtender != null)
            {
                _ParentExtender(tif);
            }
        }
Exemplo n.º 5
0
    // Use this for initialization
    void Start()
    {
        MeshRenderer r = transform.GetComponent <MeshRenderer>();
        //r.material= new Material(Shader.Find("Custom/QuadImage"));
        Material m        = r.material;
        string   FileName = Application.dataPath + "/Data/2.tiff";
        TIFF     tiff     = new TIFF();

        tiff.Init(FileName);
        //tiff.PrintInfo();

        Texture2D tex = tiff.GetUnityTexture();

        m.SetTexture("_MainTex", tex);
    }
Exemplo n.º 6
0
 public static bool TIFFFlush(TIFF tif)
 {
     if (tif.tif_mode != O.RDONLY)
     {
         if ((tif.tif_flags & TIF_FLAGS.TIFF_BEENWRITING) != 0 && !TIFFFlushData(tif))
         {
             return(false);
         }
         if ((tif.tif_flags & TIF_FLAGS.TIFF_DIRTYDIRECT) != 0 && !TIFFWriteDirectory(tif))
         {
             return(false);
         }
     }
     return(true);
 }
Exemplo n.º 7
0
 // Flush buffered data to the file.
 public static bool TIFFFlushData(TIFF tif)
 {
     if ((tif.tif_flags & TIF_FLAGS.TIFF_BEENWRITING) == 0)
     {
         return(false);
     }
     if ((tif.tif_flags & TIF_FLAGS.TIFF_POSTENCODE) != 0)
     {
         tif.tif_flags &= ~TIF_FLAGS.TIFF_POSTENCODE;
         if (!tif.tif_postencode(tif))
         {
             return(false);
         }
     }
     return(TIFFFlushData1(tif));
 }
Exemplo n.º 8
0
        internal static IEnumerable <Frame> FromPath(DirectoryInfo diri)
        {
            Regex dir_rx = new Regex(@"[1](?<number>[\d][\d\$])");

            foreach (var fi in diri.EnumerateFiles("???.tif"))
            {
                string filename    = fi.Name;
                string dirname     = fi.Directory.Name;
                string dirfullname = fi.Directory.FullName;
                Match  match       = dir_rx.Match(filename);
                if (!match.Success)
                {
                    continue;
                }
                string number = match.Groups["number"].Value;
                if (number == null)
                {
                    continue;
                }
                EXIF _exif = null;
                try
                {
                    _exif = TIFF.exif(dirfullname, filename);
                }
                catch (InvalidOperationException)
                {
                    continue;
                }
                Frame frame = new Frame()
                {
                    number      = toNumber(number),
                    filename    = filename,
                    copyright   = _exif.copyright,
                    description = _exif.description,
                    height      = _exif.height,
                    width       = _exif.width,
                    photometric = _exif.photometric,
                    resolutionX = _exif.resolutionX,
                    resolutionY = _exif.resolutionY,
                    unit        = _exif.unit,
                    software    = _exif.software,
                    make        = _exif.make,
                    model       = _exif.model,
                };
                yield return(frame);
            }
        }
Exemplo n.º 9
0
        //***********************************************************************/
        //*							GTIFPCSToImage()							*/
        //***********************************************************************/

        // Translate a projection coordinate to pixel/line coordinates.
        //
        // At this time this function does not support PCS to image translations for
        // tiepoints-only based definitions, only matrix and pixelscale/tiepoints
        // formulations are supposed.
        //
        // @param gtif The handle from GTIFNew() indicating the target file.
        // @param x A reference to the double containing the pixel offset on input,
        // and into which the easting/longitude will be put on completion.
        // @param y A reference to the double containing the line offset on input,
        // and into which the northing/latitude will be put on completion.
        //
        // @return true if the transformation succeeds, or false if it fails. It may
        // fail if the file doesn't have properly setup transformation information,
        // or it is in a form unsupported by this function.
        public static bool GTIFPCSToImage(GTIF gtif, ref double x, ref double y)
        {
            bool result = false;
            int  tiepoint_count, count, transform_count;
            TIFF tif = gtif.gt_tif;

            double[] tiepoints   = null;
            double[] pixel_scale = null;
            double[] transform   = null;

            // --------------------------------------------------------------------
            //		Fetch tiepoints and pixel scale.
            // --------------------------------------------------------------------
            object ap;

            if (!gtif.gt_methods.get(tif, (ushort)GTIFF_TIEPOINTS, out tiepoint_count, out ap))
            {
                tiepoint_count = 0;
            }
            else if (ap is double[])
            {
                tiepoints = (double[])ap;
            }

            if (!gtif.gt_methods.get(tif, (ushort)GTIFF_PIXELSCALE, out count, out ap))
            {
                count = 0;
            }
            else if (ap is double[])
            {
                pixel_scale = (double[])ap;
            }

            if (!gtif.gt_methods.get(tif, (ushort)GTIFF_TRANSMATRIX, out transform_count, out ap))
            {
                transform_count = 0;
            }
            else if (ap is double[])
            {
                transform = (double[])ap;
            }

            // --------------------------------------------------------------------
            //		Handle matrix - convert to "geotransform" format, invert and
            //		apply.
            // --------------------------------------------------------------------
            if (transform_count == 16)
            {
                double   x_in = x, y_in = y;
                double[] gt_in  = new double[6];
                double[] gt_out = new double[6];

                gt_in[0] = transform[0];
                gt_in[1] = transform[1];
                gt_in[2] = transform[3];
                gt_in[3] = transform[4];
                gt_in[4] = transform[5];
                gt_in[5] = transform[7];

                if (!inv_geotransform(gt_in, gt_out))
                {
                    result = false;
                }
                else
                {
                    x = x_in * gt_out[0] + y_in * gt_out[1] + gt_out[2];
                    y = x_in * gt_out[3] + y_in * gt_out[4] + gt_out[5];

                    result = true;
                }
            }
            // --------------------------------------------------------------------
            //		If the pixelscale count is zero, but we have tiepoints use
            //		the tiepoint based approach.
            // --------------------------------------------------------------------
            else if (tiepoint_count > 6 && count == 0)
            {
                result = GTIFTiepointTranslate(tiepoint_count / 6, tiepoints, 3, tiepoints, 0, ref x, ref y);
            }
            // --------------------------------------------------------------------
            //		For now we require one tie point, and a valid pixel scale.
            // --------------------------------------------------------------------
            else if (count >= 3 && tiepoint_count >= 6)
            {
                x = (x - tiepoints[3]) / pixel_scale[0] + tiepoints[0];
                y = (y - tiepoints[4]) / (-1 * pixel_scale[1]) + tiepoints[1];

                result = true;
            }

            return(result);
        }
Exemplo n.º 10
0
        //***********************************************************************/
        //*								GTIFImageToPCS()						*/
        //***********************************************************************/

        // Translate a pixel/line coordinate to projection coordinates.
        //
        // At this time this function does not support image to PCS translations for
        // tiepoints-only definitions, only pixelscale and transformation matrix
        // formulations.
        //
        // @param gtif The handle from GTIFNew() indicating the target file.
        // @param x A reference to the double containing the pixel offset on input,
        // and into which the easting/longitude will be put on completion.
        // @param y A reference to the double containing the line offset on input,
        // and into which the northing/latitude will be put on completion.
        //
        // @return true if the transformation succeeds, or false if it fails. It may
        // fail if the file doesn't have properly setup transformation information,
        // or it is in a form unsupported by this function.
        public static bool GTIFImageToPCS(GTIF gtif, ref double x, ref double y)
        {
            bool res = false;
            int  tiepoint_count, count, transform_count;
            TIFF tif = gtif.gt_tif;

            double[] tiepoints   = null;
            double[] pixel_scale = null;
            double[] transform   = null;

            // --------------------------------------------------------------------
            //		Fetch tiepoints and pixel scale.
            // --------------------------------------------------------------------
            object ap;

            if (!gtif.gt_methods.get(tif, (ushort)GTIFF_TIEPOINTS, out tiepoint_count, out ap))
            {
                tiepoint_count = 0;
            }
            else if (ap is double[])
            {
                tiepoints = (double[])ap;
            }

            if (!gtif.gt_methods.get(tif, (ushort)GTIFF_PIXELSCALE, out count, out ap))
            {
                count = 0;
            }
            else if (ap is double[])
            {
                pixel_scale = (double[])ap;
            }

            if (!gtif.gt_methods.get(tif, (ushort)GTIFF_TRANSMATRIX, out transform_count, out ap))
            {
                transform_count = 0;
            }
            else if (ap is double[])
            {
                transform = (double[])ap;
            }

            // --------------------------------------------------------------------
            //		If we have a transformation matrix, use it.
            // --------------------------------------------------------------------
            if (transform_count == 16)
            {
                double x_in = x, y_in = y;

                x = x_in * transform[0] + y_in * transform[1] + transform[3];
                y = x_in * transform[4] + y_in * transform[5] + transform[7];

                res = true;
            }
            // --------------------------------------------------------------------
            //		If the pixelscale count is zero, but we have tiepoints use
            //		the tiepoint based approach.
            // --------------------------------------------------------------------
            else if (tiepoint_count > 6 && count == 0)
            {
                res = GTIFTiepointTranslate(tiepoint_count / 6, tiepoints, 0, tiepoints, 3, ref x, ref y);
            }
            // --------------------------------------------------------------------
            //		For now we require one tie point, and a valid pixel scale.
            // --------------------------------------------------------------------
            else if (count >= 3 && tiepoint_count >= 6)
            {
                x = (x - tiepoints[0]) * pixel_scale[0] + tiepoints[3];
                y = (y - tiepoints[1]) * (-1 * pixel_scale[1]) + tiepoints[4];

                res = true;
            }

            return(res);
        }
Exemplo n.º 11
0
        // **************************************************************************
        // *						GTIFNewWithMethods()							*
        // *																		*
        // *	Create a new geotiff, passing in the methods structure to			*
        // *	support not libtiff implementations without replacing the			*
        // *	default methods.													*
        // **************************************************************************
        public static GTIF GTIFNewWithMethods(TIFF tif, TIFFMethod methods)
        {
            GTIF gt = null;

            try
            {
                gt            = new GTIF();
                gt.gt_methods = new TIFFMethod();
                gt.gt_keys    = new Dictionary <geokey_t, GeoKey>();
            }
            catch
            {
                return(null);
            }

            // install TIFF file and I/O methods
            gt.gt_tif          = tif;
            gt.gt_methods.get  = methods.get;
            gt.gt_methods.set  = methods.set;
            gt.gt_methods.type = methods.type;

            gt.gt_rev_major = GvCurrentRevision;
            gt.gt_rev_minor = GvCurrentMinorRev;
            gt.gt_version   = GvCurrentVersion;

            if (tif == null)
            {
                return(gt);
            }

            object data;
            int    nshorts;

            // since this is an array, GTIF will allocate the memory
            if (!gt.gt_methods.get(tif, (ushort)GTIFF_GEOKEYDIRECTORY, out nshorts, out data))
            {
                return(gt);
            }

            if (nshorts < 4)
            {
                return(null);
            }
            ushort[] shorts = data as ushort[];
            if (shorts == null || shorts.Length < 4)
            {
                return(null);
            }

            if (shorts[0] > GvCurrentVersion)
            {
                return(null);
            }
            gt.gt_version = shorts[0];

            if (shorts[1] > GvCurrentRevision)
            {
                // issue warning
            }
            gt.gt_rev_major = shorts[1];
            gt.gt_rev_minor = shorts[2];

            int count = shorts[3];

            if (count == 0)
            {
                return(gt);
            }
            if (shorts.Length < (count * 4 + 4))
            {
                return(null);
            }

            // If we got here, then the geokey can be parsed

            // Get the PARAMS Tags, if any
            int ndoubles;

            double[] doubles;
            if (!gt.gt_methods.get(tif, (ushort)GTIFF_DOUBLEPARAMS, out ndoubles, out data))
            {
                try
                {
                    doubles = new double[MAX_VALUES];
                }
                catch
                {
                    return(null);
                }
            }
            else
            {
                doubles = data as double[];
                if (doubles == null)
                {
                    return(null);
                }
            }

            int    stringsLength = 0;
            string strings       = null;

            if (gt.gt_methods.get(tif, (ushort)GTIFF_ASCIIPARAMS, out stringsLength, out data))
            {
                strings = data as string;
                if (strings == null)
                {
                    return(null);
                }
                strings       = strings.TrimEnd('\0');         // last NULL doesn't count; "|" used for delimiter
                stringsLength = strings.Length;
            }

            for (int i = 0; i < count; i++)
            {
                ushort KeyID           = shorts[i * 4 + 4];
                ushort TIFFTagLocation = shorts[i * 4 + 5];
                ushort Count           = shorts[i * 4 + 6];
                ushort Value_Offset    = shorts[i * 4 + 7];

                GeoKey keyptr;

                try
                {
                    keyptr = new GeoKey();

                    keyptr.gk_key = (geokey_t)KeyID;

                    if (TIFFTagLocation != 0)
                    {
                        keyptr.gk_type = gt.gt_methods.type(gt.gt_tif, TIFFTagLocation);
                    }
                    else
                    {
                        keyptr.gk_type = tagtype_t.TYPE_SHORT;                    //gt.gt_methods.type(gt.gt_tif, (ushort)GTIFF_GEOKEYDIRECTORY);
                    }
                    switch (TIFFTagLocation)
                    {
                    case (ushort)GTIFF_LOCAL:
                        // store value into data value
                        keyptr.gk_data  = new ushort[] { Value_Offset };
                        keyptr.gk_count = 1;
                        break;

                    case (ushort)GTIFF_GEOKEYDIRECTORY:
                        ushort[] s = new ushort[Count];
                        keyptr.gk_data = s;
                        Array.Copy(shorts, Value_Offset, s, 0, Count);
                        keyptr.gk_count = Count;
                        break;

                    case (ushort)GTIFF_DOUBLEPARAMS:
                        double[] d = new double[Count];
                        keyptr.gk_data = d;
                        Array.Copy(doubles, Value_Offset, d, 0, Count);
                        keyptr.gk_count = Count;
                        break;

                    case (ushort)GTIFF_ASCIIPARAMS:
                        string str = strings.Substring(Value_Offset, Count);
                        str             = str.Replace('|', '\0');
                        str             = str.Trim('\0');
                        keyptr.gk_count = str.Length;
                        keyptr.gk_data  = str;
                        break;

                    default:
                        return(null);                                // failure
                    }
                }
                catch
                {
                    return(null);
                }

                gt.gt_keys.Add(keyptr.gk_key, keyptr);
            }

            return(gt);
        }
Exemplo n.º 12
0
        private List <ExtendedBitmap> getImageList(string fileName, int foreshorting)
        {
            if (fileName.EndsWith(".sti", StringComparison.InvariantCultureIgnoreCase))
            {
                StciData stciData = new StciData(fileName, 0);
                infoData.Add(stciData);
                List <ExtendedBitmap> bm = new List <ExtendedBitmap>();
                if (stciData._Indexed != null)
                {
                    try
                    {
                        ETRLEData data = IndexedConverter.LoadIndexedImageData(stciData);
                        bm = IndexedConverter.ConvertEtrleDataToBitmaps(data, foreshorting);
                        infoEtrleData.Add(data);
                    }
                    catch (Exception exc)
                    {
                        MessageBox.Show(String.Format("{3} {0}/n{1}/n{2}",
                                                      fileName, exc.Message, exc.StackTrace, Resources.GetString("LoadingError")));
                    }
                }
                else
                {
                    ExtendedBitmap exBm = RGBConverter.GetBitmap(stciData);
                    exBm.ApplicationData = null;
                    bm.Add(exBm);
                }
                return(bm);
            }
            else if (fileName.EndsWith(".tif", StringComparison.InvariantCultureIgnoreCase))
            {
                List <Bitmap> bitmaps = TIFF.ConvertTiffToBitmaps(fileName);
                return(bitmaps.ConvertAll <ExtendedBitmap>(
                           delegate(Bitmap bm) { return new ExtendedBitmap(bm, 0, 0); }));
            }
            else if (fileName.EndsWith(".gif", StringComparison.InvariantCultureIgnoreCase))
            {
                List <ExtendedBitmap> result = new List <ExtendedBitmap>();
                try
                {
                    bool containsLocalPalette;
                    result = GIF.ConvertGifToBitmaps(fileName, 0, out containsLocalPalette);
                    if (containsLocalPalette)
                    {
                        MessageBox.Show(Resources.GetString("FileContainsLocaPalettes"),
                                        Resources.GetString("Attention"), MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
                catch (Exception exc)
                {
                    MessageBox.Show(exc.Message,                     //Resources.GetString("FileContainsLocaPalettes"),
                                    Resources.GetString("Attention"), MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }

                return(result);
            }
            else if (fileName.EndsWith(".bmp", StringComparison.InvariantCultureIgnoreCase))
            {
                List <ExtendedBitmap> result = new List <ExtendedBitmap>();
                Bitmap bm = new Bitmap(fileName);
                result.Add(new ExtendedBitmap(bm, 0, 0));
                return(result);
            }
            else if (fileName.EndsWith(".pcx", StringComparison.InvariantCultureIgnoreCase))
            {
                List <ExtendedBitmap> result = new List <ExtendedBitmap>();
                Bitmap bm = new Bitmap(fileName);
                result.Add(new ExtendedBitmap(bm, 0, 0));
                return(result);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 13
0
 static void XTIFFLocalDefaultDirectory(TIFF tif)
 {
     // Install the extended Tag field info
     libtiff._TIFFMergeFieldInfo(tif, xtiffFieldInfo);
 }
Exemplo n.º 14
0
 // Close a file opened with XTIFFOpen().
 //
 // @param tif The file handle returned by XTIFFOpen().
 //
 // If a GTIF structure was created with GTIFNew()
 // for this file, it should be freed with GTIFFree()
 // <i>before</i> calling XTIFFClose().
 public static void XTIFFClose(TIFF tif)
 {
     libtiff.TIFFClose(tif);
 }