Ejemplo n.º 1
0
/*
 * Set an RLE pixel using the color table
 */
void SkBmpRLECodec::setPixel(void* dst, size_t dstRowBytes,
                             const SkImageInfo& dstInfo, uint32_t x, uint32_t y,
                             uint8_t index) {
    // Set the row
    int height = dstInfo.height();
    int row;
    if (SkBmpCodec::kBottomUp_RowOrder == this->rowOrder()) {
        row = height - y - 1;
    } else {
        row = y;
    }

    // Set the pixel based on destination color type
    switch (dstInfo.colorType()) {
        case kN32_SkColorType: {
            SkPMColor* dstRow = SkTAddOffset<SkPMColor>((SkPMColor*) dst,
                    row * (int) dstRowBytes);
            dstRow[x] = fColorTable->operator[](index);
            break;
        }
        case kRGB_565_SkColorType: {
            uint16_t* dstRow = SkTAddOffset<uint16_t>(dst, row * (int) dstRowBytes);
            dstRow[x] = SkPixel32ToPixel16(fColorTable->operator[](index));
            break;
        }
        default:
            // This case should not be reached.  We should catch an invalid
            // color type when we check that the conversion is possible.
            SkASSERT(false);
            break;
    }
}
Ejemplo n.º 2
0
 bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
                  const Options& options) override {
     REPORTER_ASSERT(fReporter, pixels != nullptr);
     REPORTER_ASSERT(fReporter, rowBytes >= info.minRowBytes());
     if (fType != kSucceedGetPixels_TestType) {
         return false;
     }
     if (info.colorType() != kN32_SkColorType && info.colorType() != getInfo().colorType()) {
         return false;
     }
     char* bytePtr = static_cast<char*>(pixels);
     switch (info.colorType()) {
         case kN32_SkColorType:
             for (int y = 0; y < info.height(); ++y) {
                 sk_memset32((uint32_t*)bytePtr,
                             TestImageGenerator::PMColor(), info.width());
                 bytePtr += rowBytes;
             }
             break;
         case kRGB_565_SkColorType:
             for (int y = 0; y < info.height(); ++y) {
                 sk_memset16((uint16_t*)bytePtr,
                     SkPixel32ToPixel16(TestImageGenerator::PMColor()), info.width());
                 bytePtr += rowBytes;
             }
             break;
         default:
             return false;
     }
     return true;
 }
Ejemplo n.º 3
0
/*
 * Set an RLE pixel using the color table
 */
void SkBmpRLECodec::setPixel(void* dst, size_t dstRowBytes,
                             const SkImageInfo& dstInfo, uint32_t x, uint32_t y,
                             uint8_t index) {
    if (dst && is_coord_necessary(x, fSampleX, dstInfo.width())) {
        // Set the row
        uint32_t row = this->getDstRow(y, dstInfo.height());

        // Set the pixel based on destination color type
        const int dstX = get_dst_coord(x, fSampleX);
        switch (dstInfo.colorType()) {
            case kRGBA_8888_SkColorType:
            case kBGRA_8888_SkColorType: {
                SkPMColor* dstRow = SkTAddOffset<SkPMColor>(dst, row * (int) dstRowBytes);
                dstRow[dstX] = fColorTable->operator[](index);
                break;
            }
            case kRGB_565_SkColorType: {
                uint16_t* dstRow = SkTAddOffset<uint16_t>(dst, row * (int) dstRowBytes);
                dstRow[dstX] = SkPixel32ToPixel16(fColorTable->operator[](index));
                break;
            }
            default:
                // This case should not be reached.  We should catch an invalid
                // color type when we check that the conversion is possible.
                SkASSERT(false);
                break;
        }
    }
}
Ejemplo n.º 4
0
static void make_image(SkBitmap* bm, SkColorType ct, int configIndex) {
    const int   width = 98;
    const int   height = 100;
    const SkImageInfo info = SkImageInfo::Make(width, height, ct, kPremul_SkAlphaType);

    SkBitmap    device;
    device.allocN32Pixels(width, height);
    SkCanvas    canvas(device);
    SkPaint     paint;

    paint.setAntiAlias(true);
    canvas.drawColor(SK_ColorRED);
    paint.setColor(SK_ColorBLUE);
    canvas.drawCircle(SkIntToScalar(width)/2, SkIntToScalar(height)/2,
                      SkIntToScalar(width)/2, paint);

    switch (ct) {
        case kPMColor_SkColorType:
            bm->swap(device);
            break;
        case kRGB_565_SkColorType: {
            bm->allocPixels(info);
            for (int y = 0; y < height; y++) {
                for (int x = 0; x < width; x++) {
                    *bm->getAddr16(x, y) = SkPixel32ToPixel16(*device.getAddr32(x, y));
                }
            }
            break;
        }
        case kIndex_8_SkColorType: {
            SkPMColor colors[256];
            for (int i = 0; i < 256; i++) {
                if (configIndex & 1) {
                    colors[i] = SkPackARGB32(255-i, 0, 0, 255-i);
                } else {
                    colors[i] = SkPackARGB32(0xFF, i, 0, 255-i);
                }
            }
            SkColorTable* ctable = new SkColorTable(colors, 256);
            bm->allocPixels(info, NULL, ctable);
            ctable->unref();
            for (int y = 0; y < height; y++) {
                for (int x = 0; x < width; x++) {
                    *bm->getAddr8(x, y) = SkGetPackedR32(*device.getAddr32(x, y));
                }
            }
            break;
        }
        default:
            SkASSERT(0);
    }
}
Ejemplo n.º 5
0
static uint16_t srcatop_modeproc16_255(SkPMColor src, uint16_t dst) {
    SkASSERT(require_255(src));
    return SkPixel32ToPixel16(src);
}
 virtual void filterSpan16(const uint16_t shader[], int count,
                           uint16_t result[]) {
     SkASSERT(this->getFlags() & kHasFilter16_Flag);
     sk_memset16(result, SkPixel32ToPixel16(fPMColor), count);
 }
Ejemplo n.º 7
0
SkColor color_to_565(SkColor color) {
    SkPMColor pmColor = SkPreMultiplyColor(color);
    U16CPU color16 = SkPixel32ToPixel16(pmColor);
    return SkPixel16ToColor(color16);
}
Ejemplo n.º 8
0
    }
}

// kIndex1, kIndex2, kIndex4

static void swizzle_small_index_to_565(
        void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
        int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {

    uint16_t* dst = (uint16_t*) dstRow;
    src += offset / 8;
    int bitIndex = offset % 8;
    uint8_t currByte = *src;
    const uint8_t mask = (1 << bpp) - 1;
    uint8_t index = (currByte >> (8 - bpp - bitIndex)) & mask;
    dst[0] = SkPixel32ToPixel16(ctable[index]);

    for (int x = 1; x < dstWidth; x++) {
        int bitOffset = bitIndex + deltaSrc;
        bitIndex = bitOffset % 8;
        currByte = *(src += bitOffset / 8);
        index = (currByte >> (8 - bpp - bitIndex)) & mask;
        dst[x] = SkPixel32ToPixel16(ctable[index]);
    }
}

static void swizzle_small_index_to_n32(
        void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
        int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {

    SkPMColor* dst = (SkPMColor*) dstRow;