summaryrefslogtreecommitdiff
path: root/support/dktools/dk3bif.ctr
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2020-09-20 03:03:26 +0000
committerNorbert Preining <norbert@preining.info>2020-09-20 03:03:26 +0000
commit1f457376b478257b88d4a857f5ec1b6155442dd7 (patch)
tree2a06a60551dea362cf8cb0cb0ba66c78608717c4 /support/dktools/dk3bif.ctr
parentac690ca29ad5bf8a5203a65fd6252f7b564f4727 (diff)
CTAN sync 202009200303
Diffstat (limited to 'support/dktools/dk3bif.ctr')
-rw-r--r--support/dktools/dk3bif.ctr417
1 files changed, 227 insertions, 190 deletions
diff --git a/support/dktools/dk3bif.ctr b/support/dktools/dk3bif.ctr
index afc5e90634..8a1d8e0e3a 100644
--- a/support/dktools/dk3bif.ctr
+++ b/support/dktools/dk3bif.ctr
@@ -2,7 +2,7 @@
copyright owner = Dirk Krause
copyright year = 2011-xxxx
-license = bsd
+SPDX-License-Identifier: BSD-3-Clause
@@ -169,7 +169,7 @@ dk3bif_next_frame(dk3_bif_t *bp);
/** Check whether a bitmap image is really colored.
@param bp Bitmap image file.
- @return 1 for colored image, 0 for grey.
+ @return 1 for colored image, 0 for gray.
*/
int
dk3bif_is_colored(dk3_bif_t *bp);
@@ -509,13 +509,9 @@ static unsigned long dk3bif_temp_number = 0UL;
-static
-dk3_bif_frame_t *
-dk3bif_frame_new(dk3_bif_t *bp);
-
+#if DK3_HAVE_PNG_H
-#if DK3_HAVE_PNG_H
/** Per frame data, PNG-specific.
*/
typedef struct {
@@ -529,6 +525,7 @@ typedef struct {
int paln;
} dk3_bif_frame_png_t;
+
/** Per file data, PNG-specific.
*/
typedef struct {
@@ -542,6 +539,7 @@ typedef struct {
int np; /* Number of interlace passes. */
} dk3_bif_png_t;
+
/** Release type-specific information for PNG file.
@param is Bitmap-type specific data.
*/
@@ -563,6 +561,221 @@ dk3bif_frame_release_implspec_png(void *is)
$? "- dk3bif_frame_release_implspec_png"
}
+
+#endif
+/* if DK3_HAVE_PNG_H */
+
+
+
+#if DK3_HAVE_JPEGLIB_H
+
+
+/*
+ JPEGLIB error management.
+*/
+
+/** JPEGLIB error manager.
+*/
+typedef struct {
+ struct jpeg_error_mgr pub; /**< Default error manager. */
+#if DK3_HAVE_SETJMP_H
+ jmp_buf setjmp_buffer; /**< Buffer for setjmp. */
+#endif
+} dk3_bif_jpg_error_mgr;
+
+
+/** Per frame data, JPEG-specific.
+*/
+typedef struct {
+ JSAMPLE **rows; /**< Sample buffer. */
+ JDIMENSION w; /**< Image width. */
+ JDIMENSION h; /**< Image height. */
+ int is_adobe; /**< Flag: Adobe marker found. */
+ int num_comp; /**< Number of components found. */
+} dk3_bif_frame_jpeg_t;
+
+
+/** Per file data, JPEG-specific.
+*/
+typedef struct {
+ int st;
+ struct jpeg_decompress_struct cinfo; /**< Decompression struct. */
+ dk3_bif_jpg_error_mgr errmgr; /**< Error manager. */
+} dk3_bif_jpeg_t;
+
+
+/** Error exit replacement function.
+ @param cinfo JPEG decompression structure.
+*/
+static
+void
+dk3bif_jpeg_error_exit(j_common_ptr cinfo)
+{
+ dk3_bif_jpg_error_mgr *myerr = (dk3_bif_jpg_error_mgr *)(cinfo->err);
+ if(myerr) {
+ longjmp(myerr->setjmp_buffer, 1);
+ }
+}
+
+
+/** Release type-specific information for JPEG file (frame).
+ @param is Bitmap-type specific data.
+*/
+static
+void
+dk3bif_frame_release_implspec_jpeg(void *is)
+{
+ dk3_bif_frame_jpeg_t *fdis;
+ JSAMPLE **ptr;
+ JDIMENSION i;
+ fdis = (dk3_bif_frame_jpeg_t *)is;
+ if(fdis->rows) {
+ ptr = fdis->rows;
+ for(i = 0; i < fdis->h; i++) {
+ dk3_release(*ptr);
+ ptr++;
+ }
+ dk3_delete(fdis->rows);
+ }
+ dk3_delete(is);
+}
+
+
+#endif
+/* if DK3_HAVE_JPEGLIB_H */
+
+
+
+#if DK3_HAVE_TIFF_H
+
+
+/** Per frame data, TIFF-specific.
+*/
+typedef struct {
+ uint32 *r; /**< Raster image data. */
+ uint32 w; /**< Image width. */
+ uint32 h; /**< Image height. */
+ uint16 cps;
+ uint16 spp;
+ uint16 ori; /**< Orientation. */
+} dk3_bif_frame_tiff_t;
+
+
+/** Per file data, TIFF-specific.
+*/
+typedef struct {
+ TIFF *tiff;
+} dk3_bif_tiff_t;
+
+
+/** Release type-specific information for TIFF file.
+ @param is Bitmap-type specific data.
+*/
+static
+void
+dk3bif_frame_release_implspec_tiff(void *is)
+{
+ dk3_bif_frame_tiff_t *fdis;
+ fdis = (dk3_bif_frame_tiff_t *)is;
+ if(fdis->r) {
+ _TIFFfree(fdis->r);
+ fdis->r = NULL;
+ }
+ fdis->w = fdis->h = 0UL; fdis->spp = fdis->cps = 0U;
+ dk3_delete(fdis);
+}
+
+
+#endif
+/* if DK3_HAVE_TIFF_H */
+
+
+
+/** Delete BIF frame, release memory.
+ @param tp Image type.
+ @param fp Frame to delete.
+*/
+static
+void
+dk3bif_frame_delete(dk3_bif_frame_t *fp, int tp)
+{
+ $? "+ dk3bif_frame_delete %!8s", TR_8PTR(fp)
+ if(fp) {
+ /*
+ Release type-depending components.
+ */
+ if(fp->implspec) {
+ switch(tp) {
+ case DK3_BIF_IMAGE_TYPE_PNG: {
+#if DK3_HAVE_PNG_H
+ dk3bif_frame_release_implspec_png(fp->implspec);
+#endif
+ } break;
+ case DK3_BIF_IMAGE_TYPE_JPEG: {
+#if DK3_HAVE_JPEGLIB_H
+ dk3bif_frame_release_implspec_jpeg(fp->implspec);
+#endif
+ } break;
+ case DK3_BIF_IMAGE_TYPE_TIFF: {
+#if DK3_HAVE_TIFF_H
+ dk3bif_frame_release_implspec_tiff(fp->implspec);
+#endif
+ } break;
+ }
+ }
+ fp->implspec = NULL;
+ /*
+ Release type-independent components.
+ */
+ fp->w = fp->h = 0L; fp->realbits = fp->bits = fp->n = 0; fp->cs = 0;
+ /*
+ Release frame itself.
+ */
+ dk3_delete(fp);
+ } $? "- dk3bif_frame_delete"
+}
+
+
+
+#if (DK3_HAVE_PNG_H) || (DK3_HAVE_JPEGLIB_H) || (DK3_HAVE_TIFF_H)
+
+/** Allocate memory for new frame.
+ @param bp Bitmap image file.
+ @return Pointer to new frame on success, NULL on error.
+*/
+static
+dk3_bif_frame_t *
+dk3bif_frame_new(dk3_bif_t *bp)
+{
+ dk3_bif_frame_t *back = NULL;
+ back = dk3_new_app(dk3_bif_frame_t,1,bp->app);
+ if(back) {
+ back->implspec = NULL;
+ back->xres = -1.0;
+ back->yres = -1.0;
+ back->w = 0L;
+ back->h = 0L;
+ back->realbits = back->bits = 0;
+ back->realcolor = 1;
+ back->realalpha = 1;
+ back->n = bp->n_frames;
+ back->cs = 0;
+ back->bg = 0; back->bgr = back->bgg = back->bgb = back->bggr = 0U;
+ if(dk3sto_add(bp->s_frames, (void *)back)) {
+ bp->n_frames += 1;
+ } else {
+ dk3bif_frame_delete(back, bp->bt); back = NULL;
+ }
+ }
+ return back;
+}
+
+#endif
+
+
+
+#if DK3_HAVE_PNG_H
+
/** Release type specific information for PNG file (image).
@param is Bitmap-type specific data.
*/
@@ -612,7 +825,7 @@ dk3bif_read_png_header(dk3_bif_t *bp)
int cm; /* Compression method. */
int fm; /* Filter method. */
int ch; /* Number of channels. */
- int np = 1; /* Number of interlace passes. */
+ volatile int np = 1; /* Number of interlace passes. */
size_t szh; /* Number of header bytes read. */
int back = 0;
$? "+ dk3bif_read_png_header"
@@ -815,7 +1028,7 @@ dk3bif_read_png_data(dk3_bif_t *bp)
dk3_bif_frame_png_t *fdis;
png_bytep *rp;
dk3_bif_coord_t i;
- int back = 0;
+ volatile int back = 0;
dis = (dk3_bif_png_t *)(bp->implspec);
fdis = (dk3_bif_frame_png_t *)((bp->cf)->implspec);
#if DK3_HAVE_SETJMP_H
@@ -930,76 +1143,12 @@ dk3bif_get_png_pixel_component(
}
return back;
}
-#endif
-/* if DK3_HAVE_PNG_H */
-
-
-#if DK3_HAVE_JPEGLIB_H
-/*
- JPEGLIB error management.
-*/
-/** JPEGLIB error manager.
-*/
-typedef struct {
- struct jpeg_error_mgr pub; /**< Default error manager. */
-#if DK3_HAVE_SETJMP_H
- jmp_buf setjmp_buffer; /**< Buffer for setjmp. */
#endif
-} dk3_bif_jpg_error_mgr;
-/** Per frame data, JPEG-specific.
-*/
-typedef struct {
- JSAMPLE **rows; /**< Sample buffer. */
- JDIMENSION w; /**< Image width. */
- JDIMENSION h; /**< Image height. */
- int is_adobe; /**< Flag: Adobe marker found. */
- int num_comp; /**< Number of components found. */
-} dk3_bif_frame_jpeg_t;
-/** Per file data, JPEG-specific.
-*/
-typedef struct {
- int st;
- struct jpeg_decompress_struct cinfo; /**< Decompression struct. */
- dk3_bif_jpg_error_mgr errmgr; /**< Error manager. */
-} dk3_bif_jpeg_t;
-/** Error exit replacement function.
- @param cinfo JPEG decompression structure.
-*/
-static
-void
-dk3bif_jpeg_error_exit(j_common_ptr cinfo)
-{
- dk3_bif_jpg_error_mgr *myerr = (dk3_bif_jpg_error_mgr *)(cinfo->err);
- if(myerr) {
- longjmp(myerr->setjmp_buffer, 1);
- }
-}
-
-/** Release type-specific information for JPEG file (frame).
- @param is Bitmap-type specific data.
-*/
-static
-void
-dk3bif_frame_release_implspec_jpeg(void *is)
-{
- dk3_bif_frame_jpeg_t *fdis;
- JSAMPLE **ptr;
- JDIMENSION i;
- fdis = (dk3_bif_frame_jpeg_t *)is;
- if(fdis->rows) {
- ptr = fdis->rows;
- for(i = 0; i < fdis->h; i++) {
- dk3_release(*ptr);
- ptr++;
- }
- dk3_delete(fdis->rows);
- }
- dk3_delete(is);
-}
+#if DK3_HAVE_JPEGLIB_H
/** Release type specific information for JPEG file (image).
@param is Bitmap-type specific data.
@@ -1171,7 +1320,7 @@ dk3bif_read_jpeg_data(dk3_bif_t *bp)
jpeg_finish_decompress(&(dis->cinfo)); $? ". finished"
dis->st = 8; /* Decompression finished. */
switch((dis->cinfo).out_color_space) {
- case JCS_GRAYSCALE: { $? ". now grey"
+ case JCS_GRAYSCALE: { $? ". now gray"
(bp->cf)->cs = DK3_COLOR_SPACE_GRAY;
back = 1;
} break;
@@ -1268,45 +1417,12 @@ dk3bif_get_jpeg_pixel_component(
}
return back;
}
+
#endif
-/* if DK3_HAVE_JPEGLIB_H */
#if DK3_HAVE_TIFF_H
-/** Per frame data, TIFF-specific.
-*/
-typedef struct {
- uint32 *r; /**< Raster image data. */
- uint32 w; /**< Image width. */
- uint32 h; /**< Image height. */
- uint16 cps;
- uint16 spp;
- uint16 ori; /**< Orientation. */
-} dk3_bif_frame_tiff_t;
-
-/** Per file data, TIFF-specific.
-*/
-typedef struct {
- TIFF *tiff;
-} dk3_bif_tiff_t;
-
-/** Release type-specific information for TIFF file.
- @param is Bitmap-type specific data.
-*/
-static
-void
-dk3bif_frame_release_implspec_tiff(void *is)
-{
- dk3_bif_frame_tiff_t *fdis;
- fdis = (dk3_bif_frame_tiff_t *)is;
- if(fdis->r) {
- _TIFFfree(fdis->r);
- fdis->r = NULL;
- }
- fdis->w = fdis->h = 0UL; fdis->spp = fdis->cps = 0U;
- dk3_delete(fdis);
-}
/** Release type specific information for TIFF file (image).
@param is Bitmap-type specific data.
@@ -1578,8 +1694,8 @@ dk3bif_get_tiff_pixel_component(
}
return back;
}
+
#endif
-/* if DK3_HAVE_TIFF_H */
@@ -1606,85 +1722,6 @@ dk3bif_ntsc(dk3_bif_pixel_t r, dk3_bif_pixel_t g, dk3_bif_pixel_t b)
-/** Delete BIF frame, release memory.
- @param tp Image type.
- @param fp Frame to delete.
-*/
-static
-void
-dk3bif_frame_delete(dk3_bif_frame_t *fp, int tp)
-{
- $? "+ dk3bif_frame_delete %!8s", TR_8PTR(fp)
- if(fp) {
- /*
- Release type-depending components.
- */
- if(fp->implspec) {
- switch(tp) {
- case DK3_BIF_IMAGE_TYPE_PNG: {
-#if DK3_HAVE_PNG_H
- dk3bif_frame_release_implspec_png(fp->implspec);
-#endif
- } break;
- case DK3_BIF_IMAGE_TYPE_JPEG: {
-#if DK3_HAVE_JPEGLIB_H
- dk3bif_frame_release_implspec_jpeg(fp->implspec);
-#endif
- } break;
- case DK3_BIF_IMAGE_TYPE_TIFF: {
-#if DK3_HAVE_TIFF_H
- dk3bif_frame_release_implspec_tiff(fp->implspec);
-#endif
- } break;
- }
- }
- fp->implspec = NULL;
- /*
- Release type-independent components.
- */
- fp->w = fp->h = 0L; fp->realbits = fp->bits = fp->n = 0; fp->cs = 0;
- /*
- Release frame itself.
- */
- dk3_delete(fp);
- } $? "- dk3bif_frame_delete"
-}
-
-
-
-/** Allocate memory for new frame.
- @param bp Bitmap image file.
- @return Pointer to new frame on success, NULL on error.
-*/
-static
-dk3_bif_frame_t *
-dk3bif_frame_new(dk3_bif_t *bp)
-{
- dk3_bif_frame_t *back = NULL;
- back = dk3_new_app(dk3_bif_frame_t,1,bp->app);
- if(back) {
- back->implspec = NULL;
- back->xres = -1.0;
- back->yres = -1.0;
- back->w = 0L;
- back->h = 0L;
- back->realbits = back->bits = 0;
- back->realcolor = 1;
- back->realalpha = 1;
- back->n = bp->n_frames;
- back->cs = 0;
- back->bg = 0; back->bgr = back->bgg = back->bgb = back->bggr = 0U;
- if(dk3sto_add(bp->s_frames, (void *)back)) {
- bp->n_frames += 1;
- } else {
- dk3bif_frame_delete(back, bp->bt); back = NULL;
- }
- }
- return back;
-}
-
-
-
dk3_bif_pixel_t
dk3bif_get_pixel_component_not_resampled(
dk3_bif_t *bp,
@@ -2295,11 +2332,11 @@ dk3bif_check_c8_file_name(char const *fn)
-
/** Transfer background color from image to frame.
@param bp Bitmap image file (source).
@param fr Frame (destination).
*/
+static
void
dk3_bif_transfer_background(dk3_bif_t *bp, dk3_bif_frame_t *fr)
{