summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2018-09-04 12:18:54 +0200
committerTor Andersson <tor.andersson@artifex.com>2018-09-05 12:52:06 +0200
commit173216938390389c68af78518f3f521434cb66a9 (patch)
tree84e890a0ffc90dcebddeff8e0baa020c94a7097b
parentf825e989dc7e7e339ca525b52ea46d6ffacbacdf (diff)
downloadmupdf-173216938390389c68af78518f3f521434cb66a9.tar.xz
Use colorspace type enum instead of magic profile names.
-rw-r--r--include/mupdf/fitz/colorspace.h6
-rw-r--r--include/mupdf/fitz/font.h2
-rw-r--r--source/fitz/colorspace-imp.h6
-rw-r--r--source/fitz/colorspace.c139
-rw-r--r--source/fitz/load-jpeg.c2
-rw-r--r--source/fitz/load-png.c2
-rw-r--r--source/fitz/load-tiff.c2
-rw-r--r--source/pdf/pdf-colorspace.c12
-rw-r--r--source/tools/mudraw.c4
9 files changed, 93 insertions, 82 deletions
diff --git a/include/mupdf/fitz/colorspace.h b/include/mupdf/fitz/colorspace.h
index f027ce2e..aad1c2e1 100644
--- a/include/mupdf/fitz/colorspace.h
+++ b/include/mupdf/fitz/colorspace.h
@@ -209,9 +209,9 @@ struct fz_cal_colorspace_s {
/*
icc methods
*/
-fz_colorspace *fz_new_icc_colorspace(fz_context *ctx, const char *name, int num, fz_buffer *buf);
-fz_colorspace *fz_new_icc_colorspace_from_file(fz_context *ctx, const char *name, const char *path);
-fz_colorspace *fz_new_icc_colorspace_from_stream(fz_context *ctx, const char *name, fz_stream *in);
+fz_colorspace *fz_new_icc_colorspace(fz_context *ctx, enum fz_colorspace_type type, fz_buffer *buf);
+fz_colorspace *fz_new_icc_colorspace_from_file(fz_context *ctx, enum fz_colorspace_type type, const char *path);
+fz_colorspace *fz_new_icc_colorspace_from_stream(fz_context *ctx, enum fz_colorspace_type type, fz_stream *in);
fz_colorspace *fz_new_cal_colorspace(fz_context *ctx, const char *name, float *wp, float *bp, float *gamma, float *matrix);
fz_buffer *fz_new_icc_data_from_cal_colorspace(fz_context *ctx, fz_cal_colorspace *cal);
fz_buffer *fz_icc_data_from_icc_colorspace(fz_context *ctx, const fz_colorspace *cs);
diff --git a/include/mupdf/fitz/font.h b/include/mupdf/fitz/font.h
index aaa02552..7aaee3d7 100644
--- a/include/mupdf/fitz/font.h
+++ b/include/mupdf/fitz/font.h
@@ -275,7 +275,7 @@ const unsigned char *fz_lookup_base14_font(fz_context *ctx, const char *name, in
Returns a pointer to the icc file data, or NULL if not present.
*/
-const unsigned char *fz_lookup_icc(fz_context *ctx, const char *name, size_t *len);
+const unsigned char *fz_lookup_icc(fz_context *ctx, enum fz_colorspace_type name, size_t *len);
/*
fz_lookup_cjk_font: Search the builtin cjk fonts for a match.
diff --git a/source/fitz/colorspace-imp.h b/source/fitz/colorspace-imp.h
index 8f3b85f6..4664567f 100644
--- a/source/fitz/colorspace-imp.h
+++ b/source/fitz/colorspace-imp.h
@@ -6,12 +6,6 @@
#include "mupdf/fitz/color-management.h"
#include "mupdf/fitz/pixmap.h"
-#define FZ_ICC_PROFILE_GRAY "DeviceGray"
-#define FZ_ICC_PROFILE_RGB "DeviceRGB"
-#define FZ_ICC_PROFILE_BGR "DeviceBGR"
-#define FZ_ICC_PROFILE_CMYK "DeviceCMYK"
-#define FZ_ICC_PROFILE_LAB "Lab"
-
void fz_cmm_transform_pixmap(fz_context *ctx, fz_icclink *link, fz_pixmap *dst, fz_pixmap *src);
void fz_cmm_transform_color(fz_context *ctx, fz_icclink *link, unsigned short *dst, const unsigned short *src);
void fz_cmm_init_link(fz_context *ctx, fz_icclink *link, const fz_iccprofile *dst, int dst_extras, const fz_iccprofile *src, int src_extras, const fz_iccprofile *prf, const fz_color_params *rend, int cmm_flags, int num_bytes, int copy_spots);
diff --git a/source/fitz/colorspace.c b/source/fitz/colorspace.c
index e7a97d04..9cc178d9 100644
--- a/source/fitz/colorspace.c
+++ b/source/fitz/colorspace.c
@@ -150,7 +150,7 @@ void fz_cmm_fin_profile(fz_context *ctx, fz_iccprofile *profile)
#ifdef NO_ICC
const unsigned char *
-fz_lookup_icc(fz_context *ctx, const char *name, size_t *size)
+fz_lookup_icc(fz_context *ctx, enum fz_colorspace_type type, size_t *size)
{
return *size = 0, NULL;
}
@@ -163,23 +163,23 @@ fz_lookup_icc(fz_context *ctx, const char *name, size_t *size)
#include "icc/lab.icc.h"
const unsigned char *
-fz_lookup_icc(fz_context *ctx, const char *name, size_t *size)
+fz_lookup_icc(fz_context *ctx, enum fz_colorspace_type type, size_t *size)
{
if (fz_get_cmm_engine(ctx) == NULL)
return *size = 0, NULL;
- if (!strcmp(name, FZ_ICC_PROFILE_GRAY)) {
+ if (type == FZ_COLORSPACE_GRAY) {
*size = resources_icc_gray_icc_len;
return resources_icc_gray_icc;
}
- if (!strcmp(name, FZ_ICC_PROFILE_RGB) || !strcmp(name, FZ_ICC_PROFILE_BGR)) {
+ if (type == FZ_COLORSPACE_RGB || type == FZ_COLORSPACE_BGR) {
*size = resources_icc_rgb_icc_len;
return resources_icc_rgb_icc;
}
- if (!strcmp(name, FZ_ICC_PROFILE_CMYK)) {
+ if (type == FZ_COLORSPACE_CMYK) {
*size = resources_icc_cmyk_icc_len;
return resources_icc_cmyk_icc;
}
- if (!strcmp(name, FZ_ICC_PROFILE_LAB)) {
+ if (type == FZ_COLORSPACE_LAB) {
*size = resources_icc_lab_icc_len;
return resources_icc_lab_icc;
}
@@ -850,11 +850,11 @@ void fz_set_cmm_engine(fz_context *ctx, const fz_cmm_engine *engine)
fz_new_cmm_context(ctx);
if (engine)
{
- cct->gray = fz_new_icc_colorspace(ctx, FZ_ICC_PROFILE_GRAY, 1, NULL);
- cct->rgb = fz_new_icc_colorspace(ctx, FZ_ICC_PROFILE_RGB, 3, NULL);
- cct->bgr = fz_new_icc_colorspace(ctx, FZ_ICC_PROFILE_BGR, 3, NULL);
- cct->cmyk = fz_new_icc_colorspace(ctx, FZ_ICC_PROFILE_CMYK, 4, NULL);
- cct->lab = fz_new_icc_colorspace(ctx, FZ_ICC_PROFILE_LAB, 3, NULL);
+ cct->gray = fz_new_icc_colorspace(ctx, FZ_COLORSPACE_GRAY, NULL);
+ cct->rgb = fz_new_icc_colorspace(ctx, FZ_COLORSPACE_RGB, NULL);
+ cct->bgr = fz_new_icc_colorspace(ctx, FZ_COLORSPACE_BGR, NULL);
+ cct->cmyk = fz_new_icc_colorspace(ctx, FZ_COLORSPACE_CMYK, NULL);
+ cct->lab = fz_new_icc_colorspace(ctx, FZ_COLORSPACE_LAB, NULL);
}
else
set_no_icc(cct);
@@ -3736,17 +3736,29 @@ clamp_default_icc(const fz_colorspace *cs, const float *src, float *dst)
dst[i] = fz_clamp(src[i], 0, 1);
}
+static const char *colorspace_name_from_type(int type)
+{
+ switch (type) {
+ default: return "Unknown";
+ case FZ_COLORSPACE_GRAY: return "Gray";
+ case FZ_COLORSPACE_RGB: return "RGB";
+ case FZ_COLORSPACE_BGR: return "BGR";
+ case FZ_COLORSPACE_CMYK: return "CMYK";
+ case FZ_COLORSPACE_LAB: return "Lab";
+ }
+}
+
fz_colorspace *
-fz_new_icc_colorspace(fz_context *ctx, const char *name, int num, fz_buffer *buf)
+fz_new_icc_colorspace(fz_context *ctx, enum fz_colorspace_type type, fz_buffer *buf)
{
#ifdef NO_ICC
fz_throw(ctx, FZ_ERROR_GENERIC, "ICC Profiles not supported in NO_ICC build");
#else
fz_colorspace *cs = NULL;
fz_iccprofile *profile;
- int is_lab = 0;
- enum fz_colorspace_type type = FZ_COLORSPACE_NONE;
int flags = FZ_COLORSPACE_IS_ICC;
+ const char *name = colorspace_name_from_type(type);
+ int num;
profile = fz_malloc_struct(ctx, fz_iccprofile);
fz_try(ctx)
@@ -3755,10 +3767,9 @@ fz_new_icc_colorspace(fz_context *ctx, const char *name, int num, fz_buffer *buf
{
size_t size;
const unsigned char *data;
- data = fz_lookup_icc(ctx, name, &size);
+ data = fz_lookup_icc(ctx, type, &size);
profile->buffer = fz_new_buffer_from_shared_data(ctx, data, size);
- is_lab = (strcmp(name, FZ_ICC_PROFILE_LAB) == 0);
- profile->bgr = (strcmp(name, FZ_ICC_PROFILE_BGR) == 0);
+ profile->bgr = (type == FZ_COLORSPACE_BGR);
flags |= FZ_COLORSPACE_IS_DEVICE;
}
else
@@ -3768,58 +3779,64 @@ fz_new_icc_colorspace(fz_context *ctx, const char *name, int num, fz_buffer *buf
fz_cmm_init_profile(ctx, profile);
- /* Check if correct type, if a particular type was expected */
- if (num != 0 && num != profile->num_devcomp)
+ if (type == FZ_COLORSPACE_NONE)
{
- fz_drop_buffer(ctx, profile->buffer);
- fz_cmm_fin_profile(ctx, profile);
- fz_free(ctx, profile);
- break;
+ switch (profile->num_devcomp)
+ {
+ default: type = FZ_COLORSPACE_SEPARATION; break;
+ case 1: type = FZ_COLORSPACE_GRAY; break;
+ case 3: type = FZ_COLORSPACE_RGB; break;
+ case 4: type = FZ_COLORSPACE_CMYK; break;
+ }
}
+ switch (type)
+ {
+ default: num = profile->num_devcomp; break;
+ case FZ_COLORSPACE_GRAY: num = 1; break;
+ case FZ_COLORSPACE_RGB: num = 3; break;
+ case FZ_COLORSPACE_BGR: num = 3; break;
+ case FZ_COLORSPACE_LAB: num = 3; break;
+ case FZ_COLORSPACE_CMYK: num = 4; break;
+ }
+
+ /* Check if correct type, if a particular type was expected */
+ if (num != profile->num_devcomp)
+ fz_throw(ctx, FZ_ERROR_GENERIC, "ICC profile did not match expected colorspace type");
+
fz_md5_icc(ctx, profile);
- switch (profile->num_devcomp)
+ cs = fz_new_colorspace(ctx, name, type, flags, profile->num_devcomp,
+ NULL,
+ NULL,
+ NULL,
+ (type == FZ_COLORSPACE_LAB) ? clamp_lab_icc : clamp_default_icc,
+ free_icc,
+ profile, sizeof(profile));
+
+ switch (type)
{
default:
- type = FZ_COLORSPACE_SEPARATION;
- break;
- case 1:
- type = FZ_COLORSPACE_GRAY;
break;
- case 3:
- if (is_lab)
- type = FZ_COLORSPACE_LAB;
- else if (profile->bgr)
- type = FZ_COLORSPACE_BGR;
- else
- type = FZ_COLORSPACE_RGB;
+ case FZ_COLORSPACE_GRAY:
+ fz_colorspace_name_colorant(ctx, cs, 0, "Gray");
break;
- case 4:
- type = FZ_COLORSPACE_CMYK;
+ case FZ_COLORSPACE_LAB:
+ fz_colorspace_name_colorant(ctx, cs, 0, "L*");
+ fz_colorspace_name_colorant(ctx, cs, 1, "a*");
+ fz_colorspace_name_colorant(ctx, cs, 2, "b*");
break;
- }
-
- cs = fz_new_colorspace(ctx, name, type, flags, profile->num_devcomp, NULL, NULL, NULL, is_lab ? clamp_lab_icc : clamp_default_icc, free_icc, profile, sizeof(profile));
-
- switch (profile->num_devcomp)
- {
- case 1:
- fz_colorspace_name_colorant(ctx, cs, 0, "Gray");
+ case FZ_COLORSPACE_RGB:
+ fz_colorspace_name_colorant(ctx, cs, 0, "Red");
+ fz_colorspace_name_colorant(ctx, cs, 1, "Green");
+ fz_colorspace_name_colorant(ctx, cs, 2, "Blue");
break;
- case 3:
- if (is_lab)
- {
- fz_colorspace_name_colorant(ctx, cs, 0, "L*");
- fz_colorspace_name_colorant(ctx, cs, 1, "a*");
- fz_colorspace_name_colorant(ctx, cs, 2, "b*");
- } else {
- fz_colorspace_name_colorant(ctx, cs, profile->bgr ? 2 : 0, "Red");
- fz_colorspace_name_colorant(ctx, cs, 1, "Green");
- fz_colorspace_name_colorant(ctx, cs, profile->bgr ? 0 : 2, "Blue");
- }
+ case FZ_COLORSPACE_BGR:
+ fz_colorspace_name_colorant(ctx, cs, 2, "Red");
+ fz_colorspace_name_colorant(ctx, cs, 1, "Green");
+ fz_colorspace_name_colorant(ctx, cs, 0, "Blue");
break;
- case 4:
+ case FZ_COLORSPACE_CMYK:
fz_colorspace_name_colorant(ctx, cs, 0, "Cyan");
fz_colorspace_name_colorant(ctx, cs, 1, "Magenta");
fz_colorspace_name_colorant(ctx, cs, 2, "Yellow");
@@ -3837,12 +3854,12 @@ fz_new_icc_colorspace(fz_context *ctx, const char *name, int num, fz_buffer *buf
#endif
}
-fz_colorspace *fz_new_icc_colorspace_from_file(fz_context *ctx, const char *name, const char *path)
+fz_colorspace *fz_new_icc_colorspace_from_file(fz_context *ctx, enum fz_colorspace_type type, const char *path)
{
fz_colorspace *cs = NULL;
fz_buffer *buffer = fz_read_file(ctx, path);
fz_try(ctx)
- cs = fz_new_icc_colorspace(ctx, name, 0, buffer);
+ cs = fz_new_icc_colorspace(ctx, type, buffer);
fz_always(ctx)
fz_drop_buffer(ctx, buffer);
fz_catch(ctx)
@@ -3850,12 +3867,12 @@ fz_colorspace *fz_new_icc_colorspace_from_file(fz_context *ctx, const char *name
return cs;
}
-fz_colorspace *fz_new_icc_colorspace_from_stream(fz_context *ctx, const char *name, fz_stream *in)
+fz_colorspace *fz_new_icc_colorspace_from_stream(fz_context *ctx, enum fz_colorspace_type type, fz_stream *in)
{
fz_colorspace *cs = NULL;
fz_buffer *buffer = fz_read_all(ctx, in, 1024);
fz_try(ctx)
- cs = fz_new_icc_colorspace(ctx, name, 0, buffer);
+ cs = fz_new_icc_colorspace(ctx, type, buffer);
fz_always(ctx)
fz_drop_buffer(ctx, buffer);
fz_catch(ctx)
diff --git a/source/fitz/load-jpeg.c b/source/fitz/load-jpeg.c
index 3db94a6b..ff4d8003 100644
--- a/source/fitz/load-jpeg.c
+++ b/source/fitz/load-jpeg.c
@@ -141,7 +141,7 @@ static fz_colorspace *extract_icc_profile(fz_context *ctx, jpeg_saved_marker_ptr
fz_try(ctx)
{
buff = fz_new_buffer_from_copied_data(ctx, data, size);
- cs = fz_new_icc_colorspace(ctx, NULL, 0, buff);
+ cs = fz_new_icc_colorspace(ctx, FZ_COLORSPACE_NONE, buff);
}
fz_always(ctx)
fz_drop_buffer(ctx, buff);
diff --git a/source/fitz/load-png.c b/source/fitz/load-png.c
index cf1ab536..fbda9035 100644
--- a/source/fitz/load-png.c
+++ b/source/fitz/load-png.c
@@ -361,7 +361,7 @@ png_read_icc(fz_context *ctx, struct info *info, const unsigned char *p, unsigne
{
mstm = fz_open_memory(ctx, p + n + 2, size - n - 2);
zstm = fz_open_flated(ctx, mstm, 15);
- cs = fz_new_icc_colorspace_from_stream(ctx, (const char *)p, zstm);
+ cs = fz_new_icc_colorspace_from_stream(ctx, info->type, zstm);
/* drop old one in case we have multiple ICC profiles */
fz_drop_colorspace(ctx, info->cs);
info->cs = cs;
diff --git a/source/fitz/load-tiff.c b/source/fitz/load-tiff.c
index 3dad8a82..6e903e66 100644
--- a/source/fitz/load-tiff.c
+++ b/source/fitz/load-tiff.c
@@ -1141,7 +1141,7 @@ tiff_decode_ifd(fz_context *ctx, struct tiff *tiff)
fz_try(ctx)
{
buff = fz_new_buffer_from_copied_data(ctx, tiff->profile, tiff->profilesize);
- tiff->colorspace = fz_new_icc_colorspace(ctx, NULL, 0, buff);
+ tiff->colorspace = fz_new_icc_colorspace(ctx, FZ_COLORSPACE_NONE, buff);
}
fz_always(ctx)
fz_drop_buffer(ctx, buff);
diff --git a/source/pdf/pdf-colorspace.c b/source/pdf/pdf-colorspace.c
index a1d7d77c..d112baa7 100644
--- a/source/pdf/pdf-colorspace.c
+++ b/source/pdf/pdf-colorspace.c
@@ -58,13 +58,13 @@ load_icc_based(fz_context *ctx, pdf_obj *dict, int alt)
{
if (fz_get_cmm_engine(ctx))
{
- const char *name;
- if (n == 1) name = "ICCBased-Gray";
- else if (n == 3) name = "ICCBased-RGB";
- else if (n == 4) name = "ICCBased-CMYK";
- else name = "ICCBased";
+ enum fz_colorspace_type type;
+ if (n == 1) type = FZ_COLORSPACE_GRAY;
+ else if (n == 3) type = FZ_COLORSPACE_RGB;
+ else if (n == 4) type = FZ_COLORSPACE_CMYK;
+ else type = FZ_COLORSPACE_NONE;
buffer = pdf_load_stream(ctx, dict);
- cs = fz_new_icc_colorspace(ctx, name, n, buffer);
+ cs = fz_new_icc_colorspace(ctx, type, buffer);
}
}
fz_always(ctx)
diff --git a/source/tools/mudraw.c b/source/tools/mudraw.c
index c219b7b0..6ca08d01 100644
--- a/source/tools/mudraw.c
+++ b/source/tools/mudraw.c
@@ -1593,7 +1593,7 @@ int mudraw_main(int argc, char **argv)
}
if (proof_filename)
- proof_cs = fz_new_icc_colorspace_from_file(ctx, NULL, proof_filename);
+ proof_cs = fz_new_icc_colorspace_from_file(ctx, FZ_COLORSPACE_NONE, proof_filename);
fz_set_text_aa_level(ctx, alphabits_text);
fz_set_graphics_aa_level(ctx, alphabits_graphics);
@@ -1757,7 +1757,7 @@ int mudraw_main(int argc, char **argv)
break;
case CS_ICC:
fz_try(ctx)
- colorspace = fz_new_icc_colorspace_from_file(ctx, NULL, icc_filename);
+ colorspace = fz_new_icc_colorspace_from_file(ctx, FZ_COLORSPACE_NONE, icc_filename);
fz_catch(ctx)
{
fprintf(stderr, "Invalid ICC destination color space\n");