/* * Copyright 2015 The Android Open Source Project * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file.
*/
/* * returns a scaled dimension based on the original dimension and the sampleSize * NOTE: we round down here for scaled dimension to match the behavior of SkImageDecoder * FIXME: I think we should call this get_sampled_dimension().
*/ staticinlineint get_scaled_dimension(int srcDimension, int sampleSize) { if (sampleSize > srcDimension) { return 1;
} return srcDimension / sampleSize;
}
/* * Returns the first coordinate that we will keep during a scaled decode. * The output can be interpreted as an x-coordinate or a y-coordinate. * * This does not need to be called and is not called when sampleFactor == 1.
*/ staticinlineint get_start_coord(int sampleFactor) { return sampleFactor / 2; }
/* * Given a coordinate in the original image, this returns the corresponding * coordinate in the scaled image. This function is meaningless if * IsCoordNecessary returns false. * The output can be interpreted as an x-coordinate or a y-coordinate. * * This does not need to be called and is not called when sampleFactor == 1.
*/ staticinlineint get_dst_coord(int srcCoord, int sampleFactor) { return srcCoord / sampleFactor; }
/* * When scaling, we will discard certain y-coordinates (rows) and * x-coordinates (columns). This function returns true if we should keep the * coordinate and false otherwise. * The inputs may be x-coordinates or y-coordinates. * * This does not need to be called and is not called when sampleFactor == 1.
*/ staticinlinebool is_coord_necessary(int srcCoord, int sampleFactor, int scaledDim) { // Get the first coordinate that we want to keep int startCoord = get_start_coord(sampleFactor);
// Return false on edge cases if (srcCoord < startCoord || get_dst_coord(srcCoord, sampleFactor) >= scaledDim) { returnfalse;
}
// Every sampleFactor rows are necessary return ((srcCoord - startCoord) % sampleFactor) == 0;
}
if (srcIsOpaque) { if (kOpaque_SkAlphaType != dstAlpha) {
SkCodecPrintf("Warning: an opaque image should be decoded as opaque " "- it is being decoded as non-opaque, which will draw slower\n");
} returntrue;
}
return dstAlpha != kOpaque_SkAlphaType;
}
/* * If there is a color table, get a pointer to the colors, otherwise return nullptr
*/ staticinlineconst SkPMColor* get_color_ptr(SkColorPalette* colorTable) { return nullptr != colorTable ? colorTable->readColors() : nullptr;
}
/* * Compute row bytes for an image using pixels per byte
*/ staticinline size_t compute_row_bytes_ppb(int width, uint32_t pixelsPerByte) { return (width + pixelsPerByte - 1) / pixelsPerByte;
}
/* * Compute row bytes for an image using bytes per pixel
*/ staticinline size_t compute_row_bytes_bpp(int width, uint32_t bytesPerPixel) { return width * bytesPerPixel;
}
/* * Get a byte from a buffer * This method is unsafe, the caller is responsible for performing a check
*/ staticinline uint8_t get_byte(const uint8_t* buffer, uint32_t i) { return buffer[i];
}
/* * Get a short from a buffer * This method is unsafe, the caller is responsible for performing a check
*/ staticinline uint16_t get_short(const uint8_t* buffer, uint32_t i) {
uint16_t result;
memcpy(&result, &(buffer[i]), 2); #ifdef SK_CPU_BENDIAN return SkEndianSwap16(result); #else return result; #endif
}
/* * Get an int from a buffer * This method is unsafe, the caller is responsible for performing a check
*/ staticinline uint32_t get_int(const uint8_t* buffer, uint32_t i) {
uint32_t result;
memcpy(&result, &(buffer[i]), 4); #ifdef SK_CPU_BENDIAN return SkEndianSwap32(result); #else return result; #endif
}
/* * @param data Buffer to read bytes from * @param isLittleEndian Output parameter * Indicates if the data is little endian * Is unaffected on false returns
*/ staticinlinebool is_valid_endian_marker(const uint8_t* data, bool* isLittleEndian) { // II indicates Intel (little endian) and MM indicates motorola (big endian). if (('I' != data[0] || 'I' != data[1]) && ('M' != data[0] || 'M' != data[1])) { returnfalse;
}
staticinline SkPMColor premultiply_argb_as_rgba(U8CPU a, U8CPU r, U8CPU g, U8CPU b) { if (a != 255) {
r = SkMulDiv255Round(r, a);
g = SkMulDiv255Round(g, a);
b = SkMulDiv255Round(b, a);
}
return SkPackARGB_as_RGBA(a, r, g, b);
}
staticinline SkPMColor premultiply_argb_as_bgra(U8CPU a, U8CPU r, U8CPU g, U8CPU b) { if (a != 255) {
r = SkMulDiv255Round(r, a);
g = SkMulDiv255Round(g, a);
b = SkMulDiv255Round(b, a);
}
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.