global_settings_tc.cs 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498
  1. using System;
  2. #if UNITY_EDITOR
  3. using UnityEngine;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using System.Threading;
  7. using UnityEditor;
  8. #endif
  9. namespace WorldComposer
  10. {
  11. #if UNITY_EDITOR
  12. [Serializable]
  13. [CreateAssetMenu(fileName = "GlobalSettings", menuName = "GlobalSettings", order = 1)]
  14. public class global_settings_tc : ScriptableObject
  15. {
  16. public Material matTerrain;
  17. public int tc_script_id;
  18. public bool tc_installed;
  19. public string[] examples = new string[]
  20. {
  21. "Procedural Mountains",
  22. "Procedural Canyons",
  23. "Procedural Plateaus",
  24. "Procedural Islands",
  25. "Island Example"
  26. };
  27. public bool layer_count = true;
  28. public bool placed_count = true;
  29. public bool display_project = true;
  30. public bool tabs = true;
  31. public bool color_scheme = true;
  32. public color_settings_class color_layout = new color_settings_class();
  33. public bool color_layout_converted;
  34. public bool box_scheme;
  35. public bool display_color_curves;
  36. public bool display_mix_curves = true;
  37. public bool filter_select_text = true;
  38. public string install_path;
  39. public string install_path_full;
  40. public bool object_fast = true;
  41. public bool preview_texture = true;
  42. public int preview_texture_buffer = 100;
  43. public bool preview_colors = true;
  44. public int preview_texture_resolution = 128;
  45. public int preview_texture_resolution1 = 128;
  46. public int preview_quick_resolution_min = 16;
  47. public float preview_splat_brightness = 1;
  48. public bool preview_texture_dock = true;
  49. public int preview_target_frame = 30;
  50. public List<Color> splat_colors = new List<Color>();
  51. public int splat_custom_texture_resolution = 128;
  52. public int splat_custom_texture_resolution1 = 128;
  53. public List<Color> tree_colors = new List<Color>();
  54. public List<Color> grass_colors = new List<Color>();
  55. public List<Color> object_colors = new List<Color>();
  56. public bool toggle_text_no;
  57. public bool toggle_text_short = true;
  58. public bool toggle_text_long;
  59. public bool tooltip_text_no;
  60. public bool tooltip_text_short;
  61. public bool tooltip_text_long = true;
  62. public int tooltip_mode = 2;
  63. public bool video_help = true;
  64. public bool run_in_background = true;
  65. public bool display_bar_auto_generate = true;
  66. public bool unload_textures;
  67. public bool clean_memory;
  68. public bool auto_speed = true;
  69. public int target_frame = 40;
  70. public bool auto_save = true;
  71. public int auto_save_tc_instances = 2;
  72. public int auto_save_scene_instances = 2;
  73. public bool auto_save_tc = true;
  74. public List<string> auto_save_tc_list = new List<string>();
  75. public bool auto_save_scene = true;
  76. public List<string> auto_save_scene_list = new List<string>();
  77. public float auto_save_timer = 10;
  78. public float auto_save_time_start;
  79. public bool auto_save_on_play = true;
  80. public string auto_save_path;
  81. public int terrain_tiles_max = 15;
  82. public List<auto_search_class> auto_search_list = new List<auto_search_class>();
  83. public map_class map = new map_class();
  84. public select_window_class select_window = new select_window_class();
  85. public List<int> preview_window = new List<int>();
  86. public bool map_combine;
  87. public bool map_load;
  88. public bool map_load2;
  89. public bool map_load3;
  90. public bool map_load4;
  91. public int map_zoom1;
  92. public int map_zoom2;
  93. public int map_zoom3;
  94. public int map_zoom4;
  95. public latlong_class map_latlong = new latlong_class();
  96. public latlong_class map_latlong_center = new latlong_class();
  97. public int map_zoom = 17;
  98. public int map_zoom_old;
  99. public global_settings_class settings = new global_settings_class();
  100. }
  101. [Serializable]
  102. public class gui_class
  103. {
  104. public List<float> column;
  105. public float y;
  106. public float x;
  107. public gui_class(int columns)
  108. {
  109. column = new List<float>();
  110. for (int i = 0; i < columns; i++)
  111. {
  112. column.Add(0);
  113. }
  114. }
  115. public Rect getRect(int column_index, float width, float y1, bool add_width, bool add_height)
  116. {
  117. float num = x;
  118. float num2 = y;
  119. if (add_width)
  120. {
  121. x += width;
  122. }
  123. if (add_height)
  124. {
  125. y += y1;
  126. }
  127. return new Rect(column[column_index] + num, num2, width, y1);
  128. }
  129. public Rect getRect(int column_index, float x1, float width, float y1, bool add_width, bool add_height)
  130. {
  131. float num = x;
  132. float num2 = y;
  133. if (add_width)
  134. {
  135. x += width + x1;
  136. }
  137. if (add_height)
  138. {
  139. y += y1;
  140. }
  141. return new Rect(column[column_index] + num + x1, num2, width, y1);
  142. }
  143. }
  144. [Serializable]
  145. public class image_edit_class
  146. {
  147. public Color color1_start;
  148. public Color color1_end;
  149. public AnimationCurve curve1;
  150. public Color color2_start;
  151. public Color color2_end;
  152. public AnimationCurve curve2;
  153. public float strength;
  154. public image_output_enum output;
  155. public bool active;
  156. public bool solid_color;
  157. public float radius;
  158. public int repeat;
  159. public image_edit_class()
  160. {
  161. color1_start = new Color(0, 0, 0, 1);
  162. color1_end = new Color(0.3f, 0.3f, 0.3f, 1);
  163. curve1 = AnimationCurve.Linear(0, 0, 1, 1);
  164. color2_start = new Color(1, 1, 1, 1);
  165. color2_end = new Color(1, 1, 1, 1);
  166. curve2 = AnimationCurve.Linear(0, 0, 1, 1);
  167. strength = 1;
  168. active = true;
  169. radius = 300;
  170. repeat = 4;
  171. }
  172. }
  173. [Serializable]
  174. public enum image_output_enum
  175. {
  176. add,
  177. subtract,
  178. change,
  179. multiply,
  180. divide,
  181. difference,
  182. average,
  183. max,
  184. min,
  185. content
  186. }
  187. [Serializable]
  188. public class JPGEncoder_class
  189. {
  190. private int[] ZigZag;
  191. private int[] YTable;
  192. private int[] UVTable;
  193. private float[] fdtbl_Y;
  194. private float[] fdtbl_UV;
  195. private BitString[] YDC_HT;
  196. private BitString[] UVDC_HT;
  197. private BitString[] YAC_HT;
  198. private BitString[] UVAC_HT;
  199. private int[] std_dc_luminance_nrcodes;
  200. private int[] std_dc_luminance_values;
  201. private int[] std_ac_luminance_nrcodes;
  202. private int[] std_ac_luminance_values;
  203. private int[] std_dc_chrominance_nrcodes;
  204. private int[] std_dc_chrominance_values;
  205. private int[] std_ac_chrominance_nrcodes;
  206. private int[] std_ac_chrominance_values;
  207. private BitString[] bitcode;
  208. private int[] category;
  209. private int bytenew;
  210. private int bytepos;
  211. private ByteArray byteout;
  212. private int[] DU;
  213. private float[] YDU;
  214. private float[] UDU;
  215. private float[] VDU;
  216. public bool isDone;
  217. private BitmapData image;
  218. private int sf;
  219. public JPGEncoder_class(Texture2D texture, float quality)
  220. {
  221. ZigZag = new int[]
  222. {
  223. 0,
  224. 1,
  225. 5,
  226. 6,
  227. 14,
  228. 15,
  229. 27,
  230. 28,
  231. 2,
  232. 4,
  233. 7,
  234. 13,
  235. 16,
  236. 26,
  237. 29,
  238. 42,
  239. 3,
  240. 8,
  241. 12,
  242. 17,
  243. 25,
  244. 30,
  245. 41,
  246. 43,
  247. 9,
  248. 11,
  249. 18,
  250. 24,
  251. 31,
  252. 40,
  253. 44,
  254. 53,
  255. 10,
  256. 19,
  257. 23,
  258. 32,
  259. 39,
  260. 45,
  261. 52,
  262. 54,
  263. 20,
  264. 22,
  265. 33,
  266. 38,
  267. 46,
  268. 51,
  269. 55,
  270. 60,
  271. 21,
  272. 34,
  273. 37,
  274. 47,
  275. 50,
  276. 56,
  277. 59,
  278. 61,
  279. 35,
  280. 36,
  281. 48,
  282. 49,
  283. 57,
  284. 58,
  285. 62,
  286. 63
  287. };
  288. YTable = new int[64];
  289. UVTable = new int[64];
  290. fdtbl_Y = new float[64];
  291. fdtbl_UV = new float[64];
  292. std_dc_luminance_nrcodes = new int[]
  293. {
  294. 0,
  295. 0,
  296. 1,
  297. 5,
  298. 1,
  299. 1,
  300. 1,
  301. 1,
  302. 1,
  303. 1,
  304. 0,
  305. 0,
  306. 0,
  307. 0,
  308. 0,
  309. 0,
  310. 0
  311. };
  312. std_dc_luminance_values = new int[]
  313. {
  314. 0,
  315. 1,
  316. 2,
  317. 3,
  318. 4,
  319. 5,
  320. 6,
  321. 7,
  322. 8,
  323. 9,
  324. 10,
  325. 11
  326. };
  327. std_ac_luminance_nrcodes = new int[]
  328. {
  329. 0,
  330. 0,
  331. 2,
  332. 1,
  333. 3,
  334. 3,
  335. 2,
  336. 4,
  337. 3,
  338. 5,
  339. 5,
  340. 4,
  341. 4,
  342. 0,
  343. 0,
  344. 1,
  345. 125
  346. };
  347. std_ac_luminance_values = new int[]
  348. {
  349. 1,
  350. 2,
  351. 3,
  352. 0,
  353. 4,
  354. 17,
  355. 5,
  356. 18,
  357. 33,
  358. 49,
  359. 65,
  360. 6,
  361. 19,
  362. 81,
  363. 97,
  364. 7,
  365. 34,
  366. 113,
  367. 20,
  368. 50,
  369. 129,
  370. 145,
  371. 161,
  372. 8,
  373. 35,
  374. 66,
  375. 177,
  376. 193,
  377. 21,
  378. 82,
  379. 209,
  380. 240,
  381. 36,
  382. 51,
  383. 98,
  384. 114,
  385. 130,
  386. 9,
  387. 10,
  388. 22,
  389. 23,
  390. 24,
  391. 25,
  392. 26,
  393. 37,
  394. 38,
  395. 39,
  396. 40,
  397. 41,
  398. 42,
  399. 52,
  400. 53,
  401. 54,
  402. 55,
  403. 56,
  404. 57,
  405. 58,
  406. 67,
  407. 68,
  408. 69,
  409. 70,
  410. 71,
  411. 72,
  412. 73,
  413. 74,
  414. 83,
  415. 84,
  416. 85,
  417. 86,
  418. 87,
  419. 88,
  420. 89,
  421. 90,
  422. 99,
  423. 100,
  424. 101,
  425. 102,
  426. 103,
  427. 104,
  428. 105,
  429. 106,
  430. 115,
  431. 116,
  432. 117,
  433. 118,
  434. 119,
  435. 120,
  436. 121,
  437. 122,
  438. 131,
  439. 132,
  440. 133,
  441. 134,
  442. 135,
  443. 136,
  444. 137,
  445. 138,
  446. 146,
  447. 147,
  448. 148,
  449. 149,
  450. 150,
  451. 151,
  452. 152,
  453. 153,
  454. 154,
  455. 162,
  456. 163,
  457. 164,
  458. 165,
  459. 166,
  460. 167,
  461. 168,
  462. 169,
  463. 170,
  464. 178,
  465. 179,
  466. 180,
  467. 181,
  468. 182,
  469. 183,
  470. 184,
  471. 185,
  472. 186,
  473. 194,
  474. 195,
  475. 196,
  476. 197,
  477. 198,
  478. 199,
  479. 200,
  480. 201,
  481. 202,
  482. 210,
  483. 211,
  484. 212,
  485. 213,
  486. 214,
  487. 215,
  488. 216,
  489. 217,
  490. 218,
  491. 225,
  492. 226,
  493. 227,
  494. 228,
  495. 229,
  496. 230,
  497. 231,
  498. 232,
  499. 233,
  500. 234,
  501. 241,
  502. 242,
  503. 243,
  504. 244,
  505. 245,
  506. 246,
  507. 247,
  508. 248,
  509. 249,
  510. 250
  511. };
  512. std_dc_chrominance_nrcodes = new int[]
  513. {
  514. 0,
  515. 0,
  516. 3,
  517. 1,
  518. 1,
  519. 1,
  520. 1,
  521. 1,
  522. 1,
  523. 1,
  524. 1,
  525. 1,
  526. 0,
  527. 0,
  528. 0,
  529. 0,
  530. 0
  531. };
  532. std_dc_chrominance_values = new int[]
  533. {
  534. 0,
  535. 1,
  536. 2,
  537. 3,
  538. 4,
  539. 5,
  540. 6,
  541. 7,
  542. 8,
  543. 9,
  544. 10,
  545. 11
  546. };
  547. std_ac_chrominance_nrcodes = new int[]
  548. {
  549. 0,
  550. 0,
  551. 2,
  552. 1,
  553. 2,
  554. 4,
  555. 4,
  556. 3,
  557. 4,
  558. 7,
  559. 5,
  560. 4,
  561. 4,
  562. 0,
  563. 1,
  564. 2,
  565. 119
  566. };
  567. std_ac_chrominance_values = new int[]
  568. {
  569. 0,
  570. 1,
  571. 2,
  572. 3,
  573. 17,
  574. 4,
  575. 5,
  576. 33,
  577. 49,
  578. 6,
  579. 18,
  580. 65,
  581. 81,
  582. 7,
  583. 97,
  584. 113,
  585. 19,
  586. 34,
  587. 50,
  588. 129,
  589. 8,
  590. 20,
  591. 66,
  592. 145,
  593. 161,
  594. 177,
  595. 193,
  596. 9,
  597. 35,
  598. 51,
  599. 82,
  600. 240,
  601. 21,
  602. 98,
  603. 114,
  604. 209,
  605. 10,
  606. 22,
  607. 36,
  608. 52,
  609. 225,
  610. 37,
  611. 241,
  612. 23,
  613. 24,
  614. 25,
  615. 26,
  616. 38,
  617. 39,
  618. 40,
  619. 41,
  620. 42,
  621. 53,
  622. 54,
  623. 55,
  624. 56,
  625. 57,
  626. 58,
  627. 67,
  628. 68,
  629. 69,
  630. 70,
  631. 71,
  632. 72,
  633. 73,
  634. 74,
  635. 83,
  636. 84,
  637. 85,
  638. 86,
  639. 87,
  640. 88,
  641. 89,
  642. 90,
  643. 99,
  644. 100,
  645. 101,
  646. 102,
  647. 103,
  648. 104,
  649. 105,
  650. 106,
  651. 115,
  652. 116,
  653. 117,
  654. 118,
  655. 119,
  656. 120,
  657. 121,
  658. 122,
  659. 130,
  660. 131,
  661. 132,
  662. 133,
  663. 134,
  664. 135,
  665. 136,
  666. 137,
  667. 138,
  668. 146,
  669. 147,
  670. 148,
  671. 149,
  672. 150,
  673. 151,
  674. 152,
  675. 153,
  676. 154,
  677. 162,
  678. 163,
  679. 164,
  680. 165,
  681. 166,
  682. 167,
  683. 168,
  684. 169,
  685. 170,
  686. 178,
  687. 179,
  688. 180,
  689. 181,
  690. 182,
  691. 183,
  692. 184,
  693. 185,
  694. 186,
  695. 194,
  696. 195,
  697. 196,
  698. 197,
  699. 198,
  700. 199,
  701. 200,
  702. 201,
  703. 202,
  704. 210,
  705. 211,
  706. 212,
  707. 213,
  708. 214,
  709. 215,
  710. 216,
  711. 217,
  712. 218,
  713. 226,
  714. 227,
  715. 228,
  716. 229,
  717. 230,
  718. 231,
  719. 232,
  720. 233,
  721. 234,
  722. 242,
  723. 243,
  724. 244,
  725. 245,
  726. 246,
  727. 247,
  728. 248,
  729. 249,
  730. 250
  731. };
  732. bitcode = new BitString[65535];
  733. category = new int[65535];
  734. bytepos = 7;
  735. byteout = new ByteArray();
  736. DU = new int[64];
  737. YDU = new float[64];
  738. UDU = new float[64];
  739. VDU = new float[64];
  740. image = new BitmapData(texture);
  741. if (quality <= 0)
  742. {
  743. quality = 1;
  744. }
  745. if (quality > 100)
  746. {
  747. quality = 100;
  748. }
  749. if (quality < 50)
  750. {
  751. sf = (int)(5000 / quality);
  752. }
  753. else
  754. {
  755. sf = (int)(200 - quality * 2);
  756. }
  757. Thread thread = new Thread(new ThreadStart(doEncoding));
  758. thread.Start();
  759. }
  760. private void initQuantTables(int sf)
  761. {
  762. int i;
  763. float num;
  764. int[] array = new int[]
  765. {
  766. 16,
  767. 11,
  768. 10,
  769. 16,
  770. 24,
  771. 40,
  772. 51,
  773. 61,
  774. 12,
  775. 12,
  776. 14,
  777. 19,
  778. 26,
  779. 58,
  780. 60,
  781. 55,
  782. 14,
  783. 13,
  784. 16,
  785. 24,
  786. 40,
  787. 57,
  788. 69,
  789. 56,
  790. 14,
  791. 17,
  792. 22,
  793. 29,
  794. 51,
  795. 87,
  796. 80,
  797. 62,
  798. 18,
  799. 22,
  800. 37,
  801. 56,
  802. 68,
  803. 109,
  804. 103,
  805. 77,
  806. 24,
  807. 35,
  808. 55,
  809. 64,
  810. 81,
  811. 104,
  812. 113,
  813. 92,
  814. 49,
  815. 64,
  816. 78,
  817. 87,
  818. 103,
  819. 121,
  820. 120,
  821. 101,
  822. 72,
  823. 92,
  824. 95,
  825. 98,
  826. 112,
  827. 100,
  828. 103,
  829. 99
  830. };
  831. for (i = 0; i < 64; i++)
  832. {
  833. num = Mathf.Floor((array[i] * sf + 50) / 100);
  834. if (num < 1)
  835. {
  836. num = 1;
  837. }
  838. else if (num > 255)
  839. {
  840. num = 255;
  841. }
  842. YTable[ZigZag[i]] = (int)num;
  843. }
  844. int[] array2 = new int[]
  845. {
  846. 17,
  847. 18,
  848. 24,
  849. 47,
  850. 99,
  851. 99,
  852. 99,
  853. 99,
  854. 18,
  855. 21,
  856. 26,
  857. 66,
  858. 99,
  859. 99,
  860. 99,
  861. 99,
  862. 24,
  863. 26,
  864. 56,
  865. 99,
  866. 99,
  867. 99,
  868. 99,
  869. 99,
  870. 47,
  871. 66,
  872. 99,
  873. 99,
  874. 99,
  875. 99,
  876. 99,
  877. 99,
  878. 99,
  879. 99,
  880. 99,
  881. 99,
  882. 99,
  883. 99,
  884. 99,
  885. 99,
  886. 99,
  887. 99,
  888. 99,
  889. 99,
  890. 99,
  891. 99,
  892. 99,
  893. 99,
  894. 99,
  895. 99,
  896. 99,
  897. 99,
  898. 99,
  899. 99,
  900. 99,
  901. 99,
  902. 99,
  903. 99,
  904. 99,
  905. 99,
  906. 99,
  907. 99,
  908. 99,
  909. 99
  910. };
  911. for (i = 0; i < 64; i++)
  912. {
  913. num = Mathf.Floor((array2[i] * sf + 50) / 100);
  914. if (num < 1)
  915. {
  916. num = 1;
  917. }
  918. else if (num > 255)
  919. {
  920. num = 255;
  921. }
  922. UVTable[ZigZag[i]] = (int)num;
  923. }
  924. float[] array3 = new float[]
  925. {
  926. 1f,
  927. 1.3870399f,
  928. 1.306563f,
  929. 1.17587554f,
  930. 1f,
  931. 0.785694957f,
  932. 0.5411961f,
  933. 0.27589938f
  934. };
  935. i = 0;
  936. for (int j = 0; j < 8; j++)
  937. {
  938. for (int k = 0; k < 8; k++)
  939. {
  940. fdtbl_Y[i] = 1f / (YTable[ZigZag[i]] * array3[j] * array3[k] * 8f);
  941. fdtbl_UV[i] = 1f / (UVTable[ZigZag[i]] * array3[j] * array3[k] * 8f);
  942. i++;
  943. }
  944. }
  945. }
  946. private BitString[] computeHuffmanTbl(int[] nrcodes, int[] std_table)
  947. {
  948. int num = 0;
  949. int num2 = 0;
  950. BitString[] array = new BitString[256];
  951. for (int i = 1; i <= 16; i++)
  952. {
  953. for (int j = 1; j <= nrcodes[i]; j++)
  954. {
  955. array[std_table[num2]] = new BitString();
  956. array[std_table[num2]].val = num;
  957. array[std_table[num2]].len = i;
  958. num2++;
  959. num++;
  960. }
  961. num *= 2;
  962. }
  963. return array;
  964. }
  965. private void initHuffmanTbl()
  966. {
  967. YDC_HT = computeHuffmanTbl(std_dc_luminance_nrcodes, std_dc_luminance_values);
  968. UVDC_HT = computeHuffmanTbl(std_dc_chrominance_nrcodes, std_dc_chrominance_values);
  969. YAC_HT = computeHuffmanTbl(std_ac_luminance_nrcodes, std_ac_luminance_values);
  970. UVAC_HT = computeHuffmanTbl(std_ac_chrominance_nrcodes, std_ac_chrominance_values);
  971. }
  972. private void initCategoryfloat()
  973. {
  974. int num = 1;
  975. int num2 = 2;
  976. int i;
  977. for (int j = 1; j <= 15; j++)
  978. {
  979. for (i = num; i < num2; i++)
  980. {
  981. category[32767 + i] = j;
  982. BitString bitString = new BitString();
  983. bitString.len = j;
  984. bitString.val = i;
  985. bitcode[32767 + i] = bitString;
  986. }
  987. for (i = -(num2 - 1); i <= -num; i++)
  988. {
  989. category[32767 + i] = j;
  990. BitString bitString = new BitString();
  991. bitString.len = j;
  992. bitString.val = num2 - 1 + i;
  993. bitcode[32767 + i] = bitString;
  994. }
  995. num <<= 1;
  996. num2 <<= 1;
  997. }
  998. }
  999. public byte[] GetBytes()
  1000. {
  1001. byte[] arg_28_0;
  1002. if (!isDone)
  1003. {
  1004. Debug.LogError("JPEGEncoder not complete, cannot get bytes!");
  1005. arg_28_0 = null;
  1006. }
  1007. else
  1008. {
  1009. arg_28_0 = byteout.GetAllBytes();
  1010. }
  1011. return arg_28_0;
  1012. }
  1013. private void writeBits(BitString bs)
  1014. {
  1015. int val = bs.val;
  1016. int i = bs.len - 1;
  1017. while (i >= 0)
  1018. {
  1019. if ((int)(val & Convert.ToUInt32(1 << i)) != 0)
  1020. {
  1021. bytenew = bytenew | (int)Convert.ToUInt32(1 << bytepos);
  1022. }
  1023. i--;
  1024. bytepos--;
  1025. if (bytepos < 0)
  1026. {
  1027. if (bytenew == 255)
  1028. {
  1029. writeByte(255);
  1030. writeByte(0);
  1031. }
  1032. else
  1033. {
  1034. writeByte((byte)bytenew);
  1035. }
  1036. bytepos = 7;
  1037. bytenew = 0;
  1038. }
  1039. }
  1040. }
  1041. private void writeByte(byte value)
  1042. {
  1043. byteout.writeByte(value);
  1044. }
  1045. private void writeWord(int value)
  1046. {
  1047. writeByte((byte)(value >> 8 & 255));
  1048. writeByte((byte)(value & 255));
  1049. }
  1050. private float[] fDCTQuant(float[] data, float[] fdtbl)
  1051. {
  1052. float num;
  1053. float num2;
  1054. float num3;
  1055. float num4;
  1056. float num5;
  1057. float num6;
  1058. float num7;
  1059. float num8;
  1060. float num9;
  1061. float num10;
  1062. float num11;
  1063. float num12;
  1064. float num13;
  1065. float num14;
  1066. float num15;
  1067. float num16;
  1068. float num17;
  1069. float num18;
  1070. float num19;
  1071. int i;
  1072. int num20 = 0;
  1073. for (i = 0; i < 8; i++)
  1074. {
  1075. num = data[num20 + 0] + data[num20 + 7];
  1076. num8 = data[num20 + 0] - data[num20 + 7];
  1077. num2 = data[num20 + 1] + data[num20 + 6];
  1078. num7 = data[num20 + 1] - data[num20 + 6];
  1079. num3 = data[num20 + 2] + data[num20 + 5];
  1080. num6 = data[num20 + 2] - data[num20 + 5];
  1081. num4 = data[num20 + 3] + data[num20 + 4];
  1082. num5 = data[num20 + 3] - data[num20 + 4];
  1083. num9 = num + num4;
  1084. num12 = num - num4;
  1085. num10 = num2 + num3;
  1086. num11 = num2 - num3;
  1087. data[num20 + 0] = num9 + num10;
  1088. data[num20 + 4] = num9 - num10;
  1089. num13 = (num11 + num12) * 0.707106769f;
  1090. data[num20 + 2] = num12 + num13;
  1091. data[num20 + 6] = num12 - num13;
  1092. num9 = num5 + num6;
  1093. num10 = num6 + num7;
  1094. num11 = num7 + num8;
  1095. num17 = (num9 - num11) * 0.382683426f;
  1096. num14 = 0.5411961f * num9 + num17;
  1097. num16 = 1.306563f * num11 + num17;
  1098. num15 = num10 * 0.707106769f;
  1099. num18 = num8 + num15;
  1100. num19 = num8 - num15;
  1101. data[num20 + 5] = num19 + num14;
  1102. data[num20 + 3] = num19 - num14;
  1103. data[num20 + 1] = num18 + num16;
  1104. data[num20 + 7] = num18 - num16;
  1105. num20 += 8;
  1106. }
  1107. num20 = 0;
  1108. for (i = 0; i < 8; i++)
  1109. {
  1110. num = data[num20 + 0] + data[num20 + 56];
  1111. num8 = data[num20 + 0] - data[num20 + 56];
  1112. num2 = data[num20 + 8] + data[num20 + 48];
  1113. num7 = data[num20 + 8] - data[num20 + 48];
  1114. num3 = data[num20 + 16] + data[num20 + 40];
  1115. num6 = data[num20 + 16] - data[num20 + 40];
  1116. num4 = data[num20 + 24] + data[num20 + 32];
  1117. num5 = data[num20 + 24] - data[num20 + 32];
  1118. num9 = num + num4;
  1119. num12 = num - num4;
  1120. num10 = num2 + num3;
  1121. num11 = num2 - num3;
  1122. data[num20 + 0] = num9 + num10;
  1123. data[num20 + 32] = num9 - num10;
  1124. num13 = (num11 + num12) * 0.707106769f;
  1125. data[num20 + 16] = num12 + num13;
  1126. data[num20 + 48] = num12 - num13;
  1127. num9 = num5 + num6;
  1128. num10 = num6 + num7;
  1129. num11 = num7 + num8;
  1130. num17 = (num9 - num11) * 0.382683426f;
  1131. num14 = 0.5411961f * num9 + num17;
  1132. num16 = 1.306563f * num11 + num17;
  1133. num15 = num10 * 0.707106769f;
  1134. num18 = num8 + num15;
  1135. num19 = num8 - num15;
  1136. data[num20 + 40] = num19 + num14;
  1137. data[num20 + 24] = num19 - num14;
  1138. data[num20 + 8] = num18 + num16;
  1139. data[num20 + 56] = num18 - num16;
  1140. num20++;
  1141. }
  1142. for (i = 0; i < 64; i++)
  1143. {
  1144. data[i] = Mathf.Round(data[i] * fdtbl[i]);
  1145. }
  1146. return data;
  1147. }
  1148. private void writeAPP0()
  1149. {
  1150. writeWord(65504);
  1151. writeWord(16);
  1152. writeByte(74);
  1153. writeByte(70);
  1154. writeByte(73);
  1155. writeByte(70);
  1156. writeByte(0);
  1157. writeByte(1);
  1158. writeByte(1);
  1159. writeByte(0);
  1160. writeWord(1);
  1161. writeWord(1);
  1162. writeByte(0);
  1163. writeByte(0);
  1164. }
  1165. private void writeSOF0(int width, int height)
  1166. {
  1167. writeWord(65472);
  1168. writeWord(17);
  1169. writeByte(8);
  1170. writeWord(height);
  1171. writeWord(width);
  1172. writeByte(3);
  1173. writeByte(1);
  1174. writeByte(17);
  1175. writeByte(0);
  1176. writeByte(2);
  1177. writeByte(17);
  1178. writeByte(1);
  1179. writeByte(3);
  1180. writeByte(17);
  1181. writeByte(1);
  1182. }
  1183. private void writeDQT()
  1184. {
  1185. writeWord(65499);
  1186. writeWord(132);
  1187. writeByte(0);
  1188. int i;
  1189. for (i = 0; i < 64; i++)
  1190. {
  1191. writeByte((byte)YTable[i]);
  1192. }
  1193. writeByte(1);
  1194. for (i = 0; i < 64; i++)
  1195. {
  1196. writeByte((byte)UVTable[i]);
  1197. }
  1198. }
  1199. private void writeDHT()
  1200. {
  1201. writeWord(65476);
  1202. writeWord(418);
  1203. int i;
  1204. writeByte(0);
  1205. for (i = 0; i < 16; i++)
  1206. {
  1207. writeByte((byte)std_dc_luminance_nrcodes[i + 1]);
  1208. }
  1209. for (i = 0; i <= 11; i++)
  1210. {
  1211. writeByte((byte)std_dc_luminance_values[i]);
  1212. }
  1213. writeByte(16);
  1214. for (i = 0; i < 16; i++)
  1215. {
  1216. writeByte((byte)std_ac_luminance_nrcodes[i + 1]);
  1217. }
  1218. for (i = 0; i <= 161; i++)
  1219. {
  1220. writeByte((byte)std_ac_luminance_values[i]);
  1221. }
  1222. writeByte(1);
  1223. for (i = 0; i < 16; i++)
  1224. {
  1225. writeByte((byte)std_dc_chrominance_nrcodes[i + 1]);
  1226. }
  1227. for (i = 0; i <= 11; i++)
  1228. {
  1229. writeByte((byte)std_dc_chrominance_values[i]);
  1230. }
  1231. writeByte(17);
  1232. for (i = 0; i < 16; i++)
  1233. {
  1234. writeByte((byte)std_ac_chrominance_nrcodes[i + 1]);
  1235. }
  1236. for (i = 0; i <= 161; i++)
  1237. {
  1238. writeByte((byte)std_ac_chrominance_values[i]);
  1239. }
  1240. }
  1241. private void writeSOS()
  1242. {
  1243. writeWord(65498);
  1244. writeWord(12);
  1245. writeByte(3);
  1246. writeByte(1);
  1247. writeByte(0);
  1248. writeByte(2);
  1249. writeByte(17);
  1250. writeByte(3);
  1251. writeByte(17);
  1252. writeByte(0);
  1253. writeByte(63);
  1254. writeByte(0);
  1255. }
  1256. private float processDU(float[] CDU, float[] fdtbl, float DC, BitString[] HTDC, BitString[] HTAC)
  1257. {
  1258. BitString bs = HTAC[0];
  1259. BitString bs2 = HTAC[240];
  1260. int i;
  1261. float[] array = fDCTQuant(CDU, fdtbl);
  1262. for (i = 0; i < 64; i++)
  1263. {
  1264. DU[ZigZag[i]] = (int)array[i];
  1265. }
  1266. int num = (int)(DU[0] - DC);
  1267. DC = DU[0];
  1268. if (num == 0)
  1269. {
  1270. writeBits(HTDC[0]);
  1271. }
  1272. else
  1273. {
  1274. writeBits(HTDC[category[32767 + num]]);
  1275. writeBits(bitcode[32767 + num]);
  1276. }
  1277. int num2 = 63;
  1278. while (num2 > 0 && DU[num2] == 0)
  1279. {
  1280. num2--;
  1281. }
  1282. float arg_1A8_0;
  1283. if (num2 == 0)
  1284. {
  1285. writeBits(bs);
  1286. arg_1A8_0 = DC;
  1287. }
  1288. else
  1289. {
  1290. for (i = 1; i <= num2; i++)
  1291. {
  1292. int num3 = i;
  1293. while (DU[i] == 0 && i <= num2)
  1294. {
  1295. i++;
  1296. }
  1297. int num4 = i - num3;
  1298. if (num4 >= 16)
  1299. {
  1300. for (int j = 1; j <= num4 / 16; j++)
  1301. {
  1302. writeBits(bs2);
  1303. }
  1304. num4 &= 15;
  1305. }
  1306. writeBits(HTAC[num4 * 16 + category[32767 + DU[i]]]);
  1307. writeBits(bitcode[32767 + DU[i]]);
  1308. }
  1309. if (num2 != 63)
  1310. {
  1311. writeBits(bs);
  1312. }
  1313. arg_1A8_0 = DC;
  1314. }
  1315. return arg_1A8_0;
  1316. }
  1317. private void RGB2YUV(BitmapData img, int xpos, int ypos)
  1318. {
  1319. int num = 0;
  1320. for (int i = 0; i < 8; i++)
  1321. {
  1322. for (int j = 0; j < 8; j++)
  1323. {
  1324. Color pixelColor = img.getPixelColor(xpos + j, img.height - (ypos + i));
  1325. float num2 = pixelColor.r * 255;
  1326. float num3 = pixelColor.g * 255;
  1327. float num4 = pixelColor.b * 255;
  1328. YDU[num] = 0.299f * num2 + 0.587f * num3 + 0.114f * num4 - 128;
  1329. UDU[num] = -0.16874f * num2 + -0.33126f * num3 + 0.5f * num4;
  1330. VDU[num] = 0.5f * num2 + -0.41869f * num3 + -0.08131f * num4;
  1331. num++;
  1332. }
  1333. }
  1334. }
  1335. private void doEncoding()
  1336. {
  1337. isDone = false;
  1338. Thread.Sleep(5);
  1339. initHuffmanTbl();
  1340. initCategoryfloat();
  1341. initQuantTables(sf);
  1342. encode();
  1343. isDone = true;
  1344. image = null;
  1345. Thread.CurrentThread.Abort();
  1346. }
  1347. private void encode()
  1348. {
  1349. byteout = new ByteArray();
  1350. bytenew = 0;
  1351. bytepos = 7;
  1352. writeWord(65496);
  1353. writeAPP0();
  1354. writeDQT();
  1355. writeSOF0(image.width, image.height);
  1356. writeDHT();
  1357. writeSOS();
  1358. float dC = 0;
  1359. float dC2 = 0;
  1360. float dC3 = 0;
  1361. bytenew = 0;
  1362. bytepos = 7;
  1363. for (int i = 0; i < image.height; i += 8)
  1364. {
  1365. for (int j = 0; j < image.width; j += 8)
  1366. {
  1367. RGB2YUV(image, j, i);
  1368. dC = processDU(YDU, fdtbl_Y, dC, YDC_HT, YAC_HT);
  1369. dC2 = processDU(UDU, fdtbl_UV, dC2, UVDC_HT, UVAC_HT);
  1370. dC3 = processDU(VDU, fdtbl_UV, dC3, UVDC_HT, UVAC_HT);
  1371. Thread.Sleep(0);
  1372. }
  1373. }
  1374. if (bytepos >= 0)
  1375. {
  1376. writeBits(new BitString
  1377. {
  1378. len = bytepos + 1,
  1379. val = (1 << bytepos + 1) - 1
  1380. });
  1381. }
  1382. writeWord(65497);
  1383. isDone = true;
  1384. }
  1385. }
  1386. #endif
  1387. [Serializable]
  1388. public class latlong_area_class
  1389. {
  1390. public latlong_class latlong1;
  1391. public latlong_class latlong2;
  1392. public latlong_area_class()
  1393. {
  1394. latlong1 = new latlong_class();
  1395. latlong2 = new latlong_class();
  1396. }
  1397. }
  1398. [Serializable]
  1399. public class latlong_class
  1400. {
  1401. public double latitude;
  1402. public double longitude;
  1403. public latlong_class()
  1404. {
  1405. }
  1406. public latlong_class(double latitude1, double longitude1)
  1407. {
  1408. latitude = latitude1;
  1409. longitude = longitude1;
  1410. }
  1411. public void reset()
  1412. {
  1413. latitude = 0;
  1414. longitude = 0;
  1415. }
  1416. }
  1417. }