Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

Quelle  SkMasks.cpp

  Sprache: C
 

/*
 * Copyright 2015 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "src/core/SkMasks.h"

#include "include/private/base/SkDebug.h"

/*
 *
 * Used to convert 1-7 bit color components into 8-bit color components
 *
 */

static constexpr uint8_t n_bit_to_8_bit_lookup_table[] = {
    // 1 bit
    0255,
    // 2 bits
    085170255,
    // 3 bits
    03673109146182219255,
    // 4 bits
    01734516885102119136153170187204221238255,
    // 5 bits
    081625334149586674829099107115123132140,
    148156165173181189197206214222230239247255,
    // 6 bits
    04812162024283236404549535761656973,
    778185899397101105109113117121125130134138,
    142146150154158162166170174178182186190194198,
    202206210215219223227231235239243247251255,
    // 7 bits
    02468101214161820222426283032343638,
    40424446485052545658606264666870727476,
    7880828486889092949698100102104106108110,
    112114116118120122124126129131133135137139141,
    143145147149151153155157159161163165167169171,
    173175177179181183185187189191193195197199201,
    203205207209211213215217219221223225227229231,
    233235237239241243245247249251253255
};

/*
 *
 * Convert an n bit component to an 8-bit component
 *
 */

static uint8_t convert_to_8(uint8_t component, uint32_t n) {
    if (0 == n) {
        return 0;
    } else if (8 > n) {
        return n_bit_to_8_bit_lookup_table[(1 << n) - 2 + component];
    } else {
        SkASSERT(8 == n);
        return component;
    }
}

static uint8_t get_comp(uint32_t pixel, uint32_t mask, uint32_t shift,
                        uint32_t size) {
    return convert_to_8((pixel & mask) >> shift, size);
}

/*
 *
 * Get a color component
 *
 */

uint8_t SkMasks::getRed(uint32_t pixel) const {
    return get_comp(pixel, fRed.mask, fRed.shift, fRed.size);
}
uint8_t SkMasks::getGreen(uint32_t pixel) const {
    return get_comp(pixel, fGreen.mask, fGreen.shift, fGreen.size);
}
uint8_t SkMasks::getBlue(uint32_t pixel) const {
    return get_comp(pixel, fBlue.mask, fBlue.shift, fBlue.size);
}
uint8_t SkMasks::getAlpha(uint32_t pixel) const {
    return get_comp(pixel, fAlpha.mask, fAlpha.shift, fAlpha.size);
}

/*
 *
 * Process an input mask to obtain the necessary information
 *
 */

static SkMasks::MaskInfo process_mask(uint32_t mask) {
    // Determine properties of the mask
    uint32_t tempMask = mask;
    uint32_t shift = 0;
    uint32_t size = 0;
    if (tempMask != 0) {
        // Count trailing zeros on masks
        for (; (tempMask & 1) == 0; tempMask >>= 1) {
            shift++;
        }
        // Count the size of the mask
        for (; tempMask & 1; tempMask >>= 1) {
            size++;
        }
        // Verify that the mask is continuous
        if (tempMask) {
            SkDebugf("Warning: Bit mask is not continuous.\n");
            // Finish processing the mask
            for (; tempMask; tempMask >>= 1) {
                size++;
            }
        }
        // Truncate masks greater than 8 bits
        if (size > 8) {
            shift += size - 8;
            size = 8;
            mask &= 0xFF << shift;
        }
    }

    return { mask, shift, size };
}

/*
 *
 * Create the masks object
 *
 */

SkMasks* SkMasks::CreateMasks(InputMasks masks, int bytesPerPixel) {
    SkASSERT(0 < bytesPerPixel && bytesPerPixel <= 4);

    // Trim the input masks to match bytesPerPixel.
    if (bytesPerPixel < 4) {
        int bitsPerPixel = 8*bytesPerPixel;
        masks.red   &= (1 << bitsPerPixel) - 1;
        masks.green &= (1 << bitsPerPixel) - 1;
        masks.blue  &= (1 << bitsPerPixel) - 1;
        masks.alpha &= (1 << bitsPerPixel) - 1;
    }

    // Check that masks do not overlap.
    if (((masks.red   & masks.green) |
         (masks.red   & masks.blue ) |
         (masks.red   & masks.alpha) |
         (masks.green & masks.blue ) |
         (masks.green & masks.alpha) |
         (masks.blue  & masks.alpha) ) != 0) {
        return nullptr;
    }

    return new SkMasks(process_mask(masks.red  ),
                       process_mask(masks.green),
                       process_mask(masks.blue ),
                       process_mask(masks.alpha));
}


Messung V0.5 in Prozent
C=86 H=96 G=90

¤ Dauer der Verarbeitung: 0.1 Sekunden  (vorverarbeitet am  2026-08-26) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Open Source Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Jenseits des Üblichen ....

Besucherstatistik

Besucherstatistik

Statistik
#Sources=277311
#Domains=752002