Changeset 461 for trunk/gui/vizservers


Ignore:
Timestamp:
Jun 5, 2006, 6:42:59 PM (18 years ago)
Author:
mmc
Message:

Fixed a bug in the BMP encoding of the transmitted image. BMP wants
all data in BGR (backwards) form, and it pads each scan line to an
even multiple of 4 bytes. The OpenGL calls that fetch the screen
do the same padding, but they put out data in RGB. We needed to
swap the bytes and communicate the proper padding information for
screen sizes that weren't an even multiple of 4.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gui/vizservers/nanovis/nanovis.cpp

    r458 r461  
    21782178
    21792179
     2180#if DO_RLE
    21802181char rle[512*512*3];
    21812182int rle_size;
     
    22112212  }
    22122213}
     2214#endif
    22132215
    22142216// used internally to build up the BMP file header
     
    22312233    header[pos++] = 'M';
    22322234
     2235    // BE CAREFUL:  BMP files must have an even multiple of 4 bytes
     2236    // on each scan line.  If need be, we add padding to each line.
     2237    int pad = 0;
     2238    if ((3*win_width) % 4 > 0) {
     2239        pad = 4 - ((3*win_width) % 4);
     2240    }
     2241
    22332242    // file size in bytes
    2234     int fsize = win_width*win_height*3 + sizeof(header);
     2243    int fsize = (3*win_width+pad)*win_height + sizeof(header);
    22352244    bmp_header_add_int(header, pos, fsize);
    22362245
     
    22502259    bmp_header_add_int(header, pos, win_height);
    22512260
    2252     // 1 plane + 24 bits/pixel << 16
     2261    // 1 plane + (24 bits/pixel << 16)
    22532262    bmp_header_add_int(header, pos, 1572865);
    22542263
     
    22692278
    22702279    // BE CAREFUL: BMP format wants BGR ordering for screen data
    2271     for (int i=0; i < 3*win_width*win_height; i += 3) {
    2272         unsigned char tmp = screen_buffer[i+2];
    2273         screen_buffer[i+2] = screen_buffer[i];
    2274         screen_buffer[i] = tmp;
     2280    unsigned char* scr = screen_buffer;
     2281    for (int row=0; row < win_height; row++) {
     2282        for (int col=0; col < win_width; col++) {
     2283            unsigned char tmp = scr[2];
     2284            scr[2] = scr[0];  // B
     2285            scr[0] = tmp;     // R
     2286            scr += 3;
     2287        }
     2288        scr += pad;  // skip over padding already in screen data
    22752289    }
    22762290
     
    22802294
    22812295    write(0, header, sizeof(header));
    2282     write(0, screen_buffer, 3*win_width*win_height);
     2296    write(0, screen_buffer, (3*win_width+pad)*win_height);
    22832297}
    22842298
Note: See TracChangeset for help on using the changeset viewer.