| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
package uk.me.parabola.imgfmt.app.typ; |
| 14 |
|
| 15 |
import java.nio.charset.CharsetEncoder; |
| 16 |
import java.util.ArrayList; |
| 17 |
import java.util.List; |
| 18 |
|
| 19 |
import uk.me.parabola.imgfmt.app.ImgFileWriter; |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
public class TypIconSet extends TypElement { |
| 28 |
private final List<Xpm> icons = new ArrayList<>(); |
| 29 |
|
| 30 |
public void write(ImgFileWriter writer, CharsetEncoder encoder) { |
| 31 |
offset = writer.position(); |
| 32 |
|
| 33 |
|
| 34 |
writer.put1u(icons.size()); |
| 35 |
|
| 36 |
for (Xpm xpm : icons) { |
| 37 |
ColourInfo colourInfo = xpm.getColourInfo(); |
| 38 |
int nbits = calcBits(colourInfo); |
| 39 |
writer.put2u(nbits/2); |
| 40 |
writer.put1u(1); |
| 41 |
writer.put1u(colourInfo.getWidth()); |
| 42 |
writer.put1u(colourInfo.getHeight()); |
| 43 |
writeImage(writer, xpm); |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
private static int calcBits(ColourInfo colourInfo) { |
| 48 |
int bits = 0; |
| 49 |
int bpp = colourInfo.getBitsPerPixel(); |
| 50 |
|
| 51 |
bits += colourInfo.getWidth() * colourInfo.getHeight() * bpp; |
| 52 |
bits += colourInfo.getNumberOfSColoursForCM() * 3 * 8; |
| 53 |
if (colourInfo.getNumberOfColours() == 0 && colourInfo.getColourMode() == 0x10) |
| 54 |
bits += 3*8; |
| 55 |
bits += 0x2c; |
| 56 |
return bits; |
| 57 |
} |
| 58 |
|
| 59 |
public void addIcon(Xpm xpm) { |
| 60 |
icons.add(xpm); |
| 61 |
} |
| 62 |
|
| 63 |
public String getLabel() { |
| 64 |
if (labels.isEmpty()) |
| 65 |
return null; |
| 66 |
return labels.get(0).getText(); |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
@Override |
| 73 |
public boolean simpleBitmap() { |
| 74 |
return false; |
| 75 |
} |
| 76 |
} |