PngInfo.java
net.minecraft.util.PngInfo
信息
- 全限定名:net.minecraft.util.PngInfo
- 类型:public record
- 包:net.minecraft.util
- 源码路径:src/main/java/net/minecraft/util/PngInfo.java
- 起始行号:L11
- 职责:
TODO
字段/常量
-
FORMAT- 类型:
HexFormat - 修饰符:
private static final - 源码定位:
L12 - 说明:
TODO
- 类型:
-
PNG_HEADER- 类型:
long - 修饰符:
private static final - 源码定位:
L13 - 说明:
TODO
- 类型:
-
IHDR_TYPE- 类型:
int - 修饰符:
private static final - 源码定位:
L14 - 说明:
TODO
- 类型:
-
IHDR_SIZE- 类型:
int - 修饰符:
private static final - 源码定位:
L15 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
- 无
方法
下面的方法块按源码顺序生成。
public static PngInfo fromStream(InputStream inputStream) @ L17
- 方法名:fromStream
- 源码定位:L17
- 返回类型:PngInfo
- 修饰符:public static
参数:
- inputStream: InputStream
说明:
TODO
public static PngInfo fromBytes(byte[] bytes) @ L39
- 方法名:fromBytes
- 源码定位:L39
- 返回类型:PngInfo
- 修饰符:public static
参数:
- bytes: byte[]
说明:
TODO
public static void validateHeader(ByteBuffer buffer) @ L43
- 方法名:validateHeader
- 源码定位:L43
- 返回类型:void
- 修饰符:public static
参数:
- buffer: ByteBuffer
说明:
TODO
代码
public record PngInfo(int width, int height) {
private static final HexFormat FORMAT = HexFormat.of().withUpperCase().withPrefix("0x");
private static final long PNG_HEADER = -8552249625308161526L;
private static final int IHDR_TYPE = 1229472850;
private static final int IHDR_SIZE = 13;
public static PngInfo fromStream(InputStream inputStream) throws IOException {
DataInputStream stream = new DataInputStream(inputStream);
long magic = stream.readLong();
if (magic != -8552249625308161526L) {
throw new IOException("Bad PNG Signature: " + FORMAT.toHexDigits(magic));
} else {
int headerSize = stream.readInt();
if (headerSize != 13) {
throw new IOException("Bad length for IHDR chunk: " + headerSize);
} else {
int headerType = stream.readInt();
if (headerType != 1229472850) {
throw new IOException("Bad type for IHDR chunk: " + FORMAT.toHexDigits(headerType));
} else {
int width = stream.readInt();
int height = stream.readInt();
return new PngInfo(width, height);
}
}
}
}
public static PngInfo fromBytes(byte[] bytes) throws IOException {
return fromStream(new ByteArrayInputStream(bytes));
}
public static void validateHeader(ByteBuffer buffer) throws IOException {
ByteOrder order = buffer.order();
buffer.order(ByteOrder.BIG_ENDIAN);
if (buffer.limit() < 16) {
throw new IOException("PNG header missing");
} else if (buffer.getLong(0) != -8552249625308161526L) {
throw new IOException("Bad PNG Signature");
} else if (buffer.getInt(8) != 13) {
throw new IOException("Bad length for IHDR chunk!");
} else if (buffer.getInt(12) != 1229472850) {
throw new IOException("Bad type for IHDR chunk!");
} else {
buffer.order(order);
}
}
}引用的其他类
- 无