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

Side by Side Diff: src/core/SkScalerContext.cpp

Issue 83093005: remove kA1_Config, as it is no longer supported (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 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 | Annotate | Revision Log
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2006 The Android Open Source Project 3 * Copyright 2006 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #include "SkScalerContext.h" 10 #include "SkScalerContext.h"
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 for (int x = 0; x < width; ++x) { 516 for (int x = 0; x < width; ++x) {
517 U8CPU r = sk_apply_lut_if<APPLY_PREBLEND>(*srcP++, maskPreBlend.fR); 517 U8CPU r = sk_apply_lut_if<APPLY_PREBLEND>(*srcP++, maskPreBlend.fR);
518 U8CPU g = sk_apply_lut_if<APPLY_PREBLEND>(*srcP++, maskPreBlend.fG); 518 U8CPU g = sk_apply_lut_if<APPLY_PREBLEND>(*srcP++, maskPreBlend.fG);
519 U8CPU b = sk_apply_lut_if<APPLY_PREBLEND>(*srcP++, maskPreBlend.fB); 519 U8CPU b = sk_apply_lut_if<APPLY_PREBLEND>(*srcP++, maskPreBlend.fB);
520 dstP[x] = SkPackARGB32(0xFF, r, g, b); 520 dstP[x] = SkPackARGB32(0xFF, r, g, b);
521 } 521 }
522 dstP = (SkPMColor*)((char*)dstP + dstRB); 522 dstP = (SkPMColor*)((char*)dstP + dstRB);
523 } 523 }
524 } 524 }
525 525
526 static inline int convert_8_to_1(unsigned byte) {
527 SkASSERT(byte <= 0xFF);
528 return byte >> 7;
529 }
530
531 static uint8_t pack_8_to_1(const uint8_t alpha[8]) {
532 unsigned bits = 0;
533 for (int i = 0; i < 8; ++i) {
534 bits |= convert_8_to_1(alpha[i]);
535 bits <<= 1;
536 }
537 return SkToU8(bits);
538 }
539
540 static void packA8ToA1(const SkMask& mask, const uint8_t* src, size_t srcRB) {
541 const int height = mask.fBounds.height();
542 const int width = mask.fBounds.width();
543 const int octs = width >> 3;
544 const int leftOverBits = width & 7;
545
546 uint8_t* dst = mask.fImage;
547 const int dstPad = mask.fRowBytes - SkAlign8(width);
548 SkASSERT(dstPad >= 0);
549
550 const int srcPad = srcRB - width;
551 SkASSERT(srcPad >= 0);
552
553 for (int y = 0; y < height; ++y) {
554 for (int i = 0; i < octs; ++i) {
555 *dst++ = pack_8_to_1(src);
556 src += 8;
557 }
558 if (leftOverBits > 0) {
559 unsigned bits = 0;
560 int shift = 7;
561 for (int i = 0; i < leftOverBits; ++i, --shift) {
562 bits |= convert_8_to_1(*src++ >> 7) << shift;
563 }
564 *dst++ = bits;
565 }
566 src += srcPad;
567 dst += dstPad;
568 }
569 }
570
526 static void generateMask(const SkMask& mask, const SkPath& path, 571 static void generateMask(const SkMask& mask, const SkPath& path,
527 const SkMaskGamma::PreBlend& maskPreBlend) { 572 const SkMaskGamma::PreBlend& maskPreBlend) {
528 SkBitmap::Config config; 573 SkPaint paint;
529 SkPaint paint;
530 574
531 int srcW = mask.fBounds.width(); 575 int srcW = mask.fBounds.width();
532 int srcH = mask.fBounds.height(); 576 int srcH = mask.fBounds.height();
533 int dstW = srcW; 577 int dstW = srcW;
534 int dstH = srcH; 578 int dstH = srcH;
535 int dstRB = mask.fRowBytes; 579 int dstRB = mask.fRowBytes;
536 580
537 SkMatrix matrix; 581 SkMatrix matrix;
538 matrix.setTranslate(-SkIntToScalar(mask.fBounds.fLeft), 582 matrix.setTranslate(-SkIntToScalar(mask.fBounds.fLeft),
539 -SkIntToScalar(mask.fBounds.fTop)); 583 -SkIntToScalar(mask.fBounds.fTop));
540 584
541 if (SkMask::kBW_Format == mask.fFormat) { 585 SkBitmap::Config config = SkBitmap::kA8_Config;
542 config = SkBitmap::kA1_Config; 586 paint.setAntiAlias(SkMask::kBW_Format != mask.fFormat);
543 paint.setAntiAlias(false); 587 switch (mask.fFormat) {
544 } else { 588 case SkMask::kBW_Format:
545 config = SkBitmap::kA8_Config; 589 dstRB = 0; // signals we need a copy
546 paint.setAntiAlias(true); 590 break;
547 switch (mask.fFormat) { 591 case SkMask::kA8_Format:
548 case SkMask::kA8_Format: 592 break;
549 break; 593 case SkMask::kLCD16_Format:
550 case SkMask::kLCD16_Format: 594 case SkMask::kLCD32_Format:
551 case SkMask::kLCD32_Format: 595 // TODO: trigger off LCD orientation
552 // TODO: trigger off LCD orientation 596 dstW = 4*dstW - 8;
553 dstW = 4*dstW - 8; 597 matrix.setTranslate(-SkIntToScalar(mask.fBounds.fLeft + 1),
554 matrix.setTranslate(-SkIntToScalar(mask.fBounds.fLeft + 1), 598 -SkIntToScalar(mask.fBounds.fTop));
555 -SkIntToScalar(mask.fBounds.fTop)); 599 matrix.postScale(SkIntToScalar(4), SK_Scalar1);
556 matrix.postScale(SkIntToScalar(4), SK_Scalar1); 600 dstRB = 0; // signals we need a copy
557 dstRB = 0; // signals we need a copy 601 break;
558 break; 602 default:
559 default: 603 SkDEBUGFAIL("unexpected mask format");
560 SkDEBUGFAIL("unexpected mask format");
561 }
562 } 604 }
563 605
564 SkRasterClip clip; 606 SkRasterClip clip;
565 clip.setRect(SkIRect::MakeWH(dstW, dstH)); 607 clip.setRect(SkIRect::MakeWH(dstW, dstH));
566 608
567 SkBitmap bm; 609 SkBitmap bm;
568 bm.setConfig(config, dstW, dstH, dstRB); 610 bm.setConfig(config, dstW, dstH, dstRB);
569 611
570 if (0 == dstRB) { 612 if (0 == dstRB) {
571 if (!bm.allocPixels()) { 613 if (!bm.allocPixels()) {
572 // can't allocate offscreen, so empty the mask and return 614 // can't allocate offscreen, so empty the mask and return
573 sk_bzero(mask.fImage, mask.computeImageSize()); 615 sk_bzero(mask.fImage, mask.computeImageSize());
574 return; 616 return;
575 } 617 }
576 bm.lockPixels(); 618 bm.lockPixels();
577 } else { 619 } else {
578 bm.setPixels(mask.fImage); 620 bm.setPixels(mask.fImage);
579 } 621 }
580 sk_bzero(bm.getPixels(), bm.getSafeSize()); 622 sk_bzero(bm.getPixels(), bm.getSafeSize());
581 623
582 SkDraw draw; 624 SkDraw draw;
583 draw.fRC = &clip; 625 draw.fRC = &clip;
584 draw.fClip = &clip.bwRgn(); 626 draw.fClip = &clip.bwRgn();
585 draw.fMatrix = &matrix; 627 draw.fMatrix = &matrix;
586 draw.fBitmap = &bm; 628 draw.fBitmap = &bm;
587 draw.drawPath(path, paint); 629 draw.drawPath(path, paint);
588 630
589 switch (mask.fFormat) { 631 switch (mask.fFormat) {
632 case SkMask::kBW_Format:
633 packA8ToA1(mask, bm.getAddr8(0, 0), bm.rowBytes());
634 break;
590 case SkMask::kA8_Format: 635 case SkMask::kA8_Format:
591 if (maskPreBlend.isApplicable()) { 636 if (maskPreBlend.isApplicable()) {
592 applyLUTToA8Mask(mask, maskPreBlend.fG); 637 applyLUTToA8Mask(mask, maskPreBlend.fG);
593 } 638 }
594 break; 639 break;
595 case SkMask::kLCD16_Format: 640 case SkMask::kLCD16_Format:
596 if (maskPreBlend.isApplicable()) { 641 if (maskPreBlend.isApplicable()) {
597 pack4xHToLCD16<true>(bm, mask, maskPreBlend); 642 pack4xHToLCD16<true>(bm, mask, maskPreBlend);
598 } else { 643 } else {
599 pack4xHToLCD16<false>(bm, mask, maskPreBlend); 644 pack4xHToLCD16<false>(bm, mask, maskPreBlend);
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
935 SkScalerContext* SkTypeface::createScalerContext(const SkDescriptor* desc, 980 SkScalerContext* SkTypeface::createScalerContext(const SkDescriptor* desc,
936 bool allowFailure) const { 981 bool allowFailure) const {
937 SkScalerContext* c = this->onCreateScalerContext(desc); 982 SkScalerContext* c = this->onCreateScalerContext(desc);
938 983
939 if (!c && !allowFailure) { 984 if (!c && !allowFailure) {
940 c = SkNEW_ARGS(SkScalerContext_Empty, 985 c = SkNEW_ARGS(SkScalerContext_Empty,
941 (const_cast<SkTypeface*>(this), desc)); 986 (const_cast<SkTypeface*>(this), desc));
942 } 987 }
943 return c; 988 return c;
944 } 989 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698