mirror of
				https://github.com/webmproject/libwebp.git
				synced 2025-10-31 10:25:46 +01:00 
			
		
		
		
	gif2webp: Allow single-frame animations
Some single-frame GIF images have a canvas larger than the frame rectangle. For such images, we retain the ANMF, ANIM and VP8X chunks in the output WebP file. This ensures that the full canvas width/height and frame offsets are retained. Change-Id: I3ebae4893f953984de4072fda0938411de787a29
This commit is contained in:
		| @@ -585,9 +585,9 @@ static WebPMuxError MuxCleanup(WebPMux* const mux) { | |||||||
|   int num_fragments; |   int num_fragments; | ||||||
|   int num_anim_chunks; |   int num_anim_chunks; | ||||||
|  |  | ||||||
|   // If we have an image with single fragment or frame, convert it to a |   // If we have an image with a single fragment or frame, and its rectangle | ||||||
|   // non-animated non-fragmented image (to avoid writing FRGM/ANMF chunk |   // covers the whole canvas, convert it to a non-animated non-fragmented image | ||||||
|   // unnecessarily). |   // (to avoid writing FRGM/ANMF chunk unnecessarily). | ||||||
|   WebPMuxError err = WebPMuxNumChunks(mux, kChunks[IDX_ANMF].id, &num_frames); |   WebPMuxError err = WebPMuxNumChunks(mux, kChunks[IDX_ANMF].id, &num_frames); | ||||||
|   if (err != WEBP_MUX_OK) return err; |   if (err != WEBP_MUX_OK) return err; | ||||||
|   err = WebPMuxNumChunks(mux, kChunks[IDX_FRGM].id, &num_fragments); |   err = WebPMuxNumChunks(mux, kChunks[IDX_FRGM].id, &num_fragments); | ||||||
| @@ -596,15 +596,19 @@ static WebPMuxError MuxCleanup(WebPMux* const mux) { | |||||||
|     WebPMuxImage* frame_frag; |     WebPMuxImage* frame_frag; | ||||||
|     err = MuxImageGetNth((const WebPMuxImage**)&mux->images_, 1, &frame_frag); |     err = MuxImageGetNth((const WebPMuxImage**)&mux->images_, 1, &frame_frag); | ||||||
|     assert(err == WEBP_MUX_OK);  // We know that one frame/fragment does exist. |     assert(err == WEBP_MUX_OK);  // We know that one frame/fragment does exist. | ||||||
|     if (frame_frag->header_ != NULL) { |     assert(frame_frag != NULL); | ||||||
|  |     if (frame_frag->header_ != NULL && | ||||||
|  |         ((mux->canvas_width_ == 0 && mux->canvas_height_ == 0) || | ||||||
|  |          (frame_frag->width_ == mux->canvas_width_ && | ||||||
|  |           frame_frag->height_ == mux->canvas_height_))) { | ||||||
|       assert(frame_frag->header_->tag_ == kChunks[IDX_ANMF].tag || |       assert(frame_frag->header_->tag_ == kChunks[IDX_ANMF].tag || | ||||||
|              frame_frag->header_->tag_ == kChunks[IDX_FRGM].tag); |              frame_frag->header_->tag_ == kChunks[IDX_FRGM].tag); | ||||||
|       ChunkDelete(frame_frag->header_);  // Removes ANMF/FRGM chunk. |       ChunkDelete(frame_frag->header_);  // Removes ANMF/FRGM chunk. | ||||||
|       frame_frag->header_ = NULL; |       frame_frag->header_ = NULL; | ||||||
|     } |  | ||||||
|       num_frames = 0; |       num_frames = 0; | ||||||
|       num_fragments = 0; |       num_fragments = 0; | ||||||
|     } |     } | ||||||
|  |   } | ||||||
|   // Remove ANIM chunk if this is a non-animated image. |   // Remove ANIM chunk if this is a non-animated image. | ||||||
|   err = WebPMuxNumChunks(mux, kChunks[IDX_ANIM].id, &num_anim_chunks); |   err = WebPMuxNumChunks(mux, kChunks[IDX_ANIM].id, &num_anim_chunks); | ||||||
|   if (err != WEBP_MUX_OK) return err; |   if (err != WEBP_MUX_OK) return err; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user