protected override void PullImageProperties() { PngHeader png = new PngHeader(Stream); foreach (PngFile.Chunk chunk in png.Chunks) { if (chunk is PngFile.IhdrChunk) { PngFile.IhdrChunk ihdr = (PngFile.IhdrChunk)chunk; Width = (int)ihdr.Width; Height = (int)ihdr.Height; Depth = ihdr.Depth; bool hasAlpha = false; string colorType = null; switch (ihdr.Color) { case PngFile.ColorType.Gray: colorType = "Greyscale"; hasAlpha = false; break; case PngFile.ColorType.Rgb: colorType = "Truecolor"; hasAlpha = false; break; case PngFile.ColorType.Indexed: colorType = "Indexed"; hasAlpha = false; break; case PngFile.ColorType.GrayAlpha: colorType = "Greyscale"; hasAlpha = true; break; case PngFile.ColorType.RgbA: colorType = "Truecolor"; hasAlpha = true; break; } AddProperty(Beagle.Property.NewUnsearched("fixme:colortype", colorType)); AddProperty(Beagle.Property.NewBool("fixme:hasalpha", hasAlpha)); } else if (chunk is PngFile.TextChunk) { ExtractTextProperty((PngFile.TextChunk)chunk); } } Finished(); }
private static void RotateOrientation(string original_path, RotateDirection direction) { using (FSpot.ImageFile img = FSpot.ImageFile.Create(original_path)) { if (img is JpegFile) { FSpot.JpegFile jimg = img as FSpot.JpegFile; PixbufOrientation orientation = direction == RotateDirection.Clockwise ? PixbufUtils.Rotate90(img.Orientation) : PixbufUtils.Rotate270(img.Orientation); jimg.SetOrientation(orientation); jimg.SaveMetaData(original_path); } else if (img is PngFile) { PngFile png = img as PngFile; bool supported = false; //FIXME there isn't much png specific here except the check //the pixbuf is an accurate representation of the real file //by checking the depth. The check should be abstracted and //this code made generic. foreach (PngFile.Chunk c in png.Chunks) { PngFile.IhdrChunk ihdr = c as PngFile.IhdrChunk; if (ihdr != null && ihdr.Depth == 8) { supported = true; } } if (!supported) { throw new RotateException("Unable to rotate photo type", original_path); } string backup = ImageFile.TempPath(original_path); using (Stream stream = File.Open(backup, FileMode.Truncate, FileAccess.Write)) { using (Pixbuf pixbuf = img.Load()) { PixbufOrientation fake = (direction == RotateDirection.Clockwise) ? PixbufOrientation.RightTop : PixbufOrientation.LeftBottom; using (Pixbuf rotated = PixbufUtils.TransformOrientation(pixbuf, fake)) { img.Save(rotated, stream); } } } File.Copy(backup, original_path, true); File.Delete(backup); } else { throw new RotateException("Unable to rotate photo type", original_path); } } }