ImageBufferDownload .java

net.minecraft.client.renderer.ImageBufferDownload (class, 117 lines): members: imageHeight, imageWidth, imageData, parseUserSkin, skinAvailable.

net.minecraft.client.rendererclass117 linesclient4.4 KB

Implements

API Surface (2)

BufferedImage parseUserSkin(BufferedImage image)
void skinAvailable()

Fields & Constants (3)

imageData
imageWidth
imageHeight

Code Graph: Dependencies (1)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

ImageBufferDownload.java117 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.client.renderer;
2
3
import java.awt.Graphics;
4
import java.awt.image.BufferedImage;
5
import java.awt.image.DataBufferInt;
6
import java.awt.image.ImageObserver;
7
8
public class ImageBufferDownload implements IImageBuffer
9
{
10
    private int[] imageData;
11
    private int imageWidth;
12
    private int imageHeight;
13
14
    public BufferedImage parseUserSkin(BufferedImage image)
15
    {
16
        if (image == null)
17
        {
18
            return null;
19
        }
20
        else
21
        {
22
            this.imageWidth = 64;
23
            this.imageHeight = 64;
24
            BufferedImage bufferedimage = new BufferedImage(this.imageWidth, this.imageHeight, 2);
25
            Graphics graphics = bufferedimage.getGraphics();
26
            graphics.drawImage(image, 0, 0, (ImageObserver)null);
27
28
            if (image.getHeight() == 32)
29
            {
30
                graphics.drawImage(bufferedimage, 24, 48, 20, 52, 4, 16, 8, 20, (ImageObserver)null);
31
                graphics.drawImage(bufferedimage, 28, 48, 24, 52, 8, 16, 12, 20, (ImageObserver)null);
32
                graphics.drawImage(bufferedimage, 20, 52, 16, 64, 8, 20, 12, 32, (ImageObserver)null);
33
                graphics.drawImage(bufferedimage, 24, 52, 20, 64, 4, 20, 8, 32, (ImageObserver)null);
34
                graphics.drawImage(bufferedimage, 28, 52, 24, 64, 0, 20, 4, 32, (ImageObserver)null);
35
                graphics.drawImage(bufferedimage, 32, 52, 28, 64, 12, 20, 16, 32, (ImageObserver)null);
36
                graphics.drawImage(bufferedimage, 40, 48, 36, 52, 44, 16, 48, 20, (ImageObserver)null);
37
                graphics.drawImage(bufferedimage, 44, 48, 40, 52, 48, 16, 52, 20, (ImageObserver)null);
38
                graphics.drawImage(bufferedimage, 36, 52, 32, 64, 48, 20, 52, 32, (ImageObserver)null);
39
                graphics.drawImage(bufferedimage, 40, 52, 36, 64, 44, 20, 48, 32, (ImageObserver)null);
40
                graphics.drawImage(bufferedimage, 44, 52, 40, 64, 40, 20, 44, 32, (ImageObserver)null);
41
                graphics.drawImage(bufferedimage, 48, 52, 44, 64, 52, 20, 56, 32, (ImageObserver)null);
42
            }
43
44
            graphics.dispose();
45
            this.imageData = ((DataBufferInt)bufferedimage.getRaster().getDataBuffer()).getData();
46
            this.setAreaOpaque(0, 0, 32, 16);
47
            this.setAreaTransparent(32, 0, 64, 32);
48
            this.setAreaOpaque(0, 16, 64, 32);
49
            this.setAreaTransparent(0, 32, 16, 48);
50
            this.setAreaTransparent(16, 32, 40, 48);
51
            this.setAreaTransparent(40, 32, 56, 48);
52
            this.setAreaTransparent(0, 48, 16, 64);
53
            this.setAreaOpaque(16, 48, 48, 64);
54
            this.setAreaTransparent(48, 48, 64, 64);
55
            return bufferedimage;
56
        }
57
    }
58
59
    public void skinAvailable()
60
    {
61
    }
62
63
    /**
64
     * Makes the given area of the image transparent if it was previously completely opaque (used to remove the outer
65
     * layer of a skin around the head if it was saved all opaque; this would be redundant so it's assumed that the skin
66
     * maker is just using an image editor without an alpha channel)
67
     */
68
    private void setAreaTransparent(int p_78434_1_, int p_78434_2_, int p_78434_3_, int p_78434_4_)
69
    {
70
        if (!this.hasTransparency(p_78434_1_, p_78434_2_, p_78434_3_, p_78434_4_))
71
        {
72
            for (int i = p_78434_1_; i < p_78434_3_; ++i)
73
            {
74
                for (int j = p_78434_2_; j < p_78434_4_; ++j)
75
                {
76
                    this.imageData[i + j * this.imageWidth] &= 16777215;
77
                }
78
            }
79
        }
80
    }
81
82
    /**
83
     * Makes the given area of the image opaque
84
     */
85
    private void setAreaOpaque(int p_78433_1_, int p_78433_2_, int p_78433_3_, int p_78433_4_)
86
    {
87
        for (int i = p_78433_1_; i < p_78433_3_; ++i)
88
        {
89
            for (int j = p_78433_2_; j < p_78433_4_; ++j)
90
            {
91
                this.imageData[i + j * this.imageWidth] |= -16777216;
92
            }
93
        }
94
    }
95
96
    /**
97
     * Returns true if the given area of the image contains transparent pixels
98
     */
99
    private boolean hasTransparency(int p_78435_1_, int p_78435_2_, int p_78435_3_, int p_78435_4_)
100
    {
101
        for (int i = p_78435_1_; i < p_78435_3_; ++i)
102
        {
103
            for (int j = p_78435_2_; j < p_78435_4_; ++j)
104
            {
105
                int k = this.imageData[i + j * this.imageWidth];
106
107
                if ((k >> 24 & 255) < 128)
108
                {
109
                    return true;
110
                }
111
            }
112
        }
113
114
        return false;
115
    }
116
}
117

Deobfuscated MCP 1.8.9 source of ImageBufferDownload from Marcelektro/MavenMCP-1.8.9 (net/minecraft/client/renderer/ImageBufferDownload.java), stored verbatim.