PNG read command in VEXcode

I was looking through the API and found at line 246:

uint32_t vexImageBmpRead( const uint8_t *ibuf, v5_image *oBuf, uint32_t maxw, uint32_t maxh > );
uint32_t vexImagePngRead( const uint8_t *ibuf, v5_image *oBuf, uint32_t maxw, uint32_t maxh, > uint32_t ibuflen );
// special use only ! Talk to James.

I was wondering if the image commands could be used but first I would like to ask @jpearman

Well, yes, but I wouldn’t use those as they are rather low level and part of the C API that everything is built on. Use the functions available on Brain.Screen, they automatically deal with things like memory management and file type detection.

from vex_brain.h

  /**
   * @brief Draws an image on the screen using the contents of the memory buffer.
   * @param buffer A pointer to a buffer containing image data in either bmp or png format.
   * @param x The x-coordinate at which the left edge of the image will be drawn.
   * @param y The y-coordinate at which the top edge of the image will be drawn.
   * @param bufferLen The size of the source image buffer in bytes.
   * @return Returns true if the image was successfully drawn on the screen.
   * @details
   *  This function draws an image on the screen using the contents of a buffer into which
   *  either BMP or PNG raw data has already been read.  The contents may have come from a
   *  file on the SD card or have been statically declared in the code.  The image should be
   *  no larger than the V5 Screen, that is, a maximum of 480 pixels wide by 272 pixels high.
   *  The top/left corner of the image is placed at the coordinates given by x and y, these can
   *  be negative if desired.
  */
  bool     drawImageFromBuffer( uint8_t  *buffer, int x, int y, int bufferLen );

  /**
   * @brief Draws an image on the screen using the contents of the memory buffer.
   * @param buffer A pointer to a buffer containing raw 32 bit per pixel image data.
   * @param x The x-coordinate at which the left edge of the image will be drawn.
   * @param y The y-coordinate at which the top edge of the image will be drawn.
   * @param width The width of the image.
   * @param height The height of the image. 
   * @return Returns true if the image was successfully drawn on the screen.
   * @details
   *  This funtion draws an image on the screen using the contents of a buffer into which
   *  raw RGB pixels have been placed.  Each pixel is represented by a 32 bit value, however,
   *  only the lower 24 bits are used as transparency is not yet supported.  The buffer contains
   *  pixels for the first row of the image immediately followed by pixels for the second row and so on.
   *  The image should be no larger than the V5 Screen, that is, a maximum of 480 pixels wide by 272 pixels high.
   *  The top/left corner of the image is placed at the coordinates given by x and y, these can
   *  be negative if desired.
  */
  bool     drawImageFromBuffer( uint32_t *buffer, int x, int y, int width, int height );

  /**
   * @brief Draws an image on the screen using a file on the SD Card as the source.
   * @param name The name of the image, it must have either a ".bmp" or ".png" extension.
   * @param x The x-coordinate at which the left edge of the image will be drawn.
   * @param y The y-coordinate at which the top edge of the image will be drawn.
   * @return Returns true if the image was successfully drawn on the screen.
   * @details
   *  This funtion draws an image on the screen using the contents of a file on an SD Card.
   *  The file should be no larger than 512K bytes and must have either a ".bmp" or ".png" extension.
   *  The image should be no larger than the V5 Screen, that is, a maximum of 480 pixels wide by 272 pixels high.
   *  The top/left corner of the image is placed at the coordinates given by x and y, these can
   *  be negative if desired.
  */
  bool     drawImageFromFile( const char *name, int x, int y );

Oh, and the comment about talking to me refers to the function that follows, not the image reading ones.

2 Likes

could you show an implementation of the drawImageFromBuffer method with 5 arguments. I am having issues when implementing it of it asking for 4 arguments if there is 5 and 5 if there is four.