annotate src/com/aurellem/capture/Main.java @ 11:8a6b1684f536

refactored.
author Robert McIntyre <rlm@mit.edu>
date Thu, 27 Oct 2011 02:27:02 -0700
parents 4c5fc53778c1
children
rev   line source
rlm@3 1 /**
rlm@3 2 * @(#)Main.java 1.2 2009-08-29
rlm@3 3 *
rlm@3 4 * Copyright (c) 2008-2009 Werner Randelshofer, Immensee, Switzerland.
rlm@3 5 * All rights reserved.
rlm@3 6 *
rlm@3 7 * You may not use, copy or modify this file, except in compliance with the
rlm@3 8 * license agreement you entered into with Werner Randelshofer.
rlm@3 9 * For details see accompanying license terms.
rlm@3 10 */
rlm@3 11 package com.aurellem.capture;
rlm@3 12
rlm@3 13 import java.awt.*;
rlm@3 14 import java.awt.image.BufferedImage;
rlm@3 15 import java.awt.image.IndexColorModel;
rlm@3 16 import java.io.*;
rlm@3 17 import java.util.Random;
rlm@3 18
rlm@10 19 import ca.randelshofer.AVIOutputStream;
rlm@9 20
rlm@3 21
rlm@3 22 /**
rlm@3 23 * Main.
rlm@3 24 *
rlm@3 25 * @author Werner Randelshofer
rlm@3 26 * @version 1.1 2009-08-29 Added raw output.
rlm@3 27 * <br>1.0 2008-00-15 Created.
rlm@3 28 */
rlm@3 29 public class Main {
rlm@3 30
rlm@3 31 /**
rlm@3 32 * @param args the command line arguments
rlm@3 33 */
rlm@3 34 public static void main(String[] args) {
rlm@3 35 try {
rlm@3 36 test(new File("/home/r/avidemo-jpg.avi"), AVIOutputStream.VideoFormat.JPG, 24, 1f);
rlm@3 37 test(new File("/home/r/avidemo-png.avi"), AVIOutputStream.VideoFormat.PNG, 24, 1f);
rlm@3 38 test(new File("/home/r/avidemo-raw.avi"), AVIOutputStream.VideoFormat.RAW, 24, 1f);
rlm@3 39 test(new File("/home/r/avidemo-rle8.avi"), AVIOutputStream.VideoFormat.RLE, 8, 1f);
rlm@3 40 test(new File("avidemo-rle4.avi"), AVIOutputStream.VideoFormat.RLE, 4, 1f);
rlm@3 41
rlm@3 42 } catch (IOException ex) {
rlm@3 43 ex.printStackTrace();
rlm@3 44 }
rlm@3 45 }
rlm@3 46
rlm@3 47 private static void test(File file, AVIOutputStream.VideoFormat format, int depth, float quality) throws IOException {
rlm@3 48 System.out.println("Writing " + file);
rlm@3 49 AVIOutputStream out = null;
rlm@3 50 Graphics2D g = null;
rlm@3 51 try {
rlm@3 52 out = new AVIOutputStream(file, format, depth);
rlm@3 53 out.setVideoCompressionQuality(quality);
rlm@3 54
rlm@3 55 out.setTimeScale(1);
rlm@3 56 out.setFrameRate(30);
rlm@3 57
rlm@3 58 Random rnd = new Random(0); // use seed 0 to get reproducable output
rlm@3 59 BufferedImage img;
rlm@3 60 switch (depth) {
rlm@3 61 case 24:
rlm@3 62 default: {
rlm@3 63 img = new BufferedImage(320, 160, BufferedImage.TYPE_INT_RGB);
rlm@3 64 break;
rlm@3 65 }
rlm@3 66 case 8: {
rlm@3 67 byte[] red = new byte[256];
rlm@3 68 byte[] green = new byte[256];
rlm@3 69 byte[] blue = new byte[256];
rlm@3 70 for (int i = 0; i < 255; i++) {
rlm@3 71 red[i] = (byte) rnd.nextInt(256);
rlm@3 72 green[i] = (byte) rnd.nextInt(256);
rlm@3 73 blue[i] = (byte) rnd.nextInt(256);
rlm@3 74 }
rlm@3 75 rnd.setSeed(0); // set back to 0 for reproducable output
rlm@3 76 img = new BufferedImage(320, 160, BufferedImage.TYPE_BYTE_INDEXED, new IndexColorModel(8, 256, red, green, blue));
rlm@3 77 break;
rlm@3 78 }
rlm@3 79 case 4: {
rlm@3 80 byte[] red = new byte[16];
rlm@3 81 byte[] green = new byte[16];
rlm@3 82 byte[] blue = new byte[16];
rlm@3 83 for (int i = 0; i < 15; i++) {
rlm@3 84 red[i] = (byte) rnd.nextInt(16);
rlm@3 85 green[i] = (byte) rnd.nextInt(16);
rlm@3 86 blue[i] = (byte) rnd.nextInt(16);
rlm@3 87 }
rlm@3 88 rnd.setSeed(0); // set back to 0 for reproducable output
rlm@3 89 img = new BufferedImage(320, 160, BufferedImage.TYPE_BYTE_BINARY, new IndexColorModel(4, 16, red, green, blue));
rlm@3 90 break;
rlm@3 91 }
rlm@3 92 }
rlm@3 93 g = img.createGraphics();
rlm@3 94 g.setBackground(Color.WHITE);
rlm@3 95 g.clearRect(0, 0, img.getWidth(), img.getHeight());
rlm@3 96
rlm@3 97 for (int i = 0; i < 100; i++) {
rlm@3 98 g.setColor(new Color(rnd.nextInt()));
rlm@3 99 g.fillRect(rnd.nextInt(img.getWidth() - 30), rnd.nextInt(img.getHeight() - 30), 30, 30);
rlm@3 100 out.writeFrame(img);
rlm@3 101 }
rlm@3 102
rlm@3 103 } finally {
rlm@3 104 if (g != null) {
rlm@3 105 g.dispose();
rlm@3 106 }
rlm@3 107 if (out != null) {
rlm@3 108 out.close();
rlm@3 109 }
rlm@3 110 }
rlm@3 111 }
rlm@3 112 }