OLD | NEW |
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 #include "SampleCode.h" | 7 #include "SampleCode.h" |
8 #include "Sk1DPathEffect.h" | 8 #include "Sk1DPathEffect.h" |
9 #include "Sk2DPathEffect.h" | 9 #include "Sk2DPathEffect.h" |
10 #include "SkAlphaThresholdFilter.h" | 10 #include "SkAlphaThresholdFilter.h" |
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 light); | 480 light); |
481 } | 481 } |
482 case 2: | 482 case 2: |
483 default: | 483 default: |
484 maskFilter = nullptr; | 484 maskFilter = nullptr; |
485 break; | 485 break; |
486 } | 486 } |
487 return maskFilter; | 487 return maskFilter; |
488 } | 488 } |
489 | 489 |
490 static sk_sp<SkImageFilter> make_image_filter(bool canBeNull = true); | 490 static SkImageFilter* make_image_filter(bool canBeNull = true); |
491 | 491 |
492 static SkPaint make_paint() { | 492 static SkPaint make_paint() { |
493 SkPaint paint; | 493 SkPaint paint; |
494 paint.setHinting(make_paint_hinting()); | 494 paint.setHinting(make_paint_hinting()); |
495 paint.setAntiAlias(make_bool()); | 495 paint.setAntiAlias(make_bool()); |
496 paint.setDither(make_bool()); | 496 paint.setDither(make_bool()); |
497 paint.setLinearText(make_bool()); | 497 paint.setLinearText(make_bool()); |
498 paint.setSubpixelText(make_bool()); | 498 paint.setSubpixelText(make_bool()); |
499 paint.setLCDRenderText(make_bool()); | 499 paint.setLCDRenderText(make_bool()); |
500 paint.setEmbeddedBitmapText(make_bool()); | 500 paint.setEmbeddedBitmapText(make_bool()); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 paint.setImageFilter(make_image_filter()); | 533 paint.setImageFilter(make_image_filter()); |
534 sk_sp<SkData> data(make_3Dlut(nullptr, make_bool(), make_bool(), make_bool()
)); | 534 sk_sp<SkData> data(make_3Dlut(nullptr, make_bool(), make_bool(), make_bool()
)); |
535 paint.setTextAlign(make_paint_align()); | 535 paint.setTextAlign(make_paint_align()); |
536 paint.setTextSize(make_scalar()); | 536 paint.setTextSize(make_scalar()); |
537 paint.setTextScaleX(make_scalar()); | 537 paint.setTextScaleX(make_scalar()); |
538 paint.setTextSkewX(make_scalar()); | 538 paint.setTextSkewX(make_scalar()); |
539 paint.setTextEncoding(make_paint_text_encoding()); | 539 paint.setTextEncoding(make_paint_text_encoding()); |
540 return paint; | 540 return paint; |
541 } | 541 } |
542 | 542 |
543 static sk_sp<SkImageFilter> make_image_filter(bool canBeNull) { | 543 static SkImageFilter* make_image_filter(bool canBeNull) { |
544 sk_sp<SkImageFilter> filter; | 544 SkImageFilter* filter = 0; |
545 | 545 |
546 // Add a 1 in 3 chance to get a nullptr input | 546 // Add a 1 in 3 chance to get a nullptr input |
547 if (canBeNull && (R(3) == 1)) { | 547 if (canBeNull && (R(3) == 1)) { return filter; } |
548 return filter; | |
549 } | |
550 | 548 |
551 enum { ALPHA_THRESHOLD, MERGE, COLOR, LUT3D, BLUR, MAGNIFIER, | 549 enum { ALPHA_THRESHOLD, MERGE, COLOR, LUT3D, BLUR, MAGNIFIER, |
552 DOWN_SAMPLE, XFERMODE, OFFSET, MATRIX, MATRIX_CONVOLUTION, COMPOSE, | 550 DOWN_SAMPLE, XFERMODE, OFFSET, MATRIX, MATRIX_CONVOLUTION, COMPOSE, |
553 DISTANT_LIGHT, POINT_LIGHT, SPOT_LIGHT, NOISE, DROP_SHADOW, | 551 DISTANT_LIGHT, POINT_LIGHT, SPOT_LIGHT, NOISE, DROP_SHADOW, |
554 MORPHOLOGY, BITMAP, DISPLACE, TILE, PICTURE, PAINT, NUM_FILTERS }; | 552 MORPHOLOGY, BITMAP, DISPLACE, TILE, PICTURE, PAINT, NUM_FILTERS }; |
555 | 553 |
556 switch (R(NUM_FILTERS)) { | 554 switch (R(NUM_FILTERS)) { |
557 case ALPHA_THRESHOLD: | 555 case ALPHA_THRESHOLD: |
558 filter = sk_sp<SkImageFilter>(SkAlphaThresholdFilter::Create(make_region
(), | 556 filter = SkAlphaThresholdFilter::Create(make_region(), make_scalar(), ma
ke_scalar()); |
559 make_scalar
(), | |
560 make_scalar
())); | |
561 break; | 557 break; |
562 case MERGE: { | 558 case MERGE: |
563 sk_sp<SkImageFilter> subFilter1(make_image_filter()); | 559 filter = SkMergeImageFilter::Create(make_image_filter(), make_image_filt
er(), make_xfermode()); |
564 sk_sp<SkImageFilter> subFilter2(make_image_filter()); | |
565 filter = sk_sp<SkImageFilter>(SkMergeImageFilter::Create(subFilter1.get(
), | |
566 subFilter2.get(
), | |
567 make_xfermode()
)); | |
568 break; | 560 break; |
| 561 case COLOR: |
| 562 { |
| 563 sk_sp<SkColorFilter> cf(make_color_filter()); |
| 564 filter = cf ? SkColorFilterImageFilter::Create(cf.get(), make_image_filt
er()) : 0; |
569 } | 565 } |
570 case COLOR: { | |
571 sk_sp<SkColorFilter> cf(make_color_filter()); | |
572 sk_sp<SkImageFilter> subFilter(make_image_filter()); | |
573 filter = cf ? sk_sp<SkImageFilter>(SkColorFilterImageFilter::Create(cf.g
et(), | |
574 subF
ilter.get())) | |
575 : nullptr; | |
576 break; | 566 break; |
577 } | 567 case LUT3D: |
578 case LUT3D: { | 568 { |
579 int cubeDimension; | 569 int cubeDimension; |
580 sk_sp<SkData> lut3D(make_3Dlut(&cubeDimension, (R(2) == 1), (R(2) == 1),
(R(2) == 1))); | 570 sk_sp<SkData> lut3D(make_3Dlut(&cubeDimension, (R(2) == 1), (R(2) == 1),
(R(2) == 1))); |
581 sk_sp<SkColorFilter> cf(SkColorCubeFilter::Make(lut3D, cubeDimension)); | 571 sk_sp<SkColorFilter> cf(SkColorCubeFilter::Make(lut3D, cubeDimension)); |
582 sk_sp<SkImageFilter> subFilter(make_image_filter()); | 572 filter = cf ? SkColorFilterImageFilter::Create(cf.get(), make_image_filt
er()) : 0; |
583 filter = cf ? sk_sp<SkImageFilter>(SkColorFilterImageFilter::Create(cf.g
et(), | 573 } |
584 subF
ilter.get())) | |
585 : nullptr; | |
586 break; | 574 break; |
587 } | 575 case BLUR: |
588 case BLUR: { | 576 filter = SkBlurImageFilter::Create(make_scalar(true), make_scalar(true),
make_image_filter()); |
589 sk_sp<SkImageFilter> subFilter(make_image_filter()); | |
590 filter = sk_sp<SkImageFilter>(SkBlurImageFilter::Create(make_scalar(true
), | |
591 make_scalar(true
), | |
592 subFilter.get())
); | |
593 break; | 577 break; |
594 } | |
595 case MAGNIFIER: | 578 case MAGNIFIER: |
596 filter = sk_sp<SkImageFilter>(SkMagnifierImageFilter::Create(make_rect()
, | 579 filter = SkMagnifierImageFilter::Create(make_rect(), make_scalar(true)); |
597 make_scalar
(true))); | |
598 break; | 580 break; |
599 case DOWN_SAMPLE: | 581 case DOWN_SAMPLE: |
600 filter = sk_sp<SkImageFilter>(SkDownSampleImageFilter::Create(make_scala
r())); | 582 filter = SkDownSampleImageFilter::Create(make_scalar()); |
601 break; | 583 break; |
602 case XFERMODE: { | 584 case XFERMODE: |
603 sk_sp<SkImageFilter> subFilter1(make_image_filter()); | |
604 sk_sp<SkImageFilter> subFilter2(make_image_filter()); | |
605 filter = SkXfermodeImageFilter::Make(SkXfermode::Make(make_xfermode()), | 585 filter = SkXfermodeImageFilter::Make(SkXfermode::Make(make_xfermode()), |
606 subFilter1.get(), | 586 make_image_filter(), make_image_fil
ter(), |
607 subFilter2.get(), | 587 nullptr).release(); |
608 nullptr); | |
609 break; | 588 break; |
610 } | 589 case OFFSET: |
611 case OFFSET: { | 590 filter = SkOffsetImageFilter::Create(make_scalar(), make_scalar(), make_
image_filter()); |
612 sk_sp<SkImageFilter> subFilter(make_image_filter()); | |
613 filter = sk_sp<SkImageFilter>(SkOffsetImageFilter::Create(make_scalar(),
make_scalar(), | |
614 subFilter.get(
))); | |
615 break; | 591 break; |
616 } | 592 case MATRIX: |
617 case MATRIX: { | 593 filter = SkImageFilter::CreateMatrixFilter(make_matrix(), |
618 sk_sp<SkImageFilter> subFilter(make_image_filter()); | 594 (SkFilterQuality)R(4), |
619 filter = sk_sp<SkImageFilter>(SkImageFilter::CreateMatrixFilter(make_mat
rix(), | 595 make_image_filter()); |
620 (SkFilte
rQuality)R(4), | |
621 subFilte
r.get())); | |
622 break; | 596 break; |
623 } | 597 case MATRIX_CONVOLUTION: |
624 case MATRIX_CONVOLUTION: { | 598 { |
625 SkImageFilter::CropRect cropR(SkRect::MakeWH(SkIntToScalar(kBitmapSize), | 599 SkImageFilter::CropRect cropR(SkRect::MakeWH(SkIntToScalar(kBitmapSize), |
626 SkIntToScalar(kBitmapSize))
); | 600 SkIntToScalar(kBitmapSize))
); |
627 SkISize size = SkISize::Make(R(10)+1, R(10)+1); | 601 SkISize size = SkISize::Make(R(10)+1, R(10)+1); |
628 int arraySize = size.width() * size.height(); | 602 int arraySize = size.width() * size.height(); |
629 SkTArray<SkScalar> kernel(arraySize); | 603 SkTArray<SkScalar> kernel(arraySize); |
630 for (int i = 0; i < arraySize; ++i) { | 604 for (int i = 0; i < arraySize; ++i) { |
631 kernel.push_back() = make_scalar(); | 605 kernel.push_back() = make_scalar(); |
632 } | 606 } |
633 SkIPoint kernelOffset = SkIPoint::Make(R(SkIntToScalar(size.width())), | 607 SkIPoint kernelOffset = SkIPoint::Make(R(SkIntToScalar(size.width())), |
634 R(SkIntToScalar(size.height()))); | 608 R(SkIntToScalar(size.height()))); |
635 sk_sp<SkImageFilter> subFilter(make_image_filter()); | 609 filter = SkMatrixConvolutionImageFilter::Create(size, |
636 | |
637 filter = sk_sp<SkImageFilter>(SkMatrixConvolutionImageFilter::Create( | |
638 size, | |
639 kernel.begin(), | 610 kernel.begin(), |
640 make_scalar(), | 611 make_scalar(), |
641 make_scalar(), | 612 make_scalar(), |
642 kernelOffset, | 613 kernelOffset, |
643 (SkMatrixConvolutionImag
eFilter::TileMode)R(3), | 614 (SkMatrixConvolutionImag
eFilter::TileMode)R(3), |
644 R(2) == 1, | 615 R(2) == 1, |
645 subFilter.get(), | 616 make_image_filter(), |
646 &cropR)); | 617 &cropR); |
| 618 } |
647 break; | 619 break; |
648 } | 620 case COMPOSE: |
649 case COMPOSE: { | 621 filter = SkComposeImageFilter::Create(make_image_filter(), make_image_fi
lter()); |
650 sk_sp<SkImageFilter> subFilter1(make_image_filter()); | |
651 sk_sp<SkImageFilter> subFilter2(make_image_filter()); | |
652 filter = sk_sp<SkImageFilter>(SkComposeImageFilter::Create(subFilter1.ge
t(), | |
653 subFilter2.ge
t())); | |
654 break; | 622 break; |
655 } | 623 case DISTANT_LIGHT: |
656 case DISTANT_LIGHT: { | 624 filter = (R(2) == 1) ? |
657 sk_sp<SkImageFilter> subFilter(make_image_filter()); | 625 SkLightingImageFilter::CreateDistantLitDiffuse(make_point(), |
658 | 626 make_color(), make_scalar(), make_scalar(), make_image_filter()
) : |
659 filter = (R(2) == 1) | 627 SkLightingImageFilter::CreateDistantLitSpecular(make_point(), |
660 ? sk_sp<SkImageFilter>(SkLightingImageFilter::CreateDistantLitD
iffuse(make_point(), | 628 make_color(), make_scalar(), make_scalar(), SkIntToScalar(R(10)
), |
661 make_color(), make_scalar(), mak
e_scalar(), | 629 make_image_filter()); |
662 subFilter.get())) | |
663 : sk_sp<SkImageFilter>(SkLightingImageFilter::CreateDistantLitS
pecular(make_point(), | |
664 make_color(), make_scalar(), | |
665 make_scalar(), SkIntToScalar(R(1
0)), | |
666 subFilter.get())); | |
667 break; | 630 break; |
668 } | 631 case POINT_LIGHT: |
669 case POINT_LIGHT: { | 632 filter = (R(2) == 1) ? |
670 sk_sp<SkImageFilter> subFilter(make_image_filter()); | 633 SkLightingImageFilter::CreatePointLitDiffuse(make_point(), |
671 | 634 make_color(), make_scalar(), make_scalar(), make_image_filter()
) : |
672 filter = (R(2) == 1) | 635 SkLightingImageFilter::CreatePointLitSpecular(make_point(), |
673 ? sk_sp<SkImageFilter>(SkLightingImageFilter::CreatePointLitDif
fuse(make_point(), | 636 make_color(), make_scalar(), make_scalar(), SkIntToScalar(R(10)
), |
674 make_color(), make_scalar(), mak
e_scalar(), | 637 make_image_filter()); |
675 subFilter.get())) | |
676 : sk_sp<SkImageFilter>(SkLightingImageFilter::CreatePointLitSpe
cular(make_point(), | |
677 make_color(), make_scalar(), mak
e_scalar(), | |
678 SkIntToScalar(R(10)), | |
679 subFilter.get())); | |
680 break; | 638 break; |
681 } | 639 case SPOT_LIGHT: |
682 case SPOT_LIGHT: { | 640 filter = (R(2) == 1) ? |
683 sk_sp<SkImageFilter> subFilter(make_image_filter()); | 641 SkLightingImageFilter::CreateSpotLitDiffuse(SkPoint3::Make(0, 0
, 0), |
684 | 642 make_point(), make_scalar(), make_scalar(), make_color(), |
685 filter = (R(2) == 1) | 643 make_scalar(), make_scalar(), make_image_filter()) : |
686 ? sk_sp<SkImageFilter>(SkLightingImageFilter::CreateSpotLitDiff
use(SkPoint3::Make(0, 0, 0), | 644 SkLightingImageFilter::CreateSpotLitSpecular(SkPoint3::Make(0,
0, 0), |
687 make_point(), make_scalar(), ma
ke_scalar(), | 645 make_point(), make_scalar(), make_scalar(), make_color(), |
688 make_color(), make_scalar(), ma
ke_scalar(), | 646 make_scalar(), make_scalar(), SkIntToScalar(R(10)), make_image_
filter()); |
689 subFilter.get())) | |
690 : sk_sp<SkImageFilter>(SkLightingImageFilter::CreateSpotLitSpec
ular(SkPoint3::Make(0, 0, 0), | |
691 make_point(), make_scalar(), ma
ke_scalar(), | |
692 make_color(), make_scalar(), ma
ke_scalar(), | |
693 SkIntToScalar(R(10)), subFilter
.get())); | |
694 break; | 647 break; |
695 } | 648 case NOISE: |
696 case NOISE: { | 649 { |
697 sk_sp<SkShader> shader((R(2) == 1) ? | 650 sk_sp<SkShader> shader((R(2) == 1) ? |
698 SkPerlinNoiseShader::MakeFractalNoise( | 651 SkPerlinNoiseShader::MakeFractalNoise( |
699 make_scalar(true), make_scalar(true), R(10.0f), make_scalar()) : | 652 make_scalar(true), make_scalar(true), R(10.0f), make_scalar()) : |
700 SkPerlinNoiseShader::MakeTurbulence( | 653 SkPerlinNoiseShader::MakeTurbulence( |
701 make_scalar(true), make_scalar(true), R(10.0f), make_scalar())); | 654 make_scalar(true), make_scalar(true), R(10.0f), make_scalar())); |
702 SkPaint paint; | 655 SkPaint paint; |
703 paint.setShader(shader); | 656 paint.setShader(shader); |
704 SkImageFilter::CropRect cropR(SkRect::MakeWH(SkIntToScalar(kBitmapSize), | 657 SkImageFilter::CropRect cropR(SkRect::MakeWH(SkIntToScalar(kBitmapSize), |
705 SkIntToScalar(kBitmapSize))
); | 658 SkIntToScalar(kBitmapSize))
); |
706 filter = SkPaintImageFilter::Make(paint, &cropR); | 659 filter = SkPaintImageFilter::Create(paint, &cropR); |
| 660 } |
707 break; | 661 break; |
708 } | 662 case DROP_SHADOW: |
709 case DROP_SHADOW: { | 663 filter = SkDropShadowImageFilter::Create(make_scalar(), make_scalar(), m
ake_scalar(true), |
710 sk_sp<SkImageFilter> subFilter(make_image_filter()); | 664 make_scalar(true), make_color(), make_shadow_mode(), make_im
age_filter(), |
711 | 665 nullptr); |
712 filter = sk_sp<SkImageFilter>(SkDropShadowImageFilter::Create(make_scala
r(), | |
713 make_scala
r(), | |
714 make_scala
r(true), | |
715 make_scala
r(true), | |
716 make_color
(), | |
717 make_shado
w_mode(), | |
718 subFilter.
get(), | |
719 nullptr)); | |
720 break; | 666 break; |
721 } | 667 case MORPHOLOGY: |
722 case MORPHOLOGY: { | |
723 sk_sp<SkImageFilter> subFilter(make_image_filter()); | |
724 | |
725 if (R(2) == 1) { | 668 if (R(2) == 1) { |
726 filter = sk_sp<SkImageFilter>(SkDilateImageFilter::Create(R(static_c
ast<float>(kBitmapSize)), | 669 filter = SkDilateImageFilter::Create(R(static_cast<float>(kBitmapSiz
e)), |
727 R(static_cast<float>(kBitmapSize
)), | 670 R(static_cast<float>(kBitmapSize)), make_image_filter()); |
728 subFilter.get())); | |
729 } else { | 671 } else { |
730 filter = sk_sp<SkImageFilter>(SkErodeImageFilter::Create(R(static_ca
st<float>(kBitmapSize)), | 672 filter = SkErodeImageFilter::Create(R(static_cast<float>(kBitmapSize
)), |
731 R(static_cast<float>(kBitmapSize
)), | 673 R(static_cast<float>(kBitmapSize)), make_image_filter()); |
732 subFilter.get())); | |
733 } | 674 } |
734 break; | 675 break; |
735 } | 676 case BITMAP: |
736 case BITMAP: { | 677 { |
737 sk_sp<SkImage> image(SkImage::MakeFromBitmap(make_bitmap())); | 678 sk_sp<SkImage> image(SkImage::MakeFromBitmap(make_bitmap())); |
738 if (R(2) == 1) { | 679 if (R(2) == 1) { |
739 filter = sk_sp<SkImageFilter>(SkImageSource::Create(image.get(), | 680 filter = SkImageSource::Create(image.get(), make_rect(), make_rect()
, kHigh_SkFilterQuality); |
740 make_rect(), | |
741 make_rect(), | |
742 kHigh_SkFilterQu
ality)); | |
743 } else { | 681 } else { |
744 filter = sk_sp<SkImageFilter>(SkImageSource::Create(image.get())); | 682 filter = SkImageSource::Create(image.get()); |
745 } | 683 } |
| 684 } |
746 break; | 685 break; |
747 } | 686 case DISPLACE: |
748 case DISPLACE: { | 687 filter = SkDisplacementMapEffect::Create(make_channel_selector_type(), |
749 sk_sp<SkImageFilter> subFilter1(make_image_filter(false)); | 688 make_channel_selector_type(), m
ake_scalar(), |
750 sk_sp<SkImageFilter> subFilter2(make_image_filter()); | 689 make_image_filter(false), make_
image_filter()); |
751 | |
752 filter = sk_sp<SkImageFilter>(SkDisplacementMapEffect::Create(make_chann
el_selector_type(), | |
753 make_chann
el_selector_type(), | |
754 make_scala
r(), | |
755 subFilter1
.get(), | |
756 subFilter2
.get())); | |
757 break; | 690 break; |
758 } | 691 case TILE: |
759 case TILE: { | 692 filter = SkTileImageFilter::Create(make_rect(), make_rect(), make_image_
filter(false)); |
760 sk_sp<SkImageFilter> subFilter(make_image_filter(false)); | |
761 | |
762 filter = sk_sp<SkImageFilter>(SkTileImageFilter::Create(make_rect(), | |
763 make_rect(), | |
764 subFilter.get())
); | |
765 break; | 693 break; |
766 } | 694 case PICTURE: |
767 case PICTURE: { | 695 { |
768 SkRTreeFactory factory; | 696 SkRTreeFactory factory; |
769 SkPictureRecorder recorder; | 697 SkPictureRecorder recorder; |
770 SkCanvas* recordingCanvas = recorder.beginRecording(SkIntToScalar(kBitma
pSize), | 698 SkCanvas* recordingCanvas = recorder.beginRecording(SkIntToScalar(kBitma
pSize), |
771 SkIntToScalar(kBitma
pSize), | 699 SkIntToScalar(kBitma
pSize), |
772 &factory, 0); | 700 &factory, 0); |
773 drawSomething(recordingCanvas); | 701 drawSomething(recordingCanvas); |
774 sk_sp<SkPicture> pict(recorder.finishRecordingAsPicture()); | 702 sk_sp<SkPicture> pict(recorder.finishRecordingAsPicture()); |
775 filter = SkPictureImageFilter::Make(pict, make_rect()); | 703 filter = SkPictureImageFilter::Make(pict, make_rect()).release(); |
| 704 } |
776 break; | 705 break; |
777 } | 706 case PAINT: |
778 case PAINT: { | 707 { |
779 SkImageFilter::CropRect cropR(make_rect()); | 708 SkImageFilter::CropRect cropR(make_rect()); |
780 filter = SkPaintImageFilter::Make(make_paint(), &cropR); | 709 filter = SkPaintImageFilter::Create(make_paint(), &cropR); |
781 break; | |
782 } | 710 } |
783 default: | 711 default: |
784 break; | 712 break; |
785 } | 713 } |
786 return (filter || canBeNull) ? filter : make_image_filter(canBeNull); | 714 return (filter || canBeNull) ? filter : make_image_filter(canBeNull); |
787 } | 715 } |
788 | 716 |
789 static SkImageFilter* make_serialized_image_filter() { | 717 static SkImageFilter* make_serialized_image_filter() { |
790 sk_sp<SkImageFilter> filter(make_image_filter(false)); | 718 SkAutoTUnref<SkImageFilter> filter(make_image_filter(false)); |
791 SkAutoTUnref<SkData> data(SkValidatingSerializeFlattenable(filter.get())); | 719 SkAutoTUnref<SkData> data(SkValidatingSerializeFlattenable(filter)); |
792 const unsigned char* ptr = static_cast<const unsigned char*>(data->data()); | 720 const unsigned char* ptr = static_cast<const unsigned char*>(data->data()); |
793 size_t len = data->size(); | 721 size_t len = data->size(); |
794 #ifdef SK_ADD_RANDOM_BIT_FLIPS | 722 #ifdef SK_ADD_RANDOM_BIT_FLIPS |
795 unsigned char* p = const_cast<unsigned char*>(ptr); | 723 unsigned char* p = const_cast<unsigned char*>(ptr); |
796 for (size_t i = 0; i < len; ++i, ++p) { | 724 for (size_t i = 0; i < len; ++i, ++p) { |
797 if (R(250) == 1) { // 0.4% of the time, flip a bit or byte | 725 if (R(250) == 1) { // 0.4% of the time, flip a bit or byte |
798 if (R(10) == 1) { // Then 10% of the time, change a whole byte | 726 if (R(10) == 1) { // Then 10% of the time, change a whole byte |
799 switch(R(3)) { | 727 switch(R(3)) { |
800 case 0: | 728 case 0: |
801 *p ^= 0xFF; // Flip entire byte | 729 *p ^= 0xFF; // Flip entire byte |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
876 } | 804 } |
877 | 805 |
878 private: | 806 private: |
879 typedef SkView INHERITED; | 807 typedef SkView INHERITED; |
880 }; | 808 }; |
881 | 809 |
882 ////////////////////////////////////////////////////////////////////////////// | 810 ////////////////////////////////////////////////////////////////////////////// |
883 | 811 |
884 static SkView* MyFactory() { return new ImageFilterFuzzView; } | 812 static SkView* MyFactory() { return new ImageFilterFuzzView; } |
885 static SkViewRegister reg(MyFactory); | 813 static SkViewRegister reg(MyFactory); |
OLD | NEW |