/* Copyright (C) 2017-2020, Dirk Krause SPDX-License-Identifier: BSD-3-Clause */ /* WARNING: This file was generated by the dkct program (see http://dktools.sourceforge.net/ for details). Changes you make here will be lost if dkct is run again! You should modify the original source and run dkct on it. Original source: dk4bifto.ctr */ /** @file dk4bifto.c The dk4bifto module. */ #line 8 "dk4bifto.ctr" #ifndef DK4CONF_H_INCLUDED #include "dk4conf.h" #endif #ifndef DK4MEM_H_INCLUDED #include "dk4mem.h" #endif #ifndef DK4STRD_H_INCLUDED #include "dk4strd.h" #endif #ifndef DK4BIF_H_INCLUDED #include "dk4bif.h" #endif #ifndef BIF_H_INCLUDED #include "bif.h" #endif #ifndef DK4UNUSED_H_INCLUDED #include "dk4unused.h" #endif #if DK4_HAVE_ASSERT_H #ifndef ASSERT_H_INCLUDED #include #define ASSERT_H_INCLUDED 1 #endif #endif #line 42 "dk4bifto.ctr" /** Compare two frames by frame number. @param l Pointer to left frame. @param r Pointer to right frame. @param cr Comparison criteria (ignored). @return Comparison result. */ static int dk4biftool_frame_compare( const void *l, const void *r, int DK4_ARG_UNUSED(cr) ) { const dk4_bif_frame_t *pl; /* Left side object */ const dk4_bif_frame_t *pr; /* Right side object */ int back = 0; DK4_UNUSED_ARG(cr) if (NULL != l) { if (NULL != r) { pl = (const dk4_bif_frame_t *)l; pr = (const dk4_bif_frame_t *)r; if (pl->fno > pr->fno) { back = 1; } else { if (pl->fno < pr->fno) { back = -1; } } } else { back = 1; } } else { if (NULL != r) { back = -1; } } return back; } int dk4biftool_nc_bif_init( dk4_bif_t *bptr, dkChar const *fn, int ty, int honly, dk4_cs_conv_ctx_t const *pcsctx, dk4_er_t *erp ) { int back = 0; #line 104 "dk4bifto.ctr" #if DK4_USE_ASSERT assert(NULL != bptr); #endif /* Initialize all structure members */ if (NULL != pcsctx) { DK4_MEMCPY(&(bptr->cs_ctx), pcsctx, sizeof(dk4_cs_conv_ctx_t)); } else { dk4cs_context_init(&(bptr->cs_ctx), erp); } bptr->tsdata = NULL; bptr->s_frames = NULL; bptr->i_frames = NULL; bptr->filename = NULL; bptr->cf = NULL; bptr->n_frames = 0; bptr->imgtype = ty; bptr->hdronly = honly; if (NULL != fn) { bptr->filename = dk4str_dup(fn, erp); if (NULL != bptr->filename) { back = 1; } #if TRACE_DEBUG else { #line 131 "dk4bifto.ctr" } #endif } else { back = 1; } if (1 == back) { back = 0; bptr->s_frames = dk4sto_open(erp); if (NULL != bptr->s_frames) { (void)dk4sto_set_comp(bptr->s_frames, dk4biftool_frame_compare, 0); bptr->i_frames = dk4sto_it_open(bptr->s_frames, erp); if (NULL != bptr->i_frames) { back = 1; } #if TRACE_DEBUG else { #line 148 "dk4bifto.ctr" } #endif } #if TRACE_DEBUG else { #line 153 "dk4bifto.ctr" } #endif } #line 157 "dk4bifto.ctr" return back; } void dk4biftool_nc_frame_init( dk4_bif_frame_t *fptr ) { #line 168 "dk4bifto.ctr" #if DK4_USE_ASSERT assert(NULL != fptr); #endif fptr->bg[0] = fptr->bg[1] = fptr->bg[2] = fptr->bg[3] = 0; fptr->bglbd[0] = fptr->bglbd[1] = fptr->bglbd[2] = fptr->bglbd[3] = 0; dk4pxres_setup(&(fptr->resampler), 8, 8); fptr->tsdata = NULL; fptr->res_x = fptr->res_y = -1.0; fptr->fno = 0; fptr->n_comp = 0; fptr->dim_x = fptr->dim_y = (dk4_bif_dim_t)0L; fptr->l_cs = fptr->f_cs = -1; fptr->hbg = 0; fptr->fmres = 0; fptr->fmrmv = 0U; fptr->l_bdepth = fptr->r_bdepth = 8; #line 185 "dk4bifto.ctr" } int dk4biftool_nc_add_frame( dk4_bif_t *bptr, dk4_er_t *erp ) { dk4_bif_frame_t *fptr; /* New frame */ int back = 0; #line 198 "dk4bifto.ctr" #if DK4_USE_ASSERT assert(NULL != bptr); #endif if (SIZE_MAX > bptr->n_frames) { /* Allocate memory for frame, test allocation */ fptr = dk4mem_new(dk4_bif_frame_t,1,erp); if (NULL != fptr) { /* Initialize frame structure */ dk4biftool_nc_frame_init(fptr); fptr->fno = bptr->n_frames; bptr->n_frames += 1; /* Add frame structure to storage */ if (0 != dk4sto_add(bptr->s_frames, fptr, erp)) { bptr->cf = fptr; back = 1; } else { #line 221 "dk4bifto.ctr" dk4mem_free(fptr); } } } else { #line 226 "dk4bifto.ctr" /* Too many frames in bitmap image file, numeric overflow */ dk4error_set_simple_error_code(erp, DK4_E_MATH_OVERFLOW); } #line 231 "dk4bifto.ctr" return back; } dk4_bif_t * dk4biftool_nc_new_for_one_frame( dkChar const *fn, int ty, int honly, dk4_cs_conv_ctx_t const *pcsctx, dk4_er_t *erp ) { dk4_bif_t *back = NULL; int ok = 0; #line 248 "dk4bifto.ctr" /* Allocate memory for bitmap image file */ back = dk4mem_new(dk4_bif_t,1,erp); if (NULL == back) { goto finished; } /* Initialize bitmap image file, allocate resources for components */ if (0 == dk4biftool_nc_bif_init(back, fn, ty, honly, pcsctx, erp)) { goto finished; } /* Add the first frame */ if (0 == dk4biftool_nc_add_frame(back, erp)) { goto finished; } /* Indicate success */ ok = 1; finished: if ((NULL != back) && (0 == ok)) { #line 271 "dk4bifto.ctr" dk4bif_close(back); back = NULL; } #line 275 "dk4bifto.ctr" return back; } /* vim: set ai sw=4 ts=4 : */