001: /*
002: JSmooth: a VM wrapper toolkit for Windows
003: Copyright (C) 2003 Rodrigo Reyes <reyes@charabia.net>
004:
005: This program is free software; you can redistribute it and/or modify
006: it under the terms of the GNU General Public License as published by
007: the Free Software Foundation; either version 2 of the License, or
008: (at your option) any later version.
009:
010: This program is distributed in the hope that it will be useful,
011: but WITHOUT ANY WARRANTY; without even the implied warranty of
012: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013: GNU General Public License for more details.
014:
015: You should have received a copy of the GNU General Public License
016: along with this program; if not, write to the Free Software
017: Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
018:
019: */
020:
021: package net.charabia.jsmoothgen.pe.res;
022:
023: import java.util.*;
024: import java.io.*;
025: import java.nio.*;
026: import java.nio.channels.*;
027:
028: public class ResIconDir {
029: private int m_idReserved; // Reserved (must be 0)
030: private int m_idType; // Resource Type (1 for icons)
031: private int m_idCount; // How many images?
032:
033: private IconDirEntry[] m_entries;
034:
035: public static class IconDirEntry {
036: public short bWidth; // Width, in pixels, of the image
037: public short bHeight; // Height, in pixels, of the image
038: public short bColorCount; // Number of colors in image (0 if >=8bpp)
039: public short bReserved; // Reserved ( must be 0)
040: public int wPlanes; // Color Planes
041: public int wBitCount; // Bits per pixel
042: public long dwBytesInRes; // How many bytes in this resource?
043: public int dwImageOffset; // Where in the file is this image?
044:
045: public IconDirEntry(ByteBuffer buf) {
046: bWidth = buf.get();
047: bHeight = buf.get();
048: bColorCount = buf.get();
049: bReserved = buf.get();
050: wPlanes = buf.getShort();
051: wBitCount = buf.getShort();
052: dwBytesInRes = buf.getInt();
053: dwImageOffset = buf.getShort();
054: }
055:
056: public ByteBuffer getData() {
057: ByteBuffer buf = ByteBuffer.allocate(16);
058: buf.order(ByteOrder.LITTLE_ENDIAN);
059: buf.position(0);
060:
061: buf.put((byte) bWidth);
062: buf.put((byte) bHeight);
063: buf.put((byte) bColorCount);
064: buf.put((byte) bReserved);
065:
066: buf.putShort((short) wPlanes);
067: buf.putShort((short) wBitCount);
068:
069: buf.putInt((int) dwBytesInRes);
070: buf.putShort((short) dwImageOffset);
071:
072: buf.position(0);
073: return buf;
074: }
075:
076: public String toString() {
077: StringBuffer out = new StringBuffer();
078: out.append("bWidth: " + bWidth + "\n"); // Width, in pixels, of the image
079: out.append("bHeight: " + bHeight + "\n"); // Height, in pixels, of the image
080: out.append("bColorCount: " + bColorCount + "\n"); // Number of colors in image (0 if >=8bpp)
081: out.append("bReserved: " + bReserved + "\n"); // Reserved ( must be 0)
082: out.append("wPlanes: " + wPlanes + "\n"); // Color Planes
083: out.append("wBitCount: " + wBitCount + "\n"); // Bits per pixel
084: out.append("dwBytesInRes: " + dwBytesInRes + "\n"); // How many bytes in this resource?
085: out.append("dwImageOffset: " + dwImageOffset + "\n"); // Where in the file is this image?
086:
087: return out.toString();
088: }
089:
090: }
091:
092: /** Creates a new instance of ResIconDir */
093: public ResIconDir(ByteBuffer buf) {
094: m_idReserved = buf.getShort();
095: m_idType = buf.getShort();
096: m_idCount = buf.getShort();
097:
098: m_entries = new ResIconDir.IconDirEntry[m_idCount];
099: for (int i = 0; i < m_idCount; i++) {
100: m_entries[i] = new IconDirEntry(buf);
101: }
102: }
103:
104: public ByteBuffer getData() {
105: ByteBuffer buf = ByteBuffer.allocate(6 + (16 * m_idCount));
106: buf.order(ByteOrder.LITTLE_ENDIAN);
107: buf.position(0);
108:
109: buf.putShort((short) m_idReserved);
110: buf.putShort((short) m_idType);
111: buf.putShort((short) m_idCount);
112:
113: for (int i = 0; i < m_idCount; i++) {
114: ByteBuffer b = m_entries[i].getData();
115: b.position(0);
116: buf.put(b);
117: }
118:
119: return buf;
120: }
121:
122: public ResIconDir.IconDirEntry[] getEntries() {
123: return m_entries;
124: }
125:
126: public String toString() {
127: StringBuffer out = new StringBuffer();
128: out.append("m_idReserved: " + m_idReserved + "\n"); // Reserved (must be 0)
129: out.append("m_idType: " + m_idType + "\n"); // Resource Type (1 for icons)
130: out.append("m_idCount: " + m_idCount + "\n"); // How many images?
131: out.append("entries: ---- \n");
132: for (int i = 0; i < m_entries.length; i++) {
133: out.append(m_entries[i].toString());
134: }
135:
136: return out.toString();
137: }
138: }
|