Beispiel #1
0
    public void SetExif(Exif.ExifData value)
    {
        // Console.WriteLine ("before save");
        byte [] raw_data = value.Save();
        // Console.WriteLine ("saved");
        Marker exif = new Marker(ExifSignature.Id, raw_data);

        // Console.WriteLine ("new");
        Replace(ExifSignature, exif);
        // Console.WriteLine ("replaced");
    }
Beispiel #2
0
    public static ExposureInfo GetExposureInfo(string path)
    {
        Exif.ExifData exif_data = new Exif.ExifData (path);

        #if UNSED_CODE
        MakerType maker = MakerType.Unknown;
        string maker_tag_value = exif_data.LookupString (ExifTag.Make);
        if (maker_tag_value != null) {
            if (maker_tag_value.ToLower () == "nikon")
                maker = MakerType.Nikon;
            else if (maker_tag_value.ToLower () == "canon")
                maker = MakerType.Canon;
        }
        #endif

        ExposureInfo info = new ExposureInfo ();
        info.ApertureValue = exif_data.LookupFirstValue (Exif.Tag.ApertureValue);
        info.ExposureTime = exif_data.LookupFirstValue (Exif.Tag.ExposureTime);
        info.DateTime = exif_data.LookupFirstValue (Exif.Tag.DateTimeOriginal);
        info.IsoSpeed = exif_data.LookupFirstValue (Exif.Tag.ISOSpeedRatings);

        // FIXME not sure why, this doesn't work.
        #if BROKEN_CODE
        // Use the maker note to figure out the ISO speed rating if it's not in the standard spot.
        if (info.IsoSpeed == null && exif_data.LookupData (ExifTag.MakerNote) != null) {
            switch (maker) {
            case MakerType.Canon:
                byte [] maker_note = exif_data.LookupData (ExifTag.MakerNote);
                ExifData maker_ifd = new ExifData (maker_note_copy, (uint) maker_note_copy.Length);
                byte [] data = maker_ifd.LookupData ((ExifTag) 0x1);

                if (data.Length > 0x10) {
                    switch (data [0x10]) {
                    case 0xf: info.IsoSpeed = "AUTO"; break;
                    case 0x10: info.IsoSpeed = "ISO 50"; break;
                    case 0x11: info.IsoSpeed = "ISO 100"; break;
                    case 0x12: info.IsoSpeed = "ISO 200"; break;
                    case 0x13: info.IsoSpeed = "ISO 400"; break;
                    case 0x14: info.IsoSpeed = "ISO 800"; break;
                    case 0x15: info.IsoSpeed = "ISO 1600"; break;
                    case 0x16: info.IsoSpeed = "ISO 3200"; break;
                    }
                }
                break;

            // FIXME: Add support for other MakerNotes, see:
            // http://www.fifi.org/doc/jhead/exif-e.html#APP1
            }
        }
        #endif

        return info;
    }
    public static PixbufOrientation GetOrientation(Exif.ExifData data)
    {
        PixbufOrientation orientation = PixbufOrientation.TopLeft;

        Exif.ExifEntry e = data.GetContents(Exif.Ifd.Zero).Lookup(Exif.Tag.Orientation);

        if (e != null)
        {
            ushort [] value = e.GetDataUShort();
            orientation = (PixbufOrientation)value [0];
        }

        return(orientation);
    }
    public static void Resize(string orig_path, string dest_path, int size, bool copy_meta)
    {
        Exif.ExifData exif_data;
        if (copy_meta)
        {
            exif_data = new Exif.ExifData(orig_path);
        }
        else
        {
            exif_data = new Exif.ExifData();
        }

        Gdk.Pixbuf image = PixbufUtils.LoadAtMaxSize(orig_path, size, size);

        PixbufUtils.SaveJpeg(image, dest_path, 95, exif_data);
        image.Dispose();
    }
    public static Gdk.Pixbuf GetThumbnail(Exif.ExifData data)
    {
        byte [] thumb_data = data.Data;
        if (thumb_data.Length > 0)
        {
            PixbufOrientation orientation = GetOrientation(data);

            using (MemoryStream mem = new MemoryStream(thumb_data)) {
                Gdk.Pixbuf thumb = new Gdk.Pixbuf(mem);

                Gdk.Pixbuf rotated = PixbufUtils.TransformOrientation(thumb, orientation);

                if (rotated != thumb)
                {
                    thumb.Dispose();
                }
                return(rotated);
            }
        }
        return(null);
    }
        public void Reset(Tag tag)
        {
            unsafe {
                // Free any exsting data so that _initialize will actually set the data
                if (_handle->data != IntPtr.Zero)
                {
                    ExifData.free(_handle->data);
                }
                _handle->data = IntPtr.Zero;
            }

            exif_entry_initialize(handle, tag);

            //FIXME the month string in time fields in libexif ix currently broken so we do our own.
            if (tag == Tag.DateTime ||
                tag == Tag.DateTimeOriginal ||
                tag == Tag.DateTimeDigitized)
            {
                this.SetData(System.DateTime.Now);
            }
        }
        public void SetData(byte [] data, int size)
        {
            unsafe {
                if (data == null || data.Length == 0)
                {
                    throw new System.Exception("Invalid Length");
                }

                if (_handle->data != IntPtr.Zero)
                {
                    ExifData.free(_handle->data);
                }

                _handle->data = ExifData.malloc((uint)data.Length);
                Marshal.Copy(data, 0, _handle->data, data.Length);

                _handle->size = (uint)data.Length;
                // This needs to be set per type as well but
                // we do it here as well
                _handle->components = (uint)(data.Length / size);
            }
        }
		internal ExifContent (ExifData parent, IntPtr handle) : base (handle)
		{
			this.parent = parent;
			exif_content_ref (this.handle);
		}
Beispiel #9
0
	public static void Resize (string orig_path, string dest_path, int size, bool copy_meta)
	{
		Exif.ExifData exif_data;
		if (copy_meta)
			exif_data = new Exif.ExifData (orig_path);
		else 
			exif_data = new Exif.ExifData ();

		Gdk.Pixbuf image = PixbufUtils.LoadAtMaxSize (orig_path, size, size);

		PixbufUtils.SaveJpeg (image, dest_path, 95, exif_data);
		image.Dispose ();
	}
    public static void SaveJpeg(Pixbuf pixbuf, string path, int quality, Exif.ExifData exif_data)
    {
        Pixbuf temp = null;

        if (pixbuf.HasAlpha)
        {
            temp   = Flatten(pixbuf);
            pixbuf = temp;
        }

        // The DCF spec says thumbnails should be 160x120 always
        Pixbuf thumbnail = ScaleToAspect(pixbuf, 160, 120);

        byte [] thumb_data = Save(thumbnail, "jpeg", null, null);
        exif_data.Data = thumb_data;
        thumbnail.Dispose();

        // Most of the things we will set will be in the 0th ifd
        Exif.ExifContent content = exif_data.GetContents(Exif.Ifd.Zero);

        // reset the orientation tag the default is top/left
        content.GetEntry(Exif.Tag.Orientation).Reset();

        // set the write time in the datetime tag
        content.GetEntry(Exif.Tag.DateTime).Reset();

        // set the software tag
        content.GetEntry(Exif.Tag.Software).SetData(FSpot.Defines.PACKAGE + " version " + FSpot.Defines.VERSION);

        byte [] data = exif_data.Save();
        FPixbufJpegMarker [] marker = new FPixbufJpegMarker [0];
        bool result = false;

        unsafe {
            if (data.Length > 0)
            {
                fixed(byte *p = data)
                {
                    marker            = new FPixbufJpegMarker [1];
                    marker [0].type   = 0xe1;                   // APP1 marker
                    marker [0].data   = p;
                    marker [0].length = data.Length;

                    result = f_pixbuf_save_jpeg(pixbuf.Handle, path, quality, marker, marker.Length);
                }
            }
            else
            {
                result = f_pixbuf_save_jpeg(pixbuf.Handle, path, quality, marker, marker.Length);
            }
        }

        if (temp != null)
        {
            temp.Dispose();
        }

        if (result == false)
        {
            throw new System.Exception("Error Saving File");
        }
    }
Beispiel #11
0
 public static void SaveExif(string path, Exif.ExifData data)
 {
     f_save_jpeg_exif(path, data.Handle);
 }
 internal ExifContent(ExifData parent, IntPtr handle) : base(handle)
 {
     this.parent = parent;
     exif_content_ref(this.handle);
 }