diff options
author | Michael Vrhel <michael.vrhel@artifex.com> | 2017-03-14 18:37:25 +0000 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2017-06-22 14:59:43 +0100 |
commit | dd58ea5e2ff7e6b61cc5a5b6fd950fb62e92b8be (patch) | |
tree | b22a2dddaae41961f74a88cfafc52a3adb24e263 /include/mupdf/fitz | |
parent | 5ab2a7dad585400caef7703e0761264bb03e81b0 (diff) | |
download | mupdf-dd58ea5e2ff7e6b61cc5a5b6fd950fb62e92b8be.tar.xz |
Add Color Management interface to MuPDF, with LCMS implementation.
This commit adds an interface for a color management engine
to MuPDF, together with the internal changes required to
use it. We also add an implementation of this interface using
the LCMS2 library.
This commit is the "lcms" development branch squashed to a single
commit. The individual commits that make it up are as follows:
------
Add LCMS2 submodule.
Add required source files to MSVC libthirdparty project.
Plus changes to the Makefile.
------
Change name of libfont to libresources
The library can hold things other than fonts including
ICC profiles and eventually halftone screens etc.
------
Generate and include icc profiles on windows solution
Makefile for linux needs to be updated
------
Initial cut at interface to little cms
Methods for getting profile handles, link handles
and transform buffers as well as individual colors.
------
Install ICC profiles from source
When the source color space is an ICC profile
install the ICC space. Use alternative color
space if ICC is invalid.
------
Rename ICC resources
The way that fontdump generates the names was
causing some redundant prefix/suffix combinations.
------
Make resource ICC profiles usable
This brings in the resource profiles for use with the
target device. When mudraw is invoked with the icc
color type, it will set up the target pixmap to have an icc
based color space.
------
Make Default ICC color spaces not storable
The ICC color spaces in the color context should not be
put into the store. ICC color spaces that are contained
in the source document are however storable.
------
Add in support for single color conversion
This adds in the selection of the icc single color
converter. Note that we may want to look at using
the float conversion in lcms here since we are going
from and to float. The down side is that the creation
of such converters may be expensive.
------
Pixmap ICC conversion
Also clean up and further simplify some of the code. Use common
dst, src in function parameters instead of src, dst.
------
Add md5 calculation for profiles
Compare md5 of source and destination. If they
are the same set link as identity and do not bother
creating link from cmm.
------
Initial attempt at adding links to store
Next need to make sure I have all the dropping set up
correctly and that the links are getting freed when
we are all done with them.
------
Add drop for link
Make sure that we drop the links when we are done with them.
------
Fix icc link store ref. counting + rendering intent
The key allocations, rc and removal was wrong for the icc links.
Also added in support on the graphic state for rendering intent.
------
Add ICC profiles to Makefile.
------
Move ICC profile loading to colorspace.c
------
Fix build on linux.
------
Use hexdump in creating icc profiles
------
First cut at CalRGB CalGray handling
These color spaces are converted to equivalent ICC profiles
when the drawing operation occurs. ToDo still is avoid
creating brand new CalGray, CalRGB or ICC color spaces when
we encounter the same object in the source file. Instead
we should make use of the store.
------
Adding fz_color_params into device API
Stroke and fill of paths and text which will have color rendering related settings
including overprint, overprint mode, rendering intent and black point settings.
Images have a fz_color_params member added to them.
------
Rendering intent support for graphic and text
Graphic fills and strokes as well as text fill and strokes
handle the rendering intent settings. This works
through the display list. The parameters related to
color rendering, ri, bp, op, opm are packed in the flags
bits through the display list.
To do: Add support for images and shadings.
------
Add support for rendering intent with images
Required change to fill_image api, hence the large
number of files touched.
------
Add support for shadings rendering intent and DeviceN
This adds support for the rendering intent in shading fills.
Also, adds in support for color management of DeviceN and
Separation color spaces where the base space is defined to be
ICC.
------
Add clamping proc to colorspace-imp.h
In the head of mupdf, the index color values were not
being clamped properly. I moved the clamping operation
to be performed by a procedure in of the color space.
The a*, b* values in LAB will need to include a range value
for proper clamping as well as the ICC color space at some
point.
------
Fix assert test with index images
------
Support for DeviceN images color managed
The base space for DeviceN and separation images
is now color managed when the ICC work flow is used.
------
Add DefaultGray etc to names.txt
The DefaultGray, DefaultRGB, and DefaultCMYK settings
in the pdf page resource dictionary need to be parsed
and handled if present.
------
Remove methods for setting color space in context
The methods that existed for setting the color spaces
in the color space context were broken and we will not
be changing them from their initial setting at startup.
------
Add front end support for default color spaces
PDF can specify in the resource dictionary color spaces
that should be used for DeviceGray, DeviceRGB and DeviceCMYK.
This commit handles the extraction of these color spaces
and passes them through the display list and gets them
into a structure on a draw device (if one is used).
Next step is to have the draw device make use of them.
------
Backend of default color spaces
This handles the use of page level definitions for
DefaultGray, DefaultRGB, DefaultCMYK in the
draw device. The interface for the pixmap color
conversion had to be expanded a bit to pass the
default_cs object. This was needed due to the fact
that the image could be DeviceN or Separation and
have a base space that needs to be replaced by
a page level Default color space. Tested this
with a file that had two pages each with an common
reference image object but different DefaultCMYK
definitions in the page resource dictionary. Proper
rendering was obtained.
------
Add icc support to band-writer and png output
For image viewers that support icc profiles, it
is important that we include the icc profile
into those formats that support. Currently the
only output format we have that supports it is
PNG. But if we decide to do tiff, jpeg or psd
those also support the embedding of icc profiles.
------
Work toward multithreading
Each cloned context creates a new cmm context to
reduce contention. This may not be optimal though
as it may create conflicts in any shared store.
------
Add missing files.
Failed to check in icc-imp.h and icc34.h
------
Fix default device color calls
copy and paste errors.
------
Fixes
------
Fix clamping of lab colors
The lab colors when used with the lab resource profile
need to be properly clamped and scaled.
------
Turn off ICC create debug define
------
Fix memory leak issues
------
Set clamp proc in color context color spaces
When NO_ICC is enabled there was an issue as the
default spaces did not have the clamp proc (which was added
in the lcms branch).
------
Fix several issues after rebase
During rebase of the branch there were several
issues that came up. In addition there was
a fix related to the use of the lcms2 context branch
that did not make it in for some reason.
------
Fix for fz_store_type structure changes
------
Fixes for multithreaded
This fixes a few issues. One issue is that we can not be changing the
input and output formatter for the links if they are being shared among
threads. This adds the format as part of the link definition. Next step
is to create a link clone operation in lcms so that we can readily create
a different one with everything the same except the formatter.
Also, this shares the profiles that exist in the color context among the
threads. When a context is cloned, it will use the profiles in the current
context but it will create a new cmm context.c
------
Fix NO_ICC issues
There were a few issues that occurred when we compiled and ran
with the NO_ICC setting.
------
Change CMM to use lower resolution tables in links
The table resolution greatly affects the performance for some files. I don't see any significant color rendering issues going with a lower resolution.
Selecting cmsFLAGS_LOWRESPRECALC uses a MLUT resolution of 17. This is going to be
sufficient color wise and gives a large improvement performance wise especially for files
where the color link creation is significant compared to the rendering.
------
Fix link key creation to populate alpha and bit depth.
The store key for icc links needs to include the bit depth
and if the transform has to handle an alpha value. This
is needed due to the fact that we can't change the formatter when
we are sharing links among different threads.
------
Pull in some MSVC 2005 fixes for lcms2
------
Fix non-prototype prototype.
------
Miscellaneous typos, whitespace fixes.
------
Tidy colorspace creation API.
Rather than pass a magic implementation reference count value
(-1 for static, 1 for normal), pass a boolean "is_static" flag.
This gives a nicer API (IMAO etc).
------
Make all colorspaces use an fz_buffer.
------
Fix internal naming of MSVC project file.
------
Fix some error handling.
------
Add some consts.
------
Tweak fz_color_params and fz_store_hash.
Use uint8_t for fz_color_param entries - no need to use
larger.
Same change in fz_store_hash. This limits the size required
for the hash table too.
------
Throw on errors, rather than returning NULL.
fz_cmm_transform_pixmap should throw if it's fed pixmaps
incompatible with its transforms.
fz_cmm_new_ctx should throw if the cmm fails to initialise.
------
Ensure LCMS2_OBJs are built/linked using Makefile.
Also ensure that ICC_OBJs are included.
------
Fix some unused variable warnings.
------
cs_params fixes.
Use the ones that are passed.
------
fz_color_params tweaks.
Make them const in many places.
Cope with cs_params == NULL meaning default (i.e. fz_cs_param(ctx)).
Minimise the places we call fz_cs_params(ctx).
Consistently use cs_params rather than a mix of cs_param and cs_params.
------
Improve PDF color params handling.
PDF allows different OP settings for strokes and fills.
This means that either we need to keep separate entries in
each fz_color_param structure for the stroke one or the fill
one, OR we need to duplicate the fz_color_param structure.
It seems neatest to do the latter (not least because this
means we don't pass more information to each device function
than it actually needs).
Accordingly, we put an fz_color_param in each pdf_material.
We update the code that reads ExtGStates to set the values
appropriately. We take the opportunity to add support for the
PDF 2.0 UseBlackPtComp option too.
------
Fix colorspace ref count problems.
1) Don't drop colorspace until we've finished using it.
2) Don't drop it twice.
------
Convert NULL deref into a thrown error.
Seen with:
mutool draw -D -o out.png ../tests_private/comparefiles/Bug689760.pdf
We seem to have a pdf-cal space with no profile.
Talk to Michael about this.
------
Avoid using colorspace names to distinguish colorspaces.
Using strcmp is slow.
------
Cope with failure to parse default colorspaces during PDF page load.
------
Avoid SEGV due to to pdf_cal space with no profile.
As seen in:
tests_private/pdf/PDFIA1.7_SUBSET/CATX4879.pdf
------
Handle cases where base space of sep is pdf-cal
We handled this for images, but not for solid fills.
------
Accelerate ICC color conversion.
------
Cope with indexed images in the color management.
Some images (JPX images) come to the cm code still in
the indexed color space. Their base space could be DevN
so we need to cope with multiple base decodes. This
continues the decode until we get to a space for which
we can create an ICC link.
------
Ignore alpha presence in component count check
------
Eliminate recursion in fz_source_colorspace_cm.
------
Cope with bare ICCBased colorspace defs.
Bug692137.pdf has ICCBased colorspaced definitions given
directly as a stream, rather than as
[ /ICCBased <stream reference> ]
Acrobat copes with these, as does gs. We therefore update our
code to cope too.
Also, the PDF spec says that any problems found when reading
the Default spaces should be ignored (or at least not to abort
rendering). Update our code to do that too.
------
Tweak color converter logic for speed.
When we are using an icc profile based conversion, avoid ever
having to lookup the color converter for each conversion call;
do it at the lookup stage.
------
Harden us against failures during ICC link creation.
Seen with corrupted profiles.
------
Fix for handling alpha with lcms.
Note that this currently maintains an alpha when it is present.
We may need to do some work for the gray scale conversion to alpha mask.
------
Delay pdf-cal profile creation
Put the creation of the pdf cal profile into the link
creation function (rather than have it scattered). Also
be robust in the condition of failure to create the profile.
------
Proper clamping with embedded CIELAB ICC profile
If the ICC profiles alternate color space is LAB
then use the LAB clamping proc.
------
Use the color space clamp when converting to base color spaces
In many of the Ghent test files, we have a DeviceN image whose
alternate color space is CIELAB. We need to make sure to use
the CIELAB clamping operation in this case.
------
Make ICC runtime configurable.
Add fz_icc_flowflow, fz_set_icc_workflow functions to read ICC
workflow state, and set the ICC workflow state. The latter will
throw an error if trying to enable ICC workflow in a NO_ICC build.
Add -N flag to mutool to disable ICC.
Incorporates build fixes from Michael.
------
Ensure fz_draw_fill_image uses the pixmap colorspace
It appears that the image colorspace historically has been able
to differ from the pixmap colorspace. While we've fixed the cases
that we know about for this (see the previous commits), tweak
fz_draw_fill_image to work the way it always has in the past.
------
Add support for output intent
PDF documents can have an ICC profile defined in their Catalog
which defines the output color space and the color space to
use for one of the Device color spaces (e.g. DeviceGray,
DeviceRGB or DeviceCMYK).
------
Catch errors in default color spaces
Before setting the default color space contained in
the file, make sure it is the correct type.
Bug692213.pdf
------
Clamp to base space during sep color conversion
This was the source of a problem when the base space
was CIELAB.
------
Rename some functions to be more MuPDFy
drop rather than free etc.
------
Fix "casting away const" warning.
srcv is a const *. Do the clamping operation on src_map
(the same value) before it is assigned into the const
variable.
------
Rejig top level color management interface slightly.
Same code, just change the encapsulation.
------
Remove pre-multiplied alpha prior to color management
The pixmaps in mupdf use a premultiplied alpha format.
Prior to doing any color management we need to undo
the alpha and then reapply after color management.
------
Remove global output intent as unused.
------
Move fz_color_params to be the final arg in dev calls.
Frequently this will be NULL, and it doesn't form part of
the colorspace/color/alpha triple.
------
Rename fz_default_xxx static variables.
Remove fz prefix, to prepare for a later renaming that would conflict.
------
Rename cs_params to color_params.
------
Rename lcms branch identifiers.
------
Return device colorspaces if the default colorspace is NULL.
------
Clean up device call function for set_default_colorspaces.
------
Add missing rethrow.
------
Load page default colorspaces lazily.
------
murun: Add color params device argument.
Stubbed to always be NULL at the moment.
------
Rename extgstate processor ops.
------
Fix a few minor issues from Tor
Removes icc-imp.h
Rename color-icccreate.c
Add context to some methods
------
Fix javalib with recent lcms dev changes.
------
Update lcms2 with sub project fixes.
------
Fix build failure.
------
Add icc profile into other PNG output methods
------
Fix some ints that should be size_t's.
------
Tweak fz_new_icc_data_from_icc_colorspace.
Ensure that the colorspace is const, and that we set size to 0
if we don't find any data.
------
Combine band writer methods for header and ICC writing
For many formats (like PSD), we need to delay writing some of the
header until we know whether we are getting an ICC profile to
write or not. Makes more sense to just write them at the same
time.
------
Miscellaneous tweaks in colorspace.c
Mainly to avoid pointer aliasing, "nicer" whitespace, and a leak
on error.
------
Avoid rightward drift in get_base_icc.
------
Ensure that pdf_load_output_intent copes with exceptions.
If load_icc_based throws and exception, warn and continue. Don't
not render a file just because the inbuilt default profiles
are broken.
------
Revert change in pdf-page.c
The page resources load had been moved so we could get the default
colorspaces, but this has been moved into run_contents, so putting
stuff back as it was before.
------
Revert changes in mudraw.
We had added some colorspages in mudraw, and then later removed them.
Revert the changes to accomodate this to make the overall branch diffs
smaller.
------
Use fz_buffer in color-icc-create.c
------
Force mapping through proof icc profile always.
------
Fix behaviour on fz_cmm_new_profile failure.
If the profile fails to be made, return an error code,
and have the callers take sane steps.
------
Tweak load_icc_based
Cope better with errors in reading the ICC space not stopping
us loading the alternate.
------
Remove unused variable.
------
Get page resource for DefaultCS look-up
res = pdf_dict_get(ctx, PDF_NAME_Resources, page->obj); was not
returning resource.
Replaced with res = pdf_page_resources(ctx, page);
------
Move default color space set up to pdf_run_page_contents_with_usage
------
Review fixes for lcms branch.
------
Fixes for calibrated colorspace loading.
------
Add fz_document_output_intent wrapper. Lazy load intent for PDF.
------
Copy DefaultCS logic into pdf_run_annot_with_usage.
Same code as from pdf_run_page_contents_with_usage.
------
More review fixes.
------
Avoid rightward drift in pdf_load_cal_common
------
Rename color_converter functions to be find/drop.
Better than than lookup/discard. lookup suggests something that
doesn't need dropping, and we use drop rather than discard by
convention.
------
Move cmm from context into colorspace context.
------
Review fixes: Remove recursion and rename functions.
------
Don't access doc->oi directly in pdf_load_default_colorspaces.
------
Rename fz_colorspace_is_pdf_cal to fz_colorspace_is_cal and make it public.
------
Tweak function naming to be more consistent.
------
fz_md5_icc can be implemented using fz_md5_buffer.
------
Print full md5 checksums in link key debug prints.
------
Make fz_md5_buffer NULL safe.
------
Simplify debug saving of ICC profiles.
------
Rename fz_cmm_new/drop_profile to init/fin.
------
Indentation cleanups.
------
Move CMM static inline functions from private header to C file.
------
Tweak fz_icc_data_from_icc_colorspace to return a buffer.
Also, remove the _new_ from the name to reflect the fact that we
are passed a borrowed handle, not given a new reference.
------
java: Add ColorParams.pack() function.
------
Generate one C file for the embedded ICC profiles.
------
Return const pointer from fz_default_color_params.
------
Change misleading argument names to fz_new_colorspace.
------
Rename fz_cmm_new/drop_link to fz_cmm_init/fin_link.
------
Change definition of fz_cmm_instance.
Rather than void, use an undefined struct in keeping with the
rest of the code.
------
Add support for color managed bgr color space
------
Return unsigned char array from fz_lookup_icc.
------
Make default_color_params immutable.
Changing the defaults used by the draw device should happen via a
device call, should we need the functionality in the future.
------
Clean up error handling in color-lcms.c
------
Fix signed/unsigned warning.
Diffstat (limited to 'include/mupdf/fitz')
-rw-r--r-- | include/mupdf/fitz/band-writer.h | 6 | ||||
-rw-r--r-- | include/mupdf/fitz/buffer.h | 2 | ||||
-rw-r--r-- | include/mupdf/fitz/color-management.h | 115 | ||||
-rw-r--r-- | include/mupdf/fitz/colorspace.h | 120 | ||||
-rw-r--r-- | include/mupdf/fitz/config.h | 3 | ||||
-rw-r--r-- | include/mupdf/fitz/context.h | 3 | ||||
-rw-r--r-- | include/mupdf/fitz/device.h | 35 | ||||
-rw-r--r-- | include/mupdf/fitz/document.h | 11 | ||||
-rw-r--r-- | include/mupdf/fitz/font.h | 22 | ||||
-rw-r--r-- | include/mupdf/fitz/image.h | 2 | ||||
-rw-r--r-- | include/mupdf/fitz/output-png.h | 4 | ||||
-rw-r--r-- | include/mupdf/fitz/pixmap.h | 17 | ||||
-rw-r--r-- | include/mupdf/fitz/shade.h | 6 | ||||
-rw-r--r-- | include/mupdf/fitz/store.h | 18 |
14 files changed, 299 insertions, 65 deletions
diff --git a/include/mupdf/fitz/band-writer.h b/include/mupdf/fitz/band-writer.h index 06f885c3..95385d5f 100644 --- a/include/mupdf/fitz/band-writer.h +++ b/include/mupdf/fitz/band-writer.h @@ -10,7 +10,7 @@ */ typedef struct fz_band_writer_s fz_band_writer; -typedef void (fz_write_header_fn)(fz_context *ctx, fz_band_writer *writer); +typedef void (fz_write_header_fn)(fz_context *ctx, fz_band_writer *writer, const fz_colorspace *cs); typedef void (fz_write_band_fn)(fz_context *ctx, fz_band_writer *writer, int stride, int band_start, int band_height, const unsigned char *samples); typedef void (fz_write_trailer_fn)(fz_context *ctx, fz_band_writer *writer); typedef void (fz_drop_band_writer_fn)(fz_context *ctx, fz_band_writer *writer); @@ -51,9 +51,11 @@ fz_band_writer *fz_new_band_writer_of_size(fz_context *ctx, size_t size, fz_outp pagenum: Page number + cs: Colorspace (NULL for bitmaps) + Throws exception if incompatible data format. */ -void fz_write_header(fz_context *ctx, fz_band_writer *writer, int w, int h, int n, int alpha, int xres, int yres, int pagenum); +void fz_write_header(fz_context *ctx, fz_band_writer *writer, int w, int h, int n, int alpha, int xres, int yres, int pagenum, const fz_colorspace *cs); /* fz_write_band: Cause a band writer to write the next band diff --git a/include/mupdf/fitz/buffer.h b/include/mupdf/fitz/buffer.h index 73f254a3..c6f4c2a4 100644 --- a/include/mupdf/fitz/buffer.h +++ b/include/mupdf/fitz/buffer.h @@ -110,6 +110,8 @@ void fz_append_byte(fz_context *ctx, fz_buffer *buf, int c); void fz_append_rune(fz_context *ctx, fz_buffer *buf, int c); void fz_append_int32_le(fz_context *ctx, fz_buffer *buf, int x); void fz_append_int16_le(fz_context *ctx, fz_buffer *buf, int x); +void fz_append_int32_be(fz_context *ctx, fz_buffer *buf, int x); +void fz_append_int16_be(fz_context *ctx, fz_buffer *buf, int x); void fz_append_bits(fz_context *ctx, fz_buffer *buf, int value, int count); void fz_append_bits_pad(fz_context *ctx, fz_buffer *buf); void fz_append_printf(fz_context *ctx, fz_buffer *buffer, const char *fmt, ...); diff --git a/include/mupdf/fitz/color-management.h b/include/mupdf/fitz/color-management.h new file mode 100644 index 00000000..6c3ac356 --- /dev/null +++ b/include/mupdf/fitz/color-management.h @@ -0,0 +1,115 @@ +#ifndef MUPDF_FITZ_COLOR_MANAGEMENT_H +#define MUPDF_FITZ_COLOR_MANAGEMENT_H + +#include "mupdf/fitz/colorspace.h" +#include "mupdf/fitz/context.h" +#include "mupdf/fitz/pixmap.h" + +/* + MuPDF can either run with or without color management. By default + MuPDF runs without color management. To enable color management, + a color management engine must be given to the context. + + The context will then create one 'instance' of this engine per + cloned context. Every instance is tied to the particular context + in which it is created. + + Profiles and links can be shared between instances. +*/ + +/* + fz_cmm_new_instance_fn: Create a new instance of the color + management engine, tied to the given context. +*/ +typedef fz_cmm_instance *(fz_cmm_new_instance_fn)(fz_context *ctx); + +/* + fz_cmm_drop_instance_fn: Drop a given instance of the color + management engine. No further calls will be made to this + instance. +*/ +typedef void (fz_cmm_drop_instance_fn)(fz_cmm_instance *instance); + +/* + fz_cmm_transform_pixmap_fn: Transform a pixmap according + to a link. +*/ +typedef void (fz_cmm_transform_pixmap_fn)(fz_cmm_instance *ctx, fz_icclink *link, fz_pixmap *dst, fz_pixmap *src); + +/* + fz_cmm_transform_color_fn: Transform some color values according + to a link. +*/ +typedef void (fz_cmm_transform_color_fn)(fz_cmm_instance *ctx, fz_icclink *link, unsigned short *dst, const unsigned short *src); + +/* + fz_cmm_init_link_fn: Create a new link between icc profiles. +*/ +typedef void (fz_cmm_init_link_fn)(fz_cmm_instance *ctx, fz_icclink *link, const fz_color_params *rend, int cmm_flags, int num_bytes, int alpha, const fz_iccprofile *src, const fz_iccprofile *prf, const fz_iccprofile *des); + +/* + fz_cmm_fin_link_fn: Drop a link. +*/ +typedef void (fz_cmm_fin_link_fn)(fz_cmm_instance *ctx, fz_icclink *link); + +/* + fz_cmm_init_profile_fn: Create the cmm specific data for the given + profile. The cmm handle is stored to profile->cmm_handle. +*/ +typedef void (fz_cmm_init_profile_fn)(fz_cmm_instance *ctx, fz_iccprofile *profile); + +/* + fz_cmm_fin_profile_fn: Drop the cmm specific data for the given + profile. +*/ +typedef void (fz_cmm_fin_profile_fn)(fz_cmm_instance *ctx, fz_iccprofile *profile); + +/* + Encapsulate details for a given color management engine into a single + structure. +*/ +struct fz_cmm_engine_s { + fz_cmm_new_instance_fn *new_instance; + fz_cmm_drop_instance_fn *drop_instance; + fz_cmm_transform_pixmap_fn *transform_pixmap; + fz_cmm_transform_color_fn *transform_color; + fz_cmm_init_link_fn *init_link; + fz_cmm_fin_link_fn *fin_link; + fz_cmm_init_profile_fn *init_profile; + fz_cmm_fin_profile_fn *fin_profile; + int avoid_white_fix_flag; +}; + +/* + fz_get_cmm_engine: Read details of the current color + management engine. If NULL, we are working without + color management. +*/ +const fz_cmm_engine *fz_get_cmm_engine(fz_context *ctx); + +/* + fz_set_cmm_engine: Set the color management engine to + be used. This should only ever be called on the "base" + context before cloning it, and before opening any files. + + Attempting to change the engine in use once a file has + been opened, or to use different color management engine + for the same file in different threads will lead to + undefined behaviour, including crashing. + + Using different ICC engines for different files using + different sets of fz_contexts should theoretically be + possible. +*/ +void fz_set_cmm_engine(fz_context *ctx, const fz_cmm_engine *engine); + +/* + Currently we only provide a single color management + engine, based on a (modified) LCMS2. + + An unmodified LCMS2 should work too, but only when restricted + to a single thread. +*/ +extern fz_cmm_engine fz_cmm_engine_lcms; + +#endif diff --git a/include/mupdf/fitz/colorspace.h b/include/mupdf/fitz/colorspace.h index e7453f6c..289955c9 100644 --- a/include/mupdf/fitz/colorspace.h +++ b/include/mupdf/fitz/colorspace.h @@ -7,6 +7,29 @@ enum { FZ_MAX_COLORS = 32 }; +enum +{ + /* Same order as needed by lcms */ + FZ_RI_PERCEPTUAL, + FZ_RI_RELATIVE_COLORIMETRIC, + FZ_RI_SATURATION, + FZ_RI_ABSOLUTE_COLORIMETRIC, +}; + +typedef struct fz_color_params_s fz_color_params; + +struct fz_color_params_s +{ + uint8_t ri; + uint8_t bp; + uint8_t op; + uint8_t opm; +}; + + +int fz_lookup_rendering_intent(const char *name); +char *fz_rendering_intent_name(int ri); + /* A fz_colorspace object represents an abstract colorspace. While this should be treated as a black box by callers of the library at @@ -17,16 +40,21 @@ enum { FZ_MAX_COLORS = 32 }; typedef struct fz_colorspace_s fz_colorspace; /* - fz_colorspace_is_indexed: Return true, iff a given colorspace is - indexed. + A fz_iccprofile object encapsulates details about the icc profile. It + also includes the profile handle provided by the cmm and as such is used + in the creation of links between color spaces. +*/ +typedef struct fz_iccprofile_s fz_iccprofile; + +/* + A fz_icclink object encapsulates details about the link between profiles. */ -int fz_colorspace_is_indexed(fz_context *ctx, fz_colorspace *cs); +typedef struct fz_icclink_s fz_icclink; /* - fz_colorspace_is_lab: Return true, iff a given colorspace is - lab. + Used to communicate any document internal page specific default color spaces. */ -int fz_colorspace_is_lab(fz_context *ctx, fz_colorspace *cs); +typedef struct fz_default_colorspaces_s fz_default_colorspaces; /* fz_colorspace_is_subtractive: Return true if a colorspace is subtractive. @@ -61,40 +89,33 @@ fz_colorspace *fz_device_cmyk(fz_context *ctx); fz_colorspace *fz_device_lab(fz_context *ctx); /* - fz_set_device_gray: Set colorspace representing device specific gray. + fz_default_color_params: Get default color params for general color conversion. */ -void fz_set_device_gray(fz_context *ctx, fz_colorspace *cs); - -/* - fz_set_device_rgb: Set colorspace representing device specific rgb. -*/ -void fz_set_device_rgb(fz_context *ctx, fz_colorspace *cs); - -/* - fz_set_device_bgr: Set colorspace representing device specific bgr. -*/ -void fz_set_device_bgr(fz_context *ctx, fz_colorspace *cs); - -/* - fz_set_device_cmyk: Set colorspace representing device specific CMYK. -*/ -void fz_set_device_cmyk(fz_context *ctx, fz_colorspace *cs); +const fz_color_params *fz_default_color_params(fz_context *ctx); typedef void (fz_colorspace_convert_fn)(fz_context *ctx, fz_colorspace *cs, const float *src, float *dst); typedef void (fz_colorspace_destruct_fn)(fz_context *ctx, fz_colorspace *cs); -fz_colorspace *fz_new_colorspace(fz_context *ctx, char *name, int n, int is_subtractive, fz_colorspace_convert_fn *to_rgb, fz_colorspace_convert_fn *from_rgb, fz_colorspace_destruct_fn *destruct, void *data, size_t size); +typedef fz_colorspace *(fz_colorspace_base_fn)(const fz_colorspace *cs); + +typedef void (fz_colorspace_clamp_fn)(const fz_colorspace *cs, const float *src, float *dst); + +fz_colorspace *fz_new_colorspace(fz_context *ctx, char *name, int is_static, int n, int is_subtractive, fz_colorspace_convert_fn *to_ccs, fz_colorspace_convert_fn *from_ccs, fz_colorspace_base_fn *base, fz_colorspace_clamp_fn *clamp, fz_colorspace_destruct_fn *destruct, void *data, size_t size); fz_colorspace *fz_new_indexed_colorspace(fz_context *ctx, fz_colorspace *base, int high, unsigned char *lookup); fz_colorspace *fz_keep_colorspace(fz_context *ctx, fz_colorspace *colorspace); void fz_drop_colorspace(fz_context *ctx, fz_colorspace *colorspace); void fz_drop_colorspace_imp(fz_context *ctx, fz_storable *colorspace); -int fz_colorspace_is(fz_context *ctx, const fz_colorspace *cs, fz_colorspace_convert_fn *to_rgb); +fz_colorspace *fz_colorspace_base(fz_context *ctx, const fz_colorspace *cs); +int fz_colorspace_is_icc(fz_context *ctx, const fz_colorspace *cs); +int fz_colorspace_is_lab_icc(fz_context *ctx, const fz_colorspace *cs); +int fz_colorspace_is_cal(fz_context *ctx, const fz_colorspace *cs); +int fz_colorspace_is_indexed(fz_context *ctx, const fz_colorspace *cs); int fz_colorspace_n(fz_context *ctx, const fz_colorspace *cs); const char *fz_colorspace_name(fz_context *ctx, const fz_colorspace *cs); - -void fz_convert_color(fz_context *ctx, fz_colorspace *dsts, float *dstv, fz_colorspace *srcs, const float *srcv); +void fz_clamp_color(fz_context *ctx, const fz_colorspace *cs, const float *in, float *out); +void fz_convert_color(fz_context *ctx, const fz_color_params *params, fz_colorspace *intcs, fz_colorspace *dscs, float *dstv, fz_colorspace *srcs, const float *srcv); typedef struct fz_color_converter_s fz_color_converter; @@ -107,12 +128,51 @@ struct fz_color_converter_s void (*convert)(fz_context *, fz_color_converter *, float *, const float *); fz_colorspace *ds; fz_colorspace *ss; + fz_colorspace *is; void *opaque; + void *link; + int n; }; -void fz_lookup_color_converter(fz_context *ctx, fz_color_converter *cc, fz_colorspace *ds, fz_colorspace *ss); - -void fz_init_cached_color_converter(fz_context *ctx, fz_color_converter *cc, fz_colorspace *ds, fz_colorspace *ss); +void fz_find_color_converter(fz_context *ctx, fz_color_converter *cc, fz_colorspace *is, fz_colorspace *ds, fz_colorspace *ss, const fz_color_params *params); +void fz_drop_color_converter(fz_context *ctx, fz_color_converter *cc); +void fz_init_cached_color_converter(fz_context *ctx, fz_color_converter *cc, fz_colorspace *is, fz_colorspace *ds, fz_colorspace *ss, const fz_color_params *params); void fz_fin_cached_color_converter(fz_context *ctx, fz_color_converter *cc); +/* Public to allow use in icc creation */ +typedef struct fz_cal_colorspace_s fz_cal_colorspace; + +struct fz_cal_colorspace_s { + float wp[3]; + float bp[3]; + float gamma[3]; + float matrix[9]; + int n; + fz_iccprofile *profile; +}; + +/* + icc methods +*/ +fz_colorspace *fz_new_icc_colorspace(fz_context *ctx, int is_static, int num, fz_buffer *buf, const char *name); +fz_colorspace *fz_new_cal_colorspace(fz_context *ctx, 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); + +/* Default cs */ +fz_default_colorspaces *fz_new_default_colorspaces(fz_context *ctx); +fz_default_colorspaces* fz_keep_default_colorspaces(fz_context *ctx, fz_default_colorspaces *default_cs); +void fz_drop_default_colorspaces(fz_context *ctx, fz_default_colorspaces *default_cs); + +/* Do we want to make fz_default_colorspaces public and get rid of these? */ +void fz_set_default_gray(fz_context *ctx, fz_default_colorspaces *default_cs, fz_colorspace *cs); +void fz_set_default_rgb(fz_context *ctx, fz_default_colorspaces *default_cs, fz_colorspace *cs); +void fz_set_default_cmyk(fz_context *ctx, fz_default_colorspaces *default_cs, fz_colorspace *cs); +void fz_set_default_output_intent(fz_context *ctx, fz_default_colorspaces *default_cs, fz_colorspace *cs); + +fz_colorspace *fz_default_gray(fz_context *ctx, fz_default_colorspaces *default_cs); +fz_colorspace *fz_default_rgb(fz_context *ctx, fz_default_colorspaces *default_cs); +fz_colorspace *fz_default_cmyk(fz_context *ctx, fz_default_colorspaces *default_cs); +fz_colorspace *fz_default_output_intent(fz_context *ctx, fz_default_colorspaces *default_cs); + #endif diff --git a/include/mupdf/fitz/config.h b/include/mupdf/fitz/config.h index 97d399b9..c7bf5244 100644 --- a/include/mupdf/fitz/config.h +++ b/include/mupdf/fitz/config.h @@ -75,6 +75,9 @@ /* To skip the SIL fonts, enable: */ /* #define TOFU_SIL */ +/* To skip the ICC profiles, enable: */ +/* #define NO_ICC */ + /* To skip the Base14 fonts, enable: */ /* #define TOFU_BASE14 */ /* (You probably really don't want to do that except for measurement purposes!) */ diff --git a/include/mupdf/fitz/context.h b/include/mupdf/fitz/context.h index 35f4f74f..78e64bbc 100644 --- a/include/mupdf/fitz/context.h +++ b/include/mupdf/fitz/context.h @@ -16,6 +16,8 @@ typedef struct fz_id_context_s fz_id_context; typedef struct fz_warn_context_s fz_warn_context; typedef struct fz_font_context_s fz_font_context; typedef struct fz_colorspace_context_s fz_colorspace_context; +typedef struct fz_cmm_engine_s fz_cmm_engine; +typedef struct fz_cmm_instance_s fz_cmm_instance; typedef struct fz_aa_context_s fz_aa_context; typedef struct fz_style_context_s fz_style_context; typedef struct fz_locks_context_s fz_locks_context; @@ -118,6 +120,7 @@ struct fz_context_s fz_warn_context *warn; fz_font_context *font; fz_colorspace_context *colorspace; + fz_cmm_instance *cmm_instance; fz_aa_context *aa; fz_style_context *style; fz_store *store; diff --git a/include/mupdf/fitz/device.h b/include/mupdf/fitz/device.h index 7e7efb43..2f7971c0 100644 --- a/include/mupdf/fitz/device.h +++ b/include/mupdf/fitz/device.h @@ -86,25 +86,25 @@ struct fz_device_s void (*close_device)(fz_context *, fz_device *); void (*drop_device)(fz_context *, fz_device *); - void (*fill_path)(fz_context *, fz_device *, const fz_path *, int even_odd, const fz_matrix *, fz_colorspace *, const float *color, float alpha); - void (*stroke_path)(fz_context *, fz_device *, const fz_path *, const fz_stroke_state *, const fz_matrix *, fz_colorspace *, const float *color, float alpha); + void (*fill_path)(fz_context *, fz_device *, const fz_path *, int even_odd, const fz_matrix *, fz_colorspace *, const float *color, float alpha, const fz_color_params *); + void (*stroke_path)(fz_context *, fz_device *, const fz_path *, const fz_stroke_state *, const fz_matrix *, fz_colorspace *, const float *color, float alpha, const fz_color_params *); void (*clip_path)(fz_context *, fz_device *, const fz_path *, int even_odd, const fz_matrix *, const fz_rect *scissor); void (*clip_stroke_path)(fz_context *, fz_device *, const fz_path *, const fz_stroke_state *, const fz_matrix *, const fz_rect *scissor); - void (*fill_text)(fz_context *, fz_device *, const fz_text *, const fz_matrix *, fz_colorspace *, const float *color, float alpha); - void (*stroke_text)(fz_context *, fz_device *, const fz_text *, const fz_stroke_state *, const fz_matrix *, fz_colorspace *, const float *color, float alpha); + void (*fill_text)(fz_context *, fz_device *, const fz_text *, const fz_matrix *, fz_colorspace *, const float *color, float alpha, const fz_color_params *); + void (*stroke_text)(fz_context *, fz_device *, const fz_text *, const fz_stroke_state *, const fz_matrix *, fz_colorspace *, const float *color, float alpha, const fz_color_params *); void (*clip_text)(fz_context *, fz_device *, const fz_text *, const fz_matrix *, const fz_rect *scissor); void (*clip_stroke_text)(fz_context *, fz_device *, const fz_text *, const fz_stroke_state *, const fz_matrix *, const fz_rect *scissor); void (*ignore_text)(fz_context *, fz_device *, const fz_text *, const fz_matrix *); - void (*fill_shade)(fz_context *, fz_device *, fz_shade *shd, const fz_matrix *ctm, float alpha); - void (*fill_image)(fz_context *, fz_device *, fz_image *img, const fz_matrix *ctm, float alpha); - void (*fill_image_mask)(fz_context *, fz_device *, fz_image *img, const fz_matrix *ctm, fz_colorspace *, const float *color, float alpha); + void (*fill_shade)(fz_context *, fz_device *, fz_shade *shd, const fz_matrix *ctm, float alpha, const fz_color_params *color_params); + void (*fill_image)(fz_context *, fz_device *, fz_image *img, const fz_matrix *ctm, float alpha, const fz_color_params *color_params); + void (*fill_image_mask)(fz_context *, fz_device *, fz_image *img, const fz_matrix *ctm, fz_colorspace *, const float *color, float alpha, const fz_color_params *color_params); void (*clip_image_mask)(fz_context *, fz_device *, fz_image *img, const fz_matrix *ctm, const fz_rect *scissor); void (*pop_clip)(fz_context *, fz_device *); - void (*begin_mask)(fz_context *, fz_device *, const fz_rect *, int luminosity, fz_colorspace *, const float *bc); + void (*begin_mask)(fz_context *, fz_device *, const fz_rect *, int luminosity, fz_colorspace *, const float *bc, const fz_color_params *); void (*end_mask)(fz_context *, fz_device *); void (*begin_group)(fz_context *, fz_device *, const fz_rect *, int isolated, int knockout, int blendmode, float alpha); void (*end_group)(fz_context *, fz_device *); @@ -113,6 +113,7 @@ struct fz_device_s void (*end_tile)(fz_context *, fz_device *); void (*render_flags)(fz_context *, fz_device *, int set, int clear); + void (*set_default_colorspaces)(fz_context *, fz_device *, fz_default_colorspaces *); fz_rect d1_rect; @@ -124,21 +125,21 @@ struct fz_device_s fz_device_container_stack *container; }; -void fz_fill_path(fz_context *ctx, fz_device *dev, const fz_path *path, int even_odd, const fz_matrix *ctm, fz_colorspace *colorspace, const float *color, float alpha); -void fz_stroke_path(fz_context *ctx, fz_device *dev, const fz_path *path, const fz_stroke_state *stroke, const fz_matrix *ctm, fz_colorspace *colorspace, const float *color, float alpha); +void fz_fill_path(fz_context *ctx, fz_device *dev, const fz_path *path, int even_odd, const fz_matrix *ctm, fz_colorspace *colorspace, const float *color, float alpha, const fz_color_params *color_params); +void fz_stroke_path(fz_context *ctx, fz_device *dev, const fz_path *path, const fz_stroke_state *stroke, const fz_matrix *ctm, fz_colorspace *colorspace, const float *color, float alpha, const fz_color_params *color_params); void fz_clip_path(fz_context *ctx, fz_device *dev, const fz_path *path, int even_odd, const fz_matrix *ctm, const fz_rect *scissor); void fz_clip_stroke_path(fz_context *ctx, fz_device *dev, const fz_path *path, const fz_stroke_state *stroke, const fz_matrix *ctm, const fz_rect *scissor); -void fz_fill_text(fz_context *ctx, fz_device *dev, const fz_text *text, const fz_matrix *ctm, fz_colorspace *colorspace, const float *color, float alpha); -void fz_stroke_text(fz_context *ctx, fz_device *dev, const fz_text *text, const fz_stroke_state *stroke, const fz_matrix *ctm, fz_colorspace *colorspace, const float *color, float alpha); +void fz_fill_text(fz_context *ctx, fz_device *dev, const fz_text *text, const fz_matrix *ctm, fz_colorspace *colorspace, const float *color, float alpha, const fz_color_params *color_params); +void fz_stroke_text(fz_context *ctx, fz_device *dev, const fz_text *text, const fz_stroke_state *stroke, const fz_matrix *ctm, fz_colorspace *colorspace, const float *color, float alpha, const fz_color_params *color_params); void fz_clip_text(fz_context *ctx, fz_device *dev, const fz_text *text, const fz_matrix *ctm, const fz_rect *scissor); void fz_clip_stroke_text(fz_context *ctx, fz_device *dev, const fz_text *text, const fz_stroke_state *stroke, const fz_matrix *ctm, const fz_rect *scissor); void fz_ignore_text(fz_context *ctx, fz_device *dev, const fz_text *text, const fz_matrix *ctm); void fz_pop_clip(fz_context *ctx, fz_device *dev); -void fz_fill_shade(fz_context *ctx, fz_device *dev, fz_shade *shade, const fz_matrix *ctm, float alpha); -void fz_fill_image(fz_context *ctx, fz_device *dev, fz_image *image, const fz_matrix *ctm, float alpha); -void fz_fill_image_mask(fz_context *ctx, fz_device *dev, fz_image *image, const fz_matrix *ctm, fz_colorspace *colorspace, const float *color, float alpha); +void fz_fill_shade(fz_context *ctx, fz_device *dev, fz_shade *shade, const fz_matrix *ctm, float alpha, const fz_color_params *color_params); +void fz_fill_image(fz_context *ctx, fz_device *dev, fz_image *image, const fz_matrix *ctm, float alpha, const fz_color_params *color_params); +void fz_fill_image_mask(fz_context *ctx, fz_device *dev, fz_image *image, const fz_matrix *ctm, fz_colorspace *colorspace, const float *color, float alpha, const fz_color_params *color_params); void fz_clip_image_mask(fz_context *ctx, fz_device *dev, fz_image *image, const fz_matrix *ctm, const fz_rect *scissor); -void fz_begin_mask(fz_context *ctx, fz_device *dev, const fz_rect *area, int luminosity, fz_colorspace *colorspace, const float *bc); +void fz_begin_mask(fz_context *ctx, fz_device *dev, const fz_rect *area, int luminosity, fz_colorspace *colorspace, const float *bc, const fz_color_params *color_params); void fz_end_mask(fz_context *ctx, fz_device *dev); void fz_begin_group(fz_context *ctx, fz_device *dev, const fz_rect *area, int isolated, int knockout, int blendmode, float alpha); void fz_end_group(fz_context *ctx, fz_device *dev); @@ -146,7 +147,7 @@ void fz_begin_tile(fz_context *ctx, fz_device *dev, const fz_rect *area, const f int fz_begin_tile_id(fz_context *ctx, fz_device *dev, const fz_rect *area, const fz_rect *view, float xstep, float ystep, const fz_matrix *ctm, int id); void fz_end_tile(fz_context *ctx, fz_device *dev); void fz_render_flags(fz_context *ctx, fz_device *dev, int set, int clear); - +void fz_set_default_colorspaces(fz_context *ctx, fz_device *dev, fz_default_colorspaces *default_cs); fz_device *fz_new_device_of_size(fz_context *ctx, int size); #define fz_new_derived_device(CTX, TYPE) \ diff --git a/include/mupdf/fitz/document.h b/include/mupdf/fitz/document.h index 128087a8..23fc4b1d 100644 --- a/include/mupdf/fitz/document.h +++ b/include/mupdf/fitz/document.h @@ -98,6 +98,11 @@ typedef fz_page *(fz_document_load_page_fn)(fz_context *ctx, fz_document *doc, i typedef int (fz_document_lookup_metadata_fn)(fz_context *ctx, fz_document *doc, const char *key, char *buf, int size); /* + fz_document_output_intent_fn: Return output intent color space if it exists +*/ +typedef fz_colorspace* (fz_document_output_intent_fn)(fz_context *ctx, fz_document *doc); + +/* fz_document_make_bookmark_fn: Type for a function to make a bookmark. See fz_make_bookmark for more information. */ @@ -237,6 +242,7 @@ struct fz_document_s fz_document_count_pages_fn *count_pages; fz_document_load_page_fn *load_page; fz_document_lookup_metadata_fn *lookup_metadata; + fz_document_output_intent_fn *get_output_intent; int did_layout; int is_reflowable; }; @@ -609,6 +615,11 @@ int fz_lookup_metadata(fz_context *ctx, fz_document *doc, const char *key, char #define FZ_META_INFO_TITLE "info:Title" /* + Find the output intent colorspace if the document has defined one. +*/ +fz_colorspace *fz_document_output_intent(fz_context *ctx, fz_document *doc); + +/* Get the number of separations on a page (including CMYK). This will be 0, unless the format specifically supports separations (such as gproof files). diff --git a/include/mupdf/fitz/font.h b/include/mupdf/fitz/font.h index 7c71ca05..1a736084 100644 --- a/include/mupdf/fitz/font.h +++ b/include/mupdf/fitz/font.h @@ -266,13 +266,25 @@ const char *fz_lookup_builtin_font(fz_context *ctx, const char *name, int bold, */ const char *fz_lookup_base14_font(fz_context *ctx, const char *name, int *len); +/* ToDo: Share fz_lookup_builtin_font and fz_lookup_icc? Check with Tor */ +/* + fz_lookup_icc: Search for icc profile. + + name: The name of the profile desired (gray-icc, rgb-icc, cmyk-icc or lab-icc). + + len: Pointer to a place to receive the length of the discovered. + + 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); + /* fz_lookup_cjk_font: Search the builtin cjk fonts for a match. Whether a font is present or not will depend on the configuration in which MuPDF is built. registry: The desired registry to lookup in (e.g. - FZ_ADOBE_KOREA_1) + FZ_ADOBE_KOREA_1). serif: 1 if serif desired, 0 otherwise. @@ -293,9 +305,9 @@ const char *fz_lookup_cjk_font(fz_context *ctx, int registry, int serif, int wmo Whether a font is present or not will depend on the configuration in which MuPDF is built. - script: The script desired (e.g. UCDN_SCRIPT_KATAKANA) + script: The script desired (e.g. UCDN_SCRIPT_KATAKANA). - lang: The language desired (e.g. FZ_LANG_ja) + lang: The language desired (e.g. FZ_LANG_ja). serif: 1 if serif desired, 0 otherwise. @@ -336,9 +348,9 @@ const char *fz_lookup_noto_emoji_font(fz_context *ctx, int *len); present or not will depend on the configuration in which MuPDF is built. - script: The script desired (e.g. UCDN_SCRIPT_KATAKANA) + script: The script desired (e.g. UCDN_SCRIPT_KATAKANA). - language: The language desired (e.g. FZ_LANG_ja) + language: The language desired (e.g. FZ_LANG_ja). serif: 1 if serif desired, 0 otherwise. diff --git a/include/mupdf/fitz/image.h b/include/mupdf/fitz/image.h index 8a8f5007..13aee534 100644 --- a/include/mupdf/fitz/image.h +++ b/include/mupdf/fitz/image.h @@ -26,6 +26,8 @@ typedef struct fz_pixmap_image_s fz_pixmap_image; image: The image to retrieve a pixmap from. + color_params: The color parameters (or NULL for defaults). + subarea: The subarea of the image that we actually care about (or NULL to indicate the whole image). diff --git a/include/mupdf/fitz/output-png.h b/include/mupdf/fitz/output-png.h index 8342aead..5c299114 100644 --- a/include/mupdf/fitz/output-png.h +++ b/include/mupdf/fitz/output-png.h @@ -30,7 +30,7 @@ fz_band_writer *fz_new_png_band_writer(fz_context *ctx, fz_output *out); /* Create a new buffer containing the image/pixmap in PNG format. */ -fz_buffer *fz_new_buffer_from_image_as_png(fz_context *ctx, fz_image *image); -fz_buffer *fz_new_buffer_from_pixmap_as_png(fz_context *ctx, fz_pixmap *pixmap); +fz_buffer *fz_new_buffer_from_image_as_png(fz_context *ctx, fz_image *image, const fz_color_params *color_params); +fz_buffer *fz_new_buffer_from_pixmap_as_png(fz_context *ctx, fz_pixmap *pixmap, const fz_color_params *color_params); #endif diff --git a/include/mupdf/fitz/pixmap.h b/include/mupdf/fitz/pixmap.h index 302038ae..5b784c09 100644 --- a/include/mupdf/fitz/pixmap.h +++ b/include/mupdf/fitz/pixmap.h @@ -15,6 +15,7 @@ */ typedef struct fz_pixmap_s fz_pixmap; + /* fz_pixmap_bbox: Return the bounding box for a pixmap. */ @@ -275,12 +276,19 @@ fz_pixmap *fz_ensure_pixmap_is_additive(fz_context *ctx, fz_pixmap *pix); pix: The pixmap to convert. - cs: Desired colorspace, may be NULL to denote alpha-only. + default_cs: If NULL pix->colorspace is used. It is possible that the data + may need to be interpreted as one of the color spaces in default_cs. + + cs_des: Desired colorspace, may be NULL to denote alpha-only. + + prf: Proofing color space through which we need to convert. + + color_params: Parameters that may be used in conversion (e.g. ri). keep_alpha: If 0 any alpha component is removed, otherwise alpha is kept if present in the pixmap. */ -fz_pixmap *fz_convert_pixmap(fz_context *ctx, fz_pixmap *pix, fz_colorspace *src, int keep_alpha); +fz_pixmap *fz_convert_pixmap(fz_context *ctx, fz_pixmap *pix, fz_colorspace *cs_des, fz_colorspace *prf, fz_default_colorspaces *default_cs, const fz_color_params *color_params, int keep_alpha); /* Pixmaps represent a set of pixels for a 2 dimensional region of a @@ -357,9 +365,10 @@ void fz_decode_indexed_tile(fz_context *ctx, fz_pixmap *pix, const float *decode void fz_unpack_tile(fz_context *ctx, fz_pixmap *dst, unsigned char * restrict src, int n, int depth, size_t stride, int scale); /* - fz_lookup_pixmap_converter: Color convert a pixmap. + fz_pixmap_converter: Color convert a pixmap. The passing of default_cs is needed due to the base cs of the image possibly + needing to be treated as being in one of the page default color spaces. */ -typedef void (fz_pixmap_converter)(fz_context *ctx, fz_pixmap *dp, fz_pixmap *sp); +typedef void (fz_pixmap_converter)(fz_context *ctx, fz_pixmap *dp, fz_pixmap *sp, fz_colorspace *prf, fz_default_colorspaces *default_cs, const fz_color_params *color_params); fz_pixmap_converter *fz_lookup_pixmap_converter(fz_context *ctx, fz_colorspace *ds, fz_colorspace *ss); /* diff --git a/include/mupdf/fitz/shade.h b/include/mupdf/fitz/shade.h index 51130dce..d732b9bc 100644 --- a/include/mupdf/fitz/shade.h +++ b/include/mupdf/fitz/shade.h @@ -121,10 +121,14 @@ fz_rect *fz_bound_shade(fz_context *ctx, fz_shade *shade, const fz_matrix *ctm, dest: The pixmap to render into. + prf: Proofing color space. + + color_params: The color rendering settings + bbox: Pointer to a bounding box to limit the rendering of the shade. */ -void fz_paint_shade(fz_context *ctx, fz_shade *shade, const fz_matrix *ctm, fz_pixmap *dest, const fz_irect *bbox); +void fz_paint_shade(fz_context *ctx, fz_shade *shade, const fz_matrix *ctm, fz_pixmap *dest, fz_colorspace *prf, const fz_color_params *color_params, const fz_irect *bbox); /* * Handy routine for processing mesh based shades diff --git a/include/mupdf/fitz/store.h b/include/mupdf/fitz/store.h index 6eab5064..d014378c 100644 --- a/include/mupdf/fitz/store.h +++ b/include/mupdf/fitz/store.h @@ -123,20 +123,30 @@ typedef struct fz_store_hash_s { const void *ptr; int i; - } pi; + } pi; /* 8 or 12 bytes */ struct { const void *ptr; int i; fz_irect r; - } pir; + } pir; /* 24 or 28 bytes */ struct { int id; float m[4]; - } im; + } im; /* 20 bytes */ + struct + { + unsigned char src_md5[16]; + unsigned char dst_md5[16]; + uint8_t ri; + uint8_t bp; + uint8_t depth; + uint8_t alpha; + uint8_t proof; + } link; /* 36 bytes */ } u; -} fz_store_hash; +} fz_store_hash; /* 40 or 44 bytes */ typedef struct fz_store_type_s { |