static void SaveOutput(const WebPDecBuffer* const buffer, OutputFileFormat format, const char* const out_file) { FILE* fout = NULL; int needs_open_file = 1; int ok = 1; Stopwatch stop_watch; if (verbose) StopwatchReadAndReset(&stop_watch); #ifdef HAVE_WINCODEC_H needs_open_file = (format != PNG); #endif if (needs_open_file) { fout = fopen(out_file, "wb"); if (!fout) { fprintf(stderr, "Error opening output file %s\n", out_file); return; } } if (format == PNG) { #ifdef HAVE_WINCODEC_H ok &= WritePNG(out_file, buffer); #else ok &= WritePNG(fout, buffer); #endif } else if (format == PAM) { ok &= WritePPM(fout, buffer, 1); } else if (format == PPM) { ok &= WritePPM(fout, buffer, 0); } else if (format == PGM || format == YUV) { ok &= WritePGMOrYUV(fout, buffer, format); } else if (format == ALPHA_PLANE_ONLY) { ok &= WriteAlphaPlane(fout, buffer); } if (fout) { fclose(fout); } if (ok) { printf("Saved file %s\n", out_file); if (verbose) { const double write_time = StopwatchReadAndReset(&stop_watch); printf("Time to write output: %.3fs\n", write_time); } } else { fprintf(stderr, "Error writing file %s !!\n", out_file); } }
VP8StatusCode DecodeWebP(const uint8_t* const data, size_t data_size, int verbose, WebPDecoderConfig* const config) { Stopwatch stop_watch; VP8StatusCode status = VP8_STATUS_OK; if (config == NULL) return VP8_STATUS_INVALID_PARAM; PrintAnimationWarning(config); StopwatchReset(&stop_watch); // Decoding call. status = WebPDecode(data, data_size, config); if (verbose) { const double decode_time = StopwatchReadAndReset(&stop_watch); fprintf(stderr, "Time to decode picture: %.3fs\n", decode_time); } return status; }
VP8StatusCode DecodeWebPIncremental( const uint8_t* const data, size_t data_size, int verbose, WebPDecoderConfig* const config) { Stopwatch stop_watch; VP8StatusCode status = VP8_STATUS_OK; if (config == NULL) return VP8_STATUS_INVALID_PARAM; PrintAnimationWarning(config); StopwatchReset(&stop_watch); // Decoding call. { WebPIDecoder* const idec = WebPIDecode(data, data_size, config); if (idec == NULL) { fprintf(stderr, "Failed during WebPINewDecoder().\n"); return VP8_STATUS_OUT_OF_MEMORY; } else { #ifdef WEBP_EXPERIMENTAL_FEATURES size_t size = 0; const size_t incr = 2 + (data_size / 20); while (size < data_size) { size_t next_size = size + (rand() % incr); if (next_size > data_size) next_size = data_size; status = WebPIUpdate(idec, data, next_size); if (status != VP8_STATUS_OK && status != VP8_STATUS_SUSPENDED) break; size = next_size; } #else status = WebPIUpdate(idec, data, data_size); #endif WebPIDelete(idec); } } if (verbose) { const double decode_time = StopwatchReadAndReset(&stop_watch); fprintf(stderr, "Time to decode picture: %.3fs\n", decode_time); } return status; }