Skip to content

Commit

Permalink
JPEG2000Translator: use outsourced Jasper package
Browse files Browse the repository at this point in the history
* fixes for API changes with newer version of Jasper.
  • Loading branch information
korli committed Aug 26, 2014
1 parent e14f00e commit fdfe641
Show file tree
Hide file tree
Showing 76 changed files with 55 additions and 32,022 deletions.
4 changes: 2 additions & 2 deletions Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ AddHaikuImagePackages [ FFilterByBuildFeatures
curl freetype icu libsolv zlib

regular_image @{
bzip2 ctags ffmpeg findutils gawk glu grep gutenprint jpeg less
bzip2 ctags ffmpeg findutils gawk glu grep gutenprint jasper jpeg less
libpng libwebp mesa mesa_devel mesa_swrast sed sharutils tar tiff wget
which
}@
Expand All @@ -45,7 +45,7 @@ if $(HAIKU_PACKAGING_ARCHS[2]) {
curl freetype icu libsolv zlib

regular_image @{
ffmpeg glu jpeg libpng libwebp mesa
ffmpeg glu jasper jpeg libpng libwebp mesa
}@
] ;
if $(TARGET_PACKAGING_ARCH) != x86_gcc2 {
Expand Down
88 changes: 45 additions & 43 deletions src/add-ons/translators/jpeg2000/JPEG2000Translator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


#include "JPEG2000Translator.h"
#include "jp2_cod.h"
#include "jpc_cs.h"
#include "TranslatorWindow.h"

#include <syslog.h>
Expand Down Expand Up @@ -97,17 +95,21 @@ const uint32 kNumOutputFormats = sizeof(sOutputFormats) / sizeof(translation_for
const uint32 kNumDefaultSettings = sizeof(sDefaultSettings) / sizeof(TranSetting);


#define JP2_BOX_JP 0x6a502020
#define JPC_MS_SOC 0xff4f


namespace conversion{
//! Make RGB32 scanline from *pixels[3]
inline void
read_rgb24_to_rgb32(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width)
read_rgb24_to_rgb32(jas_matrix_t** pixels, uchar* scanline, int width)
{
int32 index = 0;
int32 x = 0;
while (x < width) {
scanline[index++] = (jpr_uchar_t)jas_matrix_getv(pixels[2], x);
scanline[index++] = (jpr_uchar_t)jas_matrix_getv(pixels[1], x);
scanline[index++] = (jpr_uchar_t)jas_matrix_getv(pixels[0], x);
scanline[index++] = (uchar)jas_matrix_getv(pixels[2], x);
scanline[index++] = (uchar)jas_matrix_getv(pixels[1], x);
scanline[index++] = (uchar)jas_matrix_getv(pixels[0], x);
scanline[index++] = 255;
x++;
}
Expand All @@ -116,13 +118,13 @@ read_rgb24_to_rgb32(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width)

//! Make gray scanline from *pixels[1]
inline void
read_gray_to_rgb32(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width)
read_gray_to_rgb32(jas_matrix_t** pixels, uchar* scanline, int width)
{
int32 index = 0;
int32 x = 0;
jpr_uchar_t color = 0;
uchar color = 0;
while (x < width) {
color = (jpr_uchar_t)jas_matrix_getv(pixels[0], x++);
color = (uchar)jas_matrix_getv(pixels[0], x++);
scanline[index++] = color;
scanline[index++] = color;
scanline[index++] = color;
Expand All @@ -136,15 +138,15 @@ read_gray_to_rgb32(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width)
(just read data to scanline)
*/
inline void
read_rgba32(jas_matrix_t** pixels, jpr_uchar_t *scanline, int width)
read_rgba32(jas_matrix_t** pixels, uchar *scanline, int width)
{
int32 index = 0;
int32 x = 0;
while (x < width) {
scanline[index++] = (jpr_uchar_t)jas_matrix_getv(pixels[2], x);
scanline[index++] = (jpr_uchar_t)jas_matrix_getv(pixels[1], x);
scanline[index++] = (jpr_uchar_t)jas_matrix_getv(pixels[0], x);
scanline[index++] = (jpr_uchar_t)jas_matrix_getv(pixels[3], x);
scanline[index++] = (uchar)jas_matrix_getv(pixels[2], x);
scanline[index++] = (uchar)jas_matrix_getv(pixels[1], x);
scanline[index++] = (uchar)jas_matrix_getv(pixels[0], x);
scanline[index++] = (uchar)jas_matrix_getv(pixels[3], x);
x++;
}
}
Expand All @@ -155,19 +157,19 @@ read_rgba32(jas_matrix_t** pixels, jpr_uchar_t *scanline, int width)
(just read data to scanline)
*/
inline void
read_gray(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width)
read_gray(jas_matrix_t** pixels, uchar* scanline, int width)
{
int32 x = 0;
while (x < width) {
scanline[x] = (jpr_uchar_t)jas_matrix_getv(pixels[0], x);
scanline[x] = (uchar)jas_matrix_getv(pixels[0], x);
x++;
}
}


//! Make *pixels[1] from gray1 scanline
inline void
write_gray1_to_gray(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width)
write_gray1_to_gray(jas_matrix_t** pixels, uchar* scanline, int width)
{
int32 x = 0;
int32 index = 0;
Expand All @@ -185,7 +187,7 @@ write_gray1_to_gray(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width)

//! Make *pixels[3] from gray1 scanline
inline void
write_gray1_to_rgb24(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width)
write_gray1_to_rgb24(jas_matrix_t** pixels, uchar* scanline, int width)
{
int32 x = 0;
int32 index = 0;
Expand All @@ -209,7 +211,7 @@ write_gray1_to_rgb24(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width)

//! Make *pixels[3] from cmap8 scanline
inline void
write_cmap8_to_rgb24(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width)
write_cmap8_to_rgb24(jas_matrix_t** pixels, uchar* scanline, int width)
{
const color_map* map = system_colors();
int32 x = 0;
Expand All @@ -229,7 +231,7 @@ write_cmap8_to_rgb24(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width)
(just write data to pixels)
*/
inline void
write_gray(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width)
write_gray(jas_matrix_t** pixels, uchar* scanline, int width)
{
int32 x = 0;
while (x < width) {
Expand All @@ -244,7 +246,7 @@ write_gray(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width)
(just write data to pixels)
*/
inline void
write_rgb15_to_rgb24(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width)
write_rgb15_to_rgb24(jas_matrix_t** pixels, uchar* scanline, int width)
{
int32 x = 0;
int32 index = 0;
Expand All @@ -269,7 +271,7 @@ write_rgb15_to_rgb24(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width)
(just write data to pixels)
*/
inline void
write_rgb15b_to_rgb24(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width)
write_rgb15b_to_rgb24(jas_matrix_t** pixels, uchar* scanline, int width)
{
int32 x = 0;
int32 index = 0;
Expand All @@ -294,7 +296,7 @@ write_rgb15b_to_rgb24(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width)
(just write data to pixels)
*/
inline void
write_rgb16_to_rgb24(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width)
write_rgb16_to_rgb24(jas_matrix_t** pixels, uchar* scanline, int width)
{
int32 x = 0;
int32 index = 0;
Expand All @@ -319,7 +321,7 @@ write_rgb16_to_rgb24(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width)
(just write data to pixels)
*/
inline void
write_rgb16b_to_rgb24(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width)
write_rgb16b_to_rgb24(jas_matrix_t** pixels, uchar* scanline, int width)
{
int32 x = 0;
int32 index = 0;
Expand All @@ -344,7 +346,7 @@ write_rgb16b_to_rgb24(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width)
(just write data to pixels)
*/
inline void
write_rgb24(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width)
write_rgb24(jas_matrix_t** pixels, uchar* scanline, int width)
{
int32 index = 0;
int32 x = 0;
Expand All @@ -362,7 +364,7 @@ write_rgb24(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width)
(just write data to pixels)
*/
inline void
write_rgb24b(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width)
write_rgb24b(jas_matrix_t** pixels, uchar* scanline, int width)
{
int32 index = 0;
int32 x = 0;
Expand All @@ -380,7 +382,7 @@ write_rgb24b(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width)
(just write data to pixels)
*/
inline void
write_rgb32_to_rgb24(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width)
write_rgb32_to_rgb24(jas_matrix_t** pixels, uchar* scanline, int width)
{
int32 index = 0;
int32 x = 0;
Expand All @@ -399,7 +401,7 @@ write_rgb32_to_rgb24(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width)
(just write data to pixels)
*/
inline void
write_rgb32b_to_rgb24(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width)
write_rgb32b_to_rgb24(jas_matrix_t** pixels, uchar* scanline, int width)
{
int32 index = 0;
int32 x = 0;
Expand All @@ -419,7 +421,7 @@ write_rgb32b_to_rgb24(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width)
!!! UNTESTED !!!
*/
inline void
write_rgba32(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width)
write_rgba32(jas_matrix_t** pixels, uchar* scanline, int width)
{
int32 index = 0;
int32 x = 0;
Expand All @@ -439,7 +441,7 @@ write_rgba32(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width)
!!! UNTESTED !!!
*/
inline void
write_rgba32b(jas_matrix_t** pixels, jpr_uchar_t* scanline, int width)
write_rgba32b(jas_matrix_t** pixels, uchar* scanline, int width)
{
int32 index = 0;
int32 x = 0;
Expand Down Expand Up @@ -905,11 +907,11 @@ JP2Translator::Compress(BPositionIO* in, BPositionIO* out)

// Function pointer to write function
// It MUST point to proper function
void (*converter)(jas_matrix_t** pixels, jpr_uchar_t* inscanline,
void (*converter)(jas_matrix_t** pixels, uchar* inscanline,
int width) = write_rgba32;

// Default color info
int out_color_space = JAS_IMAGE_CS_RGB;
int out_color_space = JAS_CLRSPC_SRGB;
int out_color_components = 3;

switch ((color_space)B_BENDIAN_TO_HOST_INT32(header.colors)) {
Expand All @@ -918,7 +920,7 @@ JP2Translator::Compress(BPositionIO* in, BPositionIO* out)
converter = write_gray1_to_rgb24;
} else {
out_color_components = 1;
out_color_space = JAS_IMAGE_CS_GRAY;
out_color_space = JAS_CLRSPC_SGRAY;
converter = write_gray1_to_gray;
}
break;
Expand All @@ -929,7 +931,7 @@ JP2Translator::Compress(BPositionIO* in, BPositionIO* out)

case B_GRAY8:
out_color_components = 1;
out_color_space = JAS_IMAGE_CS_GRAY;
out_color_space = JAS_CLRSPC_SGRAY;
converter = write_gray;
break;

Expand Down Expand Up @@ -1024,7 +1026,7 @@ JP2Translator::Compress(BPositionIO* in, BPositionIO* out)
if (image == (jas_image_t *)NULL)
return Error(outs, NULL, NULL, 0, NULL, B_ERROR);

jpr_uchar_t *in_scanline = (jpr_uchar_t*) malloc(in_row_bytes);
uchar *in_scanline = (uchar*) malloc(in_row_bytes);
if (in_scanline == NULL)
return Error(outs, image, NULL, 0, NULL, B_ERROR);

Expand Down Expand Up @@ -1102,11 +1104,11 @@ JP2Translator::Decompress(BPositionIO* in, BPositionIO* out)

// Function pointer to read function
// It MUST point to proper function
void (*converter)(jas_matrix_t** pixels, jpr_uchar_t* outscanline,
void (*converter)(jas_matrix_t** pixels, uchar* outscanline,
int width) = NULL;

switch (jas_image_colorspace(image)) {
case JAS_IMAGE_CS_RGB:
switch (jas_clrspc_fam(jas_image_clrspc(image))) {
case JAS_CLRSPC_FAM_RGB:
out_color_components = 4;
if (in_color_components == 3) {
out_color_space = B_RGB32;
Expand All @@ -1120,7 +1122,7 @@ JP2Translator::Decompress(BPositionIO* in, BPositionIO* out)
return Error(ins, image, NULL, 0, NULL, B_ERROR);
}
break;
case JAS_IMAGE_CS_GRAY:
case JAS_CLRSPC_FAM_GRAY:
if (fSettings->SetGetBool(JP2_SET_GRAY8_AS_B_RGB32)) {
out_color_space = B_RGB32;
out_color_components = 4;
Expand All @@ -1131,11 +1133,11 @@ JP2Translator::Decompress(BPositionIO* in, BPositionIO* out)
converter = read_gray;
}
break;
case JAS_IMAGE_CS_YCBCR:
case JAS_CLRSPC_FAM_YCBCR:
syslog(LOG_ERR, "Color space YCBCR not implemented yet.\n");
return Error(ins, image, NULL, 0, NULL, B_ERROR);
break;
case JAS_IMAGE_CS_UNKNOWN:
case JAS_CLRSPC_UNKNOWN:
default:
syslog(LOG_ERR, "Color space unknown. \n");
return Error(ins, image, NULL, 0, NULL, B_ERROR);
Expand Down Expand Up @@ -1171,7 +1173,7 @@ JP2Translator::Decompress(BPositionIO* in, BPositionIO* out)
if (err < (int)sizeof(TranslatorBitmap))
return Error(ins, image, NULL, 0, NULL, B_ERROR);

jpr_uchar_t *out_scanline = (jpr_uchar_t*) malloc(out_row_bytes);
uchar *out_scanline = (uchar*) malloc(out_row_bytes);
if (out_scanline == NULL)
return Error(ins, image, NULL, 0, NULL, B_ERROR);

Expand Down Expand Up @@ -1266,7 +1268,7 @@ JP2Translator::PopulateInfoFromFormat(translator_info* info,
*/
status_t
Error(jas_stream_t* stream, jas_image_t* image, jas_matrix_t** pixels,
int32 pixels_count, jpr_uchar_t* scanline, status_t error)
int32 pixels_count, uchar* scanline, status_t error)
{
if (pixels) {
int32 i;
Expand Down
5 changes: 3 additions & 2 deletions src/add-ons/translators/jpeg2000/JPEG2000Translator.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <string.h>

#include "BaseTranslator.h"
#include "libjasper/jasper.h"
#include "jasper/jasper.h"


#undef B_TRANSLATION_CONTEXT
Expand Down Expand Up @@ -155,7 +155,8 @@ class JP2Translator : public BaseTranslator {
int32 formatCount);
};


status_t Error(jas_stream_t* stream, jas_image_t* image, jas_matrix_t** pixels,
int32 pixels_count, jpr_uchar_t* scanline, status_t error = B_ERROR);
int32 pixels_count, uchar* scanline, status_t error = B_ERROR);

#endif // _JP2TRANSLATOR_H_
Loading

0 comments on commit fdfe641

Please sign in to comment.