1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/src/images/SkScaledBitmapSampler.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,94 @@ 1.4 + 1.5 +/* 1.6 + * Copyright 2011 Google Inc. 1.7 + * 1.8 + * Use of this source code is governed by a BSD-style license that can be 1.9 + * found in the LICENSE file. 1.10 + */ 1.11 +#ifndef SkScaledBitmapSampler_DEFINED 1.12 +#define SkScaledBitmapSampler_DEFINED 1.13 + 1.14 +#include "SkTypes.h" 1.15 +#include "SkColor.h" 1.16 +#include "SkImageDecoder.h" 1.17 + 1.18 +class SkBitmap; 1.19 + 1.20 +class SkScaledBitmapSampler { 1.21 +public: 1.22 + SkScaledBitmapSampler(int origWidth, int origHeight, int cellSize); 1.23 + 1.24 + int scaledWidth() const { return fScaledWidth; } 1.25 + int scaledHeight() const { return fScaledHeight; } 1.26 + 1.27 + int srcY0() const { return fY0; } 1.28 + int srcDX() const { return fDX; } 1.29 + int srcDY() const { return fDY; } 1.30 + 1.31 + enum SrcConfig { 1.32 + kGray, // 1 byte per pixel 1.33 + kIndex, // 1 byte per pixel 1.34 + kRGB, // 3 bytes per pixel 1.35 + kRGBX, // 4 byes per pixel (ignore 4th) 1.36 + kRGBA, // 4 bytes per pixel 1.37 + kRGB_565 // 2 bytes per pixel 1.38 + }; 1.39 + 1.40 + // Given a dst bitmap (with pixels already allocated) and a src-config, 1.41 + // prepares iterator to process the src colors and write them into dst. 1.42 + // Returns false if the request cannot be fulfulled. 1.43 + bool begin(SkBitmap* dst, SrcConfig sc, const SkImageDecoder& decoder, 1.44 + const SkPMColor* = NULL); 1.45 + // call with row of src pixels, for y = 0...scaledHeight-1. 1.46 + // returns true if the row had non-opaque alpha in it 1.47 + bool next(const uint8_t* SK_RESTRICT src); 1.48 + 1.49 + // Like next(), but specifies the y value of the source row, so the 1.50 + // rows can come in any order. If the row is not part of the output 1.51 + // sample, it will be skipped. Only sampleInterlaced OR next should 1.52 + // be called for one SkScaledBitmapSampler. 1.53 + bool sampleInterlaced(const uint8_t* SK_RESTRICT src, int srcY); 1.54 + 1.55 + typedef bool (*RowProc)(void* SK_RESTRICT dstRow, 1.56 + const uint8_t* SK_RESTRICT src, 1.57 + int width, int deltaSrc, int y, 1.58 + const SkPMColor[]); 1.59 + 1.60 +private: 1.61 + int fScaledWidth; 1.62 + int fScaledHeight; 1.63 + 1.64 + int fX0; // first X coord to sample 1.65 + int fY0; // first Y coord (scanline) to sample 1.66 + int fDX; // step between X samples 1.67 + int fDY; // step between Y samples 1.68 + 1.69 +#ifdef SK_DEBUG 1.70 + // Keep track of whether the caller is using next or sampleInterlaced. 1.71 + // Only one can be used per sampler. 1.72 + enum SampleMode { 1.73 + kUninitialized_SampleMode, 1.74 + kConsecutive_SampleMode, 1.75 + kInterlaced_SampleMode, 1.76 + }; 1.77 + 1.78 + SampleMode fSampleMode; 1.79 +#endif 1.80 + 1.81 + // setup state 1.82 + char* fDstRow; // points into bitmap's pixels 1.83 + size_t fDstRowBytes; 1.84 + int fCurrY; // used for dithering 1.85 + int fSrcPixelSize; // 1, 3, 4 1.86 + RowProc fRowProc; 1.87 + 1.88 + // optional reference to the src colors if the src is a palette model 1.89 + const SkPMColor* fCTable; 1.90 + 1.91 +#ifdef SK_DEBUG 1.92 + // Helper class allowing a test to have access to fRowProc. 1.93 + friend class RowProcTester; 1.94 +#endif 1.95 +}; 1.96 + 1.97 +#endif