Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

stb_image: fix gif decoding: only restore background when dispose is 2 or 3#1702

Open
cocoa-xu wants to merge1 commit intonothings:master
base:master
Choose a base branch
Loading
fromcocoa-xu:cx-git-bg-dispose-restore

Conversation

cocoa-xu
Copy link

Hi, this PR shouldfix#1688. Background should be restored only when dispose is 2 or 3.

Minimal test code

gif-background.c

#ifdef__clang__#defineSTBIDEF static inline#endif#defineSTB_IMAGE_STATIC#defineSTB_IMAGE_IMPLEMENTATION#include"stb_image.h"#defineSTB_IMAGE_WRITE_IMPLEMENTATION#include"stb_image_write.h"#include<stdio.h>#include<stdlib.h>#include<sys/stat.h>unsignedchar*read_binary_file(constchar*filename,size_t*size) {FILE*file=fopen(filename,"rb");if (file==NULL) {fprintf(stderr,"Error opening file: %s\n",filename);returnNULL;    }structstatst;if (stat(filename,&st)!=0) {fprintf(stderr,"Error getting file size\n");fclose(file);returnNULL;    }*size=st.st_size;unsignedchar*buffer= (unsignedchar*)malloc(*size);if (buffer==NULL) {fprintf(stderr,"Error allocating memory\n");fclose(file);returnNULL;    }size_tbytes_read=fread(buffer,1,*size,file);if (bytes_read!=*size) {fprintf(stderr,"Error reading file: expected %zu bytes, got %zu bytes\n",*size,bytes_read);free(buffer);fclose(file);returnNULL;    }fclose(file);returnbuffer;}intmain(intargc,constchar*argv[]) {if (argc!=3) {printf("Usage: %s <gif file> <output dir>\n",argv[0]);exit(1);    }size_tfile_size;unsignedchar*filedata=read_binary_file(argv[1],&file_size);intx,y,z,comp;int*delays=NULL;unsignedchar*data=stbi_load_gif_from_memory(filedata, (int)file_size,&delays,&x,&y,&z,&comp,0);if (data==NULL) {fprintf(stderr,"Error loading image\n");return1;    }unsignedchar*start=data;size_tframe_size=x*y*sizeof(unsignedchar)*4;char*filename= (char*)malloc(1024);for (inti=0;i<z;++i) {bzero(filename,1024);snprintf(filename,1023,"%s/%d.png",argv[2],i);stbi_write_png(filename,x,y,4,start,0);start+=frame_size;    }free(filename);STBI_FREE((void*)data);STBI_FREE((void*)delays);}

horse.gif

File from#1688:

horse

Test

Assuminggif-background.c andhorse.gif has been downloaded to the project root directory.

$cd stb$ gcc -I$(pwd) gif-background.c -o gif-background$ mkdir -p ./output$ gif-background ./horse.gif ./output

Visual check on the 6th frame

Before

5

After

5

Signed-off-by: Cocoa <i@uwucocoa.moe>
@cocoa-xucocoa-xuforce-pushed thecx-git-bg-dispose-restore branch from7a14f3b toff74b42CompareOctober 9, 2024 10:14
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Using stbi_load_gif_from_memory results in incorrect image data for each frame of the GIF
1 participant
@cocoa-xu

[8]ページ先頭

©2009-2025 Movatter.jp