Ignore:
Timestamp:
May 24, 2011, 5:19:52 PM (13 years ago)
Author:
ldelgass
Message:

New heightmap command/object in vtkvis server - contour plot with vertical
displacement. Also initial work on supporting additional data set types
such as point clouds.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/vizservers/vtkvis/TGAWriter.cpp

    r2100 r2260  
    2121 * \brief Writes image command + data to supplied file descriptor.
    2222 *
    23  * The image data must be supplied in BGR order with bottom to
     23 * The image data must be supplied in BGR(A) order with bottom to
    2424 * 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
    2532 */
    2633void
    27 Rappture::VtkVis::writeTGA(int fd, const char *cmdName, const unsigned char *data,
    28                            int width, int height)
     34Rappture::VtkVis::writeTGA(int fd, const char *cmdName,
     35                           const unsigned char *data,
     36                           int width, int height,
     37                           int bytesPerPixel)
    2938{
    3039    TRACE("(%dx%d)\n", width, height);
     
    3948    header[14] = (char)height;
    4049    header[15] = (char)(height >> 8);
    41     header[16] = (char)24; // bits per pixel
     50    header[16] = (char)(bytesPerPixel*8); // bits per pixel
    4251
    43     size_t dataLength = width * height * 3;
     52    size_t dataLength = width * height * bytesPerPixel;
    4453
    4554    char command[200];
    46     snprintf(command, sizeof(command), "%simage -type image -bytes %lu\n", cmdName,
     55    snprintf(command, sizeof(command), "%s %lu\n", cmdName,
    4756             (unsigned long)headerLength + dataLength);
    4857
     
    5968    iov[1].iov_base = header;
    6069    iov[1].iov_len = headerLength;
    61     // Image data **must be BGR!**
     70    // Image data **must be BGR(A)!**
    6271    iov[2].iov_base = const_cast<unsigned char *>(data);
    6372    iov[2].iov_len = dataLength;
     
    7483 * \brief Writes image data to supplied file name
    7584 *
    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
    7898 */
    7999void
    80 Rappture::VtkVis::writeTGAFile(const char *filename, const unsigned char *imgData,
    81                                int width, int height)
     100Rappture::VtkVis::writeTGAFile(const char *filename,
     101                               const unsigned char *imgData,
     102                               int width, int height,
     103                               int bytesPerPixel,
     104                               bool srcIsRGB)
    82105{
    83106    TRACE("%s (%dx%d)\n", filename, width, height);
     
    91114    header[14] = (char)height;
    92115    header[15] = (char)(height >> 8);
    93     header[16] = (char)24; // bits per pixel
     116    header[16] = (char)(bytesPerPixel*8); // bits per pixel
    94117
    95118    outfile.write(header, sizeof(header));
    96119
    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        }
    102132    }
    103133
Note: See TracChangeset for help on using the changeset viewer.