/// <summary> /// ThumbsFile をファイルから読み込みます。 /// 指定したファイルが存在しない場合は新しくファイルを作成します。 /// </summary> /// <param name="filename">ファイル名を指定します。</param> /// <returns>作成した ThumbsFile のインスタンスを返します。</returns> public static ThumbsFile OpenFile(string filename) { ThumbsFile thumbsfile; if (System.IO.File.Exists(filename)) { StreamAccessor accessor = new StreamAccessor(System.IO.File.OpenRead(filename)); thumbsfile = accessor.Read <ThumbsFile>(); accessor.Stream.Close(); } else if (System.IO.Path.GetExtension(filename).ToLower() != ".thm" && System.IO.File.Exists(filename + ".thm")) { filename += ".thm"; StreamAccessor accessor = new StreamAccessor(System.IO.File.OpenRead(filename)); thumbsfile = accessor.Read <ThumbsFile>(); accessor.Stream.Close(); } else { thumbsfile = new ThumbsFile(); thumbsfile.dirs = new DirectoryCollection(thumbsfile); thumbsfile.thumbs = new ImageCollection(thumbsfile); } thumbsfile.filename = filename; return(thumbsfile); }
public static ThumbsFile read(StreamAccessor accessor) { ThumbsFile r = new ThumbsFile(); Riff::RiffFile riff = Riff::RiffFile.FromStream(accessor.Stream, true); StreamAccessor ac; foreach (Riff::Chunk chunk in riff.EnumerateChunksByName("head")) { ac = new StreamAccessor(chunk.Stream); if (VERSION != ac.ReadInt32(EncodingType.I4)) { throw new System.ApplicationException("ファイルフォーマットの version が異なります。"); } break; } foreach (Riff::Chunk chunk in riff.EnumerateChunksByName("thms")) { r.thumbs = chunk.GetContent <ImageCollection>(); break; } foreach (Riff::Chunk chunk in riff.EnumerateChunksByName("dirs")) { ac = new StreamAccessor(chunk.Stream); r.dirs = ac.Read <DirectoryCollection>(); break; } riff.Close(); r.read_initialize(); return(r); }
public ImageCollection(ThumbsFile root) : base() { this.count = 0; this.root = root; this.paths = new Gen::Dictionary <string, Thumb>(); this.sorted = new afh.Collections.SortedArrayP <Thumb>(); }
/// <summary> /// 読み込んだ後に大元の ThumbsFile を設定します。 /// </summary> /// <param name="file">大元の ThumbsFile を設定します。</param> internal void read_initialize(ThumbsFile file) { this.root = file; foreach (ImageDirectory dir in this) { dir.read_initialize(file); } }
public void ReadFile(string filepath) { /* * if(!System.IO.File.Exists(filepath)){ * System.Console.WriteLine("指定したファイルは、存在していません。"); * return; * }//*/ this.file = ThumbsFile.OpenFile(filepath); this.UpdateView(); }
public static void write(ThumbsFile file, StreamAccessor accessor) { Riff::RiffWriter riffw = new afh.File.Riff.RiffWriter("thum"); StreamAccessor ac_chunk; riffw.AddChunk("head", out ac_chunk); ac_chunk.Write(VERSION, EncodingType.I4); riffw.AddChunk("thms", file.thumbs); riffw.AddChunk("dirs", out ac_chunk); ac_chunk.Write(file.dirs); riffw.Write(accessor); /* * Riff::RiffFile riff=new Riff::RiffFile("thum"); * StreamAccessor ac; * Riff::Chunk chunk; * * chunk=new Riff::Chunk("head"); * System.IO.Stream memstr=new System.IO.MemoryStream(); * ac=new StreamAccessor(memstr); * ac.Write(VERSION,EncodingType.I4); * chunk.Stream=memstr; * riff.Chunks.Add(chunk); * * chunk=new Riff::Chunk("thms"); * chunk.SetContent(file.thumbs); * riff.Chunks.Add(chunk); * * chunk=new Riff::Chunk("dirs"); * System.IO.MemoryStream memstr3=new System.IO.MemoryStream(); * ac=new StreamAccessor(memstr3); * ac.Write(file.dirs); * chunk.Stream=memstr3; * riff.Chunks.Add(chunk); * * accessor.Write(riff); * memstr.Close(); * memstr3.Close(); * //*/ }
internal Image(ThumbsFile file, Thumb thm) { this.root = file; this.thm = thm; }
/// <summary> /// DirectoryCollection のコンストラクタです。 /// </summary> /// <param name="root">根の ThumbsFile を指定します。</param> public DirectoryCollection(ThumbsFile root) : base() { this.root = root; }
/// <summary> /// 読込の後に実際に機能する様に、仕上げの初期化を行います。 /// </summary> /// <param name="file">根の ThumbsFile を設定します。</param> internal void read_initialize(ThumbsFile file) { this.root = file; this.dirs.read_initialize(file); }
/// <summary> /// ImageDirectory の初期化子です。 /// </summary> /// <param name="name">この Directory に付ける名前を指定します。</param> /// <param name="root">この ImageDirectory が所属する ThumbsFile を指定します。</param> public ImageDirectory(string name, ThumbsFile root) { this.root = root; this.name = name; this.dirs = new DirectoryCollection(root); }
internal void read_initialize(ThumbsFile root) { this.root = root; }
public static void SearchNearImage(ThumbsFile file) { ImageDirectory overlap = new ImageDirectory("<重複検索>", file); afh.Collections.SortedArrayP <Thumb> images = file.thumbs.SortedThumbs; Gen::Dictionary <Image, ImageDirectory> groups = new Gen::Dictionary <Image, ImageDirectory>(); afh.Forms.ProgressDialog progress = new afh.Forms.ProgressDialog(); progress.Title = "重複比較中 ..."; progress.ProgressMax = images.Count; progress.Show(); for (int i = 0; i < images.Count; i++) { Image img1 = new Image(file, images[i]); if (i % 50 == 0) { progress.Description = "画像 '" + img1.thm.filepath + "' の類似画像を探索中 ..."; if (progress.IsCanceled) { return; } } for (int j = i + 1; j < images.Count; j++) { Image img2 = new Image(file, images[j]); if (!Image.EqualAspect(img1, img2)) { break; } if (Image.Resembles(img1, img2)) { ImageDirectory group1 = null; ImageDirectory group2 = null; bool b1 = groups.TryGetValue(img1, out group1); bool b2 = groups.TryGetValue(img2, out group2); switch ((b1?1:0) | (b2?2:0)) { case 3: // 両方 if (group1 == group2) { break; } // 両グループの併合 overlap.dirs.Remove(group2); foreach (Image img in group2.EnumImages()) { group1.Add(img); groups[img] = group1; } break; case 1: // group1 だけ group1.Add(img2); groups.Add(img2, group1); break; case 2: // group2 だけ group2.Add(img1); groups.Add(img1, group2); break; case 0: // 両者未登録 ImageDirectory group = new ImageDirectory("Group " + overlap.dirs.Count.ToString(), file); group.Add(img1); group.Add(img2); groups.Add(img1, group); groups.Add(img2, group); overlap.Add(group); break; default: throw new System.InvalidProgramException(); } //System.Console.WriteLine("次の画像は似ています\r\n {0}\r\n {1}",thm1.filepath,thm2.filepath); } } if (i % 10 == 0) { progress.Progress = i; } } progress.Close(); file.dirs.Add(overlap); }