Changeset 248998 in webkit
- Timestamp:
- Aug 22, 2019 2:12:33 AM (5 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r248997 r248998 1 2019-08-22 Fujii Hironori <Hironori.Fujii@sony.com> 2 3 Remove the dead code of ScalableImageDecoder for scaling 4 https://bugs.webkit.org/show_bug.cgi?id=200498 5 6 Reviewed by Daniel Bates. 7 8 No ports are using the down scaling feature of 9 ScalableImageDecoder now. Removed it. 10 11 No behavior change. 12 13 * platform/image-decoders/ScalableImageDecoder.cpp: 14 (WebCore::ScalableImageDecoder::prepareScaleDataIfNecessary): Deleted. 15 (WebCore::ScalableImageDecoder::upperBoundScaledX): Deleted. 16 (WebCore::ScalableImageDecoder::lowerBoundScaledX): Deleted. 17 (WebCore::ScalableImageDecoder::upperBoundScaledY): Deleted. 18 (WebCore::ScalableImageDecoder::lowerBoundScaledY): Deleted. 19 (WebCore::ScalableImageDecoder::scaledY): Deleted. 20 * platform/image-decoders/ScalableImageDecoder.h: 21 (WebCore::ScalableImageDecoder::scaledSize): Deleted. 22 * platform/image-decoders/gif/GIFImageDecoder.cpp: 23 (WebCore::GIFImageDecoder::setSize): 24 (WebCore::GIFImageDecoder::findFirstRequiredFrameToDecode): 25 (WebCore::GIFImageDecoder::haveDecodedRow): 26 (WebCore::GIFImageDecoder::frameComplete): 27 (WebCore::GIFImageDecoder::initFrameBuffer): 28 * platform/image-decoders/jpeg/JPEGImageDecoder.cpp: 29 (WebCore::JPEGImageDecoder::outputScanlines): 30 (WebCore::JPEGImageDecoder::setSize): Deleted. 31 * platform/image-decoders/jpeg/JPEGImageDecoder.h: 32 * platform/image-decoders/jpeg2000/JPEG2000ImageDecoder.cpp: 33 (WebCore::JPEG2000ImageDecoder::decode): 34 * platform/image-decoders/png/PNGImageDecoder.cpp: 35 (WebCore::PNGImageDecoder::rowAvailable): 36 (WebCore::PNGImageDecoder::initFrameBuffer): 37 (WebCore::PNGImageDecoder::frameComplete): 38 (WebCore::PNGImageDecoder::setSize): Deleted. 39 * platform/image-decoders/png/PNGImageDecoder.h: 40 1 41 2019-08-21 Jer Noble <jer.noble@apple.com> 2 42 -
trunk/Source/WebCore/platform/image-decoders/ScalableImageDecoder.cpp
r247014 r248998 154 154 } 155 155 156 namespace {157 158 enum MatchType {159 Exact,160 UpperBound,161 LowerBound162 };163 164 inline void fillScaledValues(Vector<int>& scaledValues, double scaleRate, int length)165 {166 double inflateRate = 1. / scaleRate;167 scaledValues.reserveCapacity(static_cast<int>(length * scaleRate + 0.5));168 for (int scaledIndex = 0; ; ++scaledIndex) {169 int index = static_cast<int>(scaledIndex * inflateRate + 0.5);170 if (index >= length)171 break;172 scaledValues.append(index);173 }174 }175 176 template <MatchType type> int getScaledValue(const Vector<int>& scaledValues, int valueToMatch, int searchStart)177 {178 if (scaledValues.isEmpty())179 return valueToMatch;180 181 const int* dataStart = scaledValues.data();182 const int* dataEnd = dataStart + scaledValues.size();183 const int* matched = std::lower_bound(dataStart + searchStart, dataEnd, valueToMatch);184 switch (type) {185 case Exact:186 return matched != dataEnd && *matched == valueToMatch ? matched - dataStart : -1;187 case LowerBound:188 return matched != dataEnd && *matched == valueToMatch ? matched - dataStart : matched - dataStart - 1;189 case UpperBound:190 default:191 return matched != dataEnd ? matched - dataStart : -1;192 }193 }194 195 }196 197 156 bool ScalableImageDecoder::frameIsCompleteAtIndex(size_t index) const 198 157 { … … 265 224 } 266 225 267 void ScalableImageDecoder::prepareScaleDataIfNecessary()268 {269 m_scaled = false;270 m_scaledColumns.clear();271 m_scaledRows.clear();272 273 int width = size().width();274 int height = size().height();275 int numPixels = height * width;276 if (m_maxNumPixels <= 0 || numPixels <= m_maxNumPixels)277 return;278 279 m_scaled = true;280 double scale = sqrt(m_maxNumPixels / (double)numPixels);281 fillScaledValues(m_scaledColumns, scale, width);282 fillScaledValues(m_scaledRows, scale, height);283 }284 285 int ScalableImageDecoder::upperBoundScaledX(int origX, int searchStart)286 {287 return getScaledValue<UpperBound>(m_scaledColumns, origX, searchStart);288 }289 290 int ScalableImageDecoder::lowerBoundScaledX(int origX, int searchStart)291 {292 return getScaledValue<LowerBound>(m_scaledColumns, origX, searchStart);293 }294 295 int ScalableImageDecoder::upperBoundScaledY(int origY, int searchStart)296 {297 return getScaledValue<UpperBound>(m_scaledRows, origY, searchStart);298 }299 300 int ScalableImageDecoder::lowerBoundScaledY(int origY, int searchStart)301 {302 return getScaledValue<LowerBound>(m_scaledRows, origY, searchStart);303 }304 305 int ScalableImageDecoder::scaledY(int origY, int searchStart)306 {307 return getScaledValue<Exact>(m_scaledRows, origY, searchStart);308 }309 310 226 #if USE(DIRECT2D) 311 227 void ScalableImageDecoder::setTargetContext(ID2D1RenderTarget*) -
trunk/Source/WebCore/platform/image-decoders/ScalableImageDecoder.h
r247014 r248998 99 99 IntSize size() const override { return isSizeAvailable() ? m_size : IntSize(); } 100 100 101 IntSize scaledSize()102 {103 return m_scaled ? IntSize(m_scaledColumns.size(), m_scaledRows.size()) : size();104 }105 106 101 // This will only differ from size() for ICO (where each frame is a 107 102 // different icon) or other formats where different frames are different … … 198 193 199 194 protected: 200 void prepareScaleDataIfNecessary();201 int upperBoundScaledX(int origX, int searchStart = 0);202 int lowerBoundScaledX(int origX, int searchStart = 0);203 int upperBoundScaledY(int origY, int searchStart = 0);204 int lowerBoundScaledY(int origY, int searchStart = 0);205 int scaledY(int origY, int searchStart = 0);206 207 195 RefPtr<SharedBuffer> m_data; // The encoded data. 208 196 Vector<ScalableImageDecoderFrame, 1> m_frameBufferCache; 209 197 mutable Lock m_mutex; 210 bool m_scaled { false };211 Vector<int> m_scaledColumns;212 Vector<int> m_scaledRows;213 198 bool m_premultiplyAlpha; 214 199 bool m_ignoreGammaAndColorProfile; … … 225 210 EncodedDataStatus m_encodedDataStatus { EncodedDataStatus::TypeAvailable }; 226 211 bool m_decodingSizeFromSetData { false }; 227 228 // FIXME: Evaluate the need for decoded data scaling. m_scaled,229 // m_scaledColumns and m_scaledRows are member variables that are230 // affected by this value, and are not used at all since the value231 // is negavite (see prepareScaleDataIfNecessary()).232 static const int m_maxNumPixels { -1 };233 212 }; 234 213 -
trunk/Source/WebCore/platform/image-decoders/gif/GIFImageDecoder.cpp
r248846 r248998 54 54 return true; 55 55 56 if (!ScalableImageDecoder::setSize(size)) 57 return false; 58 59 prepareScaleDataIfNecessary(); 60 return true; 56 return ScalableImageDecoder::setSize(size); 61 57 } 62 58 … … 127 123 ASSERT(frameContext); 128 124 IntRect frameRect(frameContext->xOffset, frameContext->yOffset, frameContext->width, frameContext->height); 129 // We would need to scale frameRect and check whether it fills the whole scaledSize(). But130 // can check whether the original frameRect fills size() instead. If the frame fills the131 // whole area then it can be decoded without dependencies.132 125 if (frameRect.contains({ { }, size() })) 133 126 return i; … … 217 210 // we must ensure we don't run off the end of either the source data or the 218 211 // row's X-coordinates. 219 int xBegin = upperBoundScaledX(frameContext->xOffset);220 int yBegin = upperBoundScaledY(frameContext->yOffset + rowNumber);221 int xEnd = lowerBoundScaledX(std::min(static_cast<int>(frameContext->xOffset + width), size().width()) - 1, xBegin + 1) + 1;222 int yEnd = lowerBoundScaledY(std::min(static_cast<int>(frameContext->yOffset + rowNumber + repeatCount), size().height()) - 1, yBegin + 1) + 1;223 if (rowBuffer.isEmpty() || (xBegin < 0) || (yBegin < 0) || (xEnd <= xBegin) || (yEnd <= yBegin))212 int xBegin = frameContext->xOffset; 213 int yBegin = frameContext->yOffset + rowNumber; 214 int xEnd = std::min(static_cast<int>(frameContext->xOffset + width), size().width()); 215 int yEnd = std::min(static_cast<int>(frameContext->yOffset + rowNumber + repeatCount), size().height()); 216 if (rowBuffer.isEmpty() || xEnd <= xBegin || yEnd <= yBegin) 224 217 return true; 225 218 … … 245 238 // Write one row's worth of data into the frame. 246 239 for (int x = xBegin; x < xEnd; ++x) { 247 const unsigned char sourceValue = rowBuffer[ (m_scaled ? m_scaledColumns[x] : x)- frameContext->xOffset];240 const unsigned char sourceValue = rowBuffer[x - frameContext->xOffset]; 248 241 if ((!frameContext->isTransparent || (sourceValue != frameContext->tpixel)) && (sourceValue < colorMapSize)) { 249 242 const size_t colorIndex = static_cast<size_t>(sourceValue) * 3; … … 288 281 // The whole frame was non-transparent, so it's possible that the entire 289 282 // resulting buffer was non-transparent, and we can setHasAlpha(false). 290 if (rect.contains(IntRect(IntPoint(), s caledSize())))283 if (rect.contains(IntRect(IntPoint(), size()))) 291 284 buffer.setHasAlpha(false); 292 285 else if (frameIndex) { … … 375 368 if (!frameIndex) { 376 369 // This is the first frame, so we're not relying on any previous data. 377 if (!buffer->initialize(s caledSize(), m_premultiplyAlpha))370 if (!buffer->initialize(size(), m_premultiplyAlpha)) 378 371 return setFailed(); 379 372 } else { … … 403 396 // affecting pixels in the image outside of the frame. 404 397 IntRect prevRect = prevBuffer->backingStore()->frameRect(); 405 const IntSize& bufferSize = s caledSize();406 if (!frameIndex || prevRect.contains(IntRect(IntPoint(), s caledSize()))) {398 const IntSize& bufferSize = size(); 399 if (!frameIndex || prevRect.contains(IntRect(IntPoint(), size()))) { 407 400 // Clearing the first frame, or a frame the size of the whole 408 401 // image, results in a completely empty image. … … 425 418 frameRect.setHeight(size().height() - frameContext->yOffset); 426 419 427 int left = upperBoundScaledX(frameRect.x()); 428 int right = lowerBoundScaledX(frameRect.maxX(), left); 429 int top = upperBoundScaledY(frameRect.y()); 430 int bottom = lowerBoundScaledY(frameRect.maxY(), top); 431 buffer->backingStore()->setFrameRect(IntRect(left, top, right - left, bottom - top)); 420 buffer->backingStore()->setFrameRect(frameRect); 432 421 433 422 // Update our status to be partially complete. -
trunk/Source/WebCore/platform/image-decoders/jpeg/JPEGImageDecoder.cpp
r248846 r248998 503 503 JPEGImageDecoder::~JPEGImageDecoder() = default; 504 504 505 bool JPEGImageDecoder::setSize(const IntSize& size)506 {507 if (!ScalableImageDecoder::setSize(size))508 return false;509 510 prepareScaleDataIfNecessary();511 return true;512 }513 514 505 ScalableImageDecoderFrame* JPEGImageDecoder::frameBufferAtIndex(size_t index) 515 506 { … … 557 548 } 558 549 559 template <J_COLOR_SPACE colorSpace , bool isScaled>550 template <J_COLOR_SPACE colorSpace> 560 551 bool JPEGImageDecoder::outputScanlines(ScalableImageDecoderFrame& buffer) 561 552 { 562 553 JSAMPARRAY samples = m_reader->samples(); 563 554 jpeg_decompress_struct* info = m_reader->info(); 564 int width = i sScaled ? m_scaledColumns.size() : info->output_width;555 int width = info->output_width; 565 556 566 557 while (info->output_scanline < info->output_height) { … … 572 563 return false; 573 564 574 int destY = scaledY(sourceY); 575 if (destY < 0) 576 continue; 577 578 auto* currentAddress = buffer.backingStore()->pixelAt(0, destY); 565 auto* currentAddress = buffer.backingStore()->pixelAt(0, sourceY); 579 566 for (int x = 0; x < width; ++x) { 580 setPixel<colorSpace>(buffer, currentAddress, samples, isScaled ? m_scaledColumns[x] :x);567 setPixel<colorSpace>(buffer, currentAddress, samples, x); 581 568 ++currentAddress; 582 569 } 583 570 } 584 571 return true; 585 }586 587 template <J_COLOR_SPACE colorSpace>588 bool JPEGImageDecoder::outputScanlines(ScalableImageDecoderFrame& buffer)589 {590 return m_scaled ? outputScanlines<colorSpace, true>(buffer) : outputScanlines<colorSpace, false>(buffer);591 572 } 592 573 … … 599 580 auto& buffer = m_frameBufferCache[0]; 600 581 if (buffer.isInvalid()) { 601 if (!buffer.initialize(s caledSize(), m_premultiplyAlpha))582 if (!buffer.initialize(size(), m_premultiplyAlpha)) 602 583 return setFailed(); 603 584 buffer.setDecodingStatus(DecodingStatus::Partial); … … 610 591 611 592 #if defined(TURBO_JPEG_RGB_SWIZZLE) 612 if ( !m_scaled &&turboSwizzled(info->out_color_space)) {593 if (turboSwizzled(info->out_color_space)) { 613 594 while (info->output_scanline < info->output_height) { 614 595 unsigned char* row = reinterpret_cast<unsigned char*>(buffer.backingStore()->pixelAt(0, info->output_scanline)); … … 621 602 622 603 switch (info->out_color_space) { 623 // The code inside outputScanlines<int , bool> will be executed604 // The code inside outputScanlines<int> will be executed 624 605 // for each pixel, so we want to avoid any extra comparisons there. 625 606 // That is why we use template and template specializations here so -
trunk/Source/WebCore/platform/image-decoders/jpeg/JPEGImageDecoder.h
r233122 r248998 53 53 // ScalableImageDecoder 54 54 String filenameExtension() const override { return "jpg"_s; } 55 bool setSize(const IntSize&) override;56 55 ScalableImageDecoderFrame* frameBufferAtIndex(size_t index) override; 57 56 // CAUTION: setFailed() deletes |m_reader|. Be careful to avoid … … 59 58 // JPEGImageReader! 60 59 bool setFailed() override; 61 62 bool willDownSample()63 {64 ASSERT(ScalableImageDecoder::encodedDataStatus() >= EncodedDataStatus::SizeAvailable);65 return m_scaled;66 }67 60 68 61 bool outputScanlines(); -
trunk/Source/WebCore/platform/image-decoders/jpeg2000/JPEG2000ImageDecoder.cpp
r240428 r248998 480 480 481 481 auto& buffer = m_frameBufferCache[0]; 482 if (!buffer.initialize(s caledSize(), m_premultiplyAlpha)) {482 if (!buffer.initialize(size(), m_premultiplyAlpha)) { 483 483 setFailed(); 484 484 return; -
trunk/Source/WebCore/platform/image-decoders/png/PNGImageDecoder.cpp
r248846 r248998 249 249 #endif 250 250 251 bool PNGImageDecoder::setSize(const IntSize& size)252 {253 if (!ScalableImageDecoder::setSize(size))254 return false;255 256 prepareScaleDataIfNecessary();257 return true;258 }259 260 251 ScalableImageDecoderFrame* PNGImageDecoder::frameBufferAtIndex(size_t index) 261 252 { … … 436 427 if (buffer.isInvalid()) { 437 428 png_structp png = m_reader->pngPtr(); 438 if (!buffer.initialize(s caledSize(), m_premultiplyAlpha)) {429 if (!buffer.initialize(size(), m_premultiplyAlpha)) { 439 430 longjmp(JMPBUF(png), 1); 440 431 return; … … 478 469 if (!rowBuffer) 479 470 return; 480 int y = !m_scaled ? rowIndex : scaledY(rowIndex); 481 if (y < 0 || y >= scaledSize().height()) 471 if (rowIndex >= size().height()) 482 472 return; 483 473 … … 517 507 518 508 // Write the decoded row pixels to the frame buffer. 519 auto* address = buffer.backingStore()->pixelAt(0, y);520 int width = s caledSize().width();509 auto* address = buffer.backingStore()->pixelAt(0, rowIndex); 510 int width = size().width(); 521 511 unsigned char nonTrivialAlphaMask = 0; 522 512 … … 778 768 // affecting pixels in the image outside of the frame. 779 769 IntRect prevRect = prevBuffer->backingStore()->frameRect(); 780 if (!frameIndex || prevRect.contains(IntRect(IntPoint(), s caledSize()))) {770 if (!frameIndex || prevRect.contains(IntRect(IntPoint(), size()))) { 781 771 // Clearing the first frame, or a frame the size of the whole 782 772 // image, results in a completely empty image. … … 802 792 frameRect.setHeight(size().height() - m_yOffset); 803 793 804 int left = upperBoundScaledX(frameRect.x()); 805 int right = lowerBoundScaledX(frameRect.maxX(), left); 806 int top = upperBoundScaledY(frameRect.y()); 807 int bottom = lowerBoundScaledY(frameRect.maxY(), top); 808 buffer.backingStore()->setFrameRect(IntRect(left, top, right - left, bottom - top)); 794 buffer.backingStore()->setFrameRect(frameRect); 809 795 } 810 796 … … 827 813 m_blend = 0; 828 814 829 ASSERT(!m_scaled);830 815 png_bytep row = interlaceBuffer; 831 816 for (int y = rect.y(); y < rect.maxY(); ++y, row += colorChannels * size().width()) { … … 844 829 if (!nonTrivialAlpha) { 845 830 IntRect rect = buffer.backingStore()->frameRect(); 846 if (rect.contains(IntRect(IntPoint(), s caledSize())))831 if (rect.contains(IntRect(IntPoint(), size()))) 847 832 buffer.setHasAlpha(false); 848 833 else { -
trunk/Source/WebCore/platform/image-decoders/png/PNGImageDecoder.h
r233122 r248998 51 51 RepetitionCount repetitionCount() const override; 52 52 #endif 53 bool setSize(const IntSize&) override;54 53 ScalableImageDecoderFrame* frameBufferAtIndex(size_t index) override; 55 54 // CAUTION: setFailed() deletes |m_reader|. Be careful to avoid
Note: See TracChangeset
for help on using the changeset viewer.