Debian Codegraph @

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

raw symbols SCIP
1 package uk.me.parabola.imgfmt.app.typ;
2
3 import uk.me.parabola.imgfmt.app.BitWriter;
4 import uk.me.parabola.imgfmt.app.ImgFileWriter;
5
6 /**
7 * Holds a bitmap image for the typ file.
8 *
9 * There are a number of different formats allowed.
10 *
11 * Based on code by Thomas Lußnig, but type and colour information separated out and
12 * deals with more than just points.
13 */
14 public class BitmapImage implements Image {
15
16 private final ColourInfo colourInfo;
17 private final String image;
18
19 public BitmapImage(ColourInfo colourInfo, String image) {
20 this.colourInfo = colourInfo;
21 this.image = image;
22 }
23
24 public void write(ImgFileWriter writer) {
25
26 final int bitSize = colourInfo.getBitsPerPixel();
27 int cpp = colourInfo.getCharsPerPixel();
28
29 int width = colourInfo.getWidth();
30 int height = colourInfo.getHeight();
31
32 int i = 0;
33 for (int h = 0; h < height; h++) {
34 // Each row is padded to a byte boundary, creating a new bit writer for every
35 // row ensures that happens.
36 BitWriter bitWriter = new BitWriter();
37
38 for (int w = 0; w < width; w++) {
39 String idx = image.substring(i, i + cpp);
40 i += cpp;
41
42 int val = colourInfo.getIndex(idx);
43 bitWriter.putn(val, bitSize);
44 }
45 writer.put(bitWriter.getBytes(), 0, bitWriter.getLength());
46 }
47 }
48
49 public int compare(BitmapImage a, BitmapImage b) {
50 throw new UnsupportedOperationException();
51 //if (a == null)
52 // return 1;
53 //if (b == null)
54 // return -1;
55 //if (a.typ < b.typ)
56 // return -1;
57 //if (a.typ > b.typ)
58 // return 1;
59 //if (a.dayNight < b.dayNight)
60 // return -1;
61 //if (a.dayNight > b.dayNight)
62 // return 1;
63 //return 0;
64 }
65
66 }