Added FilterDeb from Kevin Kubasik.
[beagle.git] / Filters / FilterPng.cs
blob02977e003f605fd9af200d14b4858610c613970f
1 //
2 // FilterPng.cs
3 //
4 // Copyright (C) 2004 Novell, Inc.
5 //
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a
9 // copy of this software and associated documentation files (the "Software"),
10 // to deal in the Software without restriction, including without limitation
11 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 // and/or sell copies of the Software, and to permit persons to whom the
13 // Software is furnished to do so, subject to the following conditions:
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 // DEALINGS IN THE SOFTWARE.
27 using System;
28 using System.IO;
30 using Beagle.Util;
31 using Beagle.Daemon;
33 using SemWeb;
35 namespace Beagle.Filters {
37 public class FilterPng : FilterImage {
39 public FilterPng () : base ()
41 AddSupportedFlavor (FilterFlavor.NewFromMimeType ("image/png"));
44 protected override void PullImageProperties ()
46 PngHeader png = new PngHeader (Stream);
48 foreach (PngHeader.Chunk chunk in png.Chunks){
49 if (chunk is PngHeader.IhdrChunk) {
50 PngHeader.IhdrChunk ihdr = (PngHeader.IhdrChunk)chunk;
52 Width = (int)ihdr.Width;
53 Height = (int)ihdr.Height;
54 Depth = ihdr.Depth;
56 bool hasAlpha = false;
57 string colorType = null;
59 switch (ihdr.Color) {
60 case PngHeader.ColorType.Gray:
61 colorType = "Greyscale";
62 hasAlpha = false;
63 break;
64 case PngHeader.ColorType.Rgb:
65 colorType = "Truecolor";
66 hasAlpha = false;
67 break;
68 case PngHeader.ColorType.Indexed:
69 colorType = "Indexed";
70 hasAlpha = false;
71 break;
72 case PngHeader.ColorType.GrayAlpha:
73 colorType = "Greyscale";
74 hasAlpha = true;
75 break;
76 case PngHeader.ColorType.RgbAlpha:
77 colorType = "Truecolor";
78 hasAlpha = true;
79 break;
82 AddProperty (Beagle.Property.NewUnsearched ("fixme:colortype", colorType));
83 AddProperty (Beagle.Property.NewBool ("fixme:hasalpha", hasAlpha));
84 } else if (chunk is PngHeader.TextChunk) {
85 ExtractTextProperty ((PngHeader.TextChunk) chunk);
89 Finished ();
92 private void ExtractTextProperty (PngHeader.TextChunk tchunk)
94 switch (tchunk.Keyword) {
95 case "Title":
96 AddProperty (Beagle.Property.New ("dc:title", tchunk.Text));
97 break;
98 case "Author":
99 AddProperty (Beagle.Property.New ("dc:creator", tchunk.Text));
100 break;
101 case "Copyright":
102 AddProperty (Beagle.Property.New ("dc:rights", tchunk.Text));
103 break;
104 case "Description":
105 AddProperty (Beagle.Property.New ("png:description", tchunk.Text));
106 break;
107 case "Comment":
108 AddProperty (Beagle.Property.New ("png:comment", tchunk.Text));
109 break;
110 case "XMP":
111 case "XML:com.adobe.xmp":
112 XmpFile xmp = new XmpFile (new MemoryStream (tchunk.TextData));
113 AddXmpProperties (xmp);
114 break;
115 case "Disclaimer":
116 case "Warning":
117 case "Source":
118 case "Creation Time":
119 case "Software":
120 break;