document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. import java.awt.*;
  2. import java.awt.image.*;
  3. import javax.swing.*;
  4. /**
  5. * hana
  6. * OFImage is a class that defines an image in OF (Objects First) format.
  7. *
  8. * @author Michael Kolling and David J. Barnes
  9. * @version 1.1
  10. */
  11. public class OFImage extends BufferedImage
  12. {
  13. /**
  14. * Create an OFImage copied from a BufferedImage.
  15. * @param image The image to copy.
  16. */
  17. public OFImage(BufferedImage image)
  18. {
  19. super(image.getColorModel(), image.copyData(null),
  20. image.isAlphaPremultiplied(), null);
  21. }
  22. /**
  23. * Create an OFImage with specified size and unspecified content.
  24. * @param width The width of the image.
  25. * @param height The height of the image.
  26. */
  27. public OFImage(int width, int height)
  28. {
  29. super(width, height, TYPE_INT_RGB);
  30. }
  31. /**
  32. * Set a given pixel of this image to a specified color. The
  33. * color is represented as an (r,g,b) value.
  34. * @param x The x position of the pixel.
  35. * @param y The y position of the pixel.
  36. * @param col The color of the pixel.
  37. */
  38. public void setPixel(int x, int y, Color col)
  39. {
  40. int pixel = col.getRGB();
  41. setRGB(x, y, pixel);
  42. }
  43. /**
  44. * Get the color value at a specified pixel position.
  45. * @param x The x position of the pixel.
  46. * @param y The y position of the pixel.
  47. * @return The color of the pixel at the given position.
  48. */
  49. public Color getPixel(int x, int y)
  50. {
  51. int pixel = getRGB(x, y);
  52. return new Color(pixel);
  53. }
  54. /**
  55. * Make this image a bit darker.
  56. */
  57. public void darker()
  58. {
  59. int height = getHeight();
  60. int width = getWidth();
  61. for(int y = 0; y < height; y++) {
  62. for(int x = 0; x < width; x++) {
  63. setPixel(x, y, getPixel(x, y).darker());
  64. }
  65. }
  66. }
  67. /**
  68. * Make this image a bit lighter.
  69. */
  70. public void lighter()
  71. {
  72. int height = getHeight();
  73. int width = getWidth();
  74. for(int y = 0; y < height; y++) {
  75. for(int x = 0; x < width; x++) {
  76. setPixel(x, y, getPixel(x, y).brighter());
  77. }
  78. }
  79. }
  80. /**
  81. * Perform a three level threshold operation.
  82. * That is: repaint the image with only three color values:
  83. * white, gray, and black.
  84. */
  85. public void threshold()
  86. {
  87. int height = getHeight();
  88. int width = getWidth();
  89. for(int y = 0; y < height; y++) {
  90. for(int x = 0; x < width; x++) {
  91. Color pixel = getPixel(x, y);
  92. int brightness = (pixel.getRed() + pixel.getBlue() + pixel.getGreen()) / 3;
  93. if(brightness <= 85) {
  94. setPixel(x, y, Color.BLACK);
  95. }
  96. else if(brightness <= 170) {
  97. setPixel(x, y, Color.GRAY);
  98. }
  99. else {
  100. setPixel(x, y, Color.WHITE);
  101. }
  102. }
  103. }
  104. }
  105. }
');