예제 #1
0
void write_png(const string& filename, const image3f& img, bool flipY) {
    vector<unsigned char> img_png(img.width()*img.height()*4);
    for(int x = 0; x < img.width(); x++ ) {
        for( int y = 0; y < img.height(); y++ ) {
            int i_img = y * img.width() + x;
            int i_png = ( ( flipY ? (img.height()-1-y) : y ) * img.width() + x ) * 4;
            img_png[i_png+0] = (unsigned char)clamp(img.data()[i_img].x * 255, 0.0f, 255.0f);
            img_png[i_png+1] = (unsigned char)clamp(img.data()[i_img].y * 255, 0.0f, 255.0f);
            img_png[i_png+2] = (unsigned char)clamp(img.data()[i_img].z * 255, 0.0f, 255.0f);
            img_png[i_png+3] = 255;
        }
    }
    unsigned error = lodepng::encode(filename, img_png, img.width(), img.height());
    error_if_not(not error, "cannot write png image: %s", filename.c_str());
}
예제 #2
0
void write_pfm(const string& filename, const image3f& img, bool flipY) {
    _write_pnm(filename.c_str(), 'f', img.width(), img.height(), 3, false,
               (flipY)?(unsigned char*)img.flipy().data():(unsigned char*)img.data());
}