Skip to content

Commit

Permalink
try to split save() into open/next/close
Browse files Browse the repository at this point in the history
  • Loading branch information
dk committed Nov 1, 2023
1 parent bcad183 commit 92a884f
Show file tree
Hide file tree
Showing 7 changed files with 307 additions and 272 deletions.
4 changes: 2 additions & 2 deletions img/codec_X11.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ open_load( PImgCodec instance, PImgLoadFileInstance fi)
int yh, yw;
Byte * data;

if( XReadBitmapFileData( fi-> fileName, fi-> is_utf8, &w, &h, &data, &yw, &yh) != BitmapSuccess)
if( XReadBitmapFileData( fi-> io.fileName, fi-> io.is_utf8, &w, &h, &data, &yw, &yh) != BitmapSuccess)
return NULL;

fi-> stop = true;
Expand Down Expand Up @@ -222,7 +222,7 @@ save( PImgCodec instance, PImgSaveFileInstance fi)
Byte * l;
int h = i-> h, col = -1;
Byte * s = i-> data + ( h - 1) * i-> lineSize;
char * xc = fi-> fileName, * name;
char * xc = fi-> io.fileName, * name;
int ls = ( i-> w >> 3) + (( i-> w & 7) ? 1 : 0);
int first = 1;
HV * profile = fi-> objectExtras;
Expand Down
4 changes: 2 additions & 2 deletions img/codec_Xpm.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ open_load( PImgCodec instance, PImgLoadFileInstance fi)

info. valuemask = XpmComments | XpmColorTable | XpmExtensions;

switch ( XpmReadFileToXpmImage( fi-> fileName, &image, &info)) {
switch ( XpmReadFileToXpmImage( fi-> io.fileName, &image, &info)) {
case XpmSuccess:
break;
case XpmNoMemory:
Expand Down Expand Up @@ -609,7 +609,7 @@ save( PImgCodec instance, PImgSaveFileInstance fi)
info. valuemask |= XpmExtensions;
}

ret = XpmWriteFileFromXpmImage( fi-> fileName, &image, &info);
ret = XpmWriteFileFromXpmImage( fi-> io.fileName, &image, &info);

EXIT:
free( extholder);
Expand Down
8 changes: 4 additions & 4 deletions img/codec_heif.c
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ open_save( PImgCodec instance, PImgSaveFileInstance fi)
SaveRec *l;
int sz;

sz = sizeof(SaveRec) + (fi->frameMapSize * sizeof(struct heif_image_handle*));
sz = sizeof(SaveRec) + (fi->n_frames * sizeof(struct heif_image_handle*));
if (!(l = malloc(sz))) return NULL;
memset( l, 0, sz);
l-> handles = l->handlebuf;
Expand Down Expand Up @@ -774,7 +774,7 @@ encode_thumbnail( PImgSaveFileInstance fi, HV * profile)
return true;

thumbnail_of = pget_i(thumbnail_of);
if ( thumbnail_of < 0 || thumbnail_of >= fi->frameMapSize )
if ( thumbnail_of < 0 || thumbnail_of >= fi->n_frames )
SET_ERROR("thumbnail_of must be an integer from 0 to the last frame");
if ( thumbnail_of == fi->frame)
SET_ERROR("thumbnail_of cannot refer to itself");
Expand Down Expand Up @@ -1063,7 +1063,7 @@ save( PImgCodec instance, PImgSaveFileInstance fi)
CHECK_HEIF_ERROR;
}

if ( fi-> frame == fi-> frameMapSize - 1 ) {
if ( fi-> frame == fi-> n_frames - 1 ) {
CALL heif_context_write(l->ctx, &writer, fi->req);
CHECK_HEIF_ERROR;
}
Expand All @@ -1083,7 +1083,7 @@ close_save( PImgCodec instance, PImgSaveFileInstance fi)
SaveRec * l = ( SaveRec *) fi-> instance;
int i;

for ( i = 0; i < fi-> frameMapSize; i++) {
for ( i = 0; i < fi-> n_frames; i++) {
if ( l->handles[i] )
heif_image_handle_release(l->handles[i]);
}
Expand Down
6 changes: 3 additions & 3 deletions img/codec_png.c
Original file line number Diff line number Diff line change
Expand Up @@ -2094,7 +2094,7 @@ write_first_frame(PImgSaveFileInstance fi)
png_unknown_chunk acTL_chunk = { "acTL", actl, 8, PNG_HAVE_IHDR };
png_byte apngChunks[]= {"acTL\0fcTL\0fdAT\0"};

png_save_uint_32( &actl[0], fi->frameMapSize);
png_save_uint_32( &actl[0], fi->n_frames);
png_save_uint_32( &actl[4], pexist(loopCount) ? pget_i(loopCount) : 0);

png_set_keep_unknown_chunks( s->png_ptr, PNG_HANDLE_CHUNK_ALWAYS, apngChunks, 3);
Expand Down Expand Up @@ -2160,13 +2160,13 @@ save( PImgCodec instance, PImgSaveFileInstance fi)
if ( setjmp( png_jmpbuf( s-> png_ptr)) != 0) return false;

#ifdef APNG
if ( fi->frameMapSize == 1 )
if ( fi->n_frames == 1 )
#endif
return write_classic_png(fi);
#ifdef APNG
else if ( fi->frame == 0)
return write_first_frame(fi);
else if ( fi->frame == fi->frameMapSize - 1)
else if ( fi->frame == fi->n_frames - 1)
return write_last_frame(fi);
else
return write_middle_frame(fi);
Expand Down
4 changes: 2 additions & 2 deletions img/codec_webp.c
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ finalize_save(PImgSaveFileInstance fi, SaveRec *s)
return false;
}

need_loop_count = fi->frameMapSize > 1;
need_loop_count = fi->n_frames > 1;

if ( need_loop_count ) {
if (!(s->mux = WebPMuxCreate(&s->webp_data, 1))) {
Expand Down Expand Up @@ -734,7 +734,7 @@ save( PImgCodec instance, PImgSaveFileInstance fi)
s->timestamp += delay;

/* save file */
if ( fi->frame == fi->frameMapSize - 1) {
if ( fi->frame == fi->n_frames - 1) {
if (!finalize_save(fi, s))
return false;
}
Expand Down
Loading

0 comments on commit 92a884f

Please sign in to comment.