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

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: Add a test to DM Created 4 years, 11 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
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 SkCodec::YUVPlanesSizes* expectedSizes) {
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 queryYUV8()
517 SkCodec::YUVPlanesSizes sizes;
518 SkCodec::YUVPlanesWidthBytes widthBytes;
519 bool success = codec->queryYUV8(nullptr, nullptr, nullptr);
520 REPORTER_ASSERT(reporter, !success);
521 success = codec->queryYUV8(&sizes, nullptr, nullptr);
522 REPORTER_ASSERT(reporter, !success);
523 success = codec->queryYUV8(nullptr, &widthBytes, nullptr);
524 REPORTER_ASSERT(reporter, !success);
525 success = codec->queryYUV8(&sizes, &widthBytes, nullptr);
526 REPORTER_ASSERT(reporter, (expectedSizes == nullptr) == !success);
527 if (!success) {
528 return;
529 }
530 REPORTER_ASSERT(reporter,
531 0 == memcmp((const void*) &sizes, (const void*) expectedSizes, sizeo f(sizes)));
532 REPORTER_ASSERT(reporter, widthBytes.YWidthBytes == (uint32_t) SkAlign8(size s.YSize.width()));
533 REPORTER_ASSERT(reporter, widthBytes.UWidthBytes == (uint32_t) SkAlign8(size s.USize.width()));
534 REPORTER_ASSERT(reporter, widthBytes.VWidthBytes == (uint32_t) SkAlign8(size s.VSize.width()));
535 SkYUVColorSpace colorSpace;
536 success = codec->queryYUV8(&sizes, &widthBytes, &colorSpace);
537 REPORTER_ASSERT(reporter,
538 0 == memcmp((const void*) &sizes, (const void*) expectedSizes, s izeof(sizes)));
539 REPORTER_ASSERT(reporter, widthBytes.YWidthBytes == (uint32_t) SkAlign8(size s.YSize.width()));
540 REPORTER_ASSERT(reporter, widthBytes.UWidthBytes == (uint32_t) SkAlign8(size s.USize.width()));
541 REPORTER_ASSERT(reporter, widthBytes.VWidthBytes == (uint32_t) SkAlign8(size s.VSize.width()));
542 REPORTER_ASSERT(reporter, kJPEG_SkYUVColorSpace == colorSpace);
543
544 // Allocate the memory for the YUV decode
545 size_t totalBytes = widthBytes.YWidthBytes * sizes.YSize.height() +
546 widthBytes.UWidthBytes * sizes.USize.height() +
547 widthBytes.VWidthBytes * sizes.VSize.height();
548 SkAutoMalloc storage(totalBytes);
549 void* planes[3];
550 planes[0] = storage.get();
551 planes[1] = SkTAddOffset<void>(planes[0], widthBytes.YWidthBytes * sizes.YSi ze.height());
552 planes[2] = SkTAddOffset<void>(planes[1], widthBytes.UWidthBytes * sizes.USi ze.height());
553
554 // Test getYUV8Planes()
555 REPORTER_ASSERT(reporter, SkCodec::kInvalidInput ==
556 codec->getYUV8Planes(&sizes, planes, nullptr));
557 REPORTER_ASSERT(reporter, SkCodec::kInvalidInput ==
558 codec->getYUV8Planes(&sizes, nullptr, &widthBytes));
559 REPORTER_ASSERT(reporter, SkCodec::kInvalidInput ==
560 codec->getYUV8Planes(nullptr, planes, &widthBytes));
561 REPORTER_ASSERT(reporter, SkCodec::kSuccess ==
562 codec->getYUV8Planes(&sizes, planes, &widthBytes));
563 }
564
565 DEF_TEST(Jpeg_YUV_Codec, r) {
566 SkCodec::YUVPlanesSizes sizes;
567
568 sizes.YSize.set(128, 128);
569 sizes.USize.set(64, 64);
570 sizes.VSize.set(64, 64);
571 codec_yuv(r, "color_wheel.jpg", &sizes);
572
573 // H2V2
574 sizes.YSize.set(512, 512);
575 sizes.USize.set(256, 256);
576 sizes.VSize.set(256, 256);
577 codec_yuv(r, "mandrill_512_q075.jpg", &sizes);
578
579 // H1V1
580 sizes.USize.set(512, 512);
581 sizes.VSize.set(512, 512);
582 codec_yuv(r, "mandrill_h1v1.jpg", &sizes);
583
584 // H2V1
585 sizes.USize.set(256, 512);
586 sizes.VSize.set(256, 512);
587 codec_yuv(r, "mandrill_h2v1.jpg", &sizes);
588
589 // Non-power of two dimensions
590 sizes.YSize.set(439, 154);
591 sizes.USize.set(220, 77);
592 sizes.VSize.set(220, 77);
593 codec_yuv(r, "cropped_mandrill.jpg", &sizes);
594
595 sizes.YSize.set(8, 8);
596 sizes.USize.set(4, 4);
597 sizes.VSize.set(4, 4);
598 codec_yuv(r, "randPixels.jpg", &sizes);
599
600 // Progressive images
601 sizes.YSize.set(512, 512);
602 sizes.USize.set(512, 512);
603 sizes.VSize.set(512, 512);
604 codec_yuv(r, "brickwork-texture.jpg", &sizes);
605 codec_yuv(r, "brickwork_normal-map.jpg", &sizes);
606
607 // A CMYK encoded image should fail.
608 codec_yuv(r, "CMYK.jpg", nullptr);
609 // A grayscale encoded image should fail.
610 codec_yuv(r, "grayscale.jpg", nullptr);
611 // A PNG should fail.
612 codec_yuv(r, "arrow.png", nullptr);
613 }
OLDNEW
« src/codec/SkCodecImageGenerator.cpp ('K') | « src/codec/SkJpegCodec.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698