bool saveLdr(const Path &path, const uint8 *img, int w, int h, int channels) { if (path.testExtension("png")) return savePng(path, img, w, h, channels); return false; }
sp<Retval> GdMonCpustat::draw(int num, sp<info>& info, sp<MonBase>& dest , const char* path) { sp<Retval> retval; if( DFW_RET(retval, MonCpustat::draw(num, info, dest, path)) ) return DFW_RETVAL_D(retval); if( DFW_RET(retval, baseInit()) ) return DFW_RETVAL_D(retval); struct max_st max; struct data_st dt; getMax(&max, info, m_g.cs.w); setData(&dt); drawHead(dest->m_sec, info->m_sec); uint64_t first_sec; uint64_t last_sec = dest->m_sec; for(int k=info->m_aLists.size(), dx=m_g.cr.ex; ((k>0)&&(dx>m_g.cr.sx));) { sp<GdMonCpustat> p = info->m_aLists.get(k-1); sp<GdMonCpustat> pp = info->m_aLists.get(k-2); procData(dx, &max, &dt, p, pp); drawData(dx, &dt); k--; dx--; first_sec = p->m_sec; } drawBottom(dest, &max, &dt); drawLast(first_sec, last_sec); if( DFW_RET(retval, savePng(path, savename(), 0)) ) return DFW_RETVAL_D(retval); return NULL; }
void savePng(GImage* pImage, const char* szFilename) { FILE* pFile = fopen(szFilename, "wb"); if(!pFile) throw Ex("Failed to create file: ", szFilename); FileHolder hFile(pFile); savePng(pImage, pFile); }
bool savePng(const wchar_t* pNameFile, const ImageBase* pImage, bool isInterlaced) { if (!(pNameFile && pImage)) return false; FILE* pFile = ::_wfopen(pNameFile, L"wb"); if (!pFile) return false; bool result = savePng(pFile, pImage, isInterlaced); ::fclose(pFile); return result; }
//! Save the current window display to a file std::string Window::saveFrameBuffer(const std::string& filename) { auto surface = Surface::create(width_, height_, PixelFormat::PF::PIXELFORMAT_RGB24); int stride = surface->rowPitch(); std::vector<uint8_t> pixels; pixels.resize(stride * height_); if(display_->readPixels(0, 0, width_, height_, ReadFormat::RGB, AttrFormat::UNSIGNED_BYTE, pixels, stride)) { surface->writePixels(&pixels[0], height_ * stride); return surface->savePng(filename); } else { LOG_ERROR("Failed to save screenshot"); } return std::string(); }
void CustomPlot::saveAs() { QFileInfo info(Preferences::LastFileAccessed()); info.setFile(info.dir(), info.completeBaseName()); while (1) { QString filter(tr("PNG") + " (*.png)"); QStringList extensions; extensions << filter << tr("JPG") + " (*.jpg)" << tr("PDF") + " (*.pdf)"; QString fileName(QFileDialog::getSaveFileName(this, tr("Save File"), info.filePath(), extensions.join(";;"), &filter)); if (fileName.isEmpty()) { // This will occur if the user cancels the action. return; }else { QRegExp rx("\\*(\\..+)\\)"); if (rx.indexIn(filter) > 0) { filter = rx.cap(1); if (!fileName.endsWith(filter, Qt::CaseInsensitive)) { fileName += filter; } } QSize dim(size()); int upscale(2); if (filter == ".pdf") { qDebug() << "Saving with filter " << fileName << filter; bool noCosmeticPen = true; savePdf(fileName, noCosmeticPen, dim.width(), dim.height()); }else if (filter == ".png") { qDebug() << "Saving with filter " << fileName << filter; savePng(fileName, dim.width(), dim.height(), upscale); }else if (filter == ".jpg") { qDebug() << "Saving with filter " << fileName << filter; saveJpg(fileName, dim.width(), dim.height(), upscale); } Preferences::LastFileAccessed(fileName); break; } } }
int main(int argc, char *argv[]) { HDRImage texture; HDRImage collision; std::cout<<"Loading images..."; if(!loadPng("data/mariotexture.png", texture) || !loadPng("data/mariocollision.png", collision)) { std::cerr<<"failed :("<<std::endl; return -1; } std::cout<<"done!"<<std::endl; // Create a lightbuffer and add an ambient light HDRImage lightbuffer(texture.width, texture.height); lightbuffer.clear(vec3(32.0f)); // Simulate photon distribution into a lightbuffer int photonCount = 1000000; vec3 lightColor = vec3(1.0f, 0.9f, 0.9f); simulate(texture, collision, lightbuffer, photonCount, lightColor); // Multiplicatively blend texture with lightbuffer HDRImage result(texture.width, texture.height); for(int i = 0; i < texture.width * texture.height; ++i) { vec3 tex = texture.pixels[i]; vec3 light = lightbuffer.pixels[i]; result.pixels[i] = tex * light; } applyTonemap(result); //applyTonemap(lightbuffer); std::cout<<"Saving image..."; savePng("data/texturepp.png", result); std::cout<<"done!\n"; std::cin.get(); return 0; }
void Bitmap::save(const String &filename) { savePng(filename, _data.data(), _width, _height, _stride, _color); }
void Bitmap::savePng(const String &filename, const uint8_t *data, uint32_t width, uint32_t height, Format format, bool invert) { savePng(filename, data, width, height, 0, format, invert); }
int main(int argc, char **argv) { char *filename, *p_filename; char *base, tmpFile[PATH_MAX]; GAMEMAP *map; MAPTILE *psTile; if (argc != 2) { printf("Usage: %s <map>\n", argv[0]); return -1; } physfs_init(argv[0]); filename = physfs_addmappath(argv[1]); p_filename = strrchr(filename, '/'); if (p_filename) { p_filename++; base = strdup(p_filename); } else { base = strdup(filename); } map = mapLoad(filename); free(filename); if (!map) { return EXIT_FAILURE; } const PreviewColors* tileColors = NULL; switch (map->tileset) { case TILESET_ARIZONA: tileColors = &pArizonaColors; break; case TILESET_URBAN: tileColors = &pUrbanColors; break; case TILESET_ROCKIES: tileColors = &pRockiesColors; break; default: fprintf(stderr, "Unknown tileset: %d\n", (int)map->tileset); mapFree(map); physfs_shutdown(); return EXIT_FAILURE; } const int mapWidth = (int) map->width; const int mapHeight = (int) map->height; int col; // RGB888 pixels uint8_t *pixels = (uint8_t*) malloc(sizeof(uint8_t) * mapWidth * mapHeight * 3); for (int y = 0; y < mapHeight; y++) { for (int x = 0; x < mapWidth; x++) { // We're placing the origin at the top for aesthetic reasons psTile = mapTile(map, x, mapHeight-1-y); col = psTile->height / 2; // 2 = ELEVATION_SCALE uint8_t * const p = &pixels[(y * map->width + x) * 3]; switch(terrainType(psTile)) { case TER_CLIFFFACE: p[0] = tileColors->cliffLow.x + (tileColors->cliffHigh.x - tileColors->cliffLow.x) * col / 256; p[1] = tileColors->cliffLow.y + (tileColors->cliffHigh.y - tileColors->cliffLow.y) * col / 256; p[2] = tileColors->cliffLow.z + (tileColors->cliffHigh.z - tileColors->cliffLow.z) * col / 256; break; case TER_WATER: p[0] = tileColors->water.x; p[1] = tileColors->water.y; p[2] = tileColors->water.z; break; case TER_ROAD: p[0] = tileColors->roadLow.x + (tileColors->roadHigh.x - tileColors->roadLow.x) * col / 256; p[1] = tileColors->roadLow.y + (tileColors->roadHigh.y - tileColors->roadLow.y) * col / 256; p[2] = tileColors->roadLow.z + (tileColors->roadHigh.z - tileColors->roadLow.z) * col / 256; break; default: p[0] = tileColors->groundLow.x + (tileColors->groundHigh.x - tileColors->groundLow.x) * col / 256; p[1] = tileColors->groundLow.y + (tileColors->groundHigh.y - tileColors->groundLow.y) * col / 256; p[2] = tileColors->groundLow.z + (tileColors->groundHigh.z - tileColors->groundLow.z) * col / 256; break; } } } paintStructureData(pixels, map); strcpy(tmpFile, base); strcat(tmpFile, ".png"); savePng(tmpFile, pixels, mapWidth, mapHeight); free(pixels); mapFree(map); physfs_shutdown(); return 0; }
void savePng(GImage* pImage, FILE* pFile) { savePng(pImage, pFile, true); }