Debian Codegraph @

src/uk/me/parabola/imgfmt/app/typ/TypIconSet.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2011.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 or
6 * version 2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
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 * The new multiple icon format.
23 * There can be several icons at different resolutions.
24 *
25 * @author Steve Ratcliffe
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 // Start with the number of icons
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 * Icon sets can have full colour pixmaps.
71 */
72 @Override
73 public boolean simpleBitmap() {
74 return false;
75 }
76 }