| 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 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
d |
| 12 |
|
| 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 |
|
| 35 |
|
| 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 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
} |
| 65 |
|
| 66 |
} |