Image.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. * Copyright (c) 2016-2017, NVIDIA CORPORATION. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of NVIDIA CORPORATION nor the names of its
  13. * contributors may be used to endorse or promote products derived
  14. * from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  19. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  20. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  21. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  22. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  23. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  24. * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  26. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. */
  28. #ifndef _EGLSTREAM_IMAGE_H
  29. #define _EGLSTREAM_IMAGE_H
  30. namespace EGLStream
  31. {
  32. /**
  33. * Image objects wrap the image data included in an acquired Frame.
  34. */
  35. class Image : public Argus::InterfaceProvider
  36. {
  37. protected:
  38. ~Image() {}
  39. };
  40. /**
  41. * @class IImage
  42. *
  43. * Interface to provide the core functions for an Image.
  44. */
  45. DEFINE_UUID(Argus::InterfaceID, IID_IMAGE, 546F4522,87EF,11E5,A837,08,00,20,0C,9A,66);
  46. class IImage : public Argus::Interface
  47. {
  48. public:
  49. static const Argus::InterfaceID& id() { return IID_IMAGE; }
  50. /**
  51. * Returns the number of buffers in the Image.
  52. */
  53. virtual uint32_t getBufferCount() const = 0;
  54. /**
  55. * Returns the size of one of the Image's buffers.
  56. * @param[in] index The index of the buffer whose size to return (defaults to 0).
  57. */
  58. virtual uint64_t getBufferSize(uint32_t index = 0) const = 0;
  59. /**
  60. * Maps a buffer for CPU access and returns the mapped pointer.
  61. * How this data is laid out in memory may be described by another Frame interface,
  62. * or if the pixel format is UNKNOWN then it should be defined by the stream's producer.
  63. * @param[in] index The buffer index to map.
  64. * @param[out] status An optional pointer to return an error status code.
  65. */
  66. virtual const void* mapBuffer(uint32_t index, Argus::Status* status = NULL) = 0;
  67. /**
  68. * Maps the first/only buffer for CPU access and returns the mapped pointer.
  69. * How this data is laid out in memory may be described by another Frame interface,
  70. * or if the pixel format is UNKNOWN then it should be defined by the stream's producer.
  71. * @param[out] status An optional pointer to return an error status code.
  72. */
  73. virtual const void* mapBuffer(Argus::Status* status = NULL) = 0;
  74. protected:
  75. ~IImage() {}
  76. };
  77. /**
  78. * @class IImage2D
  79. *
  80. * Interface that describes a 2D Image.
  81. *
  82. * Note that some 2D Image formats are composed of multiple 2D planes -- for
  83. * example, the color planes of a YUV image, or the buffer pyramid of a mipmap
  84. * stack. Each buffer in the image corresponds to an image plane, and the index
  85. * parameters used by this interfaces are identical to those used in IImage.
  86. */
  87. DEFINE_UUID(Argus::InterfaceID, IID_IMAGE_2D, 546F4525,87EF,11E5,A837,08,00,20,0C,9A,66);
  88. class IImage2D : public Argus::Interface
  89. {
  90. public:
  91. static const Argus::InterfaceID& id() { return IID_IMAGE_2D; }
  92. /**
  93. * Returns the size of the image plane, in pixels.
  94. * @param[in] index buffer index to get the size of (defaults to 0).
  95. */
  96. virtual Argus::Size2D<uint32_t> getSize(uint32_t index = 0) const = 0;
  97. /**
  98. * Returns the stride, or bytes per pixel row, of the image plane.
  99. * @param[in] index buffer index to get the width of (defaults to 0).
  100. */
  101. virtual uint32_t getStride(uint32_t index = 0) const = 0;
  102. protected:
  103. ~IImage2D() {}
  104. };
  105. /**
  106. * @class IImageJPEG
  107. *
  108. * Provides a method to encode Images as JPEG data and write to disk.
  109. */
  110. DEFINE_UUID(Argus::InterfaceID, IID_IMAGE_JPEG, 48aeddc9,c8d8,11e5,a837,08,00,20,0c,9a,66);
  111. class IImageJPEG : public Argus::Interface
  112. {
  113. public:
  114. static const Argus::InterfaceID& id() { return IID_IMAGE_JPEG; }
  115. /**
  116. * Encodes the Image to JPEG and write to disk. This call blocks
  117. * until writing of the file is complete.
  118. * @param[in] path The file path to write the JPEG to.
  119. */
  120. virtual Argus::Status writeJPEG(const char* path) const = 0;
  121. protected:
  122. ~IImageJPEG() {}
  123. };
  124. /**
  125. * @class IImageHeaderlessFile
  126. *
  127. * Provides a method to write image data to disk with no encoding,
  128. * and no header.
  129. *
  130. * All pixels are written to file in buffer, row, column order, with
  131. * multi-byte pixels stored little-endian.
  132. *
  133. * Filename should specify width and height, and pixel/layout i.e. NV12, P016,
  134. * or a specific Bayer layout.
  135. */
  136. DEFINE_UUID(Argus::InterfaceID, IID_IMAGE_HEADERLESS_FILE,
  137. 03018970,9254,11e7,9598,08,00,20,0c,9a,66);
  138. class IImageHeaderlessFile : public Argus::Interface
  139. {
  140. public:
  141. static const Argus::InterfaceID& id() { return IID_IMAGE_HEADERLESS_FILE; }
  142. /**
  143. * Writes the pixels to disk.
  144. * This call blocks until writing of the file is complete.
  145. * @param[in] path The file path to write.
  146. */
  147. virtual Argus::Status writeHeaderlessFile(const char* path) const = 0;
  148. protected:
  149. ~IImageHeaderlessFile() {}
  150. };
  151. } // namespace EGLStream
  152. #endif // _EGLSTREAM_IMAGE_H