blob: 68a27212f3551e7a47e651daa585227cb58fd363 [file] [log] [blame]
jerrymf1579332013-02-07 01:56:28 +00001/*----------------------------------------------------------------------------*/
2/* Copyright (c) FIRST 2008. All Rights Reserved. */
3/* Open Source Software - may be modified and shared by FRC teams. The code */
4/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
5/*----------------------------------------------------------------------------*/
6
7#include "ImageBase.h"
8#include "nivision.h"
9
10/** Private NI function needed to write to the VxWorks target */
11IMAQ_FUNC int Priv_SetWriteFileAllowed(UINT32 enable);
12
13/**
14 * Create a new instance of an ImageBase.
15 * Imagebase is the base of all the other image classes. The constructor
16 * creates any type of image and stores the pointer to it in the class.
17 * @param type The type of image to create
18 */
19ImageBase::ImageBase(ImageType type)
20{
21 m_imaqImage = imaqCreateImage(type, DEFAULT_BORDER_SIZE);
22}
23
24/**
25 * Frees memory associated with an ImageBase.
26 * Destructor frees the imaq image allocated with the class.
27 */
28ImageBase::~ImageBase()
29{
30 if(m_imaqImage)
31 imaqDispose(m_imaqImage);
32}
33
34/**
35 * Writes an image to a file with the given filename.
36 * Write the image to a file in the flash on the cRIO.
37 * @param fileName The name of the file to write
38 */
39void ImageBase::Write(const char *fileName)
40{
41 Priv_SetWriteFileAllowed(1);
42 int success = imaqWriteFile(m_imaqImage, fileName, NULL);
43 wpi_setImaqErrorWithContext(success, "Imaq Image writeFile error");
44}
45
46/**
47 * Gets the height of an image.
48 * @return The height of the image in pixels.
49 */
50int ImageBase::GetHeight()
51{
52 int height;
53 imaqGetImageSize(m_imaqImage, NULL, &height);
54 return height;
55}
56
57/**
58 * Gets the width of an image.
59 * @return The width of the image in pixels.
60 */
61int ImageBase::GetWidth()
62{
63 int width;
64 imaqGetImageSize(m_imaqImage, &width, NULL);
65 return width;
66}
67
68/**
69 * Access the internal IMAQ Image data structure.
70 *
71 * @return A pointer to the internal IMAQ Image data structure.
72 */
73Image *ImageBase::GetImaqImage()
74{
75 return m_imaqImage;
76}
77