#ifndef Uint8ClampedArray_h
#define Uint8ClampedArray_h
#include "wtf/Uint8Array.h"
#include "wtf/MathExtras.h"
namespace WTF {
class Uint8ClampedArray FINAL : public Uint8Array {
public:
static inline PassRefPtr<Uint8ClampedArray> create(unsigned length);
static inline PassRefPtr<Uint8ClampedArray> create(const unsigned char* array, unsigned length);
static inline PassRefPtr<Uint8ClampedArray> create(PassRefPtr<ArrayBuffer>, unsigned byteOffset, unsigned length);
static inline PassRefPtr<Uint8ClampedArray> createUninitialized(unsigned length);
inline void zeroFill();
using TypedArrayBase<unsigned char>::set;
inline void set(unsigned index, double value);
inline PassRefPtr<Uint8ClampedArray> subarray(int start) const;
inline PassRefPtr<Uint8ClampedArray> subarray(int start, int end) const;
virtual ViewType type() const OVERRIDE
{
return TypeUint8Clamped;
}
private:
inline Uint8ClampedArray(PassRefPtr<ArrayBuffer>,
unsigned byteOffset,
unsigned length);
friend class TypedArrayBase<unsigned char>;
};
PassRefPtr<Uint8ClampedArray> Uint8ClampedArray::create(unsigned length)
{
return TypedArrayBase<unsigned char>::create<Uint8ClampedArray>(length);
}
PassRefPtr<Uint8ClampedArray> Uint8ClampedArray::create(const unsigned char* array, unsigned length)
{
return TypedArrayBase<unsigned char>::create<Uint8ClampedArray>(array, length);
}
PassRefPtr<Uint8ClampedArray> Uint8ClampedArray::create(PassRefPtr<ArrayBuffer> buffer, unsigned byteOffset, unsigned length)
{
return TypedArrayBase<unsigned char>::create<Uint8ClampedArray>(buffer, byteOffset, length);
}
PassRefPtr<Uint8ClampedArray> Uint8ClampedArray::createUninitialized(unsigned length)
{
return TypedArrayBase<unsigned char>::createUninitialized<Uint8ClampedArray>(length);
}
void Uint8ClampedArray::zeroFill()
{
zeroRange(0, length());
}
void Uint8ClampedArray::set(unsigned index, double value)
{
if (index >= m_length)
return;
if (std::isnan(value) || value < 0)
value = 0;
else if (value > 255)
value = 255;
data()[index] = static_cast<unsigned char>(lrint(value));
}
Uint8ClampedArray::Uint8ClampedArray(PassRefPtr<ArrayBuffer> buffer, unsigned byteOffset, unsigned length)
: Uint8Array(buffer, byteOffset, length)
{
}
PassRefPtr<Uint8ClampedArray> Uint8ClampedArray::subarray(int start) const
{
return subarray(start, length());
}
PassRefPtr<Uint8ClampedArray> Uint8ClampedArray::subarray(int start, int end) const
{
return subarrayImpl<Uint8ClampedArray>(start, end);
}
}
using WTF::Uint8ClampedArray;
#endif