PreviewResolutionSelector.java 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. package com.epson.cameracopy.device;
  2. import com.epson.mobilephone.common.wifidirect.ActivityControlWiFi;
  3. import org.opencv.videoio.Videoio;
  4. import java.util.Iterator;
  5. public class PreviewResolutionSelector {
  6. static SizeWrapper selectSize01(double d, Iterable<SizeWrapper> iterable, int i, int i2) {
  7. int score01;
  8. if (iterable == null || d < 1.0d) {
  9. return null;
  10. }
  11. int i3 = 0;
  12. SizeWrapper simpleSize = new SimpleSize(0, 0);
  13. for (SizeWrapper next : iterable) {
  14. int width = next.getWidth();
  15. int height = next.getHeight();
  16. if (width <= i && height > 0 && Math.abs(((width) / (height)) - d) < 0.05d && i3 < (score01 = getScore01(height, i2))) {
  17. simpleSize = next;
  18. i3 = score01;
  19. }
  20. }
  21. if (simpleSize.getWidth() <= 0) {
  22. return null;
  23. }
  24. return simpleSize;
  25. }
  26. static int getScore01(int i, int i2) {
  27. if (i < 400 || i > i2) {
  28. return 0;
  29. }
  30. if (i <= 600) {
  31. return ((i - 400) * 5) + 9000;
  32. }
  33. return i2 <= 600 ? ActivityControlWiFi.SCANNING_TIMEOUT : (((i - Videoio.CAP_UNICAP) * -1000) / (i2 - Videoio.CAP_UNICAP)) + ActivityControlWiFi.SCANNING_TIMEOUT;
  34. }
  35. static SizeWrapper selectSize02(double d, Iterable<SizeWrapper> iterable, int i, int i2) {
  36. if (iterable == null || d < 1.0d) {
  37. return null;
  38. }
  39. Iterator<SizeWrapper> it = iterable.iterator();
  40. if (!it.hasNext()) {
  41. return null;
  42. }
  43. SizeWrapper next = it.next();
  44. double score03 = getScore03(next.getWidth(), next.getHeight(), i, i2, d);
  45. while (it.hasNext()) {
  46. SizeWrapper next2 = it.next();
  47. double score032 = getScore03(next2.getWidth(), next2.getHeight(), i, i2, d);
  48. if (score03 < score032) {
  49. next = next2;
  50. score03 = score032;
  51. }
  52. }
  53. return next;
  54. }
  55. static double getScore03(int i, int i2, int i3, int i4, double d) {
  56. int score02 = i <= i3 ? getScore02(i2, i4) : 0;
  57. if (score02 <= 0) {
  58. return 0.0d;
  59. }
  60. return (score02) * getAspectScore((i) / (i2), d);
  61. }
  62. static int getScore02(int i, int i2) {
  63. int score01 = getScore01(i, i2);
  64. if (score01 > 0) {
  65. return score01;
  66. }
  67. if (i >= 200 && i < 400) {
  68. return ((i - 200) * 90) / 2;
  69. }
  70. return 0;
  71. }
  72. static double getAspectScore(double d, double d2) {
  73. double abs = (Math.abs(d2 - d) * -0.5d) + 1.0d;
  74. if (abs < 0.0d) {
  75. return 0.0d;
  76. }
  77. return abs;
  78. }
  79. }