001 /*----------------------------------------------------------------------------*/ 002 /* Copyright (c) FIRST 2008-2012. All Rights Reserved. */ 003 /* Open Source Software - may be modified and shared by FRC teams. The code */ 004 /* must be accompanied by the FIRST BSD license file in the root directory of */ 005 /* the project. */ 006 /*----------------------------------------------------------------------------*/ 007 package edu.wpi.first.wpilibj.image; 008 009 import com.sun.cldc.jna.Pointer; 010 011 /** 012 * Class representing a generic image. 013 * @author dtjones 014 */ 015 public abstract class Image { 016 017 /** 018 * Pointer to the image memory 019 */ 020 public final Pointer image; 021 static final int DEFAULT_BORDER_SIZE = 3; 022 023 Image(NIVision.ImageType type) throws NIVisionException { 024 image = NIVision.imaqCreateImage(type, DEFAULT_BORDER_SIZE); 025 } 026 027 /** 028 * Creates a new image pointing to the same data as the source image. The 029 * imgae data is not copied, it is just referenced by both objects. Freeing 030 * one will free both. 031 * @param sourceImage The image to reference 032 */ 033 Image(Image sourceImage) { 034 image = sourceImage.image; 035 } 036 037 /** 038 * Write the image to a file. 039 * 040 * Supported extensions: 041 * .aipd or .apd AIPD 042 * .bmp BMP 043 * .jpg or .jpeg JPEG 044 * .jp2 JPEG2000 045 * .png PNG 046 * .tif or .tiff TIFF 047 * 048 * @param fileName The path to write the image to. 049 */ 050 public void write(String fileName) throws NIVisionException { 051 NIVision.writeFile(image, fileName); 052 } 053 054 /** 055 * Release the memory associated with an image. 056 */ 057 public void free() throws NIVisionException { 058 NIVision.dispose(image); 059 } 060 061 /** 062 * Get the height of the image in pixels. 063 * @return The height of the image. 064 */ 065 public int getHeight() throws NIVisionException { 066 return NIVision.getHeight(image); 067 } 068 069 /** 070 * Get the width of the image in pixels. 071 * @return The width of the image. 072 */ 073 public int getWidth() throws NIVisionException { 074 return NIVision.getWidth(image); 075 } 076 }