Advertisement
Guest User

Untitled

a guest
Jul 5th, 2014
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.11 KB | None | 0 0
  1. package net.minecraft.client.renderer;
  2.  
  3. import cpw.mods.fml.relauncher.Side;
  4. import cpw.mods.fml.relauncher.SideOnly;
  5. import java.awt.Graphics;
  6. import java.awt.image.BufferedImage;
  7. import java.awt.image.DataBufferInt;
  8. import java.awt.image.ImageObserver;
  9.  
  10. @SideOnly(Side.CLIENT)
  11. public class ImageBufferDownload implements IImageBuffer
  12. {
  13. private int[] imageData;
  14. private int imageWidth;
  15. private int imageHeight;
  16.  
  17. public BufferedImage parseUserSkin(BufferedImage par1BufferedImage)
  18. {
  19. if (par1BufferedImage == null)
  20. {
  21. return null;
  22. }
  23. else
  24. {
  25. this.imageWidth = par1BufferedImage.getWidth();
  26. this.imageHeight = par1BufferedImage.getHeight();
  27. if(this.imageHeight != this.imageWidth/2){
  28. return null;
  29. }
  30. BufferedImage var2 = new BufferedImage(this.imageWidth, this.imageHeight, 2);
  31. Graphics var3 = var2.getGraphics();
  32. var3.drawImage(par1BufferedImage, 0, 0, (ImageObserver)null);
  33. var3.dispose();
  34. this.imageData = ((DataBufferInt)var2.getRaster().getDataBuffer()).getData();
  35. this.setAreaOpaque(0, 0, this.imageHeight, this.imageHeight/2);
  36. this.setAreaTransparent(this.imageHeight, 0, this.imageWidth, this.imageHeight);
  37. this.setAreaOpaque(0, this.imageHeight / 2, this.imageWidth, this.imageHeight);
  38. return var2;
  39. }
  40. }
  41.  
  42. /**
  43. * Makes the given area of the image transparent if it was previously completely opaque (used to remove the outer
  44. * layer of a skin around the head if it was saved all opaque; this would be redundant so it's assumed that the skin
  45. * maker is just using an image editor without an alpha channel)
  46. */
  47. private void setAreaTransparent(int par1, int par2, int par3, int par4)
  48. {
  49. if (!this.hasTransparency(par1, par2, par3, par4))
  50. {
  51. for (int i1 = par1; i1 < par3; ++i1)
  52. {
  53. for (int j1 = par2; j1 < par4; ++j1)
  54. {
  55. this.imageData[i1 + j1 * this.imageWidth] &= 16777215;
  56. }
  57. }
  58. }
  59. }
  60.  
  61. /**
  62. * Makes the given area of the image opaque
  63. */
  64. private void setAreaOpaque(int par1, int par2, int par3, int par4)
  65. {
  66. for (int i1 = par1; i1 < par3; ++i1)
  67. {
  68. for (int j1 = par2; j1 < par4; ++j1)
  69. {
  70. this.imageData[i1 + j1 * this.imageWidth] |= -16777216;
  71. }
  72. }
  73. }
  74.  
  75. /**
  76. * Returns true if the given area of the image contains transparent pixels
  77. */
  78. private boolean hasTransparency(int par1, int par2, int par3, int par4)
  79. {
  80. for (int i1 = par1; i1 < par3; ++i1)
  81. {
  82. for (int j1 = par2; j1 < par4; ++j1)
  83. {
  84. int k1 = this.imageData[i1 + j1 * this.imageWidth];
  85.  
  86. if ((k1 >> 24 & 255) < 128)
  87. {
  88. return true;
  89. }
  90. }
  91. }
  92.  
  93. return false;
  94. }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement