template <J_COLOR_SPACE colorSpace> bool outputRows(JPEGImageReader* reader, ImageFrame& buffer) { JSAMPARRAY samples = reader->samples(); jpeg_decompress_struct* info = reader->info(); int width = 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 y = info->output_scanline; // Request one scanline: returns 0 or 1 scanlines. if (jpeg_read_scanlines(info, samples, 1) != 1) return false; #if USE(QCMSLIB) if (reader->colorTransform() && colorSpace == JCS_RGB) qcms_transform_data(reader->colorTransform(), *samples, *samples, width); #endif ImageFrame::PixelData* pixel = buffer.getAddr(0, y); for (int x = 0; x < width; ++pixel, ++x) setPixel<colorSpace>(buffer, pixel, samples, x); } buffer.setPixelsChanged(true); return true; }
void WEBPImageDecoder::applyColorProfile(const uint8_t* data, size_t size, ImageFrame& buffer) { int width; int decodedHeight; if (!WebPIDecGetRGB(m_decoder, &decodedHeight, &width, 0, 0)) return; // See also https://bugs.webkit.org/show_bug.cgi?id=74062 if (decodedHeight <= 0) return; if (!m_haveReadProfile) { readColorProfile(data, size); m_haveReadProfile = true; } ASSERT(width == scaledSize().width()); ASSERT(decodedHeight <= scaledSize().height()); for (int y = m_decodedHeight; y < decodedHeight; ++y) { uint8_t* row = reinterpret_cast<uint8_t*>(buffer.getAddr(0, y)); if (qcms_transform* transform = colorTransform()) qcms_transform_data_type(transform, row, row, width, QCMS_OUTPUT_RGBX); uint8_t* pixel = row; for (int x = 0; x < width; ++x, pixel += 4) buffer.setRGBA(x, y, pixel[0], pixel[1], pixel[2], pixel[3]); } m_decodedHeight = decodedHeight; }
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; }