Changeset 2260 for trunk/packages/vizservers/vtkvis/TGAWriter.cpp
- Timestamp:
- May 24, 2011, 5:19:52 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/vizservers/vtkvis/TGAWriter.cpp
r2100 r2260 21 21 * \brief Writes image command + data to supplied file descriptor. 22 22 * 23 * The image data must be supplied in BGR order with bottom to23 * The image data must be supplied in BGR(A) order with bottom to 24 24 * top scanline ordering. 25 * 26 * \param[in] fd File descriptor that will be written to 27 * \param[in] cmdName Command name to send (byte length will be appended) 28 * \param[in] data Image data 29 * \param[in] width Width of image in pixels 30 * \param[in] height Height of image in pixels 31 * \param[in] bytesPerPixel Should be 3 or 4, depending on alpha 25 32 */ 26 33 void 27 Rappture::VtkVis::writeTGA(int fd, const char *cmdName, const unsigned char *data, 28 int width, int height) 34 Rappture::VtkVis::writeTGA(int fd, const char *cmdName, 35 const unsigned char *data, 36 int width, int height, 37 int bytesPerPixel) 29 38 { 30 39 TRACE("(%dx%d)\n", width, height); … … 39 48 header[14] = (char)height; 40 49 header[15] = (char)(height >> 8); 41 header[16] = (char) 24; // bits per pixel50 header[16] = (char)(bytesPerPixel*8); // bits per pixel 42 51 43 size_t dataLength = width * height * 3;52 size_t dataLength = width * height * bytesPerPixel; 44 53 45 54 char command[200]; 46 snprintf(command, sizeof(command), "%s image -type image -bytes%lu\n", cmdName,55 snprintf(command, sizeof(command), "%s %lu\n", cmdName, 47 56 (unsigned long)headerLength + dataLength); 48 57 … … 59 68 iov[1].iov_base = header; 60 69 iov[1].iov_len = headerLength; 61 // Image data **must be BGR !**70 // Image data **must be BGR(A)!** 62 71 iov[2].iov_base = const_cast<unsigned char *>(data); 63 72 iov[2].iov_len = dataLength; … … 74 83 * \brief Writes image data to supplied file name 75 84 * 76 * The image data must be supplied in BGR order with bottom to 77 * top scanline ordering. 85 * The image data must be supplied with bottom to top 86 * scanline ordering. Source data should have BGR(A) 87 * ordering, unless srcIsRGB is true, in which case 88 * the source data will be converted from RGB(A) to 89 * BGR(A). Note that this is slow and it is better 90 * to pass in BGR(A) data. 91 * 92 * \param[in] filename Path to file that will be written 93 * \param[in] imgData Image data 94 * \param[in] width Width of image in pixels 95 * \param[in] height Height of image in pixels 96 * \param[in] bytesPerPixel Should be 3 or 4, depending on alpha 97 * \param[in] srcIsRGB If true source data will be re-ordered 78 98 */ 79 99 void 80 Rappture::VtkVis::writeTGAFile(const char *filename, const unsigned char *imgData, 81 int width, int height) 100 Rappture::VtkVis::writeTGAFile(const char *filename, 101 const unsigned char *imgData, 102 int width, int height, 103 int bytesPerPixel, 104 bool srcIsRGB) 82 105 { 83 106 TRACE("%s (%dx%d)\n", filename, width, height); … … 91 114 header[14] = (char)height; 92 115 header[15] = (char)(height >> 8); 93 header[16] = (char) 24; // bits per pixel116 header[16] = (char)(bytesPerPixel*8); // bits per pixel 94 117 95 118 outfile.write(header, sizeof(header)); 96 119 97 // RGB -> BGR 98 for (int i = 0; i < width * height; i++) { 99 outfile << imgData[i*3+2] 100 << imgData[i*3+1] 101 << imgData[i*3]; 120 if (!srcIsRGB) { 121 outfile.write((const char *)imgData, width * height * bytesPerPixel); 122 } else { 123 // RGB(A) -> BGR(A) 124 for (int i = 0; i < width * height; i++) { 125 outfile << imgData[i*bytesPerPixel+2] 126 << imgData[i*bytesPerPixel+1] 127 << imgData[i*bytesPerPixel]; 128 if (bytesPerPixel == 4) { 129 outfile << imgData[i*bytesPerPixel+3]; 130 } 131 } 102 132 } 103 133
Note: See TracChangeset
for help on using the changeset viewer.