blob: 9ef0a61ee365c9de8c3843612221b7da221f4435 [file] [log] [blame]
Brian Silverman26e4e522015-12-17 01:56:40 -05001/*----------------------------------------------------------------------------*/
Brian Silverman1a675112016-02-20 20:42:49 -05002/* Copyright (c) FIRST 2014-2016. All Rights Reserved. */
Brian Silverman26e4e522015-12-17 01:56:40 -05003/* Open Source Software - may be modified and shared by FRC teams. The code */
Brian Silverman1a675112016-02-20 20:42:49 -05004/* must be accompanied by the FIRST BSD license file in the root directory of */
5/* the project. */
Brian Silverman26e4e522015-12-17 01:56:40 -05006/*----------------------------------------------------------------------------*/
7
8#include "Vision/ImageBase.h"
9#include "nivision.h"
10
11/**
12 * Create a new instance of an ImageBase.
13 * Imagebase is the base of all the other image classes. The constructor
14 * creates any type of image and stores the pointer to it in the class.
15 * @param type The type of image to create
16 */
17ImageBase::ImageBase(ImageType type) {
18 m_imaqImage = imaqCreateImage(type, DEFAULT_BORDER_SIZE);
19}
20
21/**
22 * Frees memory associated with an ImageBase.
23 * Destructor frees the imaq image allocated with the class.
24 */
25ImageBase::~ImageBase() {
26 if (m_imaqImage) imaqDispose(m_imaqImage);
27}
28
29/**
30 * Writes an image to a file with the given filename.
31 * Write the image to a file in the flash on the cRIO.
32 * @param fileName The name of the file to write
33 */
34void ImageBase::Write(const char *fileName) {
35 int success = imaqWriteFile(m_imaqImage, fileName, nullptr);
36 wpi_setImaqErrorWithContext(success, "Imaq Image writeFile error");
37}
38
39/**
40 * Gets the height of an image.
41 * @return The height of the image in pixels.
42 */
43int ImageBase::GetHeight() {
44 int height;
45 imaqGetImageSize(m_imaqImage, nullptr, &height);
46 return height;
47}
48
49/**
50 * Gets the width of an image.
51 * @return The width of the image in pixels.
52 */
53int ImageBase::GetWidth() {
54 int width;
55 imaqGetImageSize(m_imaqImage, &width, nullptr);
56 return width;
57}
58
59/**
60 * Access the internal IMAQ Image data structure.
61 *
62 * @return A pointer to the internal IMAQ Image data structure.
63 */
64Image *ImageBase::GetImaqImage() { return m_imaqImage; }