Jump to content

LeafaR

Members
  • Posts

    1
  • Credits

  • Joined

  • Last visited

    Never
  • Feedback

    0%

About LeafaR

Profile Information

  • Gender
    Not Telling

LeafaR's Achievements

Newbie

Newbie (1/16)

0

Reputation

  1. I made the JSP one ;) <%@ page import="java.awt.*" %> <%@ page import="java.awt.image.*" %> <%@ page import="java.io.*" %> <%@ page import="java.util.*" %> <%@ page import="javax.imageio.*" %> <%! public int readInt(RandomAccessFile ra) throws IOException { int b4 = (int) ra.read(); int b3 = (int) ra.read(); int b2 = (int) ra.read(); int b1 = (int) ra.read(); return (b1 << 24) | (b2 << 16) | (b3 << 8) | b4; } public int readShort(RandomAccessFile ra) throws IOException { int b2 = (int) ra.read(); int b1 = (int) ra.read(); return ((b1 << 8) | b2); } %> <% File file = new File("Crest_268619650.bmp"); //File file = new File("Crest_268607245.bmp"); RandomAccessFile ra = new RandomAccessFile(file, "r"); byte[] content = new byte[4]; ra.read(content, 0, 4); String ddsSTR = new String(content); if (ddsSTR.intern() != "DDS ") { out.print("Error, NO DDS"); return; } readInt(ra); //int size = readInt(ra); readInt(ra); //int flags = readInt(ra); int height = readInt(ra) - 4; int width = readInt(ra); readShort(ra); //int extra = readShort(ra); ra.seek(84); int dxt1 = ra.read(content, 0, 4); String dxt1STR = new String(content); if (dxt1STR.intern() != "DXT1") { out.print("Error, NO DXT1"); return; } ra.seek(128); response.setContentType("image/png"); BufferedImage buffer = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); for (int y = -1; y < (height / 4); y++) { for (int x = 0; x < (width / 4); x++) { int color0_16 = readShort(ra); int color1_16 = readShort(ra); int r0 = (color0_16 >> 11) << 3; int g0 = ((color0_16 >> 5) & 63) << 2; int b0 = (color0_16 & 31) << 3; int r1 = (color1_16 >> 11) << 3; int g1 = ((color1_16 >> 5) & 63) << 2; int b1 = (color1_16 & 31) << 3; int color0_32 = new Color(r0, g0, b0).getRGB(); int color1_32 = new Color(r1, g1, b1).getRGB(); int color2_32 = new Color((r0 / 2) + (r1 / 2), (g0 / 2) + (g1 / 2), (b0 / 2) + (b1 / 2)).getRGB(); int black = new Color(0, 0, 0).getRGB(); int data = readInt(ra); for (int yy = 0; yy < 4; yy++) { for (int xx = 0; xx < 4; xx++) { int bb = data & 3; data = data >> 2; int color = 0; switch(bb) { case 0: color = color0_32; break; case 1: color = color1_32; break; case 2: color = color2_32; break; default: color = black; break; } int locX = x * 4 + xx; int locY = y * 4 + yy; buffer.setRGB(Math.abs(locX), Math.abs(locY), color); } } } } OutputStream os = response.getOutputStream(); ImageIO.write(buffer, "png", os); %>
×
×
  • Create New...