732 #ifdef QT_NO_IMAGE_TEXT 736 QPoint offset = image.offset();
737 int off_x = off_x_in + offset.
x();
738 int off_y = off_y_in + offset.
y();
743 png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,0,0,0);
750 info_ptr = png_create_info_struct(png_ptr);
752 png_destroy_write_struct(&png_ptr, 0);
756 if (setjmp(png_jmpbuf(png_ptr))) {
757 png_destroy_write_struct(&png_ptr, &info_ptr);
761 int quality = quality_in;
764 qWarning(
"PNG: Quality %d out of range", quality);
767 png_set_compression_level(png_ptr, quality);
774 if (image.colorCount())
775 color_type = PNG_COLOR_TYPE_PALETTE;
776 else if (image.hasAlphaChannel())
777 color_type = PNG_COLOR_TYPE_RGB_ALPHA;
779 color_type = PNG_COLOR_TYPE_RGB;
781 png_set_IHDR(png_ptr, info_ptr, image.width(), image.height(),
782 image.depth() == 1 ? 1 : 8,
783 color_type, 0, 0, 0);
786 png_set_gAMA(png_ptr, info_ptr, 1.0/
gamma);
793 sig_bit.alpha = image.hasAlphaChannel() ? 8 : 0;
794 png_set_sBIT(png_ptr, info_ptr, &sig_bit);
797 png_set_packswap(png_ptr);
799 if (image.colorCount()) {
801 int num_palette =
qMin(256, image.colorCount());
802 png_color palette[256];
805 for (
int i=0; i<num_palette; i++) {
806 QRgb rgba=image.color(i);
807 palette[i].red =
qRed(rgba);
808 palette[i].green =
qGreen(rgba);
809 palette[i].blue =
qBlue(rgba);
811 if (trans[i] < 255) {
815 png_set_PLTE(png_ptr, info_ptr, palette, num_palette);
818 png_set_tRNS(png_ptr, info_ptr, trans, num_trans, 0);
824 if (QSysInfo::ByteOrder == QSysInfo::BigEndian) {
825 png_set_swap_alpha(png_ptr);
829 if (QSysInfo::ByteOrder == QSysInfo::LittleEndian
831 png_set_bgr(png_ptr);
834 if (off_x || off_y) {
835 png_set_oFFs(png_ptr, info_ptr, off_x, off_y, PNG_OFFSET_PIXEL);
839 png_set_sig_bytes(png_ptr, 8);
841 if (image.dotsPerMeterX() > 0 || image.dotsPerMeterY() > 0) {
842 png_set_pHYs(png_ptr, info_ptr,
843 image.dotsPerMeterX(), image.dotsPerMeterY(),
844 PNG_RESOLUTION_METER);
847 #ifndef QT_NO_IMAGE_TEXT 848 set_text(image, png_ptr, info_ptr, description);
850 png_write_info(png_ptr, info_ptr);
852 if (image.depth() != 1)
853 png_set_packing(png_ptr);
856 png_set_filler(png_ptr, 0,
857 QSysInfo::ByteOrder == QSysInfo::BigEndian ?
858 PNG_FILLER_BEFORE : PNG_FILLER_AFTER);
865 png_write_chunk(png_ptr, (png_byte*)
"gIFx", data, 13);
873 png_write_chunk(png_ptr, (png_byte*)
"gIFg", data, 4);
876 int height = image.height();
877 int width = image.width();
878 switch (image.format()) {
886 png_bytep* row_pointers =
new png_bytep[height];
887 for (
int y=0; y<height; y++)
888 row_pointers[y] = (png_bytep)image.constScanLine(y);
889 png_write_image(png_ptr, row_pointers);
890 delete [] row_pointers;
897 png_bytep row_pointers[1];
898 for (
int y=0; y<height; y++) {
901 png_write_rows(png_ptr, row_pointers, 1);
907 png_write_end(png_ptr, info_ptr);
910 png_destroy_write_struct(&png_ptr, &info_ptr);
Format
The following image formats are available in Qt.
QImage copy(const QRect &rect=QRect()) const
Returns a sub-area of the image as a new image.
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Q_GUI_EXPORT_INLINE int qAlpha(QRgb rgb)
static void CALLBACK_CALL_TYPE qpiw_flush_fn(png_structp)
Q_GUI_EXPORT_INLINE int qRed(QRgb rgb)
static void CALLBACK_CALL_TYPE qpiw_write_fn(png_structp png_ptr, png_bytep data, png_size_t length)
Q_CORE_EXPORT void qWarning(const char *,...)
The QImage class provides a hardware-independent image representation that allows direct access to th...
static const char * data(const QByteArray &arr)
Q_GUI_EXPORT_INLINE int qBlue(QRgb rgb)
const uchar * constScanLine(int) const
Returns a pointer to the pixel data at the scanline with index i.
QImage convertToFormat(Format f, Qt::ImageConversionFlags flags=Qt::AutoColor) const Q_REQUIRED_RESULT
Returns a copy of the image in the given format.
The QPoint class defines a point in the plane using integer precision.
int y() const
Returns the y coordinate of this point.
Q_GUI_EXPORT_INLINE int qGreen(QRgb rgb)
int x() const
Returns the x coordinate of this point.
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
static void CALLBACK_CALL_TYPE qt_png_warning(png_structp, png_const_charp message)
static void set_text(const QImage &image, png_structp png_ptr, png_infop info_ptr, const QString &description)