QMargins DpiScaler::scaled( int left, int top, int right, int bottom ) const { return QMargins( scaledX( left ), scaledY( top ), scaledX( right ), scaledY( bottom ) ); }
QMargins DpiScaler::scaled( const QPaintDevice* pd, int left, int top, int right, int bottom ) { return QMargins( scaledX( pd, left ), scaledY( pd, top ), scaledX( pd, right ), scaledY( pd, bottom ) ); }
bool JPEGImageDecoder::outputScanlines(ImageFrame& buffer) { JSAMPARRAY samples = m_reader->samples(); jpeg_decompress_struct* info = m_reader->info(); int width = isScaled ? m_scaledColumns.size() : info->output_width; while (info->output_scanline < info->output_height) { // jpeg_read_scanlines will increase the scanline counter, so we // save the scanline before calling it. int sourceY = info->output_scanline; /* Request one scanline. Returns 0 or 1 scanlines. */ if (jpeg_read_scanlines(info, samples, 1) != 1) return false; int destY = scaledY(sourceY); if (destY < 0) continue; #if USE(QCMSLIB) if (m_reader->colorTransform() && colorSpace == JCS_RGB) qcms_transform_data(m_reader->colorTransform(), *samples, *samples, info->output_width); #endif ImageFrame::PixelData* currentAddress = buffer.getAddr(0, destY); for (int x = 0; x < width; ++x) { setPixel<colorSpace>(buffer, currentAddress, samples, isScaled ? m_scaledColumns[x] : x); ++currentAddress; } } return true; }
bool JPEGImageDecoder::outputScanlines() { if (m_frameBufferCache.isEmpty()) return false; // Initialize the framebuffer if needed. RGBA32Buffer& buffer = m_frameBufferCache[0]; if (buffer.status() == RGBA32Buffer::FrameEmpty) { if (!buffer.setSize(scaledSize().width(), scaledSize().height())) return setFailed(); buffer.setStatus(RGBA32Buffer::FramePartial); buffer.setHasAlpha(false); buffer.setColorProfile(m_colorProfile); // For JPEGs, the frame always fills the entire image. buffer.setRect(IntRect(IntPoint(), size())); } jpeg_decompress_struct* info = m_reader->info(); JSAMPARRAY samples = m_reader->samples(); while (info->output_scanline < info->output_height) { // jpeg_read_scanlines will increase the scanline counter, so we // save the scanline before calling it. int sourceY = info->output_scanline; /* Request one scanline. Returns 0 or 1 scanlines. */ if (jpeg_read_scanlines(info, samples, 1) != 1) return false; int destY = scaledY(sourceY); if (destY < 0) continue; int width = m_scaled ? m_scaledColumns.size() : info->output_width; for (int x = 0; x < width; ++x) { JSAMPLE* jsample = *samples + (m_scaled ? m_scaledColumns[x] : x) * ((info->out_color_space == JCS_RGB) ? 3 : 4); if (info->out_color_space == JCS_RGB) buffer.setRGBA(x, destY, jsample[0], jsample[1], jsample[2], 0xFF); else if (info->out_color_space == JCS_CMYK) { // Source is 'Inverted CMYK', output is RGB. // See: http://www.easyrgb.com/math.php?MATH=M12#text12 // Or: http://www.ilkeratalay.com/colorspacesfaq.php#rgb // From CMYK to CMY: // X = X * (1 - K ) + K [for X = C, M, or Y] // Thus, from Inverted CMYK to CMY is: // X = (1-iX) * (1 - (1-iK)) + (1-iK) => 1 - iX*iK // From CMY (0..1) to RGB (0..1): // R = 1 - C => 1 - (1 - iC*iK) => iC*iK [G and B similar] unsigned k = jsample[3]; buffer.setRGBA(x, destY, jsample[0] * k / 255, jsample[1] * k / 255, jsample[2] * k / 255, 0xFF); } else { ASSERT_NOT_REACHED(); return setFailed(); } } } return true; }
void PNGImageDecoder::rowAvailable(unsigned char* rowBuffer, unsigned rowIndex, int interlacePass) { if (m_frameBufferCache.isEmpty()) return; // Initialize the framebuffer if needed. ImageFrame& buffer = m_frameBufferCache[0]; if (buffer.status() == ImageFrame::FrameEmpty) { if (!buffer.setSize(scaledSize().width(), scaledSize().height())) { longjmp(JMPBUF(m_reader->pngPtr()), 1); return; } buffer.setStatus(ImageFrame::FramePartial); buffer.setHasAlpha(false); buffer.setColorProfile(m_colorProfile); // For PNGs, the frame always fills the entire image. buffer.setOriginalFrameRect(IntRect(IntPoint(), size())); if (png_get_interlace_type(m_reader->pngPtr(), m_reader->infoPtr()) != PNG_INTERLACE_NONE) m_reader->createInterlaceBuffer((m_reader->hasAlpha() ? 4 : 3) * size().width() * size().height()); } if (!rowBuffer) return; // libpng comments (pasted in here to explain what follows) /* * this function is called for every row in the image. If the * image is interlacing, and you turned on the interlace handler, * this function will be called for every row in every pass. * Some of these rows will not be changed from the previous pass. * When the row is not changed, the new_row variable will be NULL. * The rows and passes are called in order, so you don't really * need the row_num and pass, but I'm supplying them because it * may make your life easier. * * For the non-NULL rows of interlaced images, you must call * png_progressive_combine_row() passing in the row and the * old row. You can call this function for NULL rows (it will * just return) and for non-interlaced images (it just does the * memcpy for you) if it will make the code easier. Thus, you * can just do this for all cases: * * png_progressive_combine_row(png_ptr, old_row, new_row); * * where old_row is what was displayed for previous rows. Note * that the first pass (pass == 0 really) will completely cover * the old row, so the rows do not have to be initialized. After * the first pass (and only for interlaced images), you will have * to pass the current row, and the function will combine the * old row and the new row. */ png_structp png = m_reader->pngPtr(); bool hasAlpha = m_reader->hasAlpha(); unsigned colorChannels = hasAlpha ? 4 : 3; png_bytep row; png_bytep interlaceBuffer = m_reader->interlaceBuffer(); if (interlaceBuffer) { row = interlaceBuffer + (rowIndex * colorChannels * size().width()); png_progressive_combine_row(png, row, rowBuffer); } else row = rowBuffer; // Copy the data into our buffer. int width = scaledSize().width(); int destY = scaledY(rowIndex); // Check that the row is within the image bounds. LibPNG may supply an extra row. if (destY < 0 || destY >= scaledSize().height()) return; bool nonTrivialAlpha = false; for (int x = 0; x < width; ++x) { png_bytep pixel = row + (m_scaled ? m_scaledColumns[x] : x) * colorChannels; unsigned alpha = hasAlpha ? pixel[3] : 255; buffer.setRGBA(x, destY, pixel[0], pixel[1], pixel[2], alpha); nonTrivialAlpha |= alpha < 255; } if (nonTrivialAlpha && !buffer.hasAlpha()) buffer.setHasAlpha(nonTrivialAlpha); }
AccountWidget::AccountWidget( QWidget* parent ) : QWidget( parent ) , TomahawkUtils::DpiScaler( this ) { QHBoxLayout *mainLayout = new QHBoxLayout(); TomahawkUtils::unmarginLayout( mainLayout ); setLayout( mainLayout ); setContentsMargins( 0, scaledY( 8 ), 0, scaledY( 8 ) ); m_imageLabel = new QLabel( this ); mainLayout->addWidget( m_imageLabel ); mainLayout->setSpacing( scaledX( 4 ) ); QGridLayout* vLayout = new QGridLayout(); vLayout->setSpacing( 8 ); mainLayout->addLayout( vLayout ); QFrame* idContainer = new QFrame( this ); idContainer->setAttribute( Qt::WA_TranslucentBackground, false ); vLayout->addWidget( idContainer, 0, 0 ); QHBoxLayout* idContLayout = new QHBoxLayout(); idContainer->setLayout( idContLayout ); idContainer->setContentsMargins( 0, 0, 0, 0 ); idContLayout->setMargin( 2 ); m_idLabel = new ElidedLabel( idContainer ); m_idLabel->setElideMode( Qt::ElideRight ); m_idLabel->setContentsMargins( 3, 0, 3, 0 ); m_idLabel->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred ); m_idLabel->setAlignment( Qt::AlignLeft | Qt::AlignVCenter ); idContLayout->addWidget( m_idLabel ); m_spinnerWidget = new QWidget( idContainer ); QSize spinnerSize = 16 > TomahawkUtils::defaultFontHeight() ? QSize( 16, 16 ) : QSize( TomahawkUtils::defaultFontHeight(), TomahawkUtils::defaultFontHeight() ); m_spinnerWidget->setFixedSize( spinnerSize ); idContLayout->addWidget( m_spinnerWidget ); m_spinnerWidget->setContentsMargins( 0, 1, 0, 0 ); m_spinner = new AnimatedSpinner( m_spinnerWidget->size() - QSize( 2, 2 ), m_spinnerWidget ); idContainer->setStyleSheet( QString( "QFrame {" "border: 1px solid #e9e9e9;" "border-radius: %1px;" "background: #e9e9e9;" "}" ).arg( idContainer->sizeHint().height() / 2 + 1 ) ); idContainer->setMinimumHeight( spinnerSize.height() + 6 /*margins*/ ); m_statusToggle = new SlideSwitchButton( this ); m_statusToggle->setContentsMargins( 0, 0, 0, 0 ); m_statusToggle->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Expanding ); m_statusToggle->setFixedSize( m_statusToggle->sizeHint() ); QHBoxLayout *statusToggleLayout = new QHBoxLayout(); vLayout->addLayout( statusToggleLayout, 0, 1, 1, 1 ); statusToggleLayout->addStretch(); statusToggleLayout->addWidget( m_statusToggle ); m_inviteContainer = new QFrame( this ); m_inviteContainer->setObjectName( "inviteContainer" ); vLayout->addWidget( m_inviteContainer, 1, 0 ); m_inviteContainer->setStyleSheet( QString( "QWidget { background: white; } QFrame#%1 { border: 1px solid %2; }" ).arg( m_inviteContainer->objectName() ).arg( TomahawkStyle::BORDER_LINE.name() ) ); m_inviteContainer->setMinimumWidth( m_inviteContainer->logicalDpiX() * 2 ); m_inviteContainer->setContentsMargins( 1, 1, 1, 2 ); m_inviteContainer->setAttribute( Qt::WA_TranslucentBackground, false ); QHBoxLayout* containerLayout = new QHBoxLayout(); m_inviteContainer->setLayout( containerLayout ); TomahawkUtils::unmarginLayout( containerLayout ); containerLayout->setContentsMargins( 1, 1, 0, 0 ); m_addAccountIcon = new QLabel( m_inviteContainer ); m_addAccountIcon->setContentsMargins( 1, 0, 0, 0 ); m_addAccountIcon->setPixmap( TomahawkUtils::defaultPixmap( TomahawkUtils::AddContact, TomahawkUtils::Original, QSize( 16, 16 ) ) ); m_addAccountIcon->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Expanding ); m_addAccountIcon->setAlignment( Qt::AlignCenter ); containerLayout->addWidget( m_addAccountIcon ); m_inviteEdit = new QLineEdit( m_inviteContainer ); m_inviteEdit->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); containerLayout->addWidget( m_inviteEdit ); m_inviteEdit->setFrame( false ); m_inviteButton = new QPushButton( this ); m_inviteButton->setMinimumWidth( m_inviteButton->logicalDpiX() * 0.8 ); m_inviteButton->setText( AccountWidget::tr( "Invite" ) ); m_inviteButton->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Preferred ); vLayout->addWidget( m_inviteButton, 1, 1 ); vLayout->setColumnStretch( 0, 1 ); #ifdef Q_OS_MAC layout()->setContentsMargins( 0, 0, 0, 0 ); #endif setInviteWidgetsEnabled( false ); }
void PNGImageDecoder::rowAvailable(unsigned char* rowBuffer, unsigned rowIndex, int) { if (m_frameBufferCache.isEmpty()) return; // Initialize the framebuffer if needed. ImageFrame& buffer = m_frameBufferCache[0]; if (buffer.status() == ImageFrame::FrameEmpty) { png_structp png = m_reader->pngPtr(); if (!buffer.setSize(scaledSize().width(), scaledSize().height())) { longjmp(JMPBUF(png), 1); return; } unsigned colorChannels = m_reader->hasAlpha() ? 4 : 3; if (PNG_INTERLACE_ADAM7 == png_get_interlace_type(png, m_reader->infoPtr())) { m_reader->createInterlaceBuffer(colorChannels * size().width() * size().height()); if (!m_reader->interlaceBuffer()) { longjmp(JMPBUF(png), 1); return; } } #if USE(QCMSLIB) if (m_reader->colorTransform()) { m_reader->createRowBuffer(colorChannels * size().width()); if (!m_reader->rowBuffer()) { longjmp(JMPBUF(png), 1); return; } } #endif buffer.setStatus(ImageFrame::FramePartial); buffer.setHasAlpha(false); buffer.setColorProfile(m_colorProfile); // For PNGs, the frame always fills the entire image. buffer.setOriginalFrameRect(IntRect(IntPoint(), size())); } /* libpng comments (here to explain what follows). * * this function is called for every row in the image. If the * image is interlacing, and you turned on the interlace handler, * this function will be called for every row in every pass. * Some of these rows will not be changed from the previous pass. * When the row is not changed, the new_row variable will be NULL. * The rows and passes are called in order, so you don't really * need the row_num and pass, but I'm supplying them because it * may make your life easier. */ // Nothing to do if the row is unchanged, or the row is outside // the image bounds: libpng may send extra rows, ignore them to // make our lives easier. if (!rowBuffer) return; int y = !m_scaled ? rowIndex : scaledY(rowIndex); if (y < 0 || y >= scaledSize().height()) return; /* libpng comments (continued). * * For the non-NULL rows of interlaced images, you must call * png_progressive_combine_row() passing in the row and the * old row. You can call this function for NULL rows (it will * just return) and for non-interlaced images (it just does the * memcpy for you) if it will make the code easier. Thus, you * can just do this for all cases: * * png_progressive_combine_row(png_ptr, old_row, new_row); * * where old_row is what was displayed for previous rows. Note * that the first pass (pass == 0 really) will completely cover * the old row, so the rows do not have to be initialized. After * the first pass (and only for interlaced images), you will have * to pass the current row, and the function will combine the * old row and the new row. */ bool hasAlpha = m_reader->hasAlpha(); unsigned colorChannels = hasAlpha ? 4 : 3; png_bytep row = rowBuffer; if (png_bytep interlaceBuffer = m_reader->interlaceBuffer()) { row = interlaceBuffer + (rowIndex * colorChannels * size().width()); png_progressive_combine_row(m_reader->pngPtr(), row, rowBuffer); } #if USE(QCMSLIB) if (qcms_transform* transform = m_reader->colorTransform()) { qcms_transform_data(transform, row, m_reader->rowBuffer(), size().width()); row = m_reader->rowBuffer(); } #endif // Write the decoded row pixels to the frame buffer. ImageFrame::PixelData* address = buffer.getAddr(0, y); int width = scaledSize().width(); unsigned char nonTrivialAlphaMask = 0; #if ENABLE(IMAGE_DECODER_DOWN_SAMPLING) if (m_scaled) { for (int x = 0; x < width; ++x) { png_bytep pixel = row + m_scaledColumns[x] * colorChannels; unsigned alpha = hasAlpha ? pixel[3] : 255; buffer.setRGBA(address++, pixel[0], pixel[1], pixel[2], alpha); nonTrivialAlphaMask |= (255 - alpha); } } else #endif { png_bytep pixel = row; if (hasAlpha) { if (buffer.premultiplyAlpha()) { for (int x = 0; x < width; ++x, pixel += 4) setPixelPremultipliedRGBA(address++, pixel, nonTrivialAlphaMask); } else { for (int x = 0; x < width; ++x, pixel += 4) setPixelRGBA(address++, pixel, nonTrivialAlphaMask); } } else { for (int x = 0; x < width; ++x, pixel += 3) setPixelRGB(address++, pixel); } } if (nonTrivialAlphaMask && !buffer.hasAlpha()) buffer.setHasAlpha(true); }
bool JPEGImageDecoder::outputScanlines() { if (m_frameBufferCache.isEmpty()) return false; // Initialize the framebuffer if needed. ImageFrame& buffer = m_frameBufferCache[0]; if (buffer.status() == ImageFrame::FrameEmpty) { if (!buffer.setSize(scaledSize().width(), scaledSize().height())) return setFailed(); buffer.setStatus(ImageFrame::FramePartial); // The buffer is transparent outside the decoded area while the image is // loading. The completed image will be marked fully opaque in jpegComplete(). buffer.setHasAlpha(true); buffer.setColorProfile(m_colorProfile); // For JPEGs, the frame always fills the entire image. buffer.setOriginalFrameRect(IntRect(IntPoint(), size())); } jpeg_decompress_struct* info = m_reader->info(); #if !ENABLE(IMAGE_DECODER_DOWN_SAMPLING) && defined(TURBO_JPEG_RGB_SWIZZLE) if (turboSwizzled(info->out_color_space)) { ASSERT(!m_scaled); while (info->output_scanline < info->output_height) { unsigned char* row = reinterpret_cast<unsigned char*>(buffer.getAddr(0, info->output_scanline)); if (jpeg_read_scanlines(info, &row, 1) != 1) return false; #if USE(QCMSLIB) if (qcms_transform* transform = m_reader->colorTransform()) qcms_transform_data_type(transform, row, row, info->output_width, rgbOutputColorSpace() == JCS_EXT_BGRA ? QCMS_OUTPUT_BGRX : QCMS_OUTPUT_RGBX); #endif } return true; } #endif JSAMPARRAY samples = m_reader->samples(); while (info->output_scanline < info->output_height) { // jpeg_read_scanlines will increase the scanline counter, so we // save the scanline before calling it. int sourceY = info->output_scanline; /* Request one scanline. Returns 0 or 1 scanlines. */ if (jpeg_read_scanlines(info, samples, 1) != 1) return false; int destY = scaledY(sourceY); if (destY < 0) continue; #if USE(QCMSLIB) if (m_reader->colorTransform() && info->out_color_space == JCS_RGB) qcms_transform_data(m_reader->colorTransform(), *samples, *samples, info->output_width); #endif int width = m_scaled ? m_scaledColumns.size() : info->output_width; for (int x = 0; x < width; ++x) { JSAMPLE* jsample = *samples + (m_scaled ? m_scaledColumns[x] : x) * ((info->out_color_space == JCS_RGB) ? 3 : 4); if (info->out_color_space == JCS_RGB) buffer.setRGBA(x, destY, jsample[0], jsample[1], jsample[2], 0xFF); #if defined(TURBO_JPEG_RGB_SWIZZLE) else if (info->out_color_space == JCS_EXT_RGBA) buffer.setRGBA(x, destY, jsample[0], jsample[1], jsample[2], 0xFF); else if (info->out_color_space == JCS_EXT_BGRA) buffer.setRGBA(x, destY, jsample[2], jsample[1], jsample[0], 0xFF); #endif else if (info->out_color_space == JCS_CMYK) { // Source is 'Inverted CMYK', output is RGB. // See: http://www.easyrgb.com/math.php?MATH=M12#text12 // Or: http://www.ilkeratalay.com/colorspacesfaq.php#rgb // From CMYK to CMY: // X = X * (1 - K ) + K [for X = C, M, or Y] // Thus, from Inverted CMYK to CMY is: // X = (1-iX) * (1 - (1-iK)) + (1-iK) => 1 - iX*iK // From CMY (0..1) to RGB (0..1): // R = 1 - C => 1 - (1 - iC*iK) => iC*iK [G and B similar] unsigned k = jsample[3]; buffer.setRGBA(x, destY, jsample[0] * k / 255, jsample[1] * k / 255, jsample[2] * k / 255, 0xFF); } else { ASSERT_NOT_REACHED(); return setFailed(); } } } return true; }
QSize DpiScaler::scaled( const QPaintDevice* pd, int w, int h ) { return QSize( scaledX( pd, w ), scaledY( pd, h ) ); }
QSize DpiScaler::scaled( int w, int h ) const { return QSize( scaledX( w ), scaledY( h ) ); }