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

Side by Side Diff: tests/JpegTest.cpp

Issue 1549473003: Add getYUV8Planes() API to SkCodec (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Remove random extra file :) Created 5 years 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/SkJpegCodec.cpp ('K') | « src/codec/SkJpegCodec.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 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 "SkBitmap.h" 8 #include "SkBitmap.h"
9 #include "SkCodec.h"
9 #include "SkDecodingImageGenerator.h" 10 #include "SkDecodingImageGenerator.h"
10 #include "SkForceLinking.h" 11 #include "SkForceLinking.h"
11 #include "SkImageDecoder.h" 12 #include "SkImageDecoder.h"
12 #include "SkPixelRef.h" 13 #include "SkPixelRef.h"
14 #include "Resources.h"
13 #include "SkStream.h" 15 #include "SkStream.h"
14 #include "SkTemplates.h" 16 #include "SkTemplates.h"
15 #include "Test.h" 17 #include "Test.h"
16 18
17 __SK_FORCE_IMAGE_DECODER_LINKING; 19 __SK_FORCE_IMAGE_DECODER_LINKING;
18 20
19 #define JPEG_TEST_WRITE_TO_FILE_FOR_DEBUGGING 0 // do not do this for 21 #define JPEG_TEST_WRITE_TO_FILE_FOR_DEBUGGING 0 // do not do this for
20 // normal unit testing. 22 // normal unit testing.
21 static unsigned char goodJpegImage[] = { 23 static unsigned char goodJpegImage[] = {
22 0xFF, 0xD8, 0xFF, 0xE0, 0x00, 0x10, 0x4A, 0x46, 24 0xFF, 0xD8, 0xFF, 0xE0, 0x00, 0x10, 0x4A, 0x46,
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 } 486 }
485 SkAutoMalloc storage(totalSize); 487 SkAutoMalloc storage(totalSize);
486 void* planes[3]; 488 void* planes[3];
487 planes[0] = storage.get(); 489 planes[0] = storage.get();
488 planes[1] = (uint8_t*)planes[0] + sizes[0]; 490 planes[1] = (uint8_t*)planes[0] + sizes[0];
489 planes[2] = (uint8_t*)planes[1] + sizes[1]; 491 planes[2] = (uint8_t*)planes[1] + sizes[1];
490 492
491 // Get the YUV planes 493 // Get the YUV planes
492 REPORTER_ASSERT(reporter, gen->getYUV8Planes(yuvSizes, planes, rowBytes, nul lptr)); 494 REPORTER_ASSERT(reporter, gen->getYUV8Planes(yuvSizes, planes, rowBytes, nul lptr));
493 } 495 }
496
497 static SkStreamAsset* resource(const char path[]) {
498 SkString fullPath = GetResourcePath(path);
499 return SkStream::NewFromFile(fullPath.c_str());
500 }
501
502 static void codec_yuv(skiatest::Reporter* reporter,
503 const char path[],
504 SkISize expectedSizes[3]) {
505 SkAutoTDelete<SkStream> stream(resource(path));
506 if (!stream) {
507 SkDebugf("Missing resource '%s'\n", path);
508 return;
509 }
510 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.detach()));
511 REPORTER_ASSERT(reporter, codec);
512 if (!codec) {
513 return;
514 }
515
516 // Test getYUV8Sizes()
517 SkISize sizes[3];
518 bool success = codec->getYUV8Sizes(nullptr);
519 REPORTER_ASSERT(reporter, !success);
520 success = codec->getYUV8Sizes(sizes);
521 if (expectedSizes) {
scroggo 2016/01/04 18:29:16 Instead of this if/else block, how do you feel abo
msarett 2016/01/12 14:25:27 Done.
522 REPORTER_ASSERT(reporter, success);
523 } else {
524 // Passing in nullptr for expectedSizes indicates that we expect YUV
525 // to not be supported.
526 REPORTER_ASSERT(reporter, !success);
527 }
528 if (!success) {
529 return;
530 }
531 REPORTER_ASSERT(reporter, expectedSizes[0].width() == sizes[0].width());
scroggo 2016/01/04 18:29:16 Alternatively, you could do a memcmp? I don't have
msarett 2016/01/12 14:25:27 Done.
532 REPORTER_ASSERT(reporter, expectedSizes[0].height() == sizes[0].height());
533 REPORTER_ASSERT(reporter, expectedSizes[1].width() == sizes[1].width());
534 REPORTER_ASSERT(reporter, expectedSizes[1].height() == sizes[1].height());
535 REPORTER_ASSERT(reporter, expectedSizes[2].width() == sizes[2].width());
536 REPORTER_ASSERT(reporter, expectedSizes[2].height() == sizes[2].height());
537
538 // Calculate rowBytes for the YUV decode
scroggo 2016/01/04 18:29:16 nit: It seems like no "calculation" is done. Looks
msarett 2016/01/12 14:25:27 Acknowledged. Removed this code anyway.
539 size_t rowBytes[3];
540 rowBytes[0] = sizes[0].width();
541 rowBytes[1] = sizes[1].width();
542 rowBytes[2] = sizes[2].width();
543
544 // Allocate the memory for the YUV decode
545 size_t totalBytes = rowBytes[0] * sizes[0].height() + rowBytes[1] * sizes[1] .height() +
546 rowBytes[2] * sizes[2].height();
547 SkAutoMalloc storage(totalBytes);
548 void* planes[3];
549 planes[0] = storage.get();
550 planes[1] = SkTAddOffset<void>(planes[0], rowBytes[0] * sizes[0].height());
551 planes[2] = SkTAddOffset<void>(planes[1], rowBytes[1] * sizes[1].height());
552
553 // Test getYUV8Planes()
554 REPORTER_ASSERT(reporter, SkCodec::kInvalidInput ==
555 codec->getYUV8Planes(sizes, planes, nullptr, nullptr));
556 REPORTER_ASSERT(reporter, SkCodec::kInvalidInput ==
557 codec->getYUV8Planes(sizes, nullptr, rowBytes, nullptr));
558 REPORTER_ASSERT(reporter, SkCodec::kInvalidInput ==
559 codec->getYUV8Planes(nullptr, planes, rowBytes, nullptr));
560 REPORTER_ASSERT(reporter, SkCodec::kSuccess ==
561 codec->getYUV8Planes(sizes, planes, rowBytes, nullptr));
562 SkYUVColorSpace colorSpace;
563 REPORTER_ASSERT(reporter, SkCodec::kSuccess ==
564 codec->getYUV8Planes(sizes, planes, rowBytes, &colorSpace));
565 REPORTER_ASSERT(reporter, SkYUVColorSpace::kJPEG_SkYUVColorSpace == colorSpa ce);
566 }
567
568 DEF_TEST(Jpeg_YUV_Codec, r) {
569 SkISize sizes[3];
570
571 sizes[0].set(128, 128);
572 sizes[1].set(64, 64);
573 sizes[2].set(64, 64);
574 codec_yuv(r, "color_wheel.jpg", sizes);
575
576 // H2V2
577 sizes[0].set(512, 512);
578 sizes[1].set(256, 256);
579 sizes[2].set(256, 256);
580 codec_yuv(r, "mandrill_512_q075.jpg", sizes);
581
582 // H1V1
583 sizes[1].set(512, 512);
584 sizes[2].set(512, 512);
585 codec_yuv(r, "mandrill_h1v1.jpg", sizes);
586
587 // H2V1
588 sizes[1].set(256, 512);
589 sizes[2].set(256, 512);
590 codec_yuv(r, "mandrill_h2v1.jpg", sizes);
591
592 // Non-power of two dimensions
593 sizes[0].set(440, 154);
594 sizes[1].set(224, 77);
595 sizes[2].set(224, 77);
596 codec_yuv(r, "cropped_mandrill.jpg", sizes);
597
598 sizes[0].set(8, 8);
599 sizes[1].set(8, 4);
600 sizes[2].set(8, 4);
601 codec_yuv(r, "randPixels.jpg", sizes);
602
603 // Progressive images
604 sizes[0].set(512, 512);
605 sizes[1].set(512, 512);
606 sizes[2].set(512, 512);
607 codec_yuv(r, "brickwork-texture.jpg", sizes);
608 codec_yuv(r, "brickwork_normal-map.jpg", sizes);
609
610 // A CMYK encoded image should fail.
611 codec_yuv(r, "CMYK.jpg", nullptr);
612 // A grayscale encoded image should fail.
613 codec_yuv(r, "grayscale.jpg", nullptr);
614 // A PNG should fail.
615 codec_yuv(r, "arrow.png", nullptr);
616 }
OLDNEW
« src/codec/SkJpegCodec.cpp ('K') | « src/codec/SkJpegCodec.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698