Example #1
0
WebPMuxError WebPMuxSetImage(WebPMux* mux, const WebPData* bitstream,
                             int copy_data) {
  WebPMuxImage wpi;
  WebPMuxError err;

  // Sanity checks.
  if (mux == NULL || bitstream == NULL || bitstream->bytes == NULL ||
      bitstream->size > MAX_CHUNK_PAYLOAD) {
    return WEBP_MUX_INVALID_ARGUMENT;
  }

  if (mux->images_ != NULL) {
    // Only one 'simple image' can be added in mux. So, remove present images.
    MuxImageDeleteAll(&mux->images_);
  }

  MuxImageInit(&wpi);
  err = SetAlphaAndImageChunks(bitstream, copy_data, &wpi);
  if (err != WEBP_MUX_OK) goto Err;

  // Add this WebPMuxImage to mux.
  err = MuxImagePush(&wpi, &mux->images_);
  if (err != WEBP_MUX_OK) goto Err;

  // All is well.
  return WEBP_MUX_OK;

 Err:  // Something bad happened.
  MuxImageRelease(&wpi);
  return err;
}
Example #2
0
static void MuxRelease(WebPMux* const mux) {
  if (mux == NULL) return;
  MuxImageDeleteAll(&mux->images_);
  DeleteAllChunks(&mux->vp8x_);
  DeleteAllChunks(&mux->iccp_);
  DeleteAllChunks(&mux->loop_);
  DeleteAllChunks(&mux->meta_);
  DeleteAllChunks(&mux->unknown_);
}
Example #3
0
WebPMuxError WebPMuxSetImage(WebPMux* mux,
                             const WebPData* bitstream, int copy_data) {
  WebPMuxError err;
  WebPChunk chunk;
  WebPMuxImage wpi;
  WebPData image;
  WebPData alpha;
  int is_lossless;
  int image_tag;

  if (mux == NULL || bitstream == NULL || bitstream->bytes_ == NULL ||
      bitstream->size_ > MAX_CHUNK_PAYLOAD) {
    return WEBP_MUX_INVALID_ARGUMENT;
  }

  // If given data is for a whole webp file,
  // extract only the VP8/VP8L data from it.
  err = GetImageData(bitstream, &image, &alpha, &is_lossless);
  if (err != WEBP_MUX_OK) return err;
  image_tag = is_lossless ? kChunks[IDX_VP8L].tag : kChunks[IDX_VP8].tag;

  // Delete the existing images.
  MuxImageDeleteAll(&mux->images_);

  MuxImageInit(&wpi);

  if (alpha.bytes_ != NULL) {  // Add alpha chunk.
    ChunkInit(&chunk);
    err = ChunkAssignData(&chunk, &alpha, copy_data, kChunks[IDX_ALPHA].tag);
    if (err != WEBP_MUX_OK) goto Err;
    err = ChunkSetNth(&chunk, &wpi.alpha_, 1);
    if (err != WEBP_MUX_OK) goto Err;
  }

  // Add image chunk.
  ChunkInit(&chunk);
  err = ChunkAssignData(&chunk, &image, copy_data, image_tag);
  if (err != WEBP_MUX_OK) goto Err;
  err = ChunkSetNth(&chunk, &wpi.img_, 1);
  if (err != WEBP_MUX_OK) goto Err;

  // Add this image to mux.
  err = MuxImagePush(&wpi, &mux->images_);
  if (err != WEBP_MUX_OK) goto Err;

  // All OK.
  return WEBP_MUX_OK;

 Err:
  // Something bad happened.
  ChunkRelease(&chunk);
  MuxImageRelease(&wpi);
  return err;
}
Example #4
0
WebPMuxError WebPMuxDeleteImage(WebPMux* mux) {
  WebPMuxError err;

  if (mux == NULL) return WEBP_MUX_INVALID_ARGUMENT;

  err = MuxValidateForImage(mux);
  if (err != WEBP_MUX_OK) return err;

  // All well, delete image.
  MuxImageDeleteAll(&mux->images_);
  return WEBP_MUX_OK;
}