Brian Silverman | 26e4e52 | 2015-12-17 01:56:40 -0500 | [diff] [blame^] | 1 | /*----------------------------------------------------------------------------*/ |
| 2 | /* Copyright (c) FIRST 2014. 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 "Vision/ImageBase.h" |
| 8 | #include "nivision.h" |
| 9 | |
| 10 | /** |
| 11 | * Create a new instance of an ImageBase. |
| 12 | * Imagebase is the base of all the other image classes. The constructor |
| 13 | * creates any type of image and stores the pointer to it in the class. |
| 14 | * @param type The type of image to create |
| 15 | */ |
| 16 | ImageBase::ImageBase(ImageType type) { |
| 17 | m_imaqImage = imaqCreateImage(type, DEFAULT_BORDER_SIZE); |
| 18 | } |
| 19 | |
| 20 | /** |
| 21 | * Frees memory associated with an ImageBase. |
| 22 | * Destructor frees the imaq image allocated with the class. |
| 23 | */ |
| 24 | ImageBase::~ImageBase() { |
| 25 | if (m_imaqImage) imaqDispose(m_imaqImage); |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * Writes an image to a file with the given filename. |
| 30 | * Write the image to a file in the flash on the cRIO. |
| 31 | * @param fileName The name of the file to write |
| 32 | */ |
| 33 | void ImageBase::Write(const char *fileName) { |
| 34 | int success = imaqWriteFile(m_imaqImage, fileName, nullptr); |
| 35 | wpi_setImaqErrorWithContext(success, "Imaq Image writeFile error"); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Gets the height of an image. |
| 40 | * @return The height of the image in pixels. |
| 41 | */ |
| 42 | int ImageBase::GetHeight() { |
| 43 | int height; |
| 44 | imaqGetImageSize(m_imaqImage, nullptr, &height); |
| 45 | return height; |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Gets the width of an image. |
| 50 | * @return The width of the image in pixels. |
| 51 | */ |
| 52 | int ImageBase::GetWidth() { |
| 53 | int width; |
| 54 | imaqGetImageSize(m_imaqImage, &width, nullptr); |
| 55 | return width; |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Access the internal IMAQ Image data structure. |
| 60 | * |
| 61 | * @return A pointer to the internal IMAQ Image data structure. |
| 62 | */ |
| 63 | Image *ImageBase::GetImaqImage() { return m_imaqImage; } |