Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Side by Side Diff: tests/ImageDecodingTest.cpp

Issue 435753002: add a libjpeg test (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: nits Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "Resources.h" 8 #include "Resources.h"
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 734 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 } 745 }
746 { 746 {
747 SkAutoLockPixels alp(bitmap); 747 SkAutoLockPixels alp(bitmap);
748 REPORTER_ASSERT(r, bitmap.getColorTable() && "first pass"); 748 REPORTER_ASSERT(r, bitmap.getColorTable() && "first pass");
749 } 749 }
750 { 750 {
751 SkAutoLockPixels alp(bitmap); 751 SkAutoLockPixels alp(bitmap);
752 REPORTER_ASSERT(r, bitmap.getColorTable() && "second pass"); 752 REPORTER_ASSERT(r, bitmap.getColorTable() && "second pass");
753 } 753 }
754 } 754 }
755
756
757 ////////////////////////////////////////////////////////////////////////////////
758 namespace {
759 class SingleAllocator : public SkBitmap::Allocator {
760 public:
761 SingleAllocator(void* p, size_t s) : fPixels(p), fSize(s) { }
762 ~SingleAllocator() {}
763 // If the pixels in fPixels are big enough, use them.
764 virtual bool allocPixelRef(SkBitmap* bm, SkColorTable* ct) SK_OVERRIDE {
765 SkASSERT(bm);
766 if (bm->info().getSafeSize(bm->rowBytes()) <= fSize) {
767 bm->setPixels(fPixels, ct);
768 fPixels = NULL;
769 fSize = 0;
770 return true;
771 }
772 return bm->allocPixels(NULL, ct);
773 }
774 bool ready() { return fPixels != NULL; }
775 private:
776 void* fPixels;
777 size_t fSize;
778 };
779 } // namespace
780
781 /* This tests for a bug in libjpeg where INT32 is typedefed to long
782 and memory can be written to outside of the array. */
783 DEF_TEST(ImageDecoding_JpegOverwrite, r) {
784 SkString resourceDir = GetResourcePath();
785 SkString path = SkOSPath::Join(resourceDir.c_str(), "randPixels.jpg");
786 SkAutoTUnref<SkStreamAsset> stream(
787 SkStream::NewFromFile(path.c_str()));
788 if (!stream.get()) {
789 SkDebugf("\nPath '%s' missing.\n", path.c_str());
790 return;
791 }
792 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(stream));
793 if (NULL == decoder.get()) {
794 ERRORF(r, "\nSkImageDecoder::Factory failed.\n");
795 return;
796 }
797 SkAssertResult(stream->rewind());
798
799 static const uint16_t sentinal = 0xBEEF;
800 static const int pixelCount = 16;
801 SkAutoTMalloc<uint16_t> pixels(pixelCount + 1);
802 // pixels.get() should be 4-byte aligned.
803 // This is necessary to reproduce the bug.
804
805 pixels[pixelCount] = sentinal; // This value should not be changed.
806
807 SkAutoTUnref<SingleAllocator> allocator(
808 SkNEW_ARGS(SingleAllocator,
809 ((void*)pixels.get(), sizeof(uint16_t) * pixelCount)));
810 decoder->setAllocator(allocator);
811 decoder->setSampleSize(2);
812 SkBitmap bitmap;
813 bool success = decoder->decode(stream, &bitmap, kRGB_565_SkColorType,
814 SkImageDecoder::kDecodePixels_Mode);
815 REPORTER_ASSERT(r, success);
816 REPORTER_ASSERT(r, !allocator->ready()); // Decoder used correct memory
817 REPORTER_ASSERT(r, sentinal == pixels[pixelCount]);
818 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698