markus / ConvertService / ConverterService / ImageFields / SparseImageCreator.cs @ 30d84e1a
이력 | 보기 | 이력해설 | 다운로드 (32.5 KB)
1 | 7ca218b3 | KangIngu | using System; |
---|---|---|---|
2 | using System.Collections.Generic; |
||
3 | using System.Linq; |
||
4 | using System.Text; |
||
5 | using System.Diagnostics; |
||
6 | using System.Windows.Media; |
||
7 | using System.Windows; |
||
8 | using System.Security.Permissions; |
||
9 | using System.IO; |
||
10 | using System.Xml.Linq; |
||
11 | using System.Globalization; |
||
12 | |||
13 | namespace ImageFields |
||
14 | { |
||
15 | public class SparseImageCreator : ImageFieldsBase |
||
16 | { |
||
17 | // Fields |
||
18 | private Color backgroundColor = defaultOpaqueBackgroundColor; |
||
19 | private bool copyMetadata; |
||
20 | private static Color defaultAlphaBackgroundColor = Colors.Transparent; |
||
21 | private static Color defaultOpaqueBackgroundColor = Colors.White; |
||
22 | private const double Epsilon = 1E-10; |
||
23 | private bool userSelectedBkColor = false; |
||
24 | |||
25 | // Methods |
||
26 | public SparseImageCreator() |
||
27 | { |
||
28 | this.ServerFormatXML = ServerFormats.Default; |
||
29 | this.NoCaching = false; |
||
30 | } |
||
31 | |||
32 | private Int32Rect ComputeTileRect(ref Rect levelTargetRect) |
||
33 | { |
||
34 | int x = (int)Math.Floor((double)(levelTargetRect.Left / ((double)this.TileSize))); |
||
35 | if (x < 0) |
||
36 | { |
||
37 | x = 0; |
||
38 | } |
||
39 | int num2 = (int)Math.Ceiling((double)(levelTargetRect.Right / ((double)this.TileSize))); |
||
40 | int y = (int)Math.Floor((double)(levelTargetRect.Top / ((double)this.TileSize))); |
||
41 | if (y < 0) |
||
42 | { |
||
43 | y = 0; |
||
44 | } |
||
45 | int num4 = (int)Math.Ceiling((double)(levelTargetRect.Bottom / ((double)this.TileSize))); |
||
46 | return new Int32Rect(x, y, num2 - x, num4 - y); |
||
47 | } |
||
48 | |||
49 | [FileIOPermission(SecurityAction.LinkDemand)] |
||
50 | public void Create(ICollection<Image> images, string destination) |
||
51 | { |
||
52 | double num15; |
||
53 | Rect rect; |
||
54 | double num16; |
||
55 | int num17; |
||
56 | int num18; |
||
57 | int num22; |
||
58 | int num23; |
||
59 | int num24; |
||
60 | int num25; |
||
61 | Rect rect3; |
||
62 | int num26; |
||
63 | int num27; |
||
64 | EventHandler<StreamEventArgs> handler = null; |
||
65 | EventHandler<StreamEventArgs> handler2 = null; |
||
66 | EventHandler<StreamEventArgs> handler3 = null; |
||
67 | EventHandler<StreamEventArgs> handler4 = null; |
||
68 | BitmapTransformer transformer = new BitmapTransformer |
||
69 | { |
||
70 | StripingEnabled = base.UseOptimizations |
||
71 | }; |
||
72 | bool useOptimizations = base.UseOptimizations; |
||
73 | if (this.NoCaching) |
||
74 | { |
||
75 | transformer.LargeFile = 0; |
||
76 | } |
||
77 | ImageFormat tileFormat = base.TileFormat; |
||
78 | int finishedTiles = 0; |
||
79 | int totalTiles = 0; |
||
80 | foreach (Image image in images) |
||
81 | { |
||
82 | Uri uri = new Uri(image.Path, UriKind.RelativeOrAbsolute); |
||
83 | if (!uri.IsAbsoluteUri) |
||
84 | { |
||
85 | image.Path = Path.GetFullPath(image.Path); |
||
86 | } |
||
87 | } |
||
88 | if (base.HasInputNeededHandler()) |
||
89 | { |
||
90 | if (handler == null) |
||
91 | { |
||
92 | handler = (o, e) => base.OnInputNeeded(e); |
||
93 | } |
||
94 | transformer.InputNeeded += handler; |
||
95 | } |
||
96 | if (base.HasInputCompletedHandler()) |
||
97 | { |
||
98 | if (handler2 == null) |
||
99 | { |
||
100 | handler2 = (o, e) => base.OnInputCompleted(e); |
||
101 | } |
||
102 | transformer.InputCompleted += handler2; |
||
103 | } |
||
104 | if (base.HasOutputNeededHandler()) |
||
105 | { |
||
106 | if (handler3 == null) |
||
107 | { |
||
108 | handler3 = (o, e) => base.OnOutputNeeded(e); |
||
109 | } |
||
110 | transformer.OutputNeeded += handler3; |
||
111 | } |
||
112 | if (base.HasOutputCompletedHandler()) |
||
113 | { |
||
114 | if (handler4 == null) |
||
115 | { |
||
116 | handler4 = delegate(object o, StreamEventArgs e) |
||
117 | { |
||
118 | finishedTiles++; |
||
119 | e.Progress = ((double)finishedTiles) / ((double)totalTiles); |
||
120 | this.OnOutputCompleted(e); |
||
121 | }; |
||
122 | } |
||
123 | transformer.OutputCompleted += handler4; |
||
124 | } |
||
125 | transformer.CopyMetadata = this.CopyMetadata; |
||
126 | if (string.IsNullOrEmpty(Path.GetExtension(destination))) |
||
127 | { |
||
128 | destination = Path.ChangeExtension(destination, "xml"); |
||
129 | } |
||
130 | double num = 1.0; |
||
131 | double num2 = 0.0; |
||
132 | double num3 = 0.0; |
||
133 | bool flag2 = false; |
||
134 | foreach (Image image in images) |
||
135 | { |
||
136 | if (image.ViewportWidth == 0.0) |
||
137 | { |
||
138 | throw new ArgumentException("ViewportWidth cannot be 0:" + image.Path, "images"); |
||
139 | } |
||
140 | transformer.AddInput(image.Path); |
||
141 | if (image.Size.X == 0.0) |
||
142 | { |
||
143 | image.Size = transformer.GetPixelSize(image.Path); |
||
144 | } |
||
145 | if (image.Dpi.X == 0.0) |
||
146 | { |
||
147 | Point dpi = transformer.GetDpi(image.Path); |
||
148 | if ((dpi.X == 0.0) && (dpi.Y == 0.0)) |
||
149 | { |
||
150 | image.Dpi = new Point(1.0, 1.0); |
||
151 | } |
||
152 | else |
||
153 | { |
||
154 | image.Dpi = dpi; |
||
155 | } |
||
156 | } |
||
157 | if (base.HasInputImageInfoHandler()) |
||
158 | { |
||
159 | PixelFormat pixelFormat = transformer.GetPixelFormat(image.Path); |
||
160 | ImageInfoEventArgs args = new ImageInfoEventArgs(image.Path, image.Size, image.Dpi, pixelFormat); |
||
161 | base.OnInputImageInfo(args); |
||
162 | } |
||
163 | if (!(image.Dpi.X == image.Dpi.Y)) |
||
164 | { |
||
165 | throw new ArgumentException("Image has different vertical DPI than horizontal DPI:" + image.Path, "images"); |
||
166 | } |
||
167 | if (!((flag2 || !(Path.GetExtension(image.Path) != ".jpg")) || transformer.IsOpaque(image.Path))) |
||
168 | { |
||
169 | flag2 = true; |
||
170 | } |
||
171 | if (!this.userSelectedBkColor) |
||
172 | { |
||
173 | if (flag2) |
||
174 | { |
||
175 | this.backgroundColor = defaultAlphaBackgroundColor; |
||
176 | } |
||
177 | else |
||
178 | { |
||
179 | this.backgroundColor = defaultOpaqueBackgroundColor; |
||
180 | } |
||
181 | } |
||
182 | if (this.backgroundColor.A < 0xff) |
||
183 | { |
||
184 | flag2 = true; |
||
185 | } |
||
186 | num3 += image.Size.X * image.Size.Y; |
||
187 | double num4 = (1.0 / image.ViewportWidth) / image.Size.X; |
||
188 | double num5 = (num4 * image.Dpi.X) / image.Dpi.Y; |
||
189 | double num6 = num5 * image.Size.Y; |
||
190 | double num7 = (-image.ViewportOrigin.Y / image.ViewportWidth) + num6; |
||
191 | double num8 = Math.Max(Math.Min(num4, num5), 1.0 / image.MaxViewportWidth); |
||
192 | num = Math.Min(num, num8); |
||
193 | num2 = Math.Max(num2, num7); |
||
194 | if ((((-image.ViewportOrigin.X + 1.0) / image.ViewportWidth) - 1.0) > 1E-10) |
||
195 | { |
||
196 | throw new ArgumentException("Image out of bounds " + image.Path, "images"); |
||
197 | } |
||
198 | if ((image.ViewportOrigin.X > 0.0) || (image.ViewportOrigin.Y > 0.0)) |
||
199 | { |
||
200 | throw new ArgumentException("Image out of bounds " + image.Path, "images"); |
||
201 | } |
||
202 | } |
||
203 | if (tileFormat == ImageFormat.AutoSelect) |
||
204 | { |
||
205 | if (images.Count == 1) |
||
206 | { |
||
207 | IEnumerator<Image> enumerator = images.GetEnumerator(); |
||
208 | enumerator.MoveNext(); |
||
209 | try |
||
210 | { |
||
211 | tileFormat = (ImageFormat)Enum.Parse(typeof(ImageFormat), Path.GetExtension(enumerator.Current.Path).Substring(1), true); |
||
212 | } |
||
213 | catch (Exception) |
||
214 | { |
||
215 | } |
||
216 | } |
||
217 | if (tileFormat == ImageFormat.AutoSelect) |
||
218 | { |
||
219 | if (flag2) |
||
220 | { |
||
221 | tileFormat = ImageFormat.Png; |
||
222 | } |
||
223 | else |
||
224 | { |
||
225 | tileFormat = ImageFormat.Jpg; |
||
226 | } |
||
227 | } |
||
228 | } |
||
229 | double num9 = Math.Round((double)(1.0 / num)); |
||
230 | double num10 = Math.Round((double)(num2 / num)); |
||
231 | int num11 = 0; |
||
232 | int num12 = 0; |
||
233 | if ((num9 > 2147483647.0) || (num10 > 2147483647.0)) |
||
234 | { |
||
235 | Console.WriteLine(string.Concat(new object[] { "Warning: Maximum image size exceeded; Image would be ", num9, " by ", num10 })); |
||
236 | Debug.WriteLine(string.Concat(new object[] { "Warning: Maximum image size exceeded; Image would be ", num9, " by ", num10 })); |
||
237 | if (num9 > num10) |
||
238 | { |
||
239 | num11 = (int)Math.Pow(2.0, (double)base.MaxLevel); |
||
240 | num12 = (int)Math.Round((double)((num11 * num10) / num9)); |
||
241 | } |
||
242 | else |
||
243 | { |
||
244 | num12 = (int)Math.Pow(2.0, 30.0); |
||
245 | num11 = (int)Math.Round((double)((num12 * num9) / num10)); |
||
246 | } |
||
247 | Console.WriteLine(string.Concat(new object[] { "Image will be scaled to ", num11, " by ", num12 })); |
||
248 | Debug.WriteLine(string.Concat(new object[] { "Image will be scaled to ", num11, " by ", num12 })); |
||
249 | } |
||
250 | else |
||
251 | { |
||
252 | num11 = (int)num9; |
||
253 | num12 = (int)num10; |
||
254 | } |
||
255 | int maxLevel = (int)Math.Ceiling(Math.Log((double)Math.Max(num11, num12), 2.0)); |
||
256 | if (maxLevel > base.MaxLevel) |
||
257 | { |
||
258 | num15 = Math.Pow(2.0, (double)(maxLevel - base.MaxLevel)); |
||
259 | num11 = (int)Math.Ceiling((double)(((double)num11) / num15)); |
||
260 | num12 = (int)Math.Ceiling((double)(((double)num12) / num15)); |
||
261 | maxLevel = base.MaxLevel; |
||
262 | } |
||
263 | bool flag3 = false; |
||
264 | foreach (Image image in images) |
||
265 | { |
||
266 | rect = ImageToRect(num11, num12, image); |
||
267 | num16 = Math.Max(image.Dpi.X, image.Dpi.Y); |
||
268 | num17 = maxLevel - ((int)Math.Floor(Math.Log(((rect.Width / image.Size.X) * image.Dpi.X) / num16, 2.0))); |
||
269 | num18 = maxLevel + ((int)Math.Floor(Math.Log(image.MaxViewportWidth / ((double)num11), 2.0))); |
||
270 | Debug.WriteLine(string.Concat(new object[] { image.Path, ",", num18, ",", num17 })); |
||
271 | if (num18 > 500) |
||
272 | { |
||
273 | num18 = num17; |
||
274 | } |
||
275 | else if (num18 == num17) |
||
276 | { |
||
277 | num18 = num17 + 1; |
||
278 | } |
||
279 | else if (num18 > num17) |
||
280 | { |
||
281 | throw new ArgumentException("MaxViewportWidth exteds beyond the supported value. image:" + image.Path); |
||
282 | } |
||
283 | if ((num18 > maxLevel) && (num18 <= base.MaxLevel)) |
||
284 | { |
||
285 | flag3 = true; |
||
286 | } |
||
287 | } |
||
288 | if (flag3) |
||
289 | { |
||
290 | num15 = Math.Pow(2.0, (double)(maxLevel - base.MaxLevel)); |
||
291 | num9 = Math.Ceiling((double)(num11 * 2.0)); |
||
292 | num10 = Math.Ceiling((double)(num12 * 2.0)); |
||
293 | if ((num9 > 2147483647.0) || (num10 > 2147483647.0)) |
||
294 | { |
||
295 | throw new ArgumentException("MaxViewportWidth forces a unsupported images size"); |
||
296 | } |
||
297 | num11 = (int)num9; |
||
298 | num12 = (int)num10; |
||
299 | maxLevel = (int)Math.Ceiling(Math.Log((double)Math.Max(num11, num12), 2.0)); |
||
300 | if (maxLevel > base.MaxLevel) |
||
301 | { |
||
302 | throw new ArgumentException("MaxViewportWidth forces a unsupported images size"); |
||
303 | } |
||
304 | } |
||
305 | Debug.WriteLine(string.Concat(new object[] { "Image size:", num11, " ", num12, " ", maxLevel })); |
||
306 | Debug.WriteLine(images.Count + " inputs, total pixels: " + num3); |
||
307 | string str = base.CreateDirectories(destination, maxLevel); |
||
308 | List<RectCollection> list = new List<RectCollection>(maxLevel); |
||
309 | List<RectCollection> list2 = new List<RectCollection>(maxLevel); |
||
310 | for (int i = 0; i <= maxLevel; i++) |
||
311 | { |
||
312 | list.Add(new RectCollection()); |
||
313 | list2.Add(new RectCollection()); |
||
314 | } |
||
315 | int num20 = this.FindSingleTileLevel(num11, num12, maxLevel) + 1; |
||
316 | int num21 = num20; |
||
317 | if (maxLevel < num21) |
||
318 | { |
||
319 | useOptimizations = false; |
||
320 | } |
||
321 | num20 = Math.Min(num20, maxLevel); |
||
322 | foreach (Image image in images) |
||
323 | { |
||
324 | rect = ImageToRect(num11, num12, image); |
||
325 | num16 = Math.Max(image.Dpi.X, image.Dpi.Y); |
||
326 | num17 = maxLevel - ((int)Math.Floor(Math.Log(((rect.Width / image.Size.X) * image.Dpi.X) / num16, 2.0))); |
||
327 | num18 = maxLevel + ((int)Math.Floor(Math.Log(image.MaxViewportWidth / ((double)num11), 2.0))); |
||
328 | if ((num18 < maxLevel) && (num18 < num20)) |
||
329 | { |
||
330 | useOptimizations = false; |
||
331 | } |
||
332 | else |
||
333 | { |
||
334 | num22 = maxLevel + ((int)Math.Ceiling(Math.Log(image.MinViewportWidth / ((double)num11), 2.0))); |
||
335 | if (num22 > 0) |
||
336 | { |
||
337 | useOptimizations = false; |
||
338 | } |
||
339 | } |
||
340 | Debug.WriteLine(string.Concat(new object[] { image.Path, ",", num18, ",", num17 })); |
||
341 | if (num18 > 500) |
||
342 | { |
||
343 | num18 = num17; |
||
344 | } |
||
345 | else if (num18 <= num17) |
||
346 | { |
||
347 | num18++; |
||
348 | } |
||
349 | else if (num18 > num17) |
||
350 | { |
||
351 | throw new ArgumentException("MaxViewportWidth exteds beyond the supported value. image:" + image.Path); |
||
352 | } |
||
353 | num18 = Math.Min(maxLevel, num18); |
||
354 | Int32Rect toAdd = BitmapTransformer.RectToInt32Rect(rect); |
||
355 | for (num23 = num20; num23 <= num18; num23++) |
||
356 | { |
||
357 | list2[num23].Add(ref toAdd); |
||
358 | num15 = Math.Pow(2.0, (double)(maxLevel - num23)); |
||
359 | num24 = (int)Math.Ceiling((double)(((double)num11) / num15)); |
||
360 | num25 = (int)Math.Ceiling((double)(((double)num12) / num15)); |
||
361 | rect3 = rect; |
||
362 | rect3.Scale(((double)num24) / ((double)num11), ((double)num25) / ((double)num12)); |
||
363 | if ((rect3.Bottom > num25) && (rect3.Bottom < (num25 + 0.5))) |
||
364 | { |
||
365 | rect3.Height = num25 - rect3.Top; |
||
366 | } |
||
367 | if ((rect3.Right > num24) && (rect3.Right < (num24 + 0.5))) |
||
368 | { |
||
369 | rect3.Width = num24 - rect3.Left; |
||
370 | } |
||
371 | Int32Rect rect4 = this.ComputeTileRect(ref rect3); |
||
372 | list[num23].Add(ref rect4); |
||
373 | } |
||
374 | } |
||
375 | if (useOptimizations) |
||
376 | { |
||
377 | num15 = Math.Pow(2.0, (double)(maxLevel - num21)); |
||
378 | num26 = (int)Math.Ceiling((double)(((double)num11) / num15)); |
||
379 | num27 = (int)Math.Ceiling((double)(((double)num12) / num15)); |
||
380 | int num28 = (int)Math.Ceiling((double)(((double)num26) / ((double)this.TileSize))); |
||
381 | int height = (int)Math.Ceiling((double)(((double)num27) / ((double)this.TileSize))); |
||
382 | Int32Rect rect5 = new Int32Rect(0, 0, num28, height); |
||
383 | if (!((list[num21].Rects.Count != 0) && list[num21].Rects[0].Equals(rect5))) |
||
384 | { |
||
385 | useOptimizations = false; |
||
386 | } |
||
387 | } |
||
388 | if (!useOptimizations) |
||
389 | { |
||
390 | Int32Rect rect6 = new Int32Rect(0, 0, 1, 1); |
||
391 | for (int i = 0; i < num20; i++) |
||
392 | { |
||
393 | list[i].Add(ref rect6); |
||
394 | } |
||
395 | } |
||
396 | num23 = 0; |
||
397 | while (num23 <= maxLevel) |
||
398 | { |
||
399 | foreach (Int32Rect rect4 in list[num23].Rects) |
||
400 | { |
||
401 | totalTiles += rect4.Width * rect4.Height; |
||
402 | } |
||
403 | num23++; |
||
404 | } |
||
405 | if (useOptimizations) |
||
406 | { |
||
407 | totalTiles += num20; |
||
408 | } |
||
409 | if (base.HasOutputInfoHandler()) |
||
410 | { |
||
411 | OutputInfoEventArgs args2 = new OutputInfoEventArgs(destination, new Point((double)num11, (double)num12), new Point(96.0, 96.0), transformer.ChoosePixelFormat(tileFormat), tileFormat, maxLevel, totalTiles); |
||
412 | base.OnOutputInfo(args2); |
||
413 | } |
||
414 | |||
415 | if (this.CopyMetadata) |
||
416 | { |
||
417 | |||
418 | XElement element = new XElement((XName)(DZTCommon.DeepZoomNamespace + "Size"), new object[] { new XAttribute("Width", num11), new XAttribute("Height", num12) }); |
||
419 | XElement element2 = new XElement((XName)(DZTCommon.DeepZoomNamespace + "Image"), new object[] { new XAttribute("TileSize", this.TileSize), new XAttribute("Overlap", base.TileOverlap), new XAttribute("Format", tileFormat.ToString().ToLowerInvariant()), new XAttribute("ServerFormat", this.ServerFormatXML.ToString()), element }); |
||
420 | if (images.Count > 1) |
||
421 | { |
||
422 | Int32Rect rect7 = new Int32Rect(0, 0, num11, num12); |
||
423 | while ((num20 < maxLevel) && (list2[num20 + 1].Rects[0] == rect7)) |
||
424 | { |
||
425 | num20++; |
||
426 | } |
||
427 | if ((num20 + 1) < maxLevel) |
||
428 | { |
||
429 | List<XElement> content = new List<XElement> { |
||
430 | CreateDisplayRect(0, num20, 0, 0, num11, num12) |
||
431 | }; |
||
432 | for (int i = num20 + 1; i <= maxLevel; i++) |
||
433 | { |
||
434 | foreach (Int32Rect rect2 in list2[i].Rects) |
||
435 | { |
||
436 | content.Add(CreateDisplayRect(i, i, rect2.X, rect2.Y, rect2.Width, rect2.Height)); |
||
437 | } |
||
438 | } |
||
439 | element2.Add(new XElement((XName)(DZTCommon.DeepZoomNamespace + "DisplayRects"), content)); |
||
440 | } |
||
441 | } |
||
442 | StreamEventArgs args3 = new StreamEventArgs(destination) |
||
443 | { |
||
444 | MimeType = "application/xml", |
||
445 | Compress = true |
||
446 | }; |
||
447 | if (base.HasOutputNeededHandler()) |
||
448 | { |
||
449 | base.OnOutputNeeded(args3); |
||
450 | using (StreamWriter writer = new StreamWriter(args3.Stream)) |
||
451 | { |
||
452 | element2.Save(writer, SaveOptions.DisableFormatting); |
||
453 | writer.Flush(); |
||
454 | } |
||
455 | } |
||
456 | else |
||
457 | { |
||
458 | element2.Save(destination, SaveOptions.DisableFormatting); |
||
459 | } |
||
460 | if (base.HasOutputCompletedHandler()) |
||
461 | { |
||
462 | base.OnOutputCompleted(args3); |
||
463 | } |
||
464 | element = null; |
||
465 | element2 = null; |
||
466 | list2 = null; |
||
467 | } |
||
468 | |||
469 | |||
470 | transformer.OutputAlpha = flag2; |
||
471 | string str2 = "." + tileFormat.ToString().ToLowerInvariant(); |
||
472 | int width = this.TileSize + (2 * base.TileOverlap); |
||
473 | int num31 = num21; |
||
474 | if (!useOptimizations) |
||
475 | { |
||
476 | num31 = 0; |
||
477 | } |
||
478 | for (num23 = maxLevel; num23 >= num31; num23--) |
||
479 | { |
||
480 | bool flag4; |
||
481 | if (useOptimizations && (num23 == num21)) |
||
482 | { |
||
483 | flag4 = true; |
||
484 | } |
||
485 | else |
||
486 | { |
||
487 | flag4 = false; |
||
488 | } |
||
489 | num15 = Math.Pow(2.0, (double)(maxLevel - num23)); |
||
490 | num24 = (int)Math.Ceiling((double)(((double)num11) / num15)); |
||
491 | num25 = (int)Math.Ceiling((double)(((double)num12) / num15)); |
||
492 | Int32Rect b = new Int32Rect(0, 0, num24, num25); |
||
493 | string str3 = Path.Combine(str, num23.ToString(CultureInfo.InvariantCulture)) + Path.DirectorySeparatorChar; |
||
494 | foreach (Int32Rect rect4 in list[num23].Rects) |
||
495 | { |
||
496 | int x; |
||
497 | Int32Rect rect9; |
||
498 | Rect rect10; |
||
499 | string str4; |
||
500 | int y = rect4.Y; |
||
501 | while (y < (rect4.Y + rect4.Height)) |
||
502 | { |
||
503 | x = rect4.X; |
||
504 | while (x < (rect4.X + rect4.Width)) |
||
505 | { |
||
506 | rect9 = new Int32Rect((x * this.TileSize) - base.TileOverlap, (y * this.TileSize) - base.TileOverlap, width, width); |
||
507 | rect9 = Int32RectIntersect(rect9, b); |
||
508 | rect10 = BitmapTransformer.Int32RectToRect(rect9); |
||
509 | str4 = str3 + x.ToString(CultureInfo.InvariantCulture) + "_" + y.ToString(CultureInfo.InvariantCulture) + str2; |
||
510 | transformer.AddOutput(str4, rect9.Width, rect9.Height, base.ImageQuality, tileFormat, this.BackgroundColor, flag4); |
||
511 | x++; |
||
512 | } |
||
513 | y++; |
||
514 | } |
||
515 | foreach (Image image in images) |
||
516 | { |
||
517 | num22 = maxLevel + ((int)Math.Ceiling(Math.Log(image.MinViewportWidth / ((double)num11), 2.0))); |
||
518 | num18 = maxLevel + ((int)Math.Floor(Math.Log(image.MaxViewportWidth / ((double)num11), 2.0))); |
||
519 | if ((num23 >= num22) && (num23 <= num18)) |
||
520 | { |
||
521 | rect = ImageToRect(num11, num12, image); |
||
522 | num16 = Math.Max(image.Dpi.X, image.Dpi.Y); |
||
523 | Point point2 = new Point((image.Size.X / image.Dpi.X) * num16, (image.Size.Y / image.Dpi.Y) * num16); |
||
524 | rect3 = rect; |
||
525 | rect3.Scale(((double)num24) / ((double)num11), ((double)num25) / ((double)num12)); |
||
526 | if (DoesInt32RectIntersect(this.ComputeTileRect(ref rect3), rect4)) |
||
527 | { |
||
528 | for (y = rect4.Y; y < (rect4.Y + rect4.Height); y++) |
||
529 | { |
||
530 | for (x = rect4.X; x < (rect4.X + rect4.Width); x++) |
||
531 | { |
||
532 | rect9 = new Int32Rect((x * this.TileSize) - base.TileOverlap, (y * this.TileSize) - base.TileOverlap, width, width); |
||
533 | rect9 = Int32RectIntersect(rect9, b); |
||
534 | Rect rect12 = BitmapTransformer.Int32RectToRect(rect9); |
||
535 | rect10 = Rect.Intersect(rect12, rect3); |
||
536 | if (!rect10.IsEmpty) |
||
537 | { |
||
538 | str4 = str3 + x.ToString(CultureInfo.InvariantCulture) + "_" + y.ToString(CultureInfo.InvariantCulture) + str2; |
||
539 | rect10.Offset((double)-rect9.X, (double)-rect9.Y); |
||
540 | rect12.Scale(((double)num11) / ((double)num24), ((double)num12) / ((double)num25)); |
||
541 | rect12.Intersect(rect); |
||
542 | rect12.Offset(-rect.X, -rect.Y); |
||
543 | rect12.Scale(point2.X / rect.Width, point2.Y / rect.Height); |
||
544 | transformer.AddTransformation(image.Path, str4, rect12, rect10); |
||
545 | } |
||
546 | } |
||
547 | } |
||
548 | } |
||
549 | } |
||
550 | } |
||
551 | transformer.Execute(); |
||
552 | } |
||
553 | foreach (Image image in images) |
||
554 | { |
||
555 | num18 = maxLevel + ((int)Math.Ceiling(Math.Log(image.MaxViewportWidth / ((double)num11), 2.0))); |
||
556 | if (num23 == num18) |
||
557 | { |
||
558 | transformer.CloseInput(image.Path); |
||
559 | } |
||
560 | } |
||
561 | GC.Collect(2); |
||
562 | GC.Collect(2); |
||
563 | } |
||
564 | transformer.CloseAllInputs(); |
||
565 | GC.Collect(2); |
||
566 | GC.Collect(2); |
||
567 | if (useOptimizations) |
||
568 | { |
||
569 | string str8; |
||
570 | Rect rect15; |
||
571 | int num34 = num21; |
||
572 | int num35 = num34 - 1; |
||
573 | string str5 = Path.Combine(str, num35.ToString(CultureInfo.InvariantCulture)) + Path.DirectorySeparatorChar; |
||
574 | string str6 = Path.Combine(str, num34.ToString(CultureInfo.InvariantCulture)) + Path.DirectorySeparatorChar; |
||
575 | string fileName = str5 + "0_0" + str2; |
||
576 | num15 = Math.Pow(2.0, (double)(maxLevel - num34)); |
||
577 | num26 = (int)Math.Ceiling((double)(((double)num11) / num15)); |
||
578 | num27 = (int)Math.Ceiling((double)(((double)num12) / num15)); |
||
579 | num15 = Math.Pow(2.0, (double)(maxLevel - num35)); |
||
580 | int num36 = (int)Math.Ceiling((double)(((double)num11) / num15)); |
||
581 | int num37 = (int)Math.Ceiling((double)(((double)num12) / num15)); |
||
582 | Int32Rect rect13 = new Int32Rect(0, 0, num26, num27); |
||
583 | transformer.AddOutput(fileName, num36, num37, base.ImageQuality, tileFormat, this.BackgroundColor, true); |
||
584 | int tileOverlap = 0; |
||
585 | for (int i = 0; i < num27; i += this.TileSize) |
||
586 | { |
||
587 | int tileSize = this.TileSize; |
||
588 | if ((i + tileSize) > num27) |
||
589 | { |
||
590 | tileSize = num27 % this.TileSize; |
||
591 | } |
||
592 | int num41 = 0; |
||
593 | for (int j = 0; j < num26; j += this.TileSize) |
||
594 | { |
||
595 | string[] strArray = new string[5]; |
||
596 | strArray[0] = str6; |
||
597 | int num44 = j / this.TileSize; |
||
598 | strArray[1] = num44.ToString(); |
||
599 | strArray[2] = "_"; |
||
600 | strArray[3] = (i / this.TileSize).ToString(); |
||
601 | strArray[4] = str2; |
||
602 | str8 = string.Concat(strArray); |
||
603 | transformer.AddOutputAsInput(str8); |
||
604 | int num43 = this.TileSize; |
||
605 | if ((j + num43) > num26) |
||
606 | { |
||
607 | num43 = num26 % this.TileSize; |
||
608 | } |
||
609 | Rect rect14 = new Rect((double)num41, (double)tileOverlap, (double)num43, (double)tileSize); |
||
610 | num41 = base.TileOverlap; |
||
611 | rect15 = new Rect(Math.Ceiling((double)(((double)j) / 2.0)), Math.Ceiling((double)(((double)i) / 2.0)), Math.Ceiling((double)(((double)num43) / 2.0)), Math.Ceiling((double)(((double)tileSize) / 2.0))); |
||
612 | if ((rect15.Width + rect15.X) > num36) |
||
613 | { |
||
614 | rect15.Width = num36 - rect15.X; |
||
615 | } |
||
616 | if ((rect15.Height + rect15.Y) > num37) |
||
617 | { |
||
618 | rect15.Height = num37 - rect15.Y; |
||
619 | } |
||
620 | transformer.AddTransformation(str8, fileName, rect14, rect15); |
||
621 | } |
||
622 | tileOverlap = base.TileOverlap; |
||
623 | } |
||
624 | transformer.Execute(); |
||
625 | Rect inputRect = new Rect(0.0, 0.0, (double)num36, (double)num37); |
||
626 | str8 = fileName; |
||
627 | transformer.AddOutputAsInput(str8); |
||
628 | num35--; |
||
629 | |||
630 | // 7레벨 이하 저장 |
||
631 | if(!this.LowLevelPass) |
||
632 | while (num35 >= 0) |
||
633 | { |
||
634 | fileName = (Path.Combine(str, num35.ToString(CultureInfo.InvariantCulture)) + Path.DirectorySeparatorChar) + "0_0" + str2; |
||
635 | num15 = Math.Pow(2.0, (double)(maxLevel - num35)); |
||
636 | num36 = (int)Math.Ceiling((double)(((double)num11) / num15)); |
||
637 | num37 = (int)Math.Ceiling((double)(((double)num12) / num15)); |
||
638 | rect15 = new Rect(0.0, 0.0, (double)num36, (double)num37); |
||
639 | transformer.AddOutput(fileName, num36, num37, base.ImageQuality, tileFormat, this.BackgroundColor, false); |
||
640 | transformer.AddTransformation(str8, fileName, inputRect, rect15); |
||
641 | transformer.Execute(); |
||
642 | num35--; |
||
643 | } |
||
644 | } |
||
645 | transformer.CleanUp(); |
||
646 | GC.Collect(2); |
||
647 | GC.Collect(2); |
||
648 | } |
||
649 | |||
650 | private static XElement CreateDisplayRect(int minLevel, int maxLevel, int x, int y, int width, int height) |
||
651 | { |
||
652 | XElement element = new XElement((XName)(DZTCommon.DeepZoomNamespace + "Rect"), new object[] { new XAttribute("X", x), new XAttribute("Y", y), new XAttribute("Width", width), new XAttribute("Height", height) }); |
||
653 | return new XElement((XName)(DZTCommon.DeepZoomNamespace + "DisplayRect"), new object[] { new XAttribute("MinLevel", minLevel), new XAttribute("MaxLevel", maxLevel), element }); |
||
654 | } |
||
655 | |||
656 | private static bool DoesInt32RectIntersect(Int32Rect a, Int32Rect b) |
||
657 | { |
||
658 | return (((((b.X + b.Width) >= a.X) && (b.X <= (a.X + a.Width))) && ((b.Y + b.Height) >= a.Y)) && (b.Y <= (a.Y + a.Height))); |
||
659 | } |
||
660 | |||
661 | private int FindSingleTileLevel(int width, int height, int level) |
||
662 | { |
||
663 | double num = Math.Max(width, height); |
||
664 | while (((int)Math.Ceiling((double)(num / ((double)this.TileSize)))) > 1) |
||
665 | { |
||
666 | num /= 2.0; |
||
667 | level--; |
||
668 | } |
||
669 | return level; |
||
670 | } |
||
671 | |||
672 | private static Rect ImageToRect(int fullWidth, int fullHeight, Image image) |
||
673 | { |
||
674 | double num = -image.ViewportOrigin.X / image.ViewportWidth; |
||
675 | double num2 = -image.ViewportOrigin.Y / image.ViewportWidth; |
||
676 | double num3 = 1.0 / image.ViewportWidth; |
||
677 | double num4 = Math.Max(image.Dpi.X, image.Dpi.Y); |
||
678 | Point point = new Point(((image.Size.X / image.Dpi.X) / 96.0) * num4, ((image.Size.Y / image.Dpi.Y) / 96.0) * num4); |
||
679 | double num5 = (num3 * point.Y) / point.X; |
||
680 | Rect rect = new Rect(num * fullWidth, num2 * fullWidth, num3 * fullWidth, num5 * fullWidth); |
||
681 | if (rect.Bottom > fullHeight) |
||
682 | { |
||
683 | rect.Height = fullHeight - rect.Top; |
||
684 | } |
||
685 | return rect; |
||
686 | } |
||
687 | |||
688 | private static Int32Rect Int32RectIntersect(Int32Rect a, Int32Rect b) |
||
689 | { |
||
690 | if (DoesInt32RectIntersect(a, b)) |
||
691 | { |
||
692 | int x = Math.Max(a.X, b.X); |
||
693 | int y = Math.Max(a.Y, b.Y); |
||
694 | int num3 = Math.Min((int)(a.X + a.Width), (int)(b.X + b.Width)); |
||
695 | int num4 = Math.Min((int)(a.Y + a.Height), (int)(b.Y + b.Height)); |
||
696 | return new Int32Rect(x, y, num3 - x, num4 - y); |
||
697 | } |
||
698 | return new Int32Rect(0, 0, 0, 0); |
||
699 | } |
||
700 | |||
701 | // Properties |
||
702 | public Color BackgroundColor |
||
703 | { |
||
704 | get |
||
705 | { |
||
706 | return this.backgroundColor; |
||
707 | } |
||
708 | set |
||
709 | { |
||
710 | this.backgroundColor = value; |
||
711 | this.userSelectedBkColor = true; |
||
712 | } |
||
713 | } |
||
714 | |||
715 | public bool CopyMetadata |
||
716 | { |
||
717 | get |
||
718 | { |
||
719 | return this.copyMetadata; |
||
720 | } |
||
721 | set |
||
722 | { |
||
723 | this.copyMetadata = value; |
||
724 | } |
||
725 | } |
||
726 | |||
727 | public bool NoCaching { get; set; } |
||
728 | |||
729 | public ServerFormats ServerFormat |
||
730 | { |
||
731 | get |
||
732 | { |
||
733 | return base.ServerFormat; |
||
734 | } |
||
735 | set |
||
736 | { |
||
737 | if (value == ServerFormats.SmoothStreaming) |
||
738 | { |
||
739 | throw new NotSupportedException("Smooth Streaming is not supported for Sparse Images"); |
||
740 | } |
||
741 | } |
||
742 | } |
||
743 | |||
744 | internal ServerFormats ServerFormatXML { get; set; } |
||
745 | } |
||
746 | |||
747 | |||
748 | } |