Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
|
|
@ -12,32 +12,32 @@ import javax.imageio.ImageIO;
|
|||
|
||||
public class ReadPPMFile {
|
||||
|
||||
public static void main(String[] aArgs) throws IOException {
|
||||
public static void main(String[] aArgs) throws IOException {
|
||||
// Using the file created in the Bitmap task
|
||||
String filePath = "output.ppm";
|
||||
|
||||
reader = new BufferedInputStream( new FileInputStream(filePath) );
|
||||
final char header1 = (char) reader.read();
|
||||
String filePath = "output.ppm";
|
||||
|
||||
reader = new BufferedInputStream( new FileInputStream(filePath) );
|
||||
final char header1 = (char) reader.read();
|
||||
final char header2 = (char) reader.read();
|
||||
final char header3 = (char) reader.read();
|
||||
if ( header1 != 'P' || header2 != '6' || header3 != END_OF_LINE) {
|
||||
reader.close();
|
||||
throw new IllegalArgumentException("Not a valid P6 PPM file");
|
||||
reader.close();
|
||||
throw new IllegalArgumentException("Not a valid P6 PPM file");
|
||||
}
|
||||
|
||||
final int width = processCharacters(SPACE_CHARACTER);
|
||||
final int height = processCharacters(END_OF_LINE);
|
||||
final int maxColorValue = processCharacters(END_OF_LINE);
|
||||
if ( maxColorValue < 0 || maxColorValue > 255 ) {
|
||||
reader.close();
|
||||
throw new IllegalArgumentException("Maximum color value is outside the range 0..255");
|
||||
reader.close();
|
||||
throw new IllegalArgumentException("Maximum color value is outside the range 0..255");
|
||||
}
|
||||
|
||||
// Remove any comments before reading data
|
||||
reader.mark(1);
|
||||
while ( reader.read() == START_OF_COMMENT ) {
|
||||
while ( reader.read() != END_OF_LINE );
|
||||
reader.mark(1);
|
||||
while ( reader.read() != END_OF_LINE );
|
||||
reader.mark(1);
|
||||
}
|
||||
reader.reset();
|
||||
|
||||
|
|
@ -47,10 +47,10 @@ public class ReadPPMFile {
|
|||
byte[] buffer = new byte[width * 3];
|
||||
for ( int y = 0; y < height; y++ ) {
|
||||
reader.read(buffer, 0, buffer.length);
|
||||
for ( int x = 0; x < width; x++ ) {
|
||||
for ( int x = 0; x < width; x++ ) {
|
||||
Color color = new Color(Byte.toUnsignedInt(buffer[x * 3]),
|
||||
Byte.toUnsignedInt(buffer[x * 3 + 1]),
|
||||
Byte.toUnsignedInt(buffer[x * 3 + 2]));
|
||||
Byte.toUnsignedInt(buffer[x * 3 + 1]),
|
||||
Byte.toUnsignedInt(buffer[x * 3 + 2]));
|
||||
bitmap.setPixel(x, y, color);
|
||||
}
|
||||
}
|
||||
|
|
@ -60,29 +60,29 @@ public class ReadPPMFile {
|
|||
// Convert to gray scale and save to a file
|
||||
bitmap.convertToGrayscale();
|
||||
File grayFile = new File("outputGray.jpg");
|
||||
ImageIO.write((RenderedImage) bitmap.getImage(), "jpg", grayFile);
|
||||
}
|
||||
|
||||
private static int processCharacters(char aChar) throws IOException {
|
||||
StringBuilder characters = new StringBuilder();
|
||||
char ch;
|
||||
while ( ( ch = (char) reader.read() ) != aChar ) {
|
||||
if ( ch == START_OF_COMMENT ) {
|
||||
while ( reader.read() != END_OF_LINE );
|
||||
continue;
|
||||
}
|
||||
characters.append(ch);
|
||||
}
|
||||
return Integer.valueOf(characters.toString());
|
||||
}
|
||||
|
||||
private static BufferedInputStream reader;
|
||||
|
||||
private static final char START_OF_COMMENT = '#';
|
||||
private static final char SPACE_CHARACTER = ' ';
|
||||
private static final char END_OF_LINE = '\n';
|
||||
ImageIO.write((RenderedImage) bitmap.getImage(), "jpg", grayFile);
|
||||
}
|
||||
|
||||
}
|
||||
private static int processCharacters(char aChar) throws IOException {
|
||||
StringBuilder characters = new StringBuilder();
|
||||
char ch;
|
||||
while ( ( ch = (char) reader.read() ) != aChar ) {
|
||||
if ( ch == START_OF_COMMENT ) {
|
||||
while ( reader.read() != END_OF_LINE );
|
||||
continue;
|
||||
}
|
||||
characters.append(ch);
|
||||
}
|
||||
return Integer.valueOf(characters.toString());
|
||||
}
|
||||
|
||||
private static BufferedInputStream reader;
|
||||
|
||||
private static final char START_OF_COMMENT = '#';
|
||||
private static final char SPACE_CHARACTER = ' ';
|
||||
private static final char END_OF_LINE = '\n';
|
||||
|
||||
}
|
||||
|
||||
final class BasicBitmapStorage {
|
||||
|
||||
|
|
@ -105,12 +105,12 @@ final class BasicBitmapStorage {
|
|||
}
|
||||
|
||||
public Image getImage() {
|
||||
return image;
|
||||
return image;
|
||||
}
|
||||
|
||||
public void convertToGrayscale() {
|
||||
for ( int y = 0; y < image.getHeight(); y++ ) {
|
||||
for ( int x = 0; x < image.getWidth(); x++ ) {
|
||||
for ( int x = 0; x < image.getWidth(); x++ ) {
|
||||
int color = image.getRGB(x, y);
|
||||
|
||||
int alpha = ( color >> 24 ) & 255;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue