@@ -341,6 +341,11 @@ void SixelParser::_initRasterAttributes(const VTInt macroParameter, const Dispat
341341
342342 // By default, the filled area will cover the maximum extent allowed.
343343 _backgroundSize = { til::CoordTypeMax, til::CoordTypeMax };
344+
345+ // If the requested background area can not initially be filled, we'll
346+ // handle the rest of it on demand when the image is resized. But this
347+ // will be determined later in the _fillImageBackground method.
348+ _resizeFillRequired = false ;
344349}
345350
346351void SixelParser::_updateRasterAttributes (const VTParameters& rasterAttributes)
@@ -647,6 +652,10 @@ void SixelParser::_resizeImageBuffer(const til::CoordType requiredHeight)
647652 {
648653 static constexpr auto transparentPixel = IndexedPixel{ .transparent = true };
649654 _imageBuffer.resize (requiredSize, transparentPixel);
655+ if (_resizeFillRequired)
656+ {
657+ _fillImageBackground (requiredHeight);
658+ }
650659 }
651660}
652661
@@ -656,25 +665,30 @@ void SixelParser::_fillImageBackground()
656665 {
657666 _backgroundFillRequired = false ;
658667
659- const auto backgroundHeight = std::min (_backgroundSize.height , _availablePixelHeight);
660- const auto backgroundWidth = std::min (_backgroundSize.width , _availablePixelWidth);
661- _resizeImageBuffer (backgroundHeight);
662-
663668 // When a background fill is requested, we prefill the buffer with the 0
664669 // color index, up to the boundaries set by the raster attributes (or if
665- // none were given, up to the page boundaries). The actual image output
666- // isn't limited by the background dimensions though.
667- static constexpr auto backgroundPixel = IndexedPixel{};
668- const auto backgroundOffset = _imageCursor.y * _imageMaxWidth;
669- auto dst = std::next (_imageBuffer.begin (), backgroundOffset);
670- for (auto i = 0 ; i < backgroundHeight; i++)
671- {
672- std::fill_n (dst, backgroundWidth, backgroundPixel);
673- std::advance (dst, _imageMaxWidth);
674- }
670+ // none were given, up to the page boundaries). If the requested height
671+ // is more than the available height, we'll continue filling the rest of
672+ // it on demand when the image is resized (see above).
673+ const auto backgroundHeight = std::min (_backgroundSize.height , _availablePixelHeight);
674+ _resizeImageBuffer (backgroundHeight);
675+ _fillImageBackground (backgroundHeight);
676+ _resizeFillRequired = _backgroundSize.height > _availablePixelHeight;
677+ }
678+ }
675679
676- _imageWidth = std::max (_imageWidth, backgroundWidth);
680+ void SixelParser::_fillImageBackground (const int backgroundHeight)
681+ {
682+ static constexpr auto backgroundPixel = IndexedPixel{};
683+ const auto backgroundWidth = std::min (_backgroundSize.width , _availablePixelWidth);
684+ const auto backgroundOffset = _imageCursor.y * _imageMaxWidth;
685+ auto dst = std::next (_imageBuffer.begin (), backgroundOffset);
686+ for (auto i = 0 ; i < backgroundHeight; i++)
687+ {
688+ std::fill_n (dst, backgroundWidth, backgroundPixel);
689+ std::advance (dst, _imageMaxWidth);
677690 }
691+ _imageWidth = std::max (_imageWidth, backgroundWidth);
678692}
679693
680694void SixelParser::_writeToImageBuffer (int sixelValue, int repeatCount)
0 commit comments