Skip to content

Commit

Permalink
Add J2K compression.
Browse files Browse the repository at this point in the history
  • Loading branch information
robinwatts committed Oct 13, 2023
1 parent 070e8ba commit 97e9e52
Show file tree
Hide file tree
Showing 7 changed files with 406 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/mupdf/fitz/compress.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include "mupdf/fitz/system.h"
#include "mupdf/fitz/buffer.h"
#include "mupdf/fitz/pixmap.h"

typedef enum
{
Expand Down
7 changes: 7 additions & 0 deletions include/mupdf/fitz/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,13 @@ void fz_set_pixmap_image_tile(fz_context *ctx, fz_pixmap_image *cimg, fz_pixmap
*/
fz_pixmap *fz_load_jpx(fz_context *ctx, const unsigned char *data, size_t size, fz_colorspace *cs);

/**
Exposed because compression and decompression need to share this.
*/
void opj_lock(fz_context *ctx);
void opj_unlock(fz_context *ctx);


/**
Exposed for CBZ.
*/
Expand Down
18 changes: 18 additions & 0 deletions include/mupdf/fitz/write-pixmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,22 @@ void fz_save_pixmap_as_jpeg(fz_context *ctx, fz_pixmap *pixmap, const char *file
*/
void fz_write_pixmap_as_png(fz_context *ctx, fz_output *out, const fz_pixmap *pixmap);

/**
Pixmap data as JP2K with no subsampling.
quality = 100 = lossless
otherwise for a factor of x compression use 100-x. (so 80 is 1:20 compression)
*/
void fz_write_pixmap_as_jpx(fz_context *ctx, fz_output *out, fz_pixmap *pix, int quality);

/**
Save pixmap data as JP2K with no subsampling.
quality = 100 = lossless
otherwise for a factor of x compression use 100-x. (so 80 is 1:20 compression)
*/
void fz_save_pixmap_as_jpx(fz_context *ctx, fz_pixmap *pixmap, const char *filename, int q);

/**
Create a new png band writer (greyscale or RGB, with or without
alpha).
Expand All @@ -251,6 +267,7 @@ fz_buffer *fz_new_buffer_from_image_as_pnm(fz_context *ctx, fz_image *image, fz_
fz_buffer *fz_new_buffer_from_image_as_pam(fz_context *ctx, fz_image *image, fz_color_params color_params);
fz_buffer *fz_new_buffer_from_image_as_psd(fz_context *ctx, fz_image *image, fz_color_params color_params);
fz_buffer *fz_new_buffer_from_image_as_jpeg(fz_context *ctx, fz_image *image, fz_color_params color_params, int quality, int invert_cmyk);
fz_buffer *fz_new_buffer_from_image_as_jpx(fz_context *ctx, fz_image *image, fz_color_params color_params, int quality);

/**
Reencode a given pixmap as a PNG into a buffer.
Expand All @@ -262,6 +279,7 @@ fz_buffer *fz_new_buffer_from_pixmap_as_pnm(fz_context *ctx, fz_pixmap *pixmap,
fz_buffer *fz_new_buffer_from_pixmap_as_pam(fz_context *ctx, fz_pixmap *pixmap, fz_color_params color_params);
fz_buffer *fz_new_buffer_from_pixmap_as_psd(fz_context *ctx, fz_pixmap *pix, fz_color_params color_params);
fz_buffer *fz_new_buffer_from_pixmap_as_jpeg(fz_context *ctx, fz_pixmap *pixmap, fz_color_params color_params, int quality, int invert_cmyk);
fz_buffer *fz_new_buffer_from_pixmap_as_jpx(fz_context *ctx, fz_pixmap *pix, fz_color_params color_params, int quality);

/**
Save a pixmap as a pnm (greyscale or rgb, no alpha).
Expand Down
1 change: 1 addition & 0 deletions platform/win32/libmupdf.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,7 @@
<ClCompile Include="..\..\source\fitz\draw-unpack.c" />
<ClCompile Include="..\..\source\fitz\encode-basic.c" />
<ClCompile Include="..\..\source\fitz\encode-fax.c" />
<ClCompile Include="..\..\source\fitz\encode-jpx.c" />
<ClCompile Include="..\..\source\fitz\encodings.c" />
<ClCompile Include="..\..\source\fitz\error.c" />
<ClCompile Include="..\..\source\fitz\filter-basic.c" />
Expand Down
3 changes: 3 additions & 0 deletions platform/win32/libmupdf.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,9 @@
<ClCompile Include="..\..\source\pdf\pdf-image-rewriter.c">
<Filter>pdf</Filter>
</ClCompile>
<ClCompile Include="..\..\source\fitz\encode-jpx.c">
<Filter>fitz</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\source\fitz\draw-imp.h">
Expand Down
Loading

0 comments on commit 97e9e52

Please sign in to comment.