Java Example. A First Java Program. Pixels, Rasters, Sprites, and BitBlts. Exercise #1. Experiencing JAVAphobia?



Similar documents
Image Processing. In this chapter: ImageObserver ColorModel ImageProducer ImageConsumer ImageFilter

Here's the code for our first Applet which will display 'I love Java' as a message in a Web page

Chapter 1 Java Program Design and Development

The Basic Java Applet and JApplet

Graphics Module Reference

An Overview of Java. overview-1

Package png. February 20, 2015

Introduction to Java Applets (Deitel chapter 3)

Java applets. SwIG Jing He

Single Page Web App Generator (SPWAG)

Creating Web Pages with Microsoft FrontPage

How to Convert an Application into an Applet.

public class Application extends JFrame implements ChangeListener, WindowListener, MouseListener, MouseMotionListener {

Lesson 10: Video-Out Interface

method is never called because it is automatically called by the window manager. An example of overriding the paint() method in an Applet follows:

So we're set? Have your text-editor ready. Be sure you use NotePad, NOT Word or even WordPad. Great, let's get going.

Working with forms in PHP

CSC 551: Web Programming. Spring 2004

Using Text & Graphics with Softron s OnTheAir CG and OnTheAir Video

CIS 467/602-01: Data Visualization

There are some important differences between an applet and a standalone Java application, including the following:

TABLE OF CONTENTS...2 INTRODUCTION...3 APPLETS AND APPLICATIONS...3 JAVABEANS...4 EXCEPTION HANDLING...5 JAVA DATABASE CONNECTIVITY (JDBC)...

Introduction to graphics and LCD technologies. NXP Product Line Microcontrollers Business Line Standard ICs

C# and Other Languages

How To Program In Java (Ipt) With A Bean And An Animated Object In A Powerpoint (For A Powerbook)

JAVA DEVELOPER S GUIDE TO ASPRISE SCANNING & IMAGE CAPTURE SDK

Web Development and Core Java Lab Manual V th Semester

Introduction to Web Design Curriculum Sample

Simple Image File Formats

ICT 6012: Web Programming

Introduction to Java

SE 450 Object-Oriented Software Development. Requirements. Topics. Textbooks. Prerequisite: CSC 416

Interactive Programs and Graphics in Java

Using Style Sheets for Consistency

Lesson 1 Quiz. 3. The Internet is which type of medium? a. Passive b. Broadcast c. One-to-one d. Electronic print

Visualizing an OrientDB Graph Database with KeyLines

The Web Web page Links 16-3

Please select one of the topics below.

MassArt Studio Foundation: Visual Language Digital Media Cookbook, Fall 2013

Visualizing a Neo4j Graph Database with KeyLines

Solomon Systech Image Processor for Car Entertainment Application

Using the Adventist Framework with your netadventist Site

Instruction Set Architecture (ISA)

Examples. Pac-Man, Frogger, Tempest, Joust,

First Bytes Programming Lab 2

How to develop your own app

SiteOrigin WordPress Theme Pitch

Make your own Temple Run game

Creating a Resume Webpage with

Session 12 Evolving IT Architectures: From Mainframes to Client-Server to Network Computing

Slide.Show Quick Start Guide

Working with the BCC Clouds Generator

An evaluation of JavaFX as 2D game creation tool

CS1112 Spring 2014 Project 4. Objectives. 3 Pixelation for Identity Protection. due Thursday, 3/27, at 11pm

c. Write a JavaScript statement to print out as an alert box the value of the third Radio button (whether or not selected) in the second form.

Step by step guides. Deploying your first web app to your FREE Azure Subscription with Visual Studio 2015

How to Add a Transparent Flash FLV movie to your Web Page Tutorial by R. Berdan Oct

The Java Series. Java Essentials I What is Java? Basic Language Constructs. Java Essentials I. What is Java?. Basic Language Constructs Slide 1

WIRIS quizzes web services Getting started with PHP and Java

Introduction to Imagery and Raster Data in ArcGIS

Comp 410/510. Computer Graphics Spring Introduction to Graphics Systems

CaptainCasa. CaptainCasa Enterprise Client. CaptainCasa Enterprise Client. Feature Overview

MMGD0203 Multimedia Design MMGD0203 MULTIMEDIA DESIGN. Chapter 3 Graphics and Animations

A Basic Summary of Image Formats

Chapter 3 Graphics and Image Data Representations

Below is a diagram explaining the data packet and the timing related to the mouse clock while receiving a byte from the PS-2 mouse:

PaperlessPrinter. Version 3.0. User s Manual

Last week we talked about creating your own tags: div tags and span tags. A div tag goes around other tags, e.g.,:

Assignment 2: Animated Transitions Due: Oct 12 Mon, 11:59pm, 2015 (midnight)

EARTH PEOPLE TECHNOLOGY SERIAL GRAPH TOOL FOR THE ARDUINO UNO USER MANUAL

MICROSOFT POWERPOINT STEP BY STEP GUIDE

Tutorial: Building a Java applet

ICE: HTML, CSS, and Validation

MASTERTAG DEVELOPER GUIDE

Mail Programming Topics

Note monitors controlled by analog signals CRT monitors are controlled by analog voltage. i. e. the level of analog signal delivered through the

Fundamentals of Java Programming

Frames. In this chapter

Insight Student for Chromebooks - Auto Configuration

Part 1 Foundations of object orientation

CS170 Lab 11 Abstract Data Types & Objects

QNX Software Development Platform 6.6. Screen Graphics Subsystem Developer's Guide

Fireworks 3 Animation and Rollovers

GPGPU Computing. Yong Cao

Chapter 1 Programming Languages for Web Applications

EPSON Perfection 2450 PHOTO. Scanner Parts. Scanner Specifications. Basic Specifications. US letter or A4 size ( inches [ mm])

Graphic Design Basics. Shannon B. Neely. Pacific Northwest National Laboratory Graphics and Multimedia Design Group

Bypassing Browser Memory Protections in Windows Vista

THINKDIGITAL. ZOO Ad specifications

VESA BIOS Extension/Accelerator Functions (VBE/AF)

Intel Modular Server System MFSYS25

TCP/IP Networking, Part 2: Web-Based Control

Lecture Notes, CEng 477

Lab #8: Introduction to ENVI (Environment for Visualizing Images) Image Processing

Transcription:

Pixels, Rasters, Sprites, and BitBlts Exercise #1 Set up your course homepage by next Tuesday 9/19 Experiencing JAVAphobia? Homepage Requirements: Exercise #1 A Graphical Hello World Rasters Pixels Sprites BitBlts Before 6837 I was a normal lab rat, now I am the BRAIN! My Projects: Cool Places: Project #1 MIT's Graphics Group Project #2 Avalon Project #3 My REAL homepage Project #4 6837's homepage Project #5 Narf! Locate on imagery in /mit/imagery2/6837/f00/username (you must execute "add imageory2" first) Something about you Links to all 5 projects Area for links to computer graphics sites that you find interesting A link back to the 6837 homepage Lecture 2 Slide 1 6837 Fall '00 Lecture 2 Slide 2 6837 Fall '00 http://graphicslcsmitedu/classes/6837/f00/lecture02/slide01html [9/12/2000 4:46:01 PM] http://graphicslcsmitedu/classes/6837/f00/lecture02/slide02html [9/12/2000 4:46:06 PM] A First Java Program We start by writing what is called a Java applet This is a form of a Java program that can be embedded in a HTML document and accessed from the web An example HTML document that calls our example applet is shown below: <HTML> <HEAD> <TITLE>Demo Applet</TITLE> </HEAD> <BODY> <H1>Demo Applet</H1> <P>My favorite class is 6837</P> <HR> <CENTER> <APPLET code="democlass" width=200 height=200> </APPLET> </CENTER> <HR> </BODY> </HTML> The highlighted lines add the Java code to our document Notice the class extension All Java source code files should end with a java extension The source is here Java Example Next, the source of the demojava file is shown import javaapplet*; import javaawt*; public class Demo extends Applet { Image image; int count; public void init() { image = getimage(getdocumentbase(), "Worldjpg"); count = 1; public void paint(graphics g) { gdrawimage(image, 0, 0, this); gsetcolor(colorred); for (int y = 15; y < size()height; y += 15) { int x = (int) (size()width/2 + 30*Mathcos(MathPI*y/75)); gdrawstring("hello", x, y); showstatus("paint called "+count+" time"+((count > 1)?"s":"")); count += 1; You can get the source here and the Worldjpg image here Lecture 2 Slide 3 6837 Fall '00 Lecture 2 Slide 4 6837 Fall '00 http://graphicslcsmitedu/classes/6837/f00/lecture02/slide03html [9/12/2000 4:46:07 PM] http://graphicslcsmitedu/classes/6837/f00/lecture02/slide04html [9/12/2000 4:46:10 PM]

The Applet in Action Review of Raster Displays Demo Applet My favorite class is 6837 This is all of the Java programming language that we will specifically cover in class If you have never used Java before, you might want to consider buying one of the books discussed on the course's home page Display synchronized with CRT sweep Special memory for screen update Pixels are the discrete elements displayed Generally, updates are visible Lecture 2 Slide 5 6837 Fall '00 http://graphicslcsmitedu/classes/6837/f00/lecture02/slide05html [9/12/2000 4:46:11 PM] Lecture 2 Slide 6 6837 Fall '00 http://graphicslcsmitedu/classes/6837/f00/lecture02/slide06html [9/12/2000 4:46:14 PM] High-End Graphics Display System A Memory Raster Adds a second frame buffer Swaps during vertical blanking Updates are invisible Costly Maintains a copy of the screen (or some part of it) in memory Relies on a fast copy Updates are nearly invisible Conceptual model of a physical object Lecture 2 Slide 7 6837 Fall '00 http://graphicslcsmitedu/classes/6837/f00/lecture02/slide07html [9/12/2000 4:46:16 PM] Lecture 2 Slide 8 6837 Fall '00 http://graphicslcsmitedu/classes/6837/f00/lecture02/slide08html [9/12/2000 4:46:17 PM]

A Java Model of a Memory Raster class Raster implements ImageObserver { ////////////////////////// Constructors ///////////////////// public Raster(); // allows class to be extended public Raster(int w, int h); // specify size public Raster(Image img); // set to size and contents of image ////////////////////////// Interface Method ///////////////// public boolean imageupdate(image img, int flags, int x, int y, int w, int h); ////////////////////////// Accessors ////////////////////////// public int getsize( ); // pixels in raster public int getwidth( ); // width of raster public int getheight( ); // height of raster public int[] getpixelbuffer( ); // get array of pixels ////////////////////////// Methods //////////////////////////// public void fill(int argb); // fill with packed argb public void fill(color c); // fill with Java color public Image toimage(component root); public int getpixel(int x, int y); public Color getcolor(int x, int y); public boolean setpixel(int pix, int x, int y); public boolean setcolor(color c, int x, int y); Download Rasterjava here Lecture 2 Slide 9 6837 Fall '00 http://graphicslcsmitedu/classes/6837/f00/lecture02/slide09html [9/12/2000 4:46:18 PM] The code on the right demonstrates the use of a Raster object The running Applet is shown below Clicking on the image will cause it to be negated The source code for this applet can be downloaded here: Rastestjava Example Usage: Rastestjava import javaapplet*; import javaawt*; import Raster; public class Rastest extends Applet { Raster raster; Image output; int count = 0; public void init() { String filename = getparameter("image"); output = getimage(getdocumentbase(), filename); raster = new Raster(output); showstatus("image size: " + rastergetwidth() + " x " + rastergetheight()); public void paint(graphics g) { gdrawimage(output, 0, 0, this); count += 1; showstatus("paint() called " + count + " time" + ((count > 1)? "s":"")); public void update(graphics g) { paint(g); public boolean mouseup(event e, int x, int y) { int s = rastergetsize(); int [] pixel = rastergetpixelbuffer(); for (int i = 0; i < s; i++) { rasterpixel[i] ^= 0x00ffffff; output = rastertoimage(this); repaint(); return true; Lecture 2 Slide 10 6837 Fall '00 http://graphicslcsmitedu/classes/6837/f00/lecture02/slide10html [9/12/2000 4:46:19 PM] Lets Talk About Pixels True-Color Frame Buffers Pixels are stored as a 1-dimensional array of ints Each int is formatted according to Java's standard pixel model Alpha Red Green Blue The 4 bytes of a 32-bit Pixel int if Alpha is 0 the pixel is transparent if Alpha is 255 the pixel is opaque Layout of the pixel array on the display: This is the image format used internally by Java Each pixel requires at least 3 bytes One byte for each primary color Sometimes combined with a look-up table per primary Each pixel can be one of 2^24 colors Worry about your Endians Lecture 2 Slide 11 6837 Fall '00 http://graphicslcsmitedu/classes/6837/f00/lecture02/slide11html [9/12/2000 4:46:21 PM] Lecture 2 Slide 12 6837 Fall '00 http://graphicslcsmitedu/classes/6837/f00/lecture02/slide12html [9/12/2000 4:46:22 PM]

Indexed-Color Frame Buffers High-Color Frame Buffers Pixels are packed in a short Each primary uses 5 bits Popular PC/(SVGA) standard (popular with Gamers) Each pixel can be one of 2^15 colors Can exhibit worse quantization (banding) effects than Indexed-color Each pixel uses one byte Each byte is an index into a color map If the color map is not updated synchronously then Color-map flashing may occcur Color-map Animations Each pixel may be one of 2^24 colors, but only 256 color be displayed at a time Lecture 2 Slide 13 6837 Fall '00 http://graphicslcsmitedu/classes/6837/f00/lecture02/slide13html [9/12/2000 4:46:23 PM] Lecture 2 Slide 14 6837 Fall '00 http://graphicslcsmitedu/classes/6837/f00/lecture02/slide14html [9/12/2000 4:46:25 PM] Sprites A Sprite is a Raster Sprites are rasters that can be overlaid onto a background raster called a playfield A sprite can be animated, and it generally can be repositioned freely any where within the playfield class Sprite extends Raster { int x, y; // position of sprite on playfield public void Draw(Raster bgnd); // draws sprite on a Raster Things to consider: The Draw( ) method must handle transparent pixels, and it must also handle all cases where the sprite overhangs the playfield Lecture 2 Slide 15 6837 Fall '00 http://graphicslcsmitedu/classes/6837/f00/lecture02/slide15html [9/12/2000 4:46:26 PM] Lecture 2 Slide 16 6837 Fall '00 http://graphicslcsmitedu/classes/6837/f00/lecture02/slide16html [9/12/2000 4:46:27 PM]

An Animated Sprite is a Sprite class AnimatedSprite extends Sprite { int frames; // frames in sprite // there are other private variables public AnimatedSprite(Image images, int frames); public void addstate(int track, int frame, int ticks, int dx, int dy); public void Draw(Raster bgnd); public void nextstate(); public void settrack(); A Playfield is a Raster and has Animated Sprites class Playfield extends Raster { Raster background; // background image AnimatedSprite sprite[]; // list of sprites on this playfield public Playfield(Image bgnd, int numsprites); public void addsprite(int i, AnimatedSprite s); public void Draw( ); A track is a series of frames The frame is displayed for ticks periods The sprite's position is then moved (dx, dy) pixels Lecture 2 Slide 17 6837 Fall '00 http://graphicslcsmitedu/classes/6837/f00/lecture02/slide17html [9/12/2000 4:46:29 PM] Lecture 2 Slide 18 6837 Fall '00 http://graphicslcsmitedu/classes/6837/f00/lecture02/slide18html [9/12/2000 4:46:30 PM] Other Image Formats What if we want to read in some other image format? bmp, ppm, tif, tga, rgb, ras, psd, We must implement an imageproducer to read pixels, an imageconsumer to make the image, and keep imageobservers updated Where? How? Luckily, We Already Have From our Raster class: public final Image toimage(component root) { return rootcreateimage(new MemoryImageSource(width, height, pixel, 0, width)); The MemoryImageSource method is an imageproducer (root is an imageobserver) public class ppmdecoder { Raster imgraster; // declare a Raster public ppmdecoder() { public Image getppmimage(url url) { // open url and read image header // create imgraster // copy data from file into imgraster return (imgrastertoimage()); Lecture 2 Slide 19 6837 Fall '00 http://graphicslcsmitedu/classes/6837/f00/lecture02/slide19html [9/12/2000 4:46:32 PM] Lecture 2 Slide 20 6837 Fall '00 http://graphicslcsmitedu/classes/6837/f00/lecture02/slide20html [9/12/2000 4:46:33 PM]

PixBlts PixBlts are raster methods for moving and clearing sub-blocks of pixels from one region of a raster to another Very heavily used by window systems: moving windows around scrolling text copying and clearing Here's a PixBlt method: Seems Easy public void PixBlt(int xs, int ys, int w, int h, int xd, int yd) { for (int j = 0; j < h; j++) { for (int i = 0; i < w; i++) { thissetpixel(rastergetpixel(xs+i, ys+j), xd+i, yd+j); But does this work? What are the issues? How do you fix it? Lecture 2 Slide 21 6837 Fall '00 http://graphicslcsmitedu/classes/6837/f00/lecture02/slide21html [9/12/2000 4:46:34 PM] Lecture 2 Slide 22 6837 Fall '00 http://graphicslcsmitedu/classes/6837/f00/lecture02/slide22html [9/12/2000 4:46:36 PM] The Tricky Blits Our PixBlt Method works fine when the source and destination regions do not overlap But, when these two regions do overlap we need to take special care to avoid copying the wrong pixels The best way to handle this situation is by changing the iteration direction of the copy loops to avoid problems Graphics System Architecture Computer Graphics is one of the few computer system functions where specialized H/W is still commonly used Why? The numbers: 1M pixels * 60 f/s * 1 op/(pixel frame) = 60M ops/s Wouldn't you like to compute while your screen scrolls? Isn't graphics why you have a computer? The iteration direction must always be opposite of the direction of the block's movement for each axis You could write a fancy loop which handles all four cases However, this code is usually so critical to system performace that, generally, code is written for all 4 cases and called based on a test of the source and destination origins In fact the code is usually unrolled Lecture 2 Slide 23 6837 Fall '00 Lecture 2 Slide 24 6837 Fall '00 http://graphicslcsmitedu/classes/6837/f00/lecture02/slide23html [9/12/2000 4:46:37 PM] http://graphicslcsmitedu/classes/6837/f00/lecture02/slide24html [9/12/2000 4:46:39 PM]

The Problem is Bandwidth Graphics is one of the most bandwidth intensive tasks that a computer does For graphics, caching is not the effective solution that it is for traditional computing Since we are always operating at or near the maximum capabilities of the current processing technology, graphics relys on architectural innovations to achieve the required performance The most popular solution is parallelism Lets discuss how parallelism is exploited in graphics architectures Pixel Interleaving: Finer Grain Parallelism In the absence of pixel-level interleaving, we need to constantly shuffle primitives in order to achieve a good load balance There are many possible options: Sort-First Sort-Middle Sort-Last Lately, new architures have been suggested Sort-Everywhere Eldridge, Ighey, and Hanrahan, Pomegranate: A Fully Scalable Graphics Architecture, SIGGRAPH '00 Lecture 2 Slide 25 6837 Fall '00 Lecture 2 Slide 26 6837 Fall '00 http://graphicslcsmitedu/classes/6837/f00/lecture02/slide25html [9/12/2000 4:46:40 PM] http://graphicslcsmitedu/classes/6837/f00/lecture02/slide26html [9/12/2000 4:46:41 PM] Next Time How do we see? How do we percieve color? Why do we only need red, green, and blue channels? Is gamma greek to you? What is a Just-noticable diffference anyway? Lecture 2 Slide 27 6837 Fall '00 http://graphicslcsmitedu/classes/6837/f00/lecture02/slide27html [9/12/2000 4:46:43 PM]