diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2018-11-14 00:15:14 +0100 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2018-11-14 00:15:14 +0100 |
commit | 813e78aefb939daffd8f071be0790470ab037f2c (patch) | |
tree | 487a6cf616227f96f7fbe1732fdd89698a1b8646 /source | |
parent | adb68c17dcb8f92508eda3dde0077b0d87158075 (diff) | |
download | mupdf-master.tar.xz |
It is not very useful.
Diffstat (limited to 'source')
-rw-r--r-- | source/fitz/output-tga.c | 169 | ||||
-rw-r--r-- | source/fitz/writer.c | 7 | ||||
-rw-r--r-- | source/tools/muconvert.c | 2 | ||||
-rw-r--r-- | source/tools/mudraw.c | 17 | ||||
-rw-r--r-- | source/tools/murun.c | 2 |
5 files changed, 6 insertions, 191 deletions
diff --git a/source/fitz/output-tga.c b/source/fitz/output-tga.c deleted file mode 100644 index 51ebe5db..00000000 --- a/source/fitz/output-tga.c +++ /dev/null @@ -1,169 +0,0 @@ -#include "mupdf/fitz.h" - -#include <string.h> - -/* - * Write pixmap to TGA file (with or without alpha channel) - */ - -typedef struct { - fz_band_writer super; - int is_bgr; -} tga_band_writer; - -static inline void tga_put_pixel(fz_context *ctx, fz_output *out, const unsigned char *data, int n, int is_bgr) -{ - int a, inva; - switch(n) - { - case 4: /* RGBA or BGRA */ - a = data[3]; - inva = a ? 256 * 255 / a : 0; - if (!is_bgr) { - fz_write_byte(ctx, out, (data[2] * inva + 128)>>8); - fz_write_byte(ctx, out, (data[1] * inva + 128)>>8); - fz_write_byte(ctx, out, (data[0] * inva + 128)>>8); - } else { - fz_write_byte(ctx, out, (data[0] * inva + 128)>>8); - fz_write_byte(ctx, out, (data[1] * inva + 128)>>8); - fz_write_byte(ctx, out, (data[2] * inva + 128)>>8); - } - fz_write_byte(ctx, out, a); - break; - case 3: /* RGB or BGR */ - if (!is_bgr) { - fz_write_byte(ctx, out, data[2]); - fz_write_byte(ctx, out, data[1]); - fz_write_byte(ctx, out, data[0]); - } else { - fz_write_byte(ctx, out, data[0]); - fz_write_byte(ctx, out, data[1]); - fz_write_byte(ctx, out, data[2]); - } - break; - case 2: /* GA */ - a = data[1]; - inva = a ? 256 * 255 / a : 0; - inva = (data[0] * inva + 128)>>8; - fz_write_byte(ctx, out, inva); - fz_write_byte(ctx, out, inva); - fz_write_byte(ctx, out, inva); - fz_write_byte(ctx, out, a); - break; - case 1: /* G */ - fz_write_byte(ctx, out, data[0]); - break; - } -} - -void -fz_save_pixmap_as_tga(fz_context *ctx, fz_pixmap *pixmap, const char *filename) -{ - fz_output *out = fz_new_output_with_path(ctx, filename, 0); - fz_try(ctx) - { - fz_write_pixmap_as_tga(ctx, out, pixmap); - fz_close_output(ctx, out); - } - fz_always(ctx) - fz_drop_output(ctx, out); - fz_catch(ctx) - fz_rethrow(ctx); -} - -void -fz_write_pixmap_as_tga(fz_context *ctx, fz_output *out, fz_pixmap *pixmap) -{ - fz_band_writer *writer = fz_new_tga_band_writer(ctx, out, fz_colorspace_is_bgr(ctx, pixmap->colorspace)); - fz_try(ctx) - { - fz_write_header(ctx, writer, pixmap->w, pixmap->h, pixmap->n, pixmap->alpha, pixmap->xres, pixmap->yres, 0, pixmap->colorspace, pixmap->seps); - fz_write_band(ctx, writer, -pixmap->stride, pixmap->h, pixmap->samples + pixmap->stride * (pixmap->h-1)); - } - fz_always(ctx) - fz_drop_band_writer(ctx, writer); - fz_catch(ctx) - fz_rethrow(ctx); -} - -static void -tga_write_header(fz_context *ctx, fz_band_writer *writer_, const fz_colorspace *cs) -{ - tga_band_writer *writer = (tga_band_writer *)writer_; - fz_output *out = writer->super.out; - int w = writer->super.w; - int h = writer->super.h; - int n = writer->super.n; - int alpha = writer->super.alpha; - unsigned char head[18]; - int d = (alpha && n > 1) ? 4 : (n == 1 ? 1 : 3); - - if (writer->super.s != 0) - fz_throw(ctx, FZ_ERROR_GENERIC, "TGA writer cannot cope with spot colors"); - if (n-alpha > 1 && n != 3+alpha) - fz_throw(ctx, FZ_ERROR_GENERIC, "pixmap must be grayscale/rgb/rgba (with or without alpha) to write as tga"); - memset(head, 0, sizeof(head)); - head[2] = n > 1 ? 10 /* RGB or RGBA or GA */ : 11 /* G */; - head[12] = w & 0xFF; head[13] = (w >> 8) & 0xFF; - head[14] = h & 0xFF; head[15] = (h >> 8) & 0xFF; - head[16] = d * 8; /* BPP */ - head[17] = alpha && n > 1 ? 8 : 0; /* Alpha bpp */ - - fz_write_data(ctx, out, head, sizeof(head)); -} - -static void -tga_write_band(fz_context *ctx, fz_band_writer *writer_, int stride, int band_start, int band_height, const unsigned char *samples) -{ - tga_band_writer *writer = (tga_band_writer *)writer_; - fz_output *out = writer->super.out; - int w = writer->super.w; - int n = writer->super.n; - int d = (writer->super.alpha && n > 1) ? 4 : (n == 1 ? 1 : 3); - int is_bgr = writer->is_bgr; - int k; - - for (k = 0; k < band_height; k++) - { - int i, j; - const unsigned char *line = samples + stride * k; - for (i = 0, j = 1; i < w; i += j, j = 1) - { - for (; i + j < w && j < 128 && !memcmp(line + i * n, line + (i + j) * n, d); j++); - if (j > 1) - { - fz_write_byte(ctx, out, j - 1 + 128); - tga_put_pixel(ctx, out, line + i * n, n, is_bgr); - } - else - { - for (; i + j < w && j <= 128 && memcmp(line + (i + j - 1) * n, line + (i + j) * n, d) != 0; j++); - if (i + j < w || j > 128) - j--; - fz_write_byte(ctx, out, j - 1); - for (; j > 0; j--, i++) - tga_put_pixel(ctx, out, line + i * n, n, is_bgr); - } - } - } -} - -static void -tga_write_trailer(fz_context *ctx, fz_band_writer *writer) -{ - fz_output *out = writer->out; - - fz_write_data(ctx, out, "\0\0\0\0\0\0\0\0TRUEVISION-XFILE.\0", 26); -} - -fz_band_writer *fz_new_tga_band_writer(fz_context *ctx, fz_output *out, int is_bgr) -{ - tga_band_writer *writer = fz_new_band_writer(ctx, tga_band_writer, out); - - writer->super.header = tga_write_header; - writer->super.band = tga_write_band; - writer->super.trailer = tga_write_trailer; - writer->is_bgr = is_bgr; - - return &writer->super; -} diff --git a/source/fitz/writer.c b/source/fitz/writer.c index ada07089..77512f6a 100644 --- a/source/fitz/writer.c +++ b/source/fitz/writer.c @@ -68,11 +68,6 @@ fz_document_writer *fz_new_png_pixmap_writer(fz_context *ctx, const char *path, return fz_new_pixmap_writer(ctx, path, options, "out-%04d.png", 0, fz_save_pixmap_as_png); } -fz_document_writer *fz_new_tga_pixmap_writer(fz_context *ctx, const char *path, const char *options) -{ - return fz_new_pixmap_writer(ctx, path, options, "out-%04d.tga", 0, fz_save_pixmap_as_tga); -} - fz_document_writer *fz_new_pam_pixmap_writer(fz_context *ctx, const char *path, const char *options) { return fz_new_pixmap_writer(ctx, path, options, "out-%04d.pam", 0, fz_save_pixmap_as_pam); @@ -125,8 +120,6 @@ fz_new_document_writer(fz_context *ctx, const char *path, const char *format, co if (!fz_strcasecmp(format, "png")) return fz_new_png_pixmap_writer(ctx, path, options); - if (!fz_strcasecmp(format, "tga")) - return fz_new_tga_pixmap_writer(ctx, path, options); if (!fz_strcasecmp(format, "pam")) return fz_new_pam_pixmap_writer(ctx, path, options); if (!fz_strcasecmp(format, "pnm")) diff --git a/source/tools/muconvert.c b/source/tools/muconvert.c index 04faed8c..c6fca7c1 100644 --- a/source/tools/muconvert.c +++ b/source/tools/muconvert.c @@ -42,7 +42,7 @@ static void usage(void) "\n" "\t-o -\toutput file name (%%d for page number)\n" "\t-F -\toutput format (default inferred from output file name)\n" - "\t\t\traster: cbz, png, pnm, pgm, ppm, pam, tga, pbm, pkm.\n" + "\t\t\traster: cbz, png, pnm, pgm, ppm, pam, pbm, pkm.\n" "\t\t\tprint-raster: pcl, pclm, ps, pwg.\n" "\t\t\tvector: pdf, svg.\n" "\t\t\ttext: html, xhtml, text, stext.\n" diff --git a/source/tools/mudraw.c b/source/tools/mudraw.c index 5a78ae8d..30c8a545 100644 --- a/source/tools/mudraw.c +++ b/source/tools/mudraw.c @@ -35,7 +35,7 @@ int gettimeofday(struct timeval *tv, struct timezone *tz); enum { OUT_NONE, - OUT_PNG, OUT_TGA, OUT_PNM, OUT_PGM, OUT_PPM, OUT_PAM, + OUT_PNG, OUT_PNM, OUT_PGM, OUT_PPM, OUT_PAM, OUT_PBM, OUT_PKM, OUT_PWG, OUT_PCL, OUT_PS, OUT_PSD, OUT_TEXT, OUT_HTML, OUT_XHTML, OUT_STEXT, OUT_PCLM, OUT_TRACE, OUT_SVG, @@ -74,7 +74,6 @@ static const suffix_t suffix_table[] = #endif { ".psd", OUT_PSD, 1 }, { ".ps", OUT_PS, 0 }, - { ".tga", OUT_TGA, 0 }, { ".txt", OUT_TEXT, 0 }, { ".text", OUT_TEXT, 0 }, @@ -131,7 +130,6 @@ static const format_cs_table_t format_cs_table[] = { OUT_PCLM, CS_RGB, { CS_RGB, CS_GRAY } }, { OUT_PS, CS_RGB, { CS_GRAY, CS_RGB, CS_CMYK } }, { OUT_PSD, CS_CMYK, { CS_GRAY, CS_GRAY_ALPHA, CS_RGB, CS_RGB_ALPHA, CS_CMYK, CS_CMYK_ALPHA, CS_ICC } }, - { OUT_TGA, CS_RGB, { CS_GRAY, CS_GRAY_ALPHA, CS_RGB, CS_RGB_ALPHA } }, { OUT_TRACE, CS_RGB, { CS_RGB } }, { OUT_SVG, CS_RGB, { CS_RGB } }, @@ -318,7 +316,7 @@ static void usage(void) "\n" "\t-o -\toutput file name (%%d for page number)\n" "\t-F -\toutput format (default inferred from output file name)\n" - "\t\traster: png, tga, pnm, pam, pbm, pkm, pwg, pcl, ps\n" + "\t\traster: png, pnm, pam, pbm, pkm, pwg, pcl, ps\n" "\t\tvector: svg, pdf, trace\n" "\t\ttext: txt, html, stext\n" "\n" @@ -723,11 +721,6 @@ static void dodrawpage(fz_context *ctx, fz_page *page, fz_display_list *list, in zoom = resolution / 72; ctm = fz_pre_scale(fz_rotate(rotation), zoom, zoom); - if (output_format == OUT_TGA) - { - ctm = fz_pre_scale(fz_pre_translate(ctm, 0, -height), 1, -1); - } - tbounds = fz_transform_rect(mediabox, ctm); ibounds = fz_round_rect(tbounds); @@ -844,8 +837,6 @@ static void dodrawpage(fz_context *ctx, fz_page *page, fz_display_list *list, in bander = fz_new_ps_band_writer(ctx, out); else if (output_format == OUT_PSD) bander = fz_new_psd_band_writer(ctx, out); - else if (output_format == OUT_TGA) - bander = fz_new_tga_band_writer(ctx, out, fz_colorspace_is_bgr(ctx, colorspace)); else if (output_format == OUT_PWG) { if (out_cs == CS_MONO) @@ -1710,9 +1701,9 @@ int mudraw_main(int argc, char **argv) if (band_height) { - if (output_format != OUT_PAM && output_format != OUT_PGM && output_format != OUT_PPM && output_format != OUT_PNM && output_format != OUT_PNG && output_format != OUT_PBM && output_format != OUT_PKM && output_format != OUT_PCL && output_format != OUT_PCLM && output_format != OUT_PS && output_format != OUT_PSD && output_format != OUT_TGA) + if (output_format != OUT_PAM && output_format != OUT_PGM && output_format != OUT_PPM && output_format != OUT_PNM && output_format != OUT_PNG && output_format != OUT_PBM && output_format != OUT_PKM && output_format != OUT_PCL && output_format != OUT_PCLM && output_format != OUT_PS && output_format != OUT_PSD) { - fprintf(stderr, "Banded operation only possible with PxM, PCL, PCLM, PS, PSD, PNG and TGA outputs\n"); + fprintf(stderr, "Banded operation only possible with PxM, PCL, PCLM, PS, PSD, and PNG outputs\n"); exit(1); } if (showmd5) diff --git a/source/tools/murun.c b/source/tools/murun.c index d122ce51..90fc77ea 100644 --- a/source/tools/murun.c +++ b/source/tools/murun.c @@ -4731,7 +4731,7 @@ int murun_main(int argc, char **argv) // Pixmap.scale() jsB_propfun(J, "Pixmap.saveAsPNG", ffi_Pixmap_saveAsPNG, 1); - // Pixmap.saveAsPNM, PAM, TGA, PWG, PCL + // Pixmap.saveAsPNM, PAM, PWG, PCL // Pixmap.halftone() -> Bitmap // Pixmap.md5() |