view src/com/aurellem/capture/Main.java @ 20:bc6fbfbbadd9 spazz

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