13#include <jasper/jasper.h>
18class QJp2HandlerPrivate
20 Q_DECLARE_PUBLIC(QJp2Handler)
21 Q_DISABLE_COPY(QJp2HandlerPrivate)
26 QJp2HandlerPrivate(QJp2Handler *q_ptr);
32
33
34
35
36
37
38
39
40
41
42
51 bool write(
const QImage &image,
int quality);
53 typedef void (Jpeg2000JasperReader::*ScanlineFunc)(jas_seqent_t**
const, uchar*);
54 typedef void (Jpeg2000JasperReader::*ScanlineFuncWrite)(jas_matrix_t**, uchar*);
56 void copyJasperQt(ScanlineFunc scanlinecopier);
57 void copyJasperQtGeneric();
58 void copyScanlineJasperQtRGB(jas_seqent_t **
const jasperRow, uchar *qtScanLine);
59 void copyScanlineJasperQtRGBA(jas_seqent_t **
const jasperRow, uchar *qtScanLine);
60 void copyScanlineJasperQtGray(jas_seqent_t **
const jasperRow, uchar *qtScanLine);
61 void copyScanlineJasperQtGrayA(jas_seqent_t **
const jasperRow, uchar *qtScanLine);
63 void copyQtJasper(
const ScanlineFuncWrite scanlinecopier);
64 void copyScanlineQtJasperRGB(jas_matrix_t ** jasperRow, uchar *qtScanLine);
65 void copyScanlineQtJasperRGBA(jas_matrix_t ** jasperRow, uchar *qtScanLine);
66 void copyScanlineQtJasperColormapRGB(jas_matrix_t ** jasperRow, uchar *qtScanLine);
67 void copyScanlineQtJasperColormapRGBA(jas_matrix_t ** jasperRow, uchar *qtScanLine);
68 void copyScanlineQtJasperColormapGrayscale(jas_matrix_t ** jasperRow, uchar *qtScanLine);
69 void copyScanlineQtJasperColormapGrayscaleA(jas_matrix_t ** jasperRow, uchar *qtScanLine);
71 bool attemptColorspaceChange(
int wantedColorSpace);
72 bool createJasperMatrix(jas_matrix_t **&matrix);
73 bool freeJasperMatrix(jas_matrix_t **matrix);
74 void printColorSpaceError();
75 jas_image_cmptparm_t createComponentMetadata(
const int width,
const int height);
76 jas_image_t *newRGBAImage(
const int width,
const int height,
bool alpha);
77 jas_image_t *newGrayscaleImage(
const int width,
const int height,
bool alpha);
78 bool decodeColorSpace(
int clrspc, QString &family, QString &specific);
79 void printMetadata(jas_image_t *image);
93 jas_image_t *jasper_image;
96 int jasComponentPrecicion[4];
97 int computedComponentWidth ;
98 int computedComponentHeight;
99 int computedComponentHorizontalSubsampling;
100 int computedComponentVerticalSubsampling;
101 int jasperColorspaceFamily;
104 int colorComponentMapping[4];
109 : writeQuality(100), subType(
"jp2"), q_ptr(q_ptr)
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
146
147
154
155
162
163
164
165
166
167
168
169
170
173 bool bCanRead =
false;
176 if (header.startsWith(QByteArrayLiteral(
"\000\000\000\fjP \r\n\207\n"))) {
180 *subType = QByteArray(
"jp2");
181 }
else if (header.startsWith(QByteArrayLiteral(
"\377\117\377\121\000"))) {
185 *subType = QByteArray(
"j2k");
192
204
212
215 Q_D(
const QJp2Handler);
217 if (d->subType == QByteArray(
"jp2"))
223 return writer.write(image, d->writeQuality);
227
228
229
232 Q_D(
const QJp2Handler);
233 if (option == Quality) {
234 return QVariant(d->writeQuality);
235 }
else if (option == SubType) {
236 return QVariant(d->subType);
242
243
244
245
246
247
248
249
250
251
252void QJp2Handler::setOption(ImageOption option,
const QVariant &value)
255 if (option == Quality) {
257 const int quality = value.toInt(&ok);
259 d->writeQuality = quality;
260 }
else if (option == SubType) {
261 const QByteArray subTypeCandidate = value.toByteArray();
263 if (subTypeCandidate == QByteArrayLiteral(
"jp2") ||
264 subTypeCandidate == QByteArrayLiteral(
"j2k"))
265 d->subType = subTypeCandidate;
270
271
272
275 return (option == Quality || option == SubType);
279
280
293
294
295
296
297
298
300 : jasperOk(
true), ioDevice(iod), format(format), hasAlpha(
false)
302#if JAS_VERSION_MAJOR
< 3
305 qDebug(
"Jasper Library initialization failed");
309#if QT_VERSION >= QT_VERSION_CHECK(6
, 0
, 0
)
310 if (QImageReader::allocationLimit() > 0)
311 jas_conf_set_max_mem_usage(qsizetype(QImageReader::allocationLimit()) * 1024 * 1024);
314 jas_conf_set_max_mem_usage(128 * 1024 * 1024);
316 if (jas_init_library()) {
318 qDebug(
"Jasper library initialization failed");
320 if (jas_init_thread()) {
321 jas_cleanup_library();
323 qDebug(
"Jasper thread initialization failed");
330#if JAS_VERSION_MAJOR
< 3
335 if (jas_cleanup_thread()) {
336 qDebug(
"Jasper thread cleanup failed");
338 if (jas_cleanup_library()) {
339 qDebug(
"Jasper library cleanup failed");
346
347
348
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370 QByteArray fileContents = ioDevice->readAll();
371 jas_stream_t *imageData = jas_stream_memopen(fileContents.data(),
372 fileContents.size());
373 jasper_image = jas_image_decode(imageData, jas_image_getfmt(imageData), 0);
374 jas_stream_close(imageData);
376 qDebug(
"Jasper library can't decode Jpeg2000 image data");
382 qtWidth = jas_image_width(jasper_image);
383 qtHeight = jas_image_height(jasper_image);
384 jasNumComponents = jas_image_numcmpts(jasper_image);
385 jasperColorspaceFamily = jas_clrspc_fam(jas_image_clrspc(jasper_image));
387 bool needColorspaceChange =
false;
388 if (jasperColorspaceFamily != JAS_CLRSPC_FAM_RGB &&
389 jasperColorspaceFamily != JAS_CLRSPC_FAM_GRAY)
390 needColorspaceChange =
true;
394 for (c = 0; c < jasNumComponents; ++c) {
395 jasComponentPrecicion[c] = jas_image_cmptprec(jasper_image, c);
398 if (jasComponentPrecicion[c] > 8 || jasComponentPrecicion[c] < 8)
399 needColorspaceChange =
true;
402 if (jas_image_cmpthstep(jasper_image, c) != 1 ||
403 jas_image_cmptvstep(jasper_image, c) != 1)
404 needColorspaceChange =
true;
407 if (jas_image_cmptsgnd(jasper_image, c) != 0)
408 needColorspaceChange =
true;
412
413
414
415
416
417
419 bool decodeOk =
true;
420 if (needColorspaceChange)
421 decodeOk = attemptColorspaceChange(JAS_CLRSPC_SRGB);
424 printColorSpaceError();
429 qtWidth = jas_image_width(jasper_image);
430 qtHeight = jas_image_height(jasper_image);
431 jasNumComponents = jas_image_numcmpts(jasper_image);
432 jasperColorspaceFamily = jas_clrspc_fam(jas_image_clrspc(jasper_image));
433 for (c = 0; c < jasNumComponents; ++c) {
434 jasComponentPrecicion[c] = jas_image_cmptprec(jasper_image, c);
437 if (jasperColorspaceFamily != JAS_CLRSPC_FAM_RGB &&
438 jasperColorspaceFamily != JAS_CLRSPC_FAM_GRAY) {
439 qDebug(
"The Qt JPEG 2000 reader was unable to convert colorspace to RGB or grayscale");
445 bool oddComponentSubsampling =
false;
446 for (c = 0; c < jasNumComponents; ++c) {
447 if (jas_image_cmpthstep(jasper_image, c) != 1 ||
448 jas_image_cmptvstep(jasper_image, c) != 1) {
449 oddComponentSubsampling =
true;
453 if (oddComponentSubsampling) {
456 computedComponentWidth = jas_image_cmptwidth(jasper_image, 0);
457 computedComponentHeight = jas_image_cmptheight(jasper_image, 0);
458 computedComponentHorizontalSubsampling = jas_image_cmpthstep(jasper_image, 0);
459 computedComponentVerticalSubsampling = jas_image_cmptvstep(jasper_image, 0);
461 for (c = 1; c < jasNumComponents; ++c) {
462 if (computedComponentWidth != jas_image_cmptwidth(jasper_image, c) ||
463 computedComponentWidth != jas_image_cmptwidth(jasper_image, c) ||
464 computedComponentHorizontalSubsampling != jas_image_cmpthstep(jasper_image, c) ||
465 computedComponentVerticalSubsampling != jas_image_cmptvstep(jasper_image, c)) {
466 qDebug(
"The Qt JPEG 2000 reader does not support images where "
467 "component geometry differs from image geometry");
471 qtWidth = computedComponentWidth * computedComponentHorizontalSubsampling;
472 qtHeight = computedComponentHeight * computedComponentVerticalSubsampling;
476 for (c = 0; c < jasNumComponents; ++c) {
478 if (jasComponentPrecicion[c]>8 || jasComponentPrecicion[c]<8) {
479 qDebug(
"The Qt JPEG 2000 reader does not support components with "
485 if (oddComponentSubsampling) {
486 qDebug(
"The Qt JPEG 2000 reader does not support components with "
487 "a subsampling factor != 1 (yet)");
492 if (jas_image_cmptsgnd(jasper_image, c) != 0) {
493 qDebug(
"Qt JPEG 2000 reader does not support signed components");
499 if (!oddComponentSubsampling)
500 if (jas_image_cmpttlx(jasper_image,c) != 0 ||
501 jas_image_cmpttly(jasper_image,c) != 0 ||
502 jas_image_cmptbrx(jasper_image,c) != jas_image_brx(jasper_image) ||
503 jas_image_cmptbry(jasper_image,c) != jas_image_bry(jasper_image) ||
504 jas_image_cmptwidth (jasper_image, c) != jas_image_width (jasper_image) ||
505 jas_image_cmptheight(jasper_image, c) != jas_image_height(jasper_image )) {
506 qDebug(
"The Qt JPEG 2000 reader does not support images where "
507 "component geometry differs from image geometry");
508 printMetadata(jasper_image);
521 jasperColorspaceFamily = jas_clrspc_fam(jas_image_clrspc(jasper_image));
522 if (jasperColorspaceFamily == JAS_CLRSPC_FAM_RGB) {
523 if (jasNumComponents > 4)
524 qDebug(
"JPEG 2000 reader expected 3 or 4 components, got %d",
528 colorComponentMapping[0] = jas_image_getcmptbytype(jasper_image,
530 colorComponentMapping[1] = jas_image_getcmptbytype(jasper_image,
532 colorComponentMapping[2] = jas_image_getcmptbytype(jasper_image,
535 }
else if (jasperColorspaceFamily == JAS_CLRSPC_FAM_GRAY) {
536 if (jasNumComponents > 2)
537 qDebug(
"JPEG 2000 reader expected 1 or 2 components, got %d",
539 colorComponentMapping[0] = jas_image_getcmptbytype(jasper_image,
540 JAS_IMAGE_CT_COLOR(JAS_IMAGE_CT_GRAY_Y));
543 printColorSpaceError();
550 const int posibleAlphaComponent1 = 3;
551 const int posibleAlphaComponent2 = 48;
553 if (jasNumComponents == qtNumComponents + 1) {
554 colorComponentMapping[qtNumComponents] = jas_image_getcmptbytype(jasper_image, posibleAlphaComponent1);
555 if (colorComponentMapping[qtNumComponents] < 0) {
556 colorComponentMapping[qtNumComponents] = jas_image_getcmptbytype(jasper_image, posibleAlphaComponent2);
558 if (colorComponentMapping[qtNumComponents] > 0) {
565 for (c = 0; c < qtNumComponents; ++c) {
566 if (colorComponentMapping[c] < 0) {
567 qDebug(
"JPEG 2000 reader missing a color component");
573 QImage::Format qtFormat = QImage::Format_Invalid;
574 if (jasperColorspaceFamily == JAS_CLRSPC_FAM_RGB)
575 qtFormat = hasAlpha ? QImage::Format_ARGB32 : QImage::Format_RGB32;
576 else if (jasperColorspaceFamily == JAS_CLRSPC_FAM_GRAY)
577 qtFormat = hasAlpha ? QImage::Format_ARGB32 : QImage::Format_Grayscale8;
578 if (!QImageIOHandler::allocateImage(QSize(qtWidth, qtHeight), qtFormat, &qtImage))
582 if (oddComponentSubsampling) {
585 copyJasperQtGeneric();
586 }
else if (jasperColorspaceFamily == JAS_CLRSPC_FAM_RGB) {
588 copyJasperQt(&Jpeg2000JasperReader::copyScanlineJasperQtRGBA);
590 copyJasperQt(&Jpeg2000JasperReader::copyScanlineJasperQtRGB);
591 }
else if (jasperColorspaceFamily == JAS_CLRSPC_FAM_GRAY) {
593 copyJasperQt(&Jpeg2000JasperReader::copyScanlineJasperQtGrayA);
595 copyJasperQt(&Jpeg2000JasperReader::copyScanlineJasperQtGray);
604
605
609 jas_matrix_t **jasperMatrix;
610 jas_seqent_t **jasperRow;
611 createJasperMatrix(jasperMatrix);
612 jasperRow = (jas_seqent_t**)malloc(jasNumComponents *
sizeof(jas_seqent_t *));
613 Q_CHECK_PTR(jasperRow);
616 for (
int componentY = 0; componentY < computedComponentHeight; ++componentY) {
617 for (
int c = 0; c < jasNumComponents; ++c) {
618 jas_image_readcmpt(jasper_image, colorComponentMapping[c], 0,
619 componentY, computedComponentWidth, 1,
621 jasperRow[c] = jas_matrix_getref(jasperMatrix[c], 0, 0);
623 for (
int verticalSubsample = 0;
624 verticalSubsample < computedComponentVerticalSubsampling;
625 ++verticalSubsample) {
626 uchar *scanLineUchar = qtImage.scanLine(imageY);
627 QRgb *scanLineQRgb =
reinterpret_cast<QRgb *>(scanLineUchar);
628 for (
int componentX = 0; componentX < computedComponentWidth;
630 for (
int horizontalSubsample = 0;
631 horizontalSubsample <
632 computedComponentHorizontalSubsampling;
633 ++horizontalSubsample) {
634 if (jasperColorspaceFamily == JAS_CLRSPC_FAM_RGB) {
636 *scanLineQRgb++ = (jasperRow[3][componentX] << 24) |
637 (jasperRow[0][componentX] << 16) |
638 (jasperRow[1][componentX] << 8) |
639 jasperRow[2][componentX];
641 *scanLineQRgb++ = (jasperRow[0][componentX] << 16) |
642 (jasperRow[1][componentX] << 8) |
643 jasperRow[2][componentX];
645 }
else if (jasperColorspaceFamily == JAS_CLRSPC_FAM_GRAY) {
647 *scanLineQRgb++ = (jasperRow[1][componentX] << 24) |
648 (jasperRow[0][componentX] << 16) |
649 (jasperRow[0][componentX] << 8) |
650 jasperRow[0][componentX];
652 *scanLineUchar++ = jasperRow[0][componentX];
663
664
665
666
670 jas_matrix_t **jasperMatrix;
671 jas_seqent_t **jasperRow;
673 createJasperMatrix(jasperMatrix);
674 jasperRow = (jas_seqent_t**)malloc(jasNumComponents *
sizeof(jas_seqent_t *));
675 Q_CHECK_PTR(jasperRow);
677 for (
int scanline = 0; scanline < qtHeight; ++scanline) {
678 for (
int c = 0; c < jasNumComponents; ++c) {
679 jas_image_readcmpt(jasper_image, colorComponentMapping[c], 0,
680 scanline, qtWidth, 1, jasperMatrix[c]);
681 jasperRow[c] = jas_matrix_getref(jasperMatrix[c], 0, 0);
683 (
this->*scanlineCopier)(jasperRow, qtImage.scanLine(scanline));
686 freeJasperMatrix(jasperMatrix);
691
692
693
695 jas_seqent_t **
const jasperRow, uchar *qtScanLine)
697 QRgb *scanLine =
reinterpret_cast<QRgb *>(qtScanLine);
698 for (
int c = 0; c < qtWidth; ++c) {
699 *scanLine++ = (0xFF << 24) |
700 (jasperRow[0][c] << 16) |
701 (jasperRow[1][c] << 8) |
707
708
709
710void Jpeg2000JasperReader::copyScanlineJasperQtRGBA(jas_seqent_t **
const jasperRow, uchar *qtScanLine)
712 QRgb *scanLine =
reinterpret_cast<QRgb *>(qtScanLine);
713 for (
int c = 0; c < qtWidth; ++c) {
714 *scanLine++ = (jasperRow[3][c] << 24) |
715 (jasperRow[0][c] << 16) |
716 (jasperRow[1][c] << 8) |
722
723
724
725void Jpeg2000JasperReader::copyScanlineJasperQtGray(jas_seqent_t **
const jasperRow, uchar *qtScanLine)
727 for (
int c = 0; c < qtWidth; ++c) {
729 *qtScanLine++ = jasperRow[0][c];
734
735
736
737
738
739
740void Jpeg2000JasperReader::copyScanlineJasperQtGrayA(jas_seqent_t **
const jasperRow, uchar *qtScanLine)
742 QRgb *scanLine =
reinterpret_cast<QRgb *>(qtScanLine);
743 for (
int c = 0; c < qtWidth; ++c) {
744 *scanLine++ = (jasperRow[1][c] << 24) |
745 (jasperRow[0][c] << 16) |
746 (jasperRow[0][c] << 8) |
752
753
754
755
756
757
765 qtHeight = qtImage.height();
766 qtWidth = qtImage.width();
767 qtDepth = qtImage.depth();
770 jasper_image = newRGBAImage(qtWidth, qtHeight, qtImage.hasAlphaChannel());
774 if (qtImage.hasAlphaChannel())
775 copyQtJasper(&Jpeg2000JasperReader::copyScanlineQtJasperRGBA);
777 copyQtJasper(&Jpeg2000JasperReader::copyScanlineQtJasperRGB);
778 }
else if (qtDepth == 8) {
780 if (qtImage.allGray()) {
781 jasper_image = newGrayscaleImage(qtWidth, qtHeight, qtImage.hasAlphaChannel());
785 if (qtImage.hasAlphaChannel())
786 copyQtJasper(&Jpeg2000JasperReader::copyScanlineQtJasperColormapGrayscaleA);
788 copyQtJasper(&Jpeg2000JasperReader::copyScanlineQtJasperColormapGrayscale);
791 jasper_image = newRGBAImage(qtWidth, qtHeight, qtImage.hasAlphaChannel());
795 if (qtImage.hasAlphaChannel())
796 copyQtJasper(&Jpeg2000JasperReader::copyScanlineQtJasperColormapRGBA);
798 copyQtJasper(&Jpeg2000JasperReader::copyScanlineQtJasperColormapRGB);
801 qDebug(
"Unable to handle color depth %d", qtDepth);
807 fmtid = jas_image_strtofmt(
const_cast<
char*>(
"jp2"));
810 fmtid = jas_image_strtofmt(
const_cast<
char*>(
"jpc"));
812 const int minQuality = 0;
813 const int maxQuality = 100;
817 if (quality <= minQuality)
818 quality = minQuality;
819 if (quality > maxQuality)
820 quality = maxQuality;
828 const double minRate = 0.001;
834 const double maxRate = 0.3;
838 const double jasperRate = minRate + pow((
double(quality) /
double(maxQuality)), 2) * maxRate;
843 QString jasperFormatString;
847 if (quality != maxQuality) {
848 jasperFormatString += QLatin1String(
"mode=real");
849 jasperFormatString += QString(QLatin1String(
" rate=%1")).arg(jasperRate);
853 jas_stream_t * memory_stream = jas_stream_memopen(0, 0);
856 char *str = qstrdup(jasperFormatString.toLatin1().constData());
857 jas_image_encode(jasper_image, memory_stream, fmtid, str);
859 jas_stream_flush(memory_stream);
865 char *buffer =
reinterpret_cast<
char *>(
reinterpret_cast<jas_stream_memobj_t*>(memory_stream->obj_)->buf_);
866 qint64 length = jas_stream_length(memory_stream);
867 ioDevice->write(buffer, length);
869 jas_stream_close(memory_stream);
870 jas_image_destroy(jasper_image);
876
877
878
879
883 jas_matrix_t **jasperMatrix;
884 createJasperMatrix(jasperMatrix);
886 for (
int scanline = 0; scanline < qtHeight; ++scanline) {
887 (
this->*scanlinecopier)(jasperMatrix, qtImage.scanLine(scanline));
890 for (
int c = 0; c < jasNumComponents; ++c)
891 jas_image_writecmpt(jasper_image, c, 0, scanline, qtWidth, 1,
894 freeJasperMatrix(jasperMatrix);
898
899
903 QRgb *scanLineBuffer =
reinterpret_cast<QRgb *>(qtScanLine);
904 for (
int col = 0; col < qtWidth; ++col) {
905 jas_matrix_set(jasperRow[0], 0, col, (*scanLineBuffer & 0xFF0000) >> 16);
906 jas_matrix_set(jasperRow[1], 0, col, (*scanLineBuffer & 0x00FF00) >> 8);
907 jas_matrix_set(jasperRow[2], 0, col, *scanLineBuffer & 0x0000FF);
913
914
918 QRgb *scanLineBuffer =
reinterpret_cast<QRgb *>(qtScanLine);
919 for (
int col = 0; col < qtWidth; ++col) {
920 jas_matrix_set(jasperRow[3], 0, col, (*scanLineBuffer & 0xFF000000) >> 24);
921 jas_matrix_set(jasperRow[0], 0, col, (*scanLineBuffer & 0x00FF0000) >> 16);
922 jas_matrix_set(jasperRow[1], 0, col, (*scanLineBuffer & 0x0000FF00) >> 8);
923 jas_matrix_set(jasperRow[2], 0, col, *scanLineBuffer & 0x000000FF);
929
930
934 for (
int col = 0; col < qtWidth; ++col) {
935 QRgb color = qtImage.color(*qtScanLine);
936 jas_matrix_set(jasperRow[0], 0, col, qRed(color));
937 jas_matrix_set(jasperRow[1], 0, col, qGreen(color));
938 jas_matrix_set(jasperRow[2], 0, col, qBlue(color));
944
945
949 for (
int col = 0; col < qtWidth; ++col) {
950 QRgb color = qtImage.color(*qtScanLine);
951 jas_matrix_set(jasperRow[0], 0, col, qRed(color));
952 jas_matrix_set(jasperRow[1], 0, col, qGreen(color));
953 jas_matrix_set(jasperRow[2], 0, col, qBlue(color));
954 jas_matrix_set(jasperRow[3], 0, col, qAlpha(color));
960
961
965 for (
int col = 0; col < qtWidth; ++col) {
966 QRgb color = qtImage.color(*qtScanLine);
967 jas_matrix_set(jasperRow[0], 0, col, qGray(color));
973
974
978 for (
int col = 0; col < qtWidth; ++col) {
979 QRgb color = qtImage.color(*qtScanLine);
980 jas_matrix_set(jasperRow[0], 0, col, qGray(color));
981 jas_matrix_set(jasperRow[1], 0, col, qAlpha(color));
987
988
989
990
994 jas_cmprof_t *outprof;
995 if (!(outprof = jas_cmprof_createfromclrspc(wantedColorSpace)))
998 jas_image_t *newimage;
999 if (!(newimage = jas_image_chclrspc(jasper_image, outprof,
1000 JAS_CMXFORM_INTENT_PER))) {
1001 jas_cmprof_destroy(outprof);
1004 jas_image_destroy(jasper_image);
1005 jas_cmprof_destroy(outprof);
1006 jasper_image = newimage;
1011
1012
1013
1015 const int width,
const int height)
1017 jas_image_cmptparm_t param;
1022 param.width = width;
1023 param.height = height;
1030
1031
1032
1034 const int height,
bool alpha)
1036 jasNumComponents = alpha ? 4 : 3;
1037 jas_image_cmptparm_t *params =
new jas_image_cmptparm_t[jasNumComponents];
1038 jas_image_cmptparm_t param = createComponentMetadata(width, height);
1039 for (
int c=0; c < jasNumComponents; c++)
1041 jas_image_t *newImage = jas_image_create(jasNumComponents, params,
1049 jas_image_setcmpttype(newImage, 0, JAS_IMAGE_CT_RGB_R);
1050 jas_image_setcmpttype(newImage, 1, JAS_IMAGE_CT_RGB_G);
1051 jas_image_setcmpttype(newImage, 2, JAS_IMAGE_CT_RGB_B);
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1066 jas_image_setcmpttype(newImage, 3, JAS_IMAGE_CT_OPACITY);
1072
1073
1074
1079 jasNumComponents = alpha ? 2 : 1;
1080 jas_image_cmptparm_t param = createComponentMetadata(width, height);
1081 jas_image_t *newImage = jas_image_create(1, ¶m, JAS_CLRSPC_SGRAY);
1085 jas_image_setcmpttype(newImage, 0, JAS_IMAGE_CT_GRAY_Y);
1089 jas_image_setcmpttype(newImage, 1, JAS_IMAGE_CT_OPACITY);
1094
1095
1096
1097
1100 matrix = (jas_matrix_t**)malloc(jasNumComponents *
sizeof(jas_matrix_t *));
1101 for (
int c = 0; c < jasNumComponents; ++c)
1102 matrix[c] = jas_matrix_create(1, qtWidth);
1107
1108
1109
1110
1113 for (
int c = 0; c < jasNumComponents; ++c)
1114 jas_matrix_destroy(matrix[c]);
1120
1121
1124 QString colorspaceFamily, colorspaceSpecific;
1125 decodeColorSpace(jas_image_clrspc(jasper_image), colorspaceFamily,
1126 colorspaceSpecific);
1127 qDebug(
"Jpeg2000 decoder is not able to handle color space %s - %s",
1128 qPrintable(colorspaceFamily), qPrintable(colorspaceSpecific));
1131
1132
1136 int fam = jas_clrspc_fam(clrspc);
1137 int mbr = jas_clrspc_mbr(clrspc);
1140 case 0: family = QLatin1String(
"JAS_CLRSPC_FAM_UNKNOWN");
break;
1141 case 1: family = QLatin1String(
"JAS_CLRSPC_FAM_XYZ");
break;
1142 case 2: family = QLatin1String(
"JAS_CLRSPC_FAM_LAB");
break;
1143 case 3: family = QLatin1String(
"JAS_CLRSPC_FAM_GRAY");
break;
1144 case 4: family = QLatin1String(
"JAS_CLRSPC_FAM_RGB");
break;
1145 case 5: family = QLatin1String(
"JAS_CLRSPC_FAM_YCBCR");
break;
1146 default: family = QLatin1String(
"Unknown");
return false;
1152 case 1: specific = QLatin1String(
"JAS_CLRSPC_CIEXYZ");
break;
1153 case 2: specific = QLatin1String(
"JAS_CLRSPC_CIELAB");
break;
1154 case 3: specific = QLatin1String(
"JAS_CLRSPC_SGRAY");
break;
1155 case 4: specific = QLatin1String(
"JAS_CLRSPC_SRGB");
break;
1156 case 5: specific = QLatin1String(
"JAS_CLRSPC_SYCBCR");
break;
1157 default: specific = QLatin1String(
"Unknown");
return false;
1162 case 3: specific = QLatin1String(
"JAS_CLRSPC_GENGRAY");
break;
1163 case 4: specific = QLatin1String(
"JAS_CLRSPC_GENRGB");
break;
1164 case 5: specific = QLatin1String(
"JAS_CLRSPC_GENYCBCR");
break;
1165 default: specific = QLatin1String(
"Unknown");
return false;
1174
1175
1180 qDebug(
"Image width: %ld",
long(jas_image_width(image)));
1181 qDebug(
"Image height: %ld",
long(jas_image_height(image)));
1182 qDebug(
"Coordinates on reference grid: (%ld,%ld) (%ld,%ld)",
1183 long(jas_image_tlx(image)),
long(jas_image_tly(image)),
1184 long(jas_image_brx(image)),
long(jas_image_bry(image)));
1185 qDebug(
"Number of image components: %d", jas_image_numcmpts(image));
1187 QString colorspaceFamily;
1188 QString colorspaceSpecific;
1189 decodeColorSpace(jas_image_clrspc(image), colorspaceFamily, colorspaceSpecific);
1190 qDebug(
"Color model (space): %d, %s - %s", jas_image_clrspc(image),
1191 qPrintable(colorspaceFamily), qPrintable(colorspaceSpecific));
1193 qDebug(
"Component metadata:");
1195 for (
int c = 0; c <
static_cast<
int>(jas_image_numcmpts(image)); ++c) {
1196 qDebug(
"Component %d:", c);
1197 qDebug(
" Component type: %ld",
long(jas_image_cmpttype(image, c)));
1198 qDebug(
" Width: %ld",
long(jas_image_cmptwidth(image, c)));
1199 qDebug(
" Height: %ld",
long(jas_image_cmptheight(image, c)));
1200 qDebug(
" Signedness: %d", jas_image_cmptsgnd(image, c));
1201 qDebug(
" Precision: %d", jas_image_cmptprec(image, c));
1202 qDebug(
" Horizontal subsampling factor: %ld",
long(jas_image_cmpthstep(image, c)));
1203 qDebug(
" Vertical subsampling factor: %ld",
long(jas_image_cmptvstep(image, c)));
1204 qDebug(
" Coordinates on reference grid: (%ld,%ld) (%ld,%ld)",
1205 long(jas_image_cmpttlx(image, c)),
long(jas_image_cmpttly(image, c)),
1206 long(jas_image_cmptbrx(image, c)),
long(jas_image_cmptbry(image, c)));
bool read(QImage *pImage)
Jpeg2000JasperReader(QIODevice *iod, const SubFormat format=Jp2Format)
bool write(const QImage &image, int quality)
Opens the file data and attempts to decode it using the Jasper library.
QIODevice * device() const
Returns the device currently assigned to QImageReader, or \nullptr if no device has been assigned.
The QJp2Handler class provides support for reading and writing JPEG 2000 image files with the Qt plug...
~QJp2Handler()
Destructor for QJp2Handler.
QJp2Handler()
Constructs an instance of QJp2Handler.
static bool canRead(QIODevice *iod, QByteArray *subType)
Verifies if some values (magic bytes) are set as expected in the header of the file.
bool write(const QImage &image) override
\reimp
bool read(QImage *image) override
\reimp
bool canRead() const override
\reimp
Automatic resource handling for a jas_image_t*.
ScopedJasperImage(jas_image_t *&image)