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

Side by Side Diff: tests/CodexTest.cpp

Issue 1645963002: Optimize the SkRawStream when the input is an asset stream (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Address comments and add test Created 4 years, 10 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
« src/codec/SkRawCodec.cpp ('K') | « src/codec/SkRawCodec.cpp ('k') | 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 2015 Google Inc. 2 * Copyright 2015 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 "SkAndroidCodec.h" 9 #include "SkAndroidCodec.h"
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 check(r, "mandrill_64.png", SkISize::Make(64, 64), true, false, false); 447 check(r, "mandrill_64.png", SkISize::Make(64, 64), true, false, false);
448 check(r, "plane.png", SkISize::Make(250, 126), true, false, false); 448 check(r, "plane.png", SkISize::Make(250, 126), true, false, false);
449 // FIXME: We are not ready to test incomplete interlaced pngs 449 // FIXME: We are not ready to test incomplete interlaced pngs
450 check(r, "plane_interlaced.png", SkISize::Make(250, 126), true, false, false ); 450 check(r, "plane_interlaced.png", SkISize::Make(250, 126), true, false, false );
451 check(r, "randPixels.png", SkISize::Make(8, 8), true, false, false); 451 check(r, "randPixels.png", SkISize::Make(8, 8), true, false, false);
452 check(r, "yellow_rose.png", SkISize::Make(400, 301), true, false, false); 452 check(r, "yellow_rose.png", SkISize::Make(400, 301), true, false, false);
453 453
454 // RAW 454 // RAW
455 #if defined(SK_CODEC_DECODES_RAW) 455 #if defined(SK_CODEC_DECODES_RAW)
456 check(r, "sample_1mp.dng", SkISize::Make(600, 338), false, false, false); 456 check(r, "sample_1mp.dng", SkISize::Make(600, 338), false, false, false);
457 check(r, "dng_with_preview.dng", SkISize::Make(600, 338), true, false, false );
457 #endif 458 #endif
458 } 459 }
459 460
460 // Test interlaced PNG in stripes, similar to DM's kStripe_Mode 461 // Test interlaced PNG in stripes, similar to DM's kStripe_Mode
461 DEF_TEST(Codec_stripes, r) { 462 DEF_TEST(Codec_stripes, r) {
462 const char * path = "plane_interlaced.png"; 463 const char * path = "plane_interlaced.png";
463 SkAutoTDelete<SkStream> stream(resource(path)); 464 SkAutoTDelete<SkStream> stream(resource(path));
464 if (!stream) { 465 if (!stream) {
465 SkDebugf("Missing resource '%s'\n", path); 466 SkDebugf("Missing resource '%s'\n", path);
466 } 467 }
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 test_dimensions(r, "3x3.png"); 645 test_dimensions(r, "3x3.png");
645 test_dimensions(r, "3x1.png"); 646 test_dimensions(r, "3x1.png");
646 test_dimensions(r, "1x1.png"); 647 test_dimensions(r, "1x1.png");
647 test_dimensions(r, "16x1.png"); 648 test_dimensions(r, "16x1.png");
648 test_dimensions(r, "1x16.png"); 649 test_dimensions(r, "1x16.png");
649 test_dimensions(r, "mandrill_16.png"); 650 test_dimensions(r, "mandrill_16.png");
650 651
651 // RAW 652 // RAW
652 #if defined(SK_CODEC_DECODES_RAW) 653 #if defined(SK_CODEC_DECODES_RAW)
653 test_dimensions(r, "sample_1mp.dng"); 654 test_dimensions(r, "sample_1mp.dng");
655 test_dimensions(r, "dng_with_preview.dng");
654 #endif 656 #endif
655 } 657 }
656 658
657 static void test_invalid(skiatest::Reporter* r, const char path[]) { 659 static void test_invalid(skiatest::Reporter* r, const char path[]) {
658 SkAutoTDelete<SkStream> stream(resource(path)); 660 SkAutoTDelete<SkStream> stream(resource(path));
659 if (!stream) { 661 if (!stream) {
660 SkDebugf("Missing resource '%s'\n", path); 662 SkDebugf("Missing resource '%s'\n", path);
661 return; 663 return;
662 } 664 }
663 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.detach())); 665 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.detach()));
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
887 return fStream.rewind(); 889 return fStream.rewind();
888 } 890 }
889 bool isAtEnd() const override { 891 bool isAtEnd() const override {
890 return false; 892 return false;
891 } 893 }
892 private: 894 private:
893 SkMemoryStream fStream; 895 SkMemoryStream fStream;
894 const size_t fLimit; 896 const size_t fLimit;
895 }; 897 };
896 898
899 // Stream that is not seekable (!hasPotions() or !hasLength())
scroggo 2016/02/04 15:46:24 hasPosition()*
yujieqin 2016/02/05 08:53:21 Done.
900 class NotSeekableMemStream : public SkStream {
901 public:
902 NotSeekableMemStream(SkData* data) : fStream(data) {}
903
904 bool hasPosition() const override {
905 return false;
906 }
907
908 bool hasLength() const override {
909 return false;
910 }
911
912 size_t peek(void* buf, size_t bytes) const override {
913 return fStream.peek(buf, bytes);
914 }
915 size_t read(void* buf, size_t bytes) override {
916 return fStream.read(buf, bytes);
917 }
918 bool rewind() override {
919 return fStream.rewind();
920 }
921 bool isAtEnd() const override {
922 return false;
scroggo 2016/02/04 15:46:24 Should this return fStream.isAtEnd()? (I'm guessin
yujieqin 2016/02/05 08:53:21 Done.
923 }
924 private:
925 SkMemoryStream fStream;
926 };
927
928 // Test that the RawCodec works also for not seekable stream. This will test the code path using
929 // SkRawBufferedStream instead of SkRawSeekableStream.
930 #if defined(SK_CODEC_DECODES_RAW)
931 DEF_TEST(Codec_raw_notseekable, r) {
932 const char* path = "dng_with_preview.dng";
933 SkString fullPath(GetResourcePath(path));
934 SkAutoTUnref<SkData> data(SkData::NewFromFileName(fullPath.c_str()));
935 if (!data) {
936 SkDebugf("Missing resource '%s'\n", path);
937 return;
938 }
939
940 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(new NotSeekableMemStream (data)));
941 REPORTER_ASSERT(r, codec);
942
943 test_info(r, codec, codec->getInfo(), SkCodec::kSuccess, nullptr);
944 }
945 #endif
946
897 // Test that even if webp_parse_header fails to peek enough, it will fall back t o read() 947 // Test that even if webp_parse_header fails to peek enough, it will fall back t o read()
898 // + rewind() and succeed. 948 // + rewind() and succeed.
899 DEF_TEST(Codec_webp_peek, r) { 949 DEF_TEST(Codec_webp_peek, r) {
900 const char* path = "baby_tux.webp"; 950 const char* path = "baby_tux.webp";
901 SkString fullPath(GetResourcePath(path)); 951 SkString fullPath(GetResourcePath(path));
902 SkAutoTUnref<SkData> data(SkData::NewFromFileName(fullPath.c_str())); 952 SkAutoTUnref<SkData> data(SkData::NewFromFileName(fullPath.c_str()));
903 if (!data) { 953 if (!data) {
904 SkDebugf("Missing resource '%s'\n", path); 954 SkDebugf("Missing resource '%s'\n", path);
905 return; 955 return;
906 } 956 }
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
969 // Now test an image which is too big. Any image with a larger header (i.e. 1019 // Now test an image which is too big. Any image with a larger header (i.e.
970 // has bigger width/height) is also too big. 1020 // has bigger width/height) is also too big.
971 const unsigned char tooBigWbmp[] = { 0x00, 0x00, // Header 1021 const unsigned char tooBigWbmp[] = { 0x00, 0x00, // Header
972 0x84, 0x80, 0x00, // W: 65536 1022 0x84, 0x80, 0x00, // W: 65536
973 0x84, 0x80, 0x00 }; // H: 65536 1023 0x84, 0x80, 0x00 }; // H: 65536
974 stream.reset(new SkMemoryStream(tooBigWbmp, sizeof(tooBigWbmp), false)); 1024 stream.reset(new SkMemoryStream(tooBigWbmp, sizeof(tooBigWbmp), false));
975 codec.reset(SkCodec::NewFromStream(stream.detach())); 1025 codec.reset(SkCodec::NewFromStream(stream.detach()));
976 1026
977 REPORTER_ASSERT(r, !codec); 1027 REPORTER_ASSERT(r, !codec);
978 } 1028 }
OLDNEW
« src/codec/SkRawCodec.cpp ('K') | « src/codec/SkRawCodec.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698