vcl/source/filter/jpeg/jpegc.cxx | 45 ++++++++++----------------------------- 1 file changed, 12 insertions(+), 33 deletions(-)
New commits: commit ed42442cf88ab79a333ac182076949afe30737d4 Author: Caolán McNamara <caol...@redhat.com> Date: Sun Mar 19 20:57:47 2017 +0000 ofz#909 timeout on converting gray scale jpgs but we can remove the whole setting pixels one at a time because the format matches N8BitPal, and typically that's what we're writing to anyway, so a direct copy will do Change-Id: I91c72ec37055eb064d84461ac89b6bf171ef8d79 Reviewed-on: https://gerrit.libreoffice.org/35442 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Caolán McNamara <caol...@redhat.com> Tested-by: Caolán McNamara <caol...@redhat.com> diff --git a/vcl/source/filter/jpeg/jpegc.cxx b/vcl/source/filter/jpeg/jpegc.cxx index c49c42fd5c7b..6e1e8f1c0f63 100644 --- a/vcl/source/filter/jpeg/jpegc.cxx +++ b/vcl/source/filter/jpeg/jpegc.cxx @@ -171,7 +171,14 @@ void ReadJPEG( JPEGReader* pJPEGReader, void* pInputStream, long* pLines, J_COLOR_SPACE best_out_color_space = JCS_RGB; ScanlineFormat eScanlineFormat = ScanlineFormat::N24BitTcRgb; ScanlineFormat eFinalFormat = pAccess->GetScanlineFormat(); - if (eFinalFormat == ScanlineFormat::N32BitTcBgra) + + if (bGray) + { + best_out_color_space = JCS_GRAYSCALE; + eScanlineFormat = ScanlineFormat::N8BitPal; + nPixelSize = 1; + } + else if (eFinalFormat == ScanlineFormat::N32BitTcBgra) { best_out_color_space = JCS_EXT_BGRA; eScanlineFormat = eFinalFormat; @@ -190,24 +197,17 @@ void ReadJPEG( JPEGReader* pJPEGReader, void* pInputStream, long* pLines, nPixelSize = 4; } - if ( cinfo.jpeg_color_space == JCS_YCbCr ) - cinfo.out_color_space = best_out_color_space; - else if ( cinfo.jpeg_color_space == JCS_YCCK ) + if (cinfo.jpeg_color_space == JCS_YCCK) cinfo.out_color_space = JCS_CMYK; - if (cinfo.out_color_space != JCS_CMYK && - cinfo.out_color_space != JCS_GRAYSCALE && - cinfo.out_color_space != best_out_color_space) - { - SAL_WARN("vcl.filter", "jpg with unknown out color space, forcing to :" << best_out_color_space << " gray "); + if (cinfo.out_color_space != JCS_CMYK) cinfo.out_color_space = best_out_color_space; - } jpeg_start_decompress(&cinfo); JSAMPLE* aRangeLimit = cinfo.sample_range_limit; - std::vector<sal_uInt8> pScanLineBuffer(nWidth * (bGray ? 1 : nPixelSize)); + std::vector<sal_uInt8> pScanLineBuffer(nWidth * nPixelSize); std::vector<sal_uInt8> pCYMKBuffer; if (cinfo.out_color_space == JCS_CMYK) @@ -215,19 +215,6 @@ void ReadJPEG( JPEGReader* pJPEGReader, void* pInputStream, long* pLines, pCYMKBuffer.resize(nWidth * 4); } - std::unique_ptr<BitmapColor[]> pCols; - - if (bGray) - { - pCols.reset(new BitmapColor[256]); - - for (sal_uInt16 n = 0; n < 256; n++) - { - const sal_uInt8 cGray = n; - pCols[n] = pAccess->GetBestMatchingColor(BitmapColor(cGray, cGray, cGray)); - } - } - for (*pLines = 0; *pLines < nHeight && !source->no_data_available; (*pLines)++) { size_t yIndex = *pLines; @@ -235,15 +222,7 @@ void ReadJPEG( JPEGReader* pJPEGReader, void* pInputStream, long* pLines, sal_uInt8* p = (cinfo.out_color_space == JCS_CMYK) ? pCYMKBuffer.data() : pScanLineBuffer.data(); jpeg_read_scanlines(&cinfo, reinterpret_cast<JSAMPARRAY>(&p), 1); - if (bGray) - { - for (long x = 0; x < nWidth; ++x) - { - sal_uInt8 nColorGray = pScanLineBuffer[x]; - pAccess->SetPixel(yIndex, x, pCols[nColorGray]); - } - } - else if (cinfo.out_color_space == JCS_CMYK) + if (cinfo.out_color_space == JCS_CMYK) { // convert CMYK to RGB for (long cmyk = 0, x = 0; cmyk < nWidth * 4; cmyk += 4, ++x)
_______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits