1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.imaging.formats.psd.dataparsers;
18
19 import java.awt.image.BufferedImage;
20 import java.awt.image.DataBuffer;
21
22 import org.apache.commons.imaging.formats.psd.PsdHeaderInfo;
23 import org.apache.commons.imaging.formats.psd.PsdImageContents;
24
25 public abstract class DataParser {
26 public abstract int getBasicChannelsCount();
27
28 protected abstract int getRgb(int[][][] data, int x, int y, PsdImageContents imageContents);
29
30 public final void parseData(final int[][][] data, final BufferedImage bi, final PsdImageContents imageContents) {
31 final DataBuffer buffer = bi.getRaster().getDataBuffer();
32
33 final PsdHeaderInfo header = imageContents.header;
34 final int width = header.columns;
35 final int height = header.rows;
36
37 for (int y = 0; y < height; y++) {
38 for (int x = 0; x < width; x++) {
39 final int rgb = getRgb(data, x, y, imageContents);
40 buffer.setElem(y * width + x, rgb);
41 }
42 }
43 }
44 }