repo_id
stringlengths 27
162
| file_path
stringlengths 42
195
| content
stringlengths 4
5.16M
| __index_level_0__
int64 0
0
|
---|---|---|---|
D://workCode//uploadProject\awtk\3rd\agg | D://workCode//uploadProject\awtk\3rd\agg\include\agg_array.h | //----------------------------------------------------------------------------
// Anti-Grain Geometry - Version 2.4
// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
//
//----------------------------------------------------------------------------
// Contact: mcseem@antigrain.com
// mcseemagg@yahoo.com
// http://www.antigrain.com
//----------------------------------------------------------------------------
#ifndef AGG_ARRAY_INCLUDED
#define AGG_ARRAY_INCLUDED
#include <stddef.h>
#include <string.h>
#include "agg_basics.h"
namespace agg
{
//-------------------------------------------------------pod_array_adaptor
template<class T> class pod_array_adaptor
{
public:
typedef T value_type;
pod_array_adaptor(T* array, unsigned size) :
m_array(array), m_size(size) {}
unsigned size() const { return m_size; }
const T& operator [] (unsigned i) const { return m_array[i]; }
T& operator [] (unsigned i) { return m_array[i]; }
const T& at(unsigned i) const { return m_array[i]; }
T& at(unsigned i) { return m_array[i]; }
T value_at(unsigned i) const { return m_array[i]; }
private:
T* m_array;
unsigned m_size;
};
//---------------------------------------------------------pod_auto_array
template<class T, unsigned Size> class pod_auto_array
{
public:
typedef T value_type;
typedef pod_auto_array<T, Size> self_type;
pod_auto_array() {}
explicit pod_auto_array(const T* c)
{
memcpy(m_array, c, sizeof(T) * Size);
}
const self_type& operator = (const T* c)
{
memcpy(m_array, c, sizeof(T) * Size);
return *this;
}
static unsigned size() { return Size; }
const T& operator [] (unsigned i) const { return m_array[i]; }
T& operator [] (unsigned i) { return m_array[i]; }
const T& at(unsigned i) const { return m_array[i]; }
T& at(unsigned i) { return m_array[i]; }
T value_at(unsigned i) const { return m_array[i]; }
private:
T m_array[Size];
};
//--------------------------------------------------------pod_auto_vector
template<class T, unsigned Size> class pod_auto_vector
{
public:
typedef T value_type;
typedef pod_auto_vector<T, Size> self_type;
pod_auto_vector() : m_size(0) {}
void remove_all() { m_size = 0; }
void clear() { m_size = 0; }
void add(const T& v) { m_array[m_size++] = v; }
void push_back(const T& v) { m_array[m_size++] = v; }
void inc_size(unsigned size) { m_size += size; }
unsigned size() const { return m_size; }
const T& operator [] (unsigned i) const { return m_array[i]; }
T& operator [] (unsigned i) { return m_array[i]; }
const T& at(unsigned i) const { return m_array[i]; }
T& at(unsigned i) { return m_array[i]; }
T value_at(unsigned i) const { return m_array[i]; }
private:
T m_array[Size];
unsigned m_size;
};
//---------------------------------------------------------------pod_array
template<class T> class pod_array
{
public:
typedef T value_type;
typedef pod_array<T> self_type;
~pod_array() { pod_allocator<T>::deallocate(m_array, m_size); }
pod_array() : m_array(0), m_size(0) {}
pod_array(unsigned size) :
m_array(pod_allocator<T>::allocate(size)),
m_size(size)
{}
pod_array(const self_type& v) :
m_array(pod_allocator<T>::allocate(v.m_size)),
m_size(v.m_size)
{
memcpy(m_array, v.m_array, sizeof(T) * m_size);
}
void resize(unsigned size)
{
if(size != m_size)
{
pod_allocator<T>::deallocate(m_array, m_size);
m_array = pod_allocator<T>::allocate(m_size = size);
}
}
const self_type& operator = (const self_type& v)
{
resize(v.size());
memcpy(m_array, v.m_array, sizeof(T) * m_size);
return *this;
}
unsigned size() const { return m_size; }
const T& operator [] (unsigned i) const { return m_array[i]; }
T& operator [] (unsigned i) { return m_array[i]; }
const T& at(unsigned i) const { return m_array[i]; }
T& at(unsigned i) { return m_array[i]; }
T value_at(unsigned i) const { return m_array[i]; }
const T* data() const { return m_array; }
T* data() { return m_array; }
private:
T* m_array;
unsigned m_size;
};
//--------------------------------------------------------------pod_vector
// A simple class template to store Plain Old Data, a vector
// of a fixed size. The data is continous in memory
//------------------------------------------------------------------------
template<class T> class pod_vector
{
public:
typedef T value_type;
~pod_vector() { pod_allocator<T>::deallocate(m_array, m_capacity); }
pod_vector() : m_size(0), m_capacity(0), m_array(0) {}
pod_vector(unsigned cap, unsigned extra_tail=0);
// Copying
pod_vector(const pod_vector<T>&);
const pod_vector<T>& operator = (const pod_vector<T>&);
// Set new capacity. All data is lost, size is set to zero.
void capacity(unsigned cap, unsigned extra_tail=0);
unsigned capacity() const { return m_capacity; }
// Allocate n elements. All data is lost,
// but elements can be accessed in range 0...size-1.
void allocate(unsigned size, unsigned extra_tail=0);
// Resize keeping the content.
void resize(unsigned new_size);
void zero()
{
memset(m_array, 0, sizeof(T) * m_size);
}
void add(const T& v) { m_array[m_size++] = v; }
void push_back(const T& v) { m_array[m_size++] = v; }
void insert_at(unsigned pos, const T& val);
void inc_size(unsigned size) { m_size += size; }
unsigned size() const { return m_size; }
unsigned byte_size() const { return m_size * sizeof(T); }
void serialize(int8u* ptr) const;
void deserialize(const int8u* data, unsigned byte_size);
const T& operator [] (unsigned i) const { return m_array[i]; }
T& operator [] (unsigned i) { return m_array[i]; }
const T& at(unsigned i) const { return m_array[i]; }
T& at(unsigned i) { return m_array[i]; }
T value_at(unsigned i) const { return m_array[i]; }
const T* data() const { return m_array; }
T* data() { return m_array; }
void remove_all() { m_size = 0; }
void clear() { m_size = 0; }
void cut_at(unsigned num) { if(num < m_size) m_size = num; }
private:
unsigned m_size;
unsigned m_capacity;
T* m_array;
};
//------------------------------------------------------------------------
template<class T>
void pod_vector<T>::capacity(unsigned cap, unsigned extra_tail)
{
m_size = 0;
if(cap > m_capacity)
{
pod_allocator<T>::deallocate(m_array, m_capacity);
m_capacity = cap + extra_tail;
m_array = m_capacity ? pod_allocator<T>::allocate(m_capacity) : 0;
}
}
//------------------------------------------------------------------------
template<class T>
void pod_vector<T>::allocate(unsigned size, unsigned extra_tail)
{
capacity(size, extra_tail);
m_size = size;
}
//------------------------------------------------------------------------
template<class T>
void pod_vector<T>::resize(unsigned new_size)
{
if(new_size > m_size)
{
if(new_size > m_capacity)
{
T* data = pod_allocator<T>::allocate(new_size);
memcpy(data, m_array, m_size * sizeof(T));
pod_allocator<T>::deallocate(m_array, m_capacity);
m_array = data;
}
}
else
{
m_size = new_size;
}
}
//------------------------------------------------------------------------
template<class T> pod_vector<T>::pod_vector(unsigned cap, unsigned extra_tail) :
m_size(0),
m_capacity(cap + extra_tail),
m_array(pod_allocator<T>::allocate(m_capacity)) {}
//------------------------------------------------------------------------
template<class T> pod_vector<T>::pod_vector(const pod_vector<T>& v) :
m_size(v.m_size),
m_capacity(v.m_capacity),
m_array(v.m_capacity ? pod_allocator<T>::allocate(v.m_capacity) : 0)
{
memcpy(m_array, v.m_array, sizeof(T) * v.m_size);
}
//------------------------------------------------------------------------
template<class T> const pod_vector<T>&
pod_vector<T>::operator = (const pod_vector<T>&v)
{
allocate(v.m_size);
if(v.m_size) memcpy(m_array, v.m_array, sizeof(T) * v.m_size);
return *this;
}
//------------------------------------------------------------------------
template<class T> void pod_vector<T>::serialize(int8u* ptr) const
{
if(m_size) memcpy(ptr, m_array, m_size * sizeof(T));
}
//------------------------------------------------------------------------
template<class T>
void pod_vector<T>::deserialize(const int8u* data, unsigned byte_size)
{
byte_size /= sizeof(T);
allocate(byte_size);
if(byte_size) memcpy(m_array, data, byte_size * sizeof(T));
}
//------------------------------------------------------------------------
template<class T>
void pod_vector<T>::insert_at(unsigned pos, const T& val)
{
if(pos >= m_size)
{
m_array[m_size] = val;
}
else
{
memmove(m_array + pos + 1, m_array + pos, (m_size - pos) * sizeof(T));
m_array[pos] = val;
}
++m_size;
}
//---------------------------------------------------------------pod_bvector
// A simple class template to store Plain Old Data, similar to std::deque
// It doesn't reallocate memory but instead, uses blocks of data of size
// of (1 << S), that is, power of two. The data is NOT contiguous in memory,
// so the only valid access method is operator [] or curr(), prev(), next()
//
// There reallocs occure only when the pool of pointers to blocks needs
// to be extended (it happens very rarely). You can control the value
// of increment to reallocate the pointer buffer. See the second constructor.
// By default, the incremeent value equals (1 << S), i.e., the block size.
//------------------------------------------------------------------------
template<class T, unsigned S=6> class pod_bvector
{
public:
enum block_scale_e
{
block_shift = S,
block_size = 1 << block_shift,
block_mask = block_size - 1
};
typedef T value_type;
~pod_bvector();
pod_bvector();
pod_bvector(unsigned block_ptr_inc);
// Copying
pod_bvector(const pod_bvector<T, S>& v);
const pod_bvector<T, S>& operator = (const pod_bvector<T, S>& v);
void remove_all() { m_size = 0; }
void clear() { m_size = 0; }
void free_all() { free_tail(0); }
void free_tail(unsigned size);
void add(const T& val);
void push_back(const T& val) { add(val); }
void modify_last(const T& val);
void remove_last();
int allocate_continuous_block(unsigned num_elements);
void add_array(const T* ptr, unsigned num_elem)
{
while(num_elem--)
{
add(*ptr++);
}
}
template<class DataAccessor> void add_data(DataAccessor& data)
{
while(data.size())
{
add(*data);
++data;
}
}
void cut_at(unsigned size)
{
if(size < m_size) m_size = size;
}
unsigned size() const { return m_size; }
const T& operator [] (unsigned i) const
{
return m_blocks[i >> block_shift][i & block_mask];
}
T& operator [] (unsigned i)
{
return m_blocks[i >> block_shift][i & block_mask];
}
const T& at(unsigned i) const
{
return m_blocks[i >> block_shift][i & block_mask];
}
T& at(unsigned i)
{
return m_blocks[i >> block_shift][i & block_mask];
}
T value_at(unsigned i) const
{
return m_blocks[i >> block_shift][i & block_mask];
}
const T& curr(unsigned idx) const
{
return (*this)[idx];
}
T& curr(unsigned idx)
{
return (*this)[idx];
}
const T& prev(unsigned idx) const
{
return (*this)[(idx + m_size - 1) % m_size];
}
T& prev(unsigned idx)
{
return (*this)[(idx + m_size - 1) % m_size];
}
const T& next(unsigned idx) const
{
return (*this)[(idx + 1) % m_size];
}
T& next(unsigned idx)
{
return (*this)[(idx + 1) % m_size];
}
const T& last() const
{
return (*this)[m_size - 1];
}
T& last()
{
return (*this)[m_size - 1];
}
unsigned byte_size() const;
void serialize(int8u* ptr) const;
void deserialize(const int8u* data, unsigned byte_size);
void deserialize(unsigned start, const T& empty_val,
const int8u* data, unsigned byte_size);
template<class ByteAccessor>
void deserialize(ByteAccessor data)
{
remove_all();
unsigned elem_size = data.size() / sizeof(T);
for(unsigned i = 0; i < elem_size; ++i)
{
int8u* ptr = (int8u*)data_ptr();
for(unsigned j = 0; j < sizeof(T); ++j)
{
*ptr++ = *data;
++data;
}
++m_size;
}
}
template<class ByteAccessor>
void deserialize(unsigned start, const T& empty_val, ByteAccessor data)
{
while(m_size < start)
{
add(empty_val);
}
unsigned elem_size = data.size() / sizeof(T);
for(unsigned i = 0; i < elem_size; ++i)
{
int8u* ptr;
if(start + i < m_size)
{
ptr = (int8u*)(&((*this)[start + i]));
}
else
{
ptr = (int8u*)data_ptr();
++m_size;
}
for(unsigned j = 0; j < sizeof(T); ++j)
{
*ptr++ = *data;
++data;
}
}
}
const T* block(unsigned nb) const { return m_blocks[nb]; }
private:
void allocate_block(unsigned nb);
T* data_ptr();
unsigned m_size;
unsigned m_num_blocks;
unsigned m_max_blocks;
T** m_blocks;
unsigned m_block_ptr_inc;
};
//------------------------------------------------------------------------
template<class T, unsigned S> pod_bvector<T, S>::~pod_bvector()
{
if(m_num_blocks)
{
T** blk = m_blocks + m_num_blocks - 1;
while(m_num_blocks--)
{
pod_allocator<T>::deallocate(*blk, block_size);
--blk;
}
}
pod_allocator<T*>::deallocate(m_blocks, m_max_blocks);
}
//------------------------------------------------------------------------
template<class T, unsigned S>
void pod_bvector<T, S>::free_tail(unsigned size)
{
if(size < m_size)
{
unsigned nb = (size + block_mask) >> block_shift;
while(m_num_blocks > nb)
{
pod_allocator<T>::deallocate(m_blocks[--m_num_blocks], block_size);
}
if(m_num_blocks == 0)
{
pod_allocator<T*>::deallocate(m_blocks, m_max_blocks);
m_blocks = 0;
m_max_blocks = 0;
}
m_size = size;
}
}
//------------------------------------------------------------------------
template<class T, unsigned S> pod_bvector<T, S>::pod_bvector() :
m_size(0),
m_num_blocks(0),
m_max_blocks(0),
m_blocks(0),
m_block_ptr_inc(block_size)
{
}
//------------------------------------------------------------------------
template<class T, unsigned S>
pod_bvector<T, S>::pod_bvector(unsigned block_ptr_inc) :
m_size(0),
m_num_blocks(0),
m_max_blocks(0),
m_blocks(0),
m_block_ptr_inc(block_ptr_inc)
{
}
//------------------------------------------------------------------------
template<class T, unsigned S>
pod_bvector<T, S>::pod_bvector(const pod_bvector<T, S>& v) :
m_size(v.m_size),
m_num_blocks(v.m_num_blocks),
m_max_blocks(v.m_max_blocks),
m_blocks(v.m_max_blocks ?
pod_allocator<T*>::allocate(v.m_max_blocks) :
0),
m_block_ptr_inc(v.m_block_ptr_inc)
{
unsigned i;
for(i = 0; i < v.m_num_blocks; ++i)
{
m_blocks[i] = pod_allocator<T>::allocate(block_size);
memcpy(m_blocks[i], v.m_blocks[i], block_size * sizeof(T));
}
}
//------------------------------------------------------------------------
template<class T, unsigned S>
const pod_bvector<T, S>&
pod_bvector<T, S>::operator = (const pod_bvector<T, S>& v)
{
unsigned i;
for(i = m_num_blocks; i < v.m_num_blocks; ++i)
{
allocate_block(i);
}
for(i = 0; i < v.m_num_blocks; ++i)
{
memcpy(m_blocks[i], v.m_blocks[i], block_size * sizeof(T));
}
m_size = v.m_size;
return *this;
}
//------------------------------------------------------------------------
template<class T, unsigned S>
void pod_bvector<T, S>::allocate_block(unsigned nb)
{
if(nb >= m_max_blocks)
{
T** new_blocks = pod_allocator<T*>::allocate(m_max_blocks + m_block_ptr_inc);
if(m_blocks)
{
memcpy(new_blocks,
m_blocks,
m_num_blocks * sizeof(T*));
pod_allocator<T*>::deallocate(m_blocks, m_max_blocks);
}
m_blocks = new_blocks;
m_max_blocks += m_block_ptr_inc;
}
m_blocks[nb] = pod_allocator<T>::allocate(block_size);
m_num_blocks++;
}
//------------------------------------------------------------------------
template<class T, unsigned S>
inline T* pod_bvector<T, S>::data_ptr()
{
unsigned nb = m_size >> block_shift;
if(nb >= m_num_blocks)
{
allocate_block(nb);
}
return m_blocks[nb] + (m_size & block_mask);
}
//------------------------------------------------------------------------
template<class T, unsigned S>
inline void pod_bvector<T, S>::add(const T& val)
{
*data_ptr() = val;
++m_size;
}
//------------------------------------------------------------------------
template<class T, unsigned S>
inline void pod_bvector<T, S>::remove_last()
{
if(m_size) --m_size;
}
//------------------------------------------------------------------------
template<class T, unsigned S>
void pod_bvector<T, S>::modify_last(const T& val)
{
remove_last();
add(val);
}
//------------------------------------------------------------------------
template<class T, unsigned S>
int pod_bvector<T, S>::allocate_continuous_block(unsigned num_elements)
{
if(num_elements < block_size)
{
data_ptr(); // Allocate initial block if necessary
unsigned rest = block_size - (m_size & block_mask);
unsigned index;
if(num_elements <= rest)
{
// The rest of the block is good, we can use it
//-----------------
index = m_size;
m_size += num_elements;
return index;
}
// New block
//---------------
m_size += rest;
data_ptr();
index = m_size;
m_size += num_elements;
return index;
}
return -1; // Impossible to allocate
}
//------------------------------------------------------------------------
template<class T, unsigned S>
unsigned pod_bvector<T, S>::byte_size() const
{
return m_size * sizeof(T);
}
//------------------------------------------------------------------------
template<class T, unsigned S>
void pod_bvector<T, S>::serialize(int8u* ptr) const
{
unsigned i;
for(i = 0; i < m_size; i++)
{
memcpy(ptr, &(*this)[i], sizeof(T));
ptr += sizeof(T);
}
}
//------------------------------------------------------------------------
template<class T, unsigned S>
void pod_bvector<T, S>::deserialize(const int8u* data, unsigned byte_size)
{
remove_all();
byte_size /= sizeof(T);
for(unsigned i = 0; i < byte_size; ++i)
{
T* ptr = data_ptr();
memcpy(ptr, data, sizeof(T));
++m_size;
data += sizeof(T);
}
}
// Replace or add a number of elements starting from "start" position
//------------------------------------------------------------------------
template<class T, unsigned S>
void pod_bvector<T, S>::deserialize(unsigned start, const T& empty_val,
const int8u* data, unsigned byte_size)
{
while(m_size < start)
{
add(empty_val);
}
byte_size /= sizeof(T);
for(unsigned i = 0; i < byte_size; ++i)
{
if(start + i < m_size)
{
memcpy(&((*this)[start + i]), data, sizeof(T));
}
else
{
T* ptr = data_ptr();
memcpy(ptr, data, sizeof(T));
++m_size;
}
data += sizeof(T);
}
}
//---------------------------------------------------------block_allocator
// Allocator for arbitrary POD data. Most usable in different cache
// systems for efficient memory allocations.
// Memory is allocated with blocks of fixed size ("block_size" in
// the constructor). If required size exceeds the block size the allocator
// creates a new block of the required size. However, the most efficient
// use is when the average reqired size is much less than the block size.
//------------------------------------------------------------------------
class block_allocator
{
struct block_type
{
int8u* data;
unsigned size;
};
public:
void remove_all()
{
if(m_num_blocks)
{
block_type* blk = m_blocks + m_num_blocks - 1;
while(m_num_blocks--)
{
pod_allocator<int8u>::deallocate(blk->data, blk->size);
--blk;
}
pod_allocator<block_type>::deallocate(m_blocks, m_max_blocks);
}
m_num_blocks = 0;
m_max_blocks = 0;
m_blocks = 0;
m_buf_ptr = 0;
m_rest = 0;
}
~block_allocator()
{
remove_all();
}
block_allocator(unsigned block_size, unsigned block_ptr_inc=256-8) :
m_block_size(block_size),
m_block_ptr_inc(block_ptr_inc),
m_num_blocks(0),
m_max_blocks(0),
m_blocks(0),
m_buf_ptr(0),
m_rest(0)
{
}
int8u* allocate(unsigned size, unsigned alignment=1)
{
if(size == 0) return 0;
if(size <= m_rest)
{
int8u* ptr = m_buf_ptr;
if(alignment > 1)
{
unsigned align =
(alignment - unsigned((size_t)ptr) % alignment) % alignment;
size += align;
ptr += align;
if(size <= m_rest)
{
m_rest -= size;
m_buf_ptr += size;
return ptr;
}
allocate_block(size);
return allocate(size - align, alignment);
}
m_rest -= size;
m_buf_ptr += size;
return ptr;
}
allocate_block(size + alignment - 1);
return allocate(size, alignment);
}
private:
void allocate_block(unsigned size)
{
if(size < m_block_size) size = m_block_size;
if(m_num_blocks >= m_max_blocks)
{
block_type* new_blocks =
pod_allocator<block_type>::allocate(m_max_blocks + m_block_ptr_inc);
if(m_blocks)
{
memcpy(new_blocks,
m_blocks,
m_num_blocks * sizeof(block_type));
pod_allocator<block_type>::deallocate(m_blocks, m_max_blocks);
}
m_blocks = new_blocks;
m_max_blocks += m_block_ptr_inc;
}
m_blocks[m_num_blocks].size = size;
m_blocks[m_num_blocks].data =
m_buf_ptr =
pod_allocator<int8u>::allocate(size);
m_num_blocks++;
m_rest = size;
}
unsigned m_block_size;
unsigned m_block_ptr_inc;
unsigned m_num_blocks;
unsigned m_max_blocks;
block_type* m_blocks;
int8u* m_buf_ptr;
unsigned m_rest;
};
//------------------------------------------------------------------------
enum quick_sort_threshold_e
{
quick_sort_threshold = 9
};
//-----------------------------------------------------------swap_elements
template<class T> inline void swap_elements(T& a, T& b)
{
T temp = a;
a = b;
b = temp;
}
//--------------------------------------------------------------quick_sort
template<class Array, class Less>
void quick_sort(Array& arr, Less less)
{
if(arr.size() < 2) return;
typename Array::value_type* e1;
typename Array::value_type* e2;
int stack[80];
int* top = stack;
int limit = arr.size();
int base = 0;
for(;;)
{
int len = limit - base;
int i;
int j;
int pivot;
if(len > quick_sort_threshold)
{
// we use base + len/2 as the pivot
pivot = base + len / 2;
swap_elements(arr[base], arr[pivot]);
i = base + 1;
j = limit - 1;
// now ensure that *i <= *base <= *j
e1 = &(arr[j]);
e2 = &(arr[i]);
if(less(*e1, *e2)) swap_elements(*e1, *e2);
e1 = &(arr[base]);
e2 = &(arr[i]);
if(less(*e1, *e2)) swap_elements(*e1, *e2);
e1 = &(arr[j]);
e2 = &(arr[base]);
if(less(*e1, *e2)) swap_elements(*e1, *e2);
for(;;)
{
do i++; while( less(arr[i], arr[base]) );
do j--; while( less(arr[base], arr[j]) );
if( i > j )
{
break;
}
swap_elements(arr[i], arr[j]);
}
swap_elements(arr[base], arr[j]);
// now, push the largest sub-array
if(j - base > limit - i)
{
top[0] = base;
top[1] = j;
base = i;
}
else
{
top[0] = i;
top[1] = limit;
limit = j;
}
top += 2;
}
else
{
// the sub-array is small, perform insertion sort
j = base;
i = j + 1;
for(; i < limit; j = i, i++)
{
for(; less(*(e1 = &(arr[j + 1])), *(e2 = &(arr[j]))); j--)
{
swap_elements(*e1, *e2);
if(j == base)
{
break;
}
}
}
if(top > stack)
{
top -= 2;
base = top[0];
limit = top[1];
}
else
{
break;
}
}
}
}
//------------------------------------------------------remove_duplicates
// Remove duplicates from a sorted array. It doesn't cut the
// tail of the array, it just returns the number of remaining elements.
//-----------------------------------------------------------------------
template<class Array, class Equal>
unsigned remove_duplicates(Array& arr, Equal equal)
{
if(arr.size() < 2) return arr.size();
unsigned i, j;
for(i = 1, j = 1; i < arr.size(); i++)
{
typename Array::value_type& e = arr[i];
if(!equal(e, arr[i - 1]))
{
arr[j++] = e;
}
}
return j;
}
//--------------------------------------------------------invert_container
template<class Array> void invert_container(Array& arr)
{
int i = 0;
int j = arr.size() - 1;
while(i < j)
{
swap_elements(arr[i++], arr[j--]);
}
}
//------------------------------------------------------binary_search_pos
template<class Array, class Value, class Less>
unsigned binary_search_pos(const Array& arr, const Value& val, Less less)
{
if(arr.size() == 0) return 0;
unsigned beg = 0;
unsigned end = arr.size() - 1;
if(less(val, arr[0])) return 0;
if(less(arr[end], val)) return end + 1;
while(end - beg > 1)
{
unsigned mid = (end + beg) >> 1;
if(less(val, arr[mid])) end = mid;
else beg = mid;
}
//if(beg <= 0 && less(val, arr[0])) return 0;
//if(end >= arr.size() - 1 && less(arr[end], val)) ++end;
return end;
}
//----------------------------------------------------------range_adaptor
template<class Array> class range_adaptor
{
public:
typedef typename Array::value_type value_type;
range_adaptor(Array& array, unsigned start, unsigned size) :
m_array(array), m_start(start), m_size(size)
{}
unsigned size() const { return m_size; }
const value_type& operator [] (unsigned i) const { return m_array[m_start + i]; }
value_type& operator [] (unsigned i) { return m_array[m_start + i]; }
const value_type& at(unsigned i) const { return m_array[m_start + i]; }
value_type& at(unsigned i) { return m_array[m_start + i]; }
value_type value_at(unsigned i) const { return m_array[m_start + i]; }
private:
Array& m_array;
unsigned m_start;
unsigned m_size;
};
//---------------------------------------------------------------int_less
inline bool int_less(int a, int b) { return a < b; }
//------------------------------------------------------------int_greater
inline bool int_greater(int a, int b) { return a > b; }
//----------------------------------------------------------unsigned_less
inline bool unsigned_less(unsigned a, unsigned b) { return a < b; }
//-------------------------------------------------------unsigned_greater
inline bool unsigned_greater(unsigned a, unsigned b) { return a > b; }
}
#endif
| 0 |
D://workCode//uploadProject\awtk\3rd\agg | D://workCode//uploadProject\awtk\3rd\agg\include\agg_basics.h | //----------------------------------------------------------------------------
// Anti-Grain Geometry - Version 2.4
// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
//
//----------------------------------------------------------------------------
// Contact: mcseem@antigrain.com
// mcseemagg@yahoo.com
// http://www.antigrain.com
//----------------------------------------------------------------------------
#ifndef AGG_BASICS_INCLUDED
#define AGG_BASICS_INCLUDED
#include <math.h>
#include "agg_config.h"
//---------------------------------------------------------AGG_CUSTOM_ALLOCATOR
#ifdef AGG_CUSTOM_ALLOCATOR
#include "agg_allocator.h"
#else
namespace agg
{
// The policy of all AGG containers and memory allocation strategy
// in general is that no allocated data requires explicit construction.
// It means that the allocator can be really simple; you can even
// replace new/delete to malloc/free. The constructors and destructors
// won't be called in this case, however everything will remain working.
// The second argument of deallocate() is the size of the allocated
// block. You can use this information if you wish.
//------------------------------------------------------------pod_allocator
template<class T> struct pod_allocator
{
static T* allocate(unsigned num) { return new T [num]; }
static void deallocate(T* ptr, unsigned) { delete [] ptr; }
};
// Single object allocator. It's also can be replaced with your custom
// allocator. The difference is that it can only allocate a single
// object and the constructor and destructor must be called.
// In AGG there is no need to allocate an array of objects with
// calling their constructors (only single ones). So that, if you
// replace these new/delete to malloc/free make sure that the in-place
// new is called and take care of calling the destructor too.
//------------------------------------------------------------obj_allocator
template<class T> struct obj_allocator
{
static T* allocate() { return new T; }
static void deallocate(T* ptr) { delete ptr; }
};
}
#endif
//-------------------------------------------------------- Default basic types
//
// If the compiler has different capacity of the basic types you can redefine
// them via the compiler command line or by generating agg_config.h that is
// empty by default.
//
#ifndef AGG_INT8
#define AGG_INT8 signed char
#endif
#ifndef AGG_INT8U
#define AGG_INT8U unsigned char
#endif
#ifndef AGG_INT16
#define AGG_INT16 short
#endif
#ifndef AGG_INT16U
#define AGG_INT16U unsigned short
#endif
#ifndef AGG_INT32
#define AGG_INT32 int
#endif
#ifndef AGG_INT32U
#define AGG_INT32U unsigned
#endif
#ifndef AGG_INT64
#if defined(_MSC_VER) || defined(__BORLANDC__)
#define AGG_INT64 signed __int64
#else
#define AGG_INT64 signed long long
#endif
#endif
#ifndef AGG_INT64U
#if defined(_MSC_VER) || defined(__BORLANDC__)
#define AGG_INT64U unsigned __int64
#else
#define AGG_INT64U unsigned long long
#endif
#endif
//------------------------------------------------ Some fixes for MS Visual C++
#if defined(_MSC_VER)
#pragma warning(disable:4786) // Identifier was truncated...
#endif
#if defined(_MSC_VER)
#define AGG_INLINE __forceinline
#else
#define AGG_INLINE inline
#endif
namespace agg
{
//-------------------------------------------------------------------------
typedef AGG_INT8 int8; //----int8
typedef AGG_INT8U int8u; //----int8u
typedef AGG_INT16 int16; //----int16
typedef AGG_INT16U int16u; //----int16u
typedef AGG_INT32 int32; //----int32
typedef AGG_INT32U int32u; //----int32u
typedef AGG_INT64 int64; //----int64
typedef AGG_INT64U int64u; //----int64u
#if defined(AGG_FISTP)
#pragma warning(push)
#pragma warning(disable : 4035) //Disable warning "no return value"
AGG_INLINE int iround(double v) //-------iround
{
int t;
__asm fld qword ptr [v]
__asm fistp dword ptr [t]
__asm mov eax, dword ptr [t]
}
AGG_INLINE unsigned uround(double v) //-------uround
{
unsigned t;
__asm fld qword ptr [v]
__asm fistp dword ptr [t]
__asm mov eax, dword ptr [t]
}
#pragma warning(pop)
AGG_INLINE int ifloor(double v)
{
return int(floor(v));
}
AGG_INLINE unsigned ufloor(double v) //-------ufloor
{
return unsigned(floor(v));
}
AGG_INLINE int iceil(double v)
{
return int(ceil(v));
}
AGG_INLINE unsigned uceil(double v) //--------uceil
{
return unsigned(ceil(v));
}
#elif defined(AGG_QIFIST)
AGG_INLINE int iround(double v)
{
return int(v);
}
AGG_INLINE int uround(double v)
{
return unsigned(v);
}
AGG_INLINE int ifloor(double v)
{
return int(floor(v));
}
AGG_INLINE unsigned ufloor(double v)
{
return unsigned(floor(v));
}
AGG_INLINE int iceil(double v)
{
return int(ceil(v));
}
AGG_INLINE unsigned uceil(double v)
{
return unsigned(ceil(v));
}
#else
AGG_INLINE int iround(double v)
{
return int((v < 0.0) ? v - 0.5 : v + 0.5);
}
AGG_INLINE int uround(double v)
{
return unsigned(v + 0.5);
}
AGG_INLINE int ifloor(double v)
{
int i = int(v);
return i - (i > v);
}
AGG_INLINE unsigned ufloor(double v)
{
return unsigned(v);
}
AGG_INLINE int iceil(double v)
{
return int(ceil(v));
}
AGG_INLINE unsigned uceil(double v)
{
return unsigned(ceil(v));
}
#endif
//---------------------------------------------------------------saturation
template<int Limit> struct saturation
{
AGG_INLINE static int iround(double v)
{
if(v < double(-Limit)) return -Limit;
if(v > double( Limit)) return Limit;
return agg::iround(v);
}
};
//------------------------------------------------------------------mul_one
template<unsigned Shift> struct mul_one
{
AGG_INLINE static unsigned mul(unsigned a, unsigned b)
{
unsigned q = a * b + (1 << (Shift-1));
return (q + (q >> Shift)) >> Shift;
}
};
//-------------------------------------------------------------------------
typedef unsigned char cover_type; //----cover_type
enum cover_scale_e
{
cover_shift = 8, //----cover_shift
cover_size = 1 << cover_shift, //----cover_size
cover_mask = cover_size - 1, //----cover_mask
cover_none = 0, //----cover_none
cover_full = cover_mask //----cover_full
};
//----------------------------------------------------poly_subpixel_scale_e
// These constants determine the subpixel accuracy, to be more precise,
// the number of bits of the fractional part of the coordinates.
// The possible coordinate capacity in bits can be calculated by formula:
// sizeof(int) * 8 - poly_subpixel_shift, i.e, for 32-bit integers and
// 8-bits fractional part the capacity is 24 bits.
enum poly_subpixel_scale_e
{
poly_subpixel_shift = 8, //----poly_subpixel_shift
poly_subpixel_scale = 1<<poly_subpixel_shift, //----poly_subpixel_scale
poly_subpixel_mask = poly_subpixel_scale-1 //----poly_subpixel_mask
};
//----------------------------------------------------------filling_rule_e
enum filling_rule_e
{
fill_non_zero,
fill_even_odd
};
//-----------------------------------------------------------------------pi
const double pi = 3.14159265358979323846;
//------------------------------------------------------------------deg2rad
inline double deg2rad(double deg)
{
return deg * pi / 180.0;
}
//------------------------------------------------------------------rad2deg
inline double rad2deg(double rad)
{
return rad * 180.0 / pi;
}
//----------------------------------------------------------------rect_base
template<class T> struct rect_base
{
typedef T value_type;
typedef rect_base<T> self_type;
T x1, y1, x2, y2;
rect_base() {}
rect_base(T x1_, T y1_, T x2_, T y2_) :
x1(x1_), y1(y1_), x2(x2_), y2(y2_) {}
void init(T x1_, T y1_, T x2_, T y2_)
{
x1 = x1_; y1 = y1_; x2 = x2_; y2 = y2_;
}
const self_type& normalize()
{
T t;
if(x1 > x2) { t = x1; x1 = x2; x2 = t; }
if(y1 > y2) { t = y1; y1 = y2; y2 = t; }
return *this;
}
bool clip(const self_type& r)
{
if(x2 > r.x2) x2 = r.x2;
if(y2 > r.y2) y2 = r.y2;
if(x1 < r.x1) x1 = r.x1;
if(y1 < r.y1) y1 = r.y1;
return x1 <= x2 && y1 <= y2;
}
bool is_valid() const
{
return x1 <= x2 && y1 <= y2;
}
bool hit_test(T x, T y) const
{
return (x >= x1 && x <= x2 && y >= y1 && y <= y2);
}
bool overlaps(const self_type& r) const
{
return !(r.x1 > x2 || r.x2 < x1
|| r.y1 > y2 || r.y2 < y1);
}
};
//-----------------------------------------------------intersect_rectangles
template<class Rect>
inline Rect intersect_rectangles(const Rect& r1, const Rect& r2)
{
Rect r = r1;
// First process x2,y2 because the other order
// results in Internal Compiler Error under
// Microsoft Visual C++ .NET 2003 69462-335-0000007-18038 in
// case of "Maximize Speed" optimization option.
//-----------------
if(r.x2 > r2.x2) r.x2 = r2.x2;
if(r.y2 > r2.y2) r.y2 = r2.y2;
if(r.x1 < r2.x1) r.x1 = r2.x1;
if(r.y1 < r2.y1) r.y1 = r2.y1;
return r;
}
//---------------------------------------------------------unite_rectangles
template<class Rect>
inline Rect unite_rectangles(const Rect& r1, const Rect& r2)
{
Rect r = r1;
if(r.x2 < r2.x2) r.x2 = r2.x2;
if(r.y2 < r2.y2) r.y2 = r2.y2;
if(r.x1 > r2.x1) r.x1 = r2.x1;
if(r.y1 > r2.y1) r.y1 = r2.y1;
return r;
}
typedef rect_base<int> rect_i; //----rect_i
typedef rect_base<float> rect_f; //----rect_f
typedef rect_base<double> rect_d; //----rect_d
//---------------------------------------------------------path_commands_e
enum path_commands_e
{
path_cmd_stop = 0, //----path_cmd_stop
path_cmd_move_to = 1, //----path_cmd_move_to
path_cmd_line_to = 2, //----path_cmd_line_to
path_cmd_curve3 = 3, //----path_cmd_curve3
path_cmd_curve4 = 4, //----path_cmd_curve4
path_cmd_curveN = 5, //----path_cmd_curveN
path_cmd_catrom = 6, //----path_cmd_catrom
path_cmd_ubspline = 7, //----path_cmd_ubspline
path_cmd_end_poly = 0x0F, //----path_cmd_end_poly
path_cmd_mask = 0x0F //----path_cmd_mask
};
//------------------------------------------------------------path_flags_e
enum path_flags_e
{
path_flags_none = 0, //----path_flags_none
path_flags_ccw = 0x10, //----path_flags_ccw
path_flags_cw = 0x20, //----path_flags_cw
path_flags_close = 0x40, //----path_flags_close
path_flags_mask = 0xF0 //----path_flags_mask
};
//---------------------------------------------------------------is_vertex
inline bool is_vertex(unsigned c)
{
return c >= path_cmd_move_to && c < path_cmd_end_poly;
}
//--------------------------------------------------------------is_drawing
inline bool is_drawing(unsigned c)
{
return c >= path_cmd_line_to && c < path_cmd_end_poly;
}
//-----------------------------------------------------------------is_stop
inline bool is_stop(unsigned c)
{
return c == path_cmd_stop;
}
//--------------------------------------------------------------is_move_to
inline bool is_move_to(unsigned c)
{
return c == path_cmd_move_to;
}
//--------------------------------------------------------------is_line_to
inline bool is_line_to(unsigned c)
{
return c == path_cmd_line_to;
}
//----------------------------------------------------------------is_curve
inline bool is_curve(unsigned c)
{
return c == path_cmd_curve3 || c == path_cmd_curve4;
}
//---------------------------------------------------------------is_curve3
inline bool is_curve3(unsigned c)
{
return c == path_cmd_curve3;
}
//---------------------------------------------------------------is_curve4
inline bool is_curve4(unsigned c)
{
return c == path_cmd_curve4;
}
//-------------------------------------------------------------is_end_poly
inline bool is_end_poly(unsigned c)
{
return (c & path_cmd_mask) == path_cmd_end_poly;
}
//----------------------------------------------------------------is_close
inline bool is_close(unsigned c)
{
return (c & ~(path_flags_cw | path_flags_ccw)) ==
(path_cmd_end_poly | path_flags_close);
}
//------------------------------------------------------------is_next_poly
inline bool is_next_poly(unsigned c)
{
return is_stop(c) || is_move_to(c) || is_end_poly(c);
}
//-------------------------------------------------------------------is_cw
inline bool is_cw(unsigned c)
{
return (c & path_flags_cw) != 0;
}
//------------------------------------------------------------------is_ccw
inline bool is_ccw(unsigned c)
{
return (c & path_flags_ccw) != 0;
}
//-------------------------------------------------------------is_oriented
inline bool is_oriented(unsigned c)
{
return (c & (path_flags_cw | path_flags_ccw)) != 0;
}
//---------------------------------------------------------------is_closed
inline bool is_closed(unsigned c)
{
return (c & path_flags_close) != 0;
}
//----------------------------------------------------------get_close_flag
inline unsigned get_close_flag(unsigned c)
{
return c & path_flags_close;
}
//-------------------------------------------------------clear_orientation
inline unsigned clear_orientation(unsigned c)
{
return c & ~(path_flags_cw | path_flags_ccw);
}
//---------------------------------------------------------get_orientation
inline unsigned get_orientation(unsigned c)
{
return c & (path_flags_cw | path_flags_ccw);
}
//---------------------------------------------------------set_orientation
inline unsigned set_orientation(unsigned c, unsigned o)
{
return clear_orientation(c) | o;
}
//--------------------------------------------------------------point_base
template<class T> struct point_base
{
typedef T value_type;
T x,y;
point_base() {}
point_base(T x_, T y_) : x(x_), y(y_) {}
};
typedef point_base<int> point_i; //-----point_i
typedef point_base<float> point_f; //-----point_f
typedef point_base<double> point_d; //-----point_d
//-------------------------------------------------------------vertex_base
template<class T> struct vertex_base
{
typedef T value_type;
T x,y;
unsigned cmd;
vertex_base() {}
vertex_base(T x_, T y_, unsigned cmd_) : x(x_), y(y_), cmd(cmd_) {}
};
typedef vertex_base<int> vertex_i; //-----vertex_i
typedef vertex_base<float> vertex_f; //-----vertex_f
typedef vertex_base<double> vertex_d; //-----vertex_d
//----------------------------------------------------------------row_info
template<class T> struct row_info
{
int x1, x2;
T* ptr;
row_info() {}
row_info(int x1_, int x2_, T* ptr_) : x1(x1_), x2(x2_), ptr(ptr_) {}
};
//----------------------------------------------------------const_row_info
template<class T> struct const_row_info
{
int x1, x2;
const T* ptr;
const_row_info() {}
const_row_info(int x1_, int x2_, const T* ptr_) :
x1(x1_), x2(x2_), ptr(ptr_) {}
};
//------------------------------------------------------------is_equal_eps
template<class T> inline bool is_equal_eps(T v1, T v2, T epsilon)
{
return fabs(v1 - v2) <= double(epsilon);
}
}
#endif
| 0 |
D://workCode//uploadProject\awtk\3rd\agg | D://workCode//uploadProject\awtk\3rd\agg\include\agg_clip_liang_barsky.h | //----------------------------------------------------------------------------
// Anti-Grain Geometry - Version 2.4
// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
//
//----------------------------------------------------------------------------
// Contact: mcseem@antigrain.com
// mcseemagg@yahoo.com
// http://www.antigrain.com
//----------------------------------------------------------------------------
//
// Liang-Barsky clipping
//
//----------------------------------------------------------------------------
#ifndef AGG_CLIP_LIANG_BARSKY_INCLUDED
#define AGG_CLIP_LIANG_BARSKY_INCLUDED
#include "agg_basics.h"
namespace agg
{
//------------------------------------------------------------------------
enum clipping_flags_e
{
clipping_flags_x1_clipped = 4,
clipping_flags_x2_clipped = 1,
clipping_flags_y1_clipped = 8,
clipping_flags_y2_clipped = 2,
clipping_flags_x_clipped = clipping_flags_x1_clipped | clipping_flags_x2_clipped,
clipping_flags_y_clipped = clipping_flags_y1_clipped | clipping_flags_y2_clipped
};
//----------------------------------------------------------clipping_flags
// Determine the clipping code of the vertex according to the
// Cyrus-Beck line clipping algorithm
//
// | |
// 0110 | 0010 | 0011
// | |
// -------+--------+-------- clip_box.y2
// | |
// 0100 | 0000 | 0001
// | |
// -------+--------+-------- clip_box.y1
// | |
// 1100 | 1000 | 1001
// | |
// clip_box.x1 clip_box.x2
//
//
template<class T>
inline unsigned clipping_flags(T x, T y, const rect_base<T>& clip_box)
{
return (x > clip_box.x2) |
((y > clip_box.y2) << 1) |
((x < clip_box.x1) << 2) |
((y < clip_box.y1) << 3);
}
//--------------------------------------------------------clipping_flags_x
template<class T>
inline unsigned clipping_flags_x(T x, const rect_base<T>& clip_box)
{
return (x > clip_box.x2) | ((x < clip_box.x1) << 2);
}
//--------------------------------------------------------clipping_flags_y
template<class T>
inline unsigned clipping_flags_y(T y, const rect_base<T>& clip_box)
{
return ((y > clip_box.y2) << 1) | ((y < clip_box.y1) << 3);
}
//-------------------------------------------------------clip_liang_barsky
template<class T>
inline unsigned clip_liang_barsky(T x1, T y1, T x2, T y2,
const rect_base<T>& clip_box,
T* x, T* y)
{
const double nearzero = 1e-30;
double deltax = x2 - x1;
double deltay = y2 - y1;
double xin;
double xout;
double yin;
double yout;
double tinx;
double tiny;
double toutx;
double touty;
double tin1;
double tin2;
double tout1;
unsigned np = 0;
if(deltax == 0.0)
{
// bump off of the vertical
deltax = (x1 > clip_box.x1) ? -nearzero : nearzero;
}
if(deltay == 0.0)
{
// bump off of the horizontal
deltay = (y1 > clip_box.y1) ? -nearzero : nearzero;
}
if(deltax > 0.0)
{
// points to right
xin = clip_box.x1;
xout = clip_box.x2;
}
else
{
xin = clip_box.x2;
xout = clip_box.x1;
}
if(deltay > 0.0)
{
// points up
yin = clip_box.y1;
yout = clip_box.y2;
}
else
{
yin = clip_box.y2;
yout = clip_box.y1;
}
tinx = (xin - x1) / deltax;
tiny = (yin - y1) / deltay;
if (tinx < tiny)
{
// hits x first
tin1 = tinx;
tin2 = tiny;
}
else
{
// hits y first
tin1 = tiny;
tin2 = tinx;
}
if(tin1 <= 1.0)
{
if(0.0 < tin1)
{
*x++ = (T)xin;
*y++ = (T)yin;
++np;
}
if(tin2 <= 1.0)
{
toutx = (xout - x1) / deltax;
touty = (yout - y1) / deltay;
tout1 = (toutx < touty) ? toutx : touty;
if(tin2 > 0.0 || tout1 > 0.0)
{
if(tin2 <= tout1)
{
if(tin2 > 0.0)
{
if(tinx > tiny)
{
*x++ = (T)xin;
*y++ = (T)(y1 + tinx * deltay);
}
else
{
*x++ = (T)(x1 + tiny * deltax);
*y++ = (T)yin;
}
++np;
}
if(tout1 < 1.0)
{
if(toutx < touty)
{
*x++ = (T)xout;
*y++ = (T)(y1 + toutx * deltay);
}
else
{
*x++ = (T)(x1 + touty * deltax);
*y++ = (T)yout;
}
}
else
{
*x++ = x2;
*y++ = y2;
}
++np;
}
else
{
if(tinx > tiny)
{
*x++ = (T)xin;
*y++ = (T)yout;
}
else
{
*x++ = (T)xout;
*y++ = (T)yin;
}
++np;
}
}
}
}
return np;
}
//----------------------------------------------------------------------------
template<class T>
bool clip_move_point(T x1, T y1, T x2, T y2,
const rect_base<T>& clip_box,
T* x, T* y, unsigned flags)
{
T bound;
if(flags & clipping_flags_x_clipped)
{
if(x1 == x2)
{
return false;
}
bound = (flags & clipping_flags_x1_clipped) ? clip_box.x1 : clip_box.x2;
*y = (T)(double(bound - x1) * (y2 - y1) / (x2 - x1) + y1);
*x = bound;
}
flags = clipping_flags_y(*y, clip_box);
if(flags & clipping_flags_y_clipped)
{
if(y1 == y2)
{
return false;
}
bound = (flags & clipping_flags_y1_clipped) ? clip_box.y1 : clip_box.y2;
*x = (T)(double(bound - y1) * (x2 - x1) / (y2 - y1) + x1);
*y = bound;
}
return true;
}
//-------------------------------------------------------clip_line_segment
// Returns: ret >= 4 - Fully clipped
// (ret & 1) != 0 - First point has been moved
// (ret & 2) != 0 - Second point has been moved
//
template<class T>
unsigned clip_line_segment(T* x1, T* y1, T* x2, T* y2,
const rect_base<T>& clip_box)
{
unsigned f1 = clipping_flags(*x1, *y1, clip_box);
unsigned f2 = clipping_flags(*x2, *y2, clip_box);
unsigned ret = 0;
if((f2 | f1) == 0)
{
// Fully visible
return 0;
}
if((f1 & clipping_flags_x_clipped) != 0 &&
(f1 & clipping_flags_x_clipped) == (f2 & clipping_flags_x_clipped))
{
// Fully clipped
return 4;
}
if((f1 & clipping_flags_y_clipped) != 0 &&
(f1 & clipping_flags_y_clipped) == (f2 & clipping_flags_y_clipped))
{
// Fully clipped
return 4;
}
T tx1 = *x1;
T ty1 = *y1;
T tx2 = *x2;
T ty2 = *y2;
if(f1)
{
if(!clip_move_point(tx1, ty1, tx2, ty2, clip_box, x1, y1, f1))
{
return 4;
}
if(*x1 == *x2 && *y1 == *y2)
{
return 4;
}
ret |= 1;
}
if(f2)
{
if(!clip_move_point(tx1, ty1, tx2, ty2, clip_box, x2, y2, f2))
{
return 4;
}
if(*x1 == *x2 && *y1 == *y2)
{
return 4;
}
ret |= 2;
}
return ret;
}
}
#endif
| 0 |
D://workCode//uploadProject\awtk\3rd\agg | D://workCode//uploadProject\awtk\3rd\agg\include\agg_color_gray.h | //----------------------------------------------------------------------------
// Anti-Grain Geometry - Version 2.4
// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
//
//----------------------------------------------------------------------------
// Contact: mcseem@antigrain.com
// mcseemagg@yahoo.com
// http://www.antigrain.com
//----------------------------------------------------------------------------
//
// Adaptation for high precision colors has been sponsored by
// Liberty Technology Systems, Inc., visit http://lib-sys.com
//
// Liberty Technology Systems, Inc. is the provider of
// PostScript and PDF technology for software developers.
//
//----------------------------------------------------------------------------
//
// color types gray8, gray16
//
//----------------------------------------------------------------------------
#ifndef AGG_COLOR_GRAY_INCLUDED
#define AGG_COLOR_GRAY_INCLUDED
#include "agg_basics.h"
#include "agg_color_rgba.h"
namespace agg
{
//===================================================================gray8
template<class Colorspace>
struct gray8T
{
typedef int8u value_type;
typedef int32u calc_type;
typedef int32 long_type;
enum base_scale_e
{
base_shift = 8,
base_scale = 1 << base_shift,
base_mask = base_scale - 1,
base_MSB = 1 << (base_shift - 1)
};
typedef gray8T self_type;
value_type v;
value_type a;
static value_type luminance(const rgba& c)
{
// Calculate grayscale value as per ITU-R BT.709.
return value_type(uround((0.2126 * c.r + 0.7152 * c.g + 0.0722 * c.b) * base_mask));
}
static value_type luminance(const rgba8& c)
{
// Calculate grayscale value as per ITU-R BT.709.
return value_type((55u * c.r + 184u * c.g + 18u * c.b) >> 8);
}
static void convert(gray8T<linear>& dst, const gray8T<sRGB>& src)
{
dst.v = sRGB_conv<value_type>::rgb_from_sRGB(src.v);
dst.a = src.a;
}
static void convert(gray8T<sRGB>& dst, const gray8T<linear>& src)
{
dst.v = sRGB_conv<value_type>::rgb_to_sRGB(src.v);
dst.a = src.a;
}
static void convert(gray8T<linear>& dst, const rgba8& src)
{
dst.v = luminance(src);
dst.a = src.a;
}
static void convert(gray8T<linear>& dst, const srgba8& src)
{
// The RGB weights are only valid for linear values.
convert(dst, rgba8(src));
}
static void convert(gray8T<sRGB>& dst, const rgba8& src)
{
dst.v = sRGB_conv<value_type>::rgb_to_sRGB(luminance(src));
dst.a = src.a;
}
static void convert(gray8T<sRGB>& dst, const srgba8& src)
{
// The RGB weights are only valid for linear values.
convert(dst, rgba8(src));
}
//--------------------------------------------------------------------
gray8T() {}
//--------------------------------------------------------------------
explicit gray8T(unsigned v_, unsigned a_ = base_mask) :
v(int8u(v_)), a(int8u(a_)) {}
//--------------------------------------------------------------------
gray8T(const self_type& c, unsigned a_) :
v(c.v), a(value_type(a_)) {}
//--------------------------------------------------------------------
gray8T(const rgba& c) :
v(luminance(c)),
a(value_type(uround(c.a * base_mask))) {}
//--------------------------------------------------------------------
template<class T>
gray8T(const gray8T<T>& c)
{
convert(*this, c);
}
//--------------------------------------------------------------------
template<class T>
gray8T(const rgba8T<T>& c)
{
convert(*this, c);
}
//--------------------------------------------------------------------
template<class T>
T convert_from_sRGB() const
{
typename T::value_type y = sRGB_conv<typename T::value_type>::rgb_from_sRGB(v);
return T(y, y, y, sRGB_conv<typename T::value_type>::alpha_from_sRGB(a));
}
template<class T>
T convert_to_sRGB() const
{
typename T::value_type y = sRGB_conv<typename T::value_type>::rgb_to_sRGB(v);
return T(y, y, y, sRGB_conv<typename T::value_type>::alpha_to_sRGB(a));
}
//--------------------------------------------------------------------
rgba8 make_rgba8(const linear&) const
{
return rgba8(v, v, v, a);
}
rgba8 make_rgba8(const sRGB&) const
{
return convert_from_sRGB<srgba8>();
}
operator rgba8() const
{
return make_rgba8(Colorspace());
}
//--------------------------------------------------------------------
srgba8 make_srgba8(const linear&) const
{
return convert_to_sRGB<rgba8>();
}
srgba8 make_srgba8(const sRGB&) const
{
return srgba8(v, v, v, a);
}
operator srgba8() const
{
return make_rgba8(Colorspace());
}
//--------------------------------------------------------------------
rgba16 make_rgba16(const linear&) const
{
rgba16::value_type rgb = (v << 8) | v;
return rgba16(rgb, rgb, rgb, (a << 8) | a);
}
rgba16 make_rgba16(const sRGB&) const
{
return convert_from_sRGB<rgba16>();
}
operator rgba16() const
{
return make_rgba16(Colorspace());
}
//--------------------------------------------------------------------
rgba32 make_rgba32(const linear&) const
{
rgba32::value_type v32 = v / 255.0f;
return rgba32(v32, v32, v32, a / 255.0f);
}
rgba32 make_rgba32(const sRGB&) const
{
return convert_from_sRGB<rgba32>();
}
operator rgba32() const
{
return make_rgba32(Colorspace());
}
//--------------------------------------------------------------------
static AGG_INLINE double to_double(value_type a)
{
return double(a) / base_mask;
}
//--------------------------------------------------------------------
static AGG_INLINE value_type from_double(double a)
{
return value_type(uround(a * base_mask));
}
//--------------------------------------------------------------------
static AGG_INLINE value_type empty_value()
{
return 0;
}
//--------------------------------------------------------------------
static AGG_INLINE value_type full_value()
{
return base_mask;
}
//--------------------------------------------------------------------
AGG_INLINE bool is_transparent() const
{
return a == 0;
}
//--------------------------------------------------------------------
AGG_INLINE bool is_opaque() const
{
return a == base_mask;
}
//--------------------------------------------------------------------
// Fixed-point multiply, exact over int8u.
static AGG_INLINE value_type multiply(value_type a, value_type b)
{
calc_type t = a * b + base_MSB;
return value_type(((t >> base_shift) + t) >> base_shift);
}
//--------------------------------------------------------------------
static AGG_INLINE value_type demultiply(value_type a, value_type b)
{
if (a * b == 0)
{
return 0;
}
else if (a >= b)
{
return base_mask;
}
else return value_type((a * base_mask + (b >> 1)) / b);
}
//--------------------------------------------------------------------
template<typename T>
static AGG_INLINE T downscale(T a)
{
return a >> base_shift;
}
//--------------------------------------------------------------------
template<typename T>
static AGG_INLINE T downshift(T a, unsigned n)
{
return a >> n;
}
//--------------------------------------------------------------------
// Fixed-point multiply, exact over int8u.
// Specifically for multiplying a color component by a cover.
static AGG_INLINE value_type mult_cover(value_type a, value_type b)
{
return multiply(a, b);
}
//--------------------------------------------------------------------
static AGG_INLINE cover_type scale_cover(cover_type a, value_type b)
{
return multiply(b, a);
}
//--------------------------------------------------------------------
// Interpolate p to q by a, assuming q is premultiplied by a.
static AGG_INLINE value_type prelerp(value_type p, value_type q, value_type a)
{
return p + q - multiply(p, a);
}
//--------------------------------------------------------------------
// Interpolate p to q by a.
static AGG_INLINE value_type lerp(value_type p, value_type q, value_type a)
{
int t = (q - p) * a + base_MSB - (p > q);
return value_type(p + (((t >> base_shift) + t) >> base_shift));
}
//--------------------------------------------------------------------
self_type& clear()
{
v = a = 0;
return *this;
}
//--------------------------------------------------------------------
self_type& transparent()
{
a = 0;
return *this;
}
//--------------------------------------------------------------------
self_type& opacity(double a_)
{
if (a_ < 0) a = 0;
else if (a_ > 1) a = 1;
else a = (value_type)uround(a_ * double(base_mask));
return *this;
}
//--------------------------------------------------------------------
double opacity() const
{
return double(a) / double(base_mask);
}
//--------------------------------------------------------------------
self_type& premultiply()
{
if (a < base_mask)
{
if (a == 0) v = 0;
else v = multiply(v, a);
}
return *this;
}
//--------------------------------------------------------------------
self_type& demultiply()
{
if (a < base_mask)
{
if (a == 0)
{
v = 0;
}
else
{
calc_type v_ = (calc_type(v) * base_mask) / a;
v = value_type((v_ > base_mask) ? (value_type)base_mask : v_);
}
}
return *this;
}
//--------------------------------------------------------------------
self_type gradient(self_type c, double k) const
{
self_type ret;
calc_type ik = uround(k * base_scale);
ret.v = lerp(v, c.v, ik);
ret.a = lerp(a, c.a, ik);
return ret;
}
//--------------------------------------------------------------------
AGG_INLINE void add(const self_type& c, unsigned cover)
{
calc_type cv, ca;
if (cover == cover_mask)
{
if (c.a == base_mask)
{
*this = c;
return;
}
else
{
cv = v + c.v;
ca = a + c.a;
}
}
else
{
cv = v + mult_cover(c.v, cover);
ca = a + mult_cover(c.a, cover);
}
v = (value_type)((cv > calc_type(base_mask)) ? calc_type(base_mask) : cv);
a = (value_type)((ca > calc_type(base_mask)) ? calc_type(base_mask) : ca);
}
//--------------------------------------------------------------------
static self_type no_color() { return self_type(0,0); }
};
typedef gray8T<linear> gray8;
typedef gray8T<sRGB> sgray8;
//==================================================================gray16
struct gray16
{
typedef int16u value_type;
typedef int32u calc_type;
typedef int64 long_type;
enum base_scale_e
{
base_shift = 16,
base_scale = 1 << base_shift,
base_mask = base_scale - 1,
base_MSB = 1 << (base_shift - 1)
};
typedef gray16 self_type;
value_type v;
value_type a;
static value_type luminance(const rgba& c)
{
// Calculate grayscale value as per ITU-R BT.709.
return value_type(uround((0.2126 * c.r + 0.7152 * c.g + 0.0722 * c.b) * base_mask));
}
static value_type luminance(const rgba16& c)
{
// Calculate grayscale value as per ITU-R BT.709.
return value_type((13933u * c.r + 46872u * c.g + 4732u * c.b) >> 16);
}
static value_type luminance(const rgba8& c)
{
return luminance(rgba16(c));
}
static value_type luminance(const srgba8& c)
{
return luminance(rgba16(c));
}
static value_type luminance(const rgba32& c)
{
return luminance(rgba(c));
}
//--------------------------------------------------------------------
gray16() {}
//--------------------------------------------------------------------
explicit gray16(unsigned v_, unsigned a_ = base_mask) :
v(int16u(v_)), a(int16u(a_)) {}
//--------------------------------------------------------------------
gray16(const self_type& c, unsigned a_) :
v(c.v), a(value_type(a_)) {}
//--------------------------------------------------------------------
gray16(const rgba& c) :
v(luminance(c)),
a((value_type)uround(c.a * double(base_mask))) {}
//--------------------------------------------------------------------
gray16(const rgba8& c) :
v(luminance(c)),
a((value_type(c.a) << 8) | c.a) {}
//--------------------------------------------------------------------
gray16(const srgba8& c) :
v(luminance(c)),
a((value_type(c.a) << 8) | c.a) {}
//--------------------------------------------------------------------
gray16(const rgba16& c) :
v(luminance(c)),
a(c.a) {}
//--------------------------------------------------------------------
gray16(const gray8& c) :
v((value_type(c.v) << 8) | c.v),
a((value_type(c.a) << 8) | c.a) {}
//--------------------------------------------------------------------
gray16(const sgray8& c) :
v(sRGB_conv<value_type>::rgb_from_sRGB(c.v)),
a(sRGB_conv<value_type>::alpha_from_sRGB(c.a)) {}
//--------------------------------------------------------------------
operator rgba8() const
{
return rgba8(v >> 8, v >> 8, v >> 8, a >> 8);
}
//--------------------------------------------------------------------
operator srgba8() const
{
value_type y = sRGB_conv<value_type>::rgb_to_sRGB(v);
return srgba8(y, y, y, sRGB_conv<value_type>::alpha_to_sRGB(a));
}
//--------------------------------------------------------------------
operator rgba16() const
{
return rgba16(v, v, v, a);
}
//--------------------------------------------------------------------
operator rgba32() const
{
rgba32::value_type v32 = v / 65535.0f;
return rgba32(v32, v32, v32, a / 65535.0f);
}
//--------------------------------------------------------------------
operator gray8() const
{
return gray8(v >> 8, a >> 8);
}
//--------------------------------------------------------------------
operator sgray8() const
{
return sgray8(
sRGB_conv<value_type>::rgb_to_sRGB(v),
sRGB_conv<value_type>::alpha_to_sRGB(a));
}
//--------------------------------------------------------------------
static AGG_INLINE double to_double(value_type a)
{
return double(a) / base_mask;
}
//--------------------------------------------------------------------
static AGG_INLINE value_type from_double(double a)
{
return value_type(uround(a * base_mask));
}
//--------------------------------------------------------------------
static AGG_INLINE value_type empty_value()
{
return 0;
}
//--------------------------------------------------------------------
static AGG_INLINE value_type full_value()
{
return base_mask;
}
//--------------------------------------------------------------------
AGG_INLINE bool is_transparent() const
{
return a == 0;
}
//--------------------------------------------------------------------
AGG_INLINE bool is_opaque() const
{
return a == base_mask;
}
//--------------------------------------------------------------------
// Fixed-point multiply, exact over int16u.
static AGG_INLINE value_type multiply(value_type a, value_type b)
{
calc_type t = a * b + base_MSB;
return value_type(((t >> base_shift) + t) >> base_shift);
}
//--------------------------------------------------------------------
static AGG_INLINE value_type demultiply(value_type a, value_type b)
{
if (a * b == 0)
{
return 0;
}
else if (a >= b)
{
return base_mask;
}
else return value_type((a * base_mask + (b >> 1)) / b);
}
//--------------------------------------------------------------------
template<typename T>
static AGG_INLINE T downscale(T a)
{
return a >> base_shift;
}
//--------------------------------------------------------------------
template<typename T>
static AGG_INLINE T downshift(T a, unsigned n)
{
return a >> n;
}
//--------------------------------------------------------------------
// Fixed-point multiply, almost exact over int16u.
// Specifically for multiplying a color component by a cover.
static AGG_INLINE value_type mult_cover(value_type a, cover_type b)
{
return multiply(a, b << 8 | b);
}
//--------------------------------------------------------------------
static AGG_INLINE cover_type scale_cover(cover_type a, value_type b)
{
return mult_cover(b, a) >> 8;
}
//--------------------------------------------------------------------
// Interpolate p to q by a, assuming q is premultiplied by a.
static AGG_INLINE value_type prelerp(value_type p, value_type q, value_type a)
{
return p + q - multiply(p, a);
}
//--------------------------------------------------------------------
// Interpolate p to q by a.
static AGG_INLINE value_type lerp(value_type p, value_type q, value_type a)
{
int t = (q - p) * a + base_MSB - (p > q);
return value_type(p + (((t >> base_shift) + t) >> base_shift));
}
//--------------------------------------------------------------------
self_type& clear()
{
v = a = 0;
return *this;
}
//--------------------------------------------------------------------
self_type& transparent()
{
a = 0;
return *this;
}
//--------------------------------------------------------------------
self_type& opacity(double a_)
{
if (a_ < 0) a = 0;
else if(a_ > 1) a = 1;
else a = (value_type)uround(a_ * double(base_mask));
return *this;
}
//--------------------------------------------------------------------
double opacity() const
{
return double(a) / double(base_mask);
}
//--------------------------------------------------------------------
self_type& premultiply()
{
if (a < base_mask)
{
if(a == 0) v = 0;
else v = multiply(v, a);
}
return *this;
}
//--------------------------------------------------------------------
self_type& demultiply()
{
if (a < base_mask)
{
if (a == 0)
{
v = 0;
}
else
{
calc_type v_ = (calc_type(v) * base_mask) / a;
v = value_type((v_ > base_mask) ? base_mask : v_);
}
}
return *this;
}
//--------------------------------------------------------------------
self_type gradient(self_type c, double k) const
{
self_type ret;
calc_type ik = uround(k * base_scale);
ret.v = lerp(v, c.v, ik);
ret.a = lerp(a, c.a, ik);
return ret;
}
//--------------------------------------------------------------------
AGG_INLINE void add(const self_type& c, unsigned cover)
{
calc_type cv, ca;
if (cover == cover_mask)
{
if (c.a == base_mask)
{
*this = c;
return;
}
else
{
cv = v + c.v;
ca = a + c.a;
}
}
else
{
cv = v + mult_cover(c.v, cover);
ca = a + mult_cover(c.a, cover);
}
v = (value_type)((cv > calc_type(base_mask)) ? calc_type(base_mask) : cv);
a = (value_type)((ca > calc_type(base_mask)) ? calc_type(base_mask) : ca);
}
//--------------------------------------------------------------------
static self_type no_color() { return self_type(0,0); }
};
//===================================================================gray32
struct gray32
{
typedef float value_type;
typedef double calc_type;
typedef double long_type;
typedef gray32 self_type;
value_type v;
value_type a;
// Calculate grayscale value as per ITU-R BT.709.
static value_type luminance(double r, double g, double b)
{
return value_type(0.2126 * r + 0.7152 * g + 0.0722 * b);
}
static value_type luminance(const rgba& c)
{
return luminance(c.r, c.g, c.b);
}
static value_type luminance(const rgba32& c)
{
return luminance(c.r, c.g, c.b);
}
static value_type luminance(const rgba8& c)
{
return luminance(c.r / 255.0, c.g / 255.0, c.g / 255.0);
}
static value_type luminance(const rgba16& c)
{
return luminance(c.r / 65535.0, c.g / 65535.0, c.g / 65535.0);
}
//--------------------------------------------------------------------
gray32() {}
//--------------------------------------------------------------------
explicit gray32(value_type v_, value_type a_ = 1) :
v(v_), a(a_) {}
//--------------------------------------------------------------------
gray32(const self_type& c, value_type a_) :
v(c.v), a(a_) {}
//--------------------------------------------------------------------
gray32(const rgba& c) :
v(luminance(c)),
a(value_type(c.a)) {}
//--------------------------------------------------------------------
gray32(const rgba8& c) :
v(luminance(c)),
a(value_type(c.a / 255.0)) {}
//--------------------------------------------------------------------
gray32(const srgba8& c) :
v(luminance(rgba32(c))),
a(value_type(c.a / 255.0)) {}
//--------------------------------------------------------------------
gray32(const rgba16& c) :
v(luminance(c)),
a(value_type(c.a / 65535.0)) {}
//--------------------------------------------------------------------
gray32(const rgba32& c) :
v(luminance(c)),
a(value_type(c.a)) {}
//--------------------------------------------------------------------
gray32(const gray8& c) :
v(value_type(c.v / 255.0)),
a(value_type(c.a / 255.0)) {}
//--------------------------------------------------------------------
gray32(const sgray8& c) :
v(sRGB_conv<value_type>::rgb_from_sRGB(c.v)),
a(sRGB_conv<value_type>::alpha_from_sRGB(c.a)) {}
//--------------------------------------------------------------------
gray32(const gray16& c) :
v(value_type(c.v / 65535.0)),
a(value_type(c.a / 65535.0)) {}
//--------------------------------------------------------------------
operator rgba() const
{
return rgba(v, v, v, a);
}
//--------------------------------------------------------------------
operator gray8() const
{
return gray8(uround(v * 255.0), uround(a * 255.0));
}
//--------------------------------------------------------------------
operator sgray8() const
{
// Return (non-premultiplied) sRGB values.
return sgray8(
sRGB_conv<value_type>::rgb_to_sRGB(v),
sRGB_conv<value_type>::alpha_to_sRGB(a));
}
//--------------------------------------------------------------------
operator gray16() const
{
return gray16(uround(v * 65535.0), uround(a * 65535.0));
}
//--------------------------------------------------------------------
operator rgba8() const
{
rgba8::value_type y = uround(v * 255.0);
return rgba8(y, y, y, uround(a * 255.0));
}
//--------------------------------------------------------------------
operator srgba8() const
{
srgba8::value_type y = sRGB_conv<value_type>::rgb_to_sRGB(v);
return srgba8(y, y, y, sRGB_conv<value_type>::alpha_to_sRGB(a));
}
//--------------------------------------------------------------------
operator rgba16() const
{
rgba16::value_type y = uround(v * 65535.0);
return rgba16(y, y, y, uround(a * 65535.0));
}
//--------------------------------------------------------------------
operator rgba32() const
{
return rgba32(v, v, v, a);
}
//--------------------------------------------------------------------
static AGG_INLINE double to_double(value_type a)
{
return a;
}
//--------------------------------------------------------------------
static AGG_INLINE value_type from_double(double a)
{
return value_type(a);
}
//--------------------------------------------------------------------
static AGG_INLINE value_type empty_value()
{
return 0;
}
//--------------------------------------------------------------------
static AGG_INLINE value_type full_value()
{
return 1;
}
//--------------------------------------------------------------------
AGG_INLINE bool is_transparent() const
{
return a <= 0;
}
//--------------------------------------------------------------------
AGG_INLINE bool is_opaque() const
{
return a >= 1;
}
//--------------------------------------------------------------------
static AGG_INLINE value_type invert(value_type x)
{
return 1 - x;
}
//--------------------------------------------------------------------
static AGG_INLINE value_type multiply(value_type a, value_type b)
{
return value_type(a * b);
}
//--------------------------------------------------------------------
static AGG_INLINE value_type demultiply(value_type a, value_type b)
{
return (b == 0) ? 0 : value_type(a / b);
}
//--------------------------------------------------------------------
template<typename T>
static AGG_INLINE T downscale(T a)
{
return a;
}
//--------------------------------------------------------------------
template<typename T>
static AGG_INLINE T downshift(T a, unsigned n)
{
return n > 0 ? a / (1 << n) : a;
}
//--------------------------------------------------------------------
static AGG_INLINE value_type mult_cover(value_type a, cover_type b)
{
return value_type(a * b / cover_mask);
}
//--------------------------------------------------------------------
static AGG_INLINE cover_type scale_cover(cover_type a, value_type b)
{
return cover_type(uround(a * b));
}
//--------------------------------------------------------------------
// Interpolate p to q by a, assuming q is premultiplied by a.
static AGG_INLINE value_type prelerp(value_type p, value_type q, value_type a)
{
return (1 - a) * p + q; // more accurate than "p + q - p * a"
}
//--------------------------------------------------------------------
// Interpolate p to q by a.
static AGG_INLINE value_type lerp(value_type p, value_type q, value_type a)
{
// The form "p + a * (q - p)" avoids a multiplication, but may produce an
// inaccurate result. For example, "p + (q - p)" may not be exactly equal
// to q. Therefore, stick to the basic expression, which at least produces
// the correct result at either extreme.
return (1 - a) * p + a * q;
}
//--------------------------------------------------------------------
self_type& clear()
{
v = a = 0;
return *this;
}
//--------------------------------------------------------------------
self_type& transparent()
{
a = 0;
return *this;
}
//--------------------------------------------------------------------
self_type& opacity(double a_)
{
if (a_ < 0) a = 0;
else if (a_ > 1) a = 1;
else a = value_type(a_);
return *this;
}
//--------------------------------------------------------------------
double opacity() const
{
return a;
}
//--------------------------------------------------------------------
self_type& premultiply()
{
if (a < 0) v = 0;
else if(a < 1) v *= a;
return *this;
}
//--------------------------------------------------------------------
self_type& demultiply()
{
if (a < 0) v = 0;
else if (a < 1) v /= a;
return *this;
}
//--------------------------------------------------------------------
self_type gradient(self_type c, double k) const
{
return self_type(
value_type(v + (c.v - v) * k),
value_type(a + (c.a - a) * k));
}
//--------------------------------------------------------------------
static self_type no_color() { return self_type(0,0); }
};
}
#endif
| 0 |
D://workCode//uploadProject\awtk\3rd\agg | D://workCode//uploadProject\awtk\3rd\agg\include\agg_color_rgba.h | //----------------------------------------------------------------------------
// Anti-Grain Geometry - Version 2.4
// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
//
//----------------------------------------------------------------------------
//
// Adaptation for high precision colors has been sponsored by
// Liberty Technology Systems, Inc., visit http://lib-sys.com
//
// Liberty Technology Systems, Inc. is the provider of
// PostScript and PDF technology for software developers.
//
//----------------------------------------------------------------------------
// Contact: mcseem@antigrain.com
// mcseemagg@yahoo.com
// http://www.antigrain.com
//----------------------------------------------------------------------------
#ifndef AGG_COLOR_RGBA_INCLUDED
#define AGG_COLOR_RGBA_INCLUDED
#include <math.h>
#include "agg_basics.h"
#include "agg_gamma_lut.h"
namespace agg
{
// Supported component orders for RGB and RGBA pixel formats
//=======================================================================
struct order_rgb { enum rgb_e { R=0, G=1, B=2, N=3 }; };
struct order_bgr { enum bgr_e { B=0, G=1, R=2, N=3 }; };
struct order_rgba { enum rgba_e { R=0, G=1, B=2, A=3, N=4 }; };
struct order_argb { enum argb_e { A=0, R=1, G=2, B=3, N=4 }; };
struct order_abgr { enum abgr_e { A=0, B=1, G=2, R=3, N=4 }; };
struct order_bgra { enum bgra_e { B=0, G=1, R=2, A=3, N=4 }; };
// Colorspace tag types.
struct linear {};
struct sRGB {};
//====================================================================rgba
struct rgba
{
typedef double value_type;
double r;
double g;
double b;
double a;
//--------------------------------------------------------------------
rgba() {}
//--------------------------------------------------------------------
rgba(double r_, double g_, double b_, double a_=1.0) :
r(r_), g(g_), b(b_), a(a_) {}
//--------------------------------------------------------------------
rgba(const rgba& c, double a_) : r(c.r), g(c.g), b(c.b), a(a_) {}
//--------------------------------------------------------------------
rgba& clear()
{
r = g = b = a = 0;
return *this;
}
//--------------------------------------------------------------------
rgba& transparent()
{
a = 0;
return *this;
}
//--------------------------------------------------------------------
rgba& opacity(double a_)
{
if (a_ < 0) a = 0;
else if (a_ > 1) a = 1;
else a = a_;
return *this;
}
//--------------------------------------------------------------------
double opacity() const
{
return a;
}
//--------------------------------------------------------------------
rgba& premultiply()
{
r *= a;
g *= a;
b *= a;
return *this;
}
//--------------------------------------------------------------------
rgba& premultiply(double a_)
{
if (a <= 0 || a_ <= 0)
{
r = g = b = a = 0;
}
else
{
a_ /= a;
r *= a_;
g *= a_;
b *= a_;
a = a_;
}
return *this;
}
//--------------------------------------------------------------------
rgba& demultiply()
{
if (a == 0)
{
r = g = b = 0;
}
else
{
double a_ = 1.0 / a;
r *= a_;
g *= a_;
b *= a_;
}
return *this;
}
//--------------------------------------------------------------------
rgba gradient(rgba c, double k) const
{
rgba ret;
ret.r = r + (c.r - r) * k;
ret.g = g + (c.g - g) * k;
ret.b = b + (c.b - b) * k;
ret.a = a + (c.a - a) * k;
return ret;
}
rgba& operator+=(const rgba& c)
{
r += c.r;
g += c.g;
b += c.b;
a += c.a;
return *this;
}
rgba& operator*=(double k)
{
r *= k;
g *= k;
b *= k;
a *= k;
return *this;
}
//--------------------------------------------------------------------
static rgba no_color() { return rgba(0,0,0,0); }
//--------------------------------------------------------------------
static rgba from_wavelength(double wl, double gamma = 1.0);
//--------------------------------------------------------------------
explicit rgba(double wavelen, double gamma=1.0)
{
*this = from_wavelength(wavelen, gamma);
}
};
inline rgba operator+(const rgba& a, const rgba& b)
{
return rgba(a) += b;
}
inline rgba operator*(const rgba& a, double b)
{
return rgba(a) *= b;
}
//------------------------------------------------------------------------
inline rgba rgba::from_wavelength(double wl, double gamma)
{
rgba t(0.0, 0.0, 0.0);
if (wl >= 380.0 && wl <= 440.0)
{
t.r = -1.0 * (wl - 440.0) / (440.0 - 380.0);
t.b = 1.0;
}
else if (wl >= 440.0 && wl <= 490.0)
{
t.g = (wl - 440.0) / (490.0 - 440.0);
t.b = 1.0;
}
else if (wl >= 490.0 && wl <= 510.0)
{
t.g = 1.0;
t.b = -1.0 * (wl - 510.0) / (510.0 - 490.0);
}
else if (wl >= 510.0 && wl <= 580.0)
{
t.r = (wl - 510.0) / (580.0 - 510.0);
t.g = 1.0;
}
else if (wl >= 580.0 && wl <= 645.0)
{
t.r = 1.0;
t.g = -1.0 * (wl - 645.0) / (645.0 - 580.0);
}
else if (wl >= 645.0 && wl <= 780.0)
{
t.r = 1.0;
}
double s = 1.0;
if (wl > 700.0) s = 0.3 + 0.7 * (780.0 - wl) / (780.0 - 700.0);
else if (wl < 420.0) s = 0.3 + 0.7 * (wl - 380.0) / (420.0 - 380.0);
t.r = pow(t.r * s, gamma);
t.g = pow(t.g * s, gamma);
t.b = pow(t.b * s, gamma);
return t;
}
inline rgba rgba_pre(double r, double g, double b, double a)
{
return rgba(r, g, b, a).premultiply();
}
//===================================================================rgba8
template<class Colorspace>
struct rgba8T
{
typedef int8u value_type;
typedef int32u calc_type;
typedef int32 long_type;
enum base_scale_e
{
base_shift = 8,
base_scale = 1 << base_shift,
base_mask = base_scale - 1,
base_MSB = 1 << (base_shift - 1)
};
typedef rgba8T self_type;
value_type r;
value_type g;
value_type b;
value_type a;
static void convert(rgba8T<linear>& dst, const rgba8T<sRGB>& src)
{
dst.r = sRGB_conv<value_type>::rgb_from_sRGB(src.r);
dst.g = sRGB_conv<value_type>::rgb_from_sRGB(src.g);
dst.b = sRGB_conv<value_type>::rgb_from_sRGB(src.b);
dst.a = src.a;
}
static void convert(rgba8T<sRGB>& dst, const rgba8T<linear>& src)
{
dst.r = sRGB_conv<value_type>::rgb_to_sRGB(src.r);
dst.g = sRGB_conv<value_type>::rgb_to_sRGB(src.g);
dst.b = sRGB_conv<value_type>::rgb_to_sRGB(src.b);
dst.a = src.a;
}
static void convert(rgba8T<linear>& dst, const rgba& src)
{
dst.r = value_type(uround(src.r * base_mask));
dst.g = value_type(uround(src.g * base_mask));
dst.b = value_type(uround(src.b * base_mask));
dst.a = value_type(uround(src.a * base_mask));
}
static void convert(rgba8T<sRGB>& dst, const rgba& src)
{
// Use the "float" table.
dst.r = sRGB_conv<float>::rgb_to_sRGB(float(src.r));
dst.g = sRGB_conv<float>::rgb_to_sRGB(float(src.g));
dst.b = sRGB_conv<float>::rgb_to_sRGB(float(src.b));
dst.a = sRGB_conv<float>::alpha_to_sRGB(float(src.a));
}
static void convert(rgba& dst, const rgba8T<linear>& src)
{
dst.r = src.r / 255.0;
dst.g = src.g / 255.0;
dst.b = src.b / 255.0;
dst.a = src.a / 255.0;
}
static void convert(rgba& dst, const rgba8T<sRGB>& src)
{
// Use the "float" table.
dst.r = sRGB_conv<float>::rgb_from_sRGB(src.r);
dst.g = sRGB_conv<float>::rgb_from_sRGB(src.g);
dst.b = sRGB_conv<float>::rgb_from_sRGB(src.b);
dst.a = sRGB_conv<float>::alpha_from_sRGB(src.a);
}
//--------------------------------------------------------------------
rgba8T() {}
//--------------------------------------------------------------------
rgba8T(unsigned r_, unsigned g_, unsigned b_, unsigned a_ = base_mask) :
r(value_type(r_)),
g(value_type(g_)),
b(value_type(b_)),
a(value_type(a_)) {}
//--------------------------------------------------------------------
rgba8T(const rgba& c)
{
convert(*this, c);
}
//--------------------------------------------------------------------
rgba8T(const self_type& c, unsigned a_) :
r(c.r), g(c.g), b(c.b), a(value_type(a_)) {}
//--------------------------------------------------------------------
template<class T>
rgba8T(const rgba8T<T>& c)
{
convert(*this, c);
}
//--------------------------------------------------------------------
operator rgba() const
{
rgba c;
convert(c, *this);
return c;
}
//--------------------------------------------------------------------
static AGG_INLINE double to_double(value_type a)
{
return double(a) / base_mask;
}
//--------------------------------------------------------------------
static AGG_INLINE value_type from_double(double a)
{
return value_type(uround(a * base_mask));
}
//--------------------------------------------------------------------
static AGG_INLINE value_type empty_value()
{
return 0;
}
//--------------------------------------------------------------------
static AGG_INLINE value_type full_value()
{
return base_mask;
}
//--------------------------------------------------------------------
AGG_INLINE bool is_transparent() const
{
return a == 0;
}
//--------------------------------------------------------------------
AGG_INLINE bool is_opaque() const
{
return a == base_mask;
}
//--------------------------------------------------------------------
static AGG_INLINE value_type invert(value_type x)
{
return base_mask - x;
}
//--------------------------------------------------------------------
// Fixed-point multiply, exact over int8u.
static AGG_INLINE value_type multiply(value_type a, value_type b)
{
calc_type t = a * b + base_MSB;
return value_type(((t >> base_shift) + t) >> base_shift);
}
//--------------------------------------------------------------------
static AGG_INLINE value_type demultiply(value_type a, value_type b)
{
if (a * b == 0)
{
return 0;
}
else if (a >= b)
{
return base_mask;
}
else return value_type((a * base_mask + (b >> 1)) / b);
}
//--------------------------------------------------------------------
template<typename T>
static AGG_INLINE T downscale(T a)
{
return a >> base_shift;
}
//--------------------------------------------------------------------
template<typename T>
static AGG_INLINE T downshift(T a, unsigned n)
{
return a >> n;
}
//--------------------------------------------------------------------
// Fixed-point multiply, exact over int8u.
// Specifically for multiplying a color component by a cover.
static AGG_INLINE value_type mult_cover(value_type a, cover_type b)
{
return multiply(a, b);
}
//--------------------------------------------------------------------
static AGG_INLINE cover_type scale_cover(cover_type a, value_type b)
{
return multiply(b, a);
}
//--------------------------------------------------------------------
// Interpolate p to q by a, assuming q is premultiplied by a.
static AGG_INLINE value_type prelerp(value_type p, value_type q, value_type a)
{
return p + q - multiply(p, a);
}
//--------------------------------------------------------------------
// Interpolate p to q by a.
static AGG_INLINE value_type lerp(value_type p, value_type q, value_type a)
{
int t = (q - p) * a + base_MSB - (p > q);
return value_type(p + (((t >> base_shift) + t) >> base_shift));
}
//--------------------------------------------------------------------
self_type& clear()
{
r = g = b = a = 0;
return *this;
}
//--------------------------------------------------------------------
self_type& transparent()
{
a = 0;
return *this;
}
//--------------------------------------------------------------------
self_type& opacity(double a_)
{
if (a_ < 0) a = 0;
else if (a_ > 1) a = 1;
else a = (value_type)uround(a_ * double(base_mask));
return *this;
}
//--------------------------------------------------------------------
double opacity() const
{
return double(a) / double(base_mask);
}
//--------------------------------------------------------------------
AGG_INLINE self_type& premultiply()
{
if (a != base_mask)
{
if (a == 0)
{
r = g = b = 0;
}
else
{
r = multiply(r, a);
g = multiply(g, a);
b = multiply(b, a);
}
}
return *this;
}
//--------------------------------------------------------------------
AGG_INLINE self_type& premultiply(unsigned a_)
{
if (a != base_mask || a_ < base_mask)
{
if (a == 0 || a_ == 0)
{
r = g = b = a = 0;
}
else
{
calc_type r_ = (calc_type(r) * a_) / a;
calc_type g_ = (calc_type(g) * a_) / a;
calc_type b_ = (calc_type(b) * a_) / a;
r = value_type((r_ > a_) ? a_ : r_);
g = value_type((g_ > a_) ? a_ : g_);
b = value_type((b_ > a_) ? a_ : b_);
a = value_type(a_);
}
}
return *this;
}
//--------------------------------------------------------------------
AGG_INLINE self_type& demultiply()
{
if (a < base_mask)
{
if (a == 0)
{
r = g = b = 0;
}
else
{
calc_type r_ = (calc_type(r) * base_mask) / a;
calc_type g_ = (calc_type(g) * base_mask) / a;
calc_type b_ = (calc_type(b) * base_mask) / a;
r = value_type((r_ > calc_type(base_mask)) ? calc_type(base_mask) : r_);
g = value_type((g_ > calc_type(base_mask)) ? calc_type(base_mask) : g_);
b = value_type((b_ > calc_type(base_mask)) ? calc_type(base_mask) : b_);
}
}
return *this;
}
//--------------------------------------------------------------------
AGG_INLINE self_type gradient(const self_type& c, double k) const
{
self_type ret;
calc_type ik = uround(k * base_mask);
ret.r = lerp(r, c.r, ik);
ret.g = lerp(g, c.g, ik);
ret.b = lerp(b, c.b, ik);
ret.a = lerp(a, c.a, ik);
return ret;
}
//--------------------------------------------------------------------
AGG_INLINE void add(const self_type& c, unsigned cover)
{
calc_type cr, cg, cb, ca;
if (cover == cover_mask)
{
if (c.a == base_mask)
{
*this = c;
return;
}
else
{
cr = r + c.r;
cg = g + c.g;
cb = b + c.b;
ca = a + c.a;
}
}
else
{
cr = r + mult_cover(c.r, cover);
cg = g + mult_cover(c.g, cover);
cb = b + mult_cover(c.b, cover);
ca = a + mult_cover(c.a, cover);
}
r = (value_type)((cr > calc_type(base_mask)) ? calc_type(base_mask) : cr);
g = (value_type)((cg > calc_type(base_mask)) ? calc_type(base_mask) : cg);
b = (value_type)((cb > calc_type(base_mask)) ? calc_type(base_mask) : cb);
a = (value_type)((ca > calc_type(base_mask)) ? calc_type(base_mask) : ca);
}
//--------------------------------------------------------------------
template<class GammaLUT>
AGG_INLINE void apply_gamma_dir(const GammaLUT& gamma)
{
r = gamma.dir(r);
g = gamma.dir(g);
b = gamma.dir(b);
}
//--------------------------------------------------------------------
template<class GammaLUT>
AGG_INLINE void apply_gamma_inv(const GammaLUT& gamma)
{
r = gamma.inv(r);
g = gamma.inv(g);
b = gamma.inv(b);
}
//--------------------------------------------------------------------
static self_type no_color() { return self_type(0,0,0,0); }
//--------------------------------------------------------------------
static self_type from_wavelength(double wl, double gamma = 1.0)
{
return self_type(rgba::from_wavelength(wl, gamma));
}
};
typedef rgba8T<linear> rgba8;
typedef rgba8T<sRGB> srgba8;
//-------------------------------------------------------------rgb8_packed
inline rgba8 rgb8_packed(unsigned v)
{
return rgba8((v >> 16) & 0xFF, (v >> 8) & 0xFF, v & 0xFF);
}
//-------------------------------------------------------------bgr8_packed
inline rgba8 bgr8_packed(unsigned v)
{
return rgba8(v & 0xFF, (v >> 8) & 0xFF, (v >> 16) & 0xFF);
}
//------------------------------------------------------------argb8_packed
inline rgba8 argb8_packed(unsigned v)
{
return rgba8((v >> 16) & 0xFF, (v >> 8) & 0xFF, v & 0xFF, v >> 24);
}
//---------------------------------------------------------rgba8_gamma_dir
template<class GammaLUT>
rgba8 rgba8_gamma_dir(rgba8 c, const GammaLUT& gamma)
{
return rgba8(gamma.dir(c.r), gamma.dir(c.g), gamma.dir(c.b), c.a);
}
//---------------------------------------------------------rgba8_gamma_inv
template<class GammaLUT>
rgba8 rgba8_gamma_inv(rgba8 c, const GammaLUT& gamma)
{
return rgba8(gamma.inv(c.r), gamma.inv(c.g), gamma.inv(c.b), c.a);
}
//==================================================================rgba16
struct rgba16
{
typedef int16u value_type;
typedef int32u calc_type;
typedef int64 long_type;
enum base_scale_e
{
base_shift = 16,
base_scale = 1 << base_shift,
base_mask = base_scale - 1,
base_MSB = 1 << (base_shift - 1)
};
typedef rgba16 self_type;
value_type r;
value_type g;
value_type b;
value_type a;
//--------------------------------------------------------------------
rgba16() {}
//--------------------------------------------------------------------
rgba16(unsigned r_, unsigned g_, unsigned b_, unsigned a_=base_mask) :
r(value_type(r_)),
g(value_type(g_)),
b(value_type(b_)),
a(value_type(a_)) {}
//--------------------------------------------------------------------
rgba16(const self_type& c, unsigned a_) :
r(c.r), g(c.g), b(c.b), a(value_type(a_)) {}
//--------------------------------------------------------------------
rgba16(const rgba& c) :
r((value_type)uround(c.r * double(base_mask))),
g((value_type)uround(c.g * double(base_mask))),
b((value_type)uround(c.b * double(base_mask))),
a((value_type)uround(c.a * double(base_mask))) {}
//--------------------------------------------------------------------
rgba16(const rgba8& c) :
r(value_type((value_type(c.r) << 8) | c.r)),
g(value_type((value_type(c.g) << 8) | c.g)),
b(value_type((value_type(c.b) << 8) | c.b)),
a(value_type((value_type(c.a) << 8) | c.a)) {}
//--------------------------------------------------------------------
rgba16(const srgba8& c) :
r(sRGB_conv<value_type>::rgb_from_sRGB(c.r)),
g(sRGB_conv<value_type>::rgb_from_sRGB(c.g)),
b(sRGB_conv<value_type>::rgb_from_sRGB(c.b)),
a(sRGB_conv<value_type>::alpha_from_sRGB(c.a)) {}
//--------------------------------------------------------------------
operator rgba() const
{
return rgba(
r / 65535.0,
g / 65535.0,
b / 65535.0,
a / 65535.0);
}
//--------------------------------------------------------------------
operator rgba8() const
{
return rgba8(r >> 8, g >> 8, b >> 8, a >> 8);
}
//--------------------------------------------------------------------
operator srgba8() const
{
// Return (non-premultiplied) sRGB values.
return srgba8(
sRGB_conv<value_type>::rgb_to_sRGB(r),
sRGB_conv<value_type>::rgb_to_sRGB(g),
sRGB_conv<value_type>::rgb_to_sRGB(b),
sRGB_conv<value_type>::alpha_to_sRGB(a));
}
//--------------------------------------------------------------------
static AGG_INLINE double to_double(value_type a)
{
return double(a) / base_mask;
}
//--------------------------------------------------------------------
static AGG_INLINE value_type from_double(double a)
{
return value_type(uround(a * base_mask));
}
//--------------------------------------------------------------------
static AGG_INLINE value_type empty_value()
{
return 0;
}
//--------------------------------------------------------------------
static AGG_INLINE value_type full_value()
{
return base_mask;
}
//--------------------------------------------------------------------
AGG_INLINE bool is_transparent() const
{
return a == 0;
}
//--------------------------------------------------------------------
AGG_INLINE bool is_opaque() const
{
return a == base_mask;
}
//--------------------------------------------------------------------
static AGG_INLINE value_type invert(value_type x)
{
return base_mask - x;
}
//--------------------------------------------------------------------
// Fixed-point multiply, exact over int16u.
static AGG_INLINE value_type multiply(value_type a, value_type b)
{
calc_type t = a * b + base_MSB;
return value_type(((t >> base_shift) + t) >> base_shift);
}
//--------------------------------------------------------------------
static AGG_INLINE value_type demultiply(value_type a, value_type b)
{
if (a * b == 0)
{
return 0;
}
else if (a >= b)
{
return base_mask;
}
else return value_type((a * base_mask + (b >> 1)) / b);
}
//--------------------------------------------------------------------
template<typename T>
static AGG_INLINE T downscale(T a)
{
return a >> base_shift;
}
//--------------------------------------------------------------------
template<typename T>
static AGG_INLINE T downshift(T a, unsigned n)
{
return a >> n;
}
//--------------------------------------------------------------------
// Fixed-point multiply, almost exact over int16u.
// Specifically for multiplying a color component by a cover.
static AGG_INLINE value_type mult_cover(value_type a, cover_type b)
{
return multiply(a, (b << 8) | b);
}
//--------------------------------------------------------------------
static AGG_INLINE cover_type scale_cover(cover_type a, value_type b)
{
return multiply((a << 8) | a, b) >> 8;
}
//--------------------------------------------------------------------
// Interpolate p to q by a, assuming q is premultiplied by a.
static AGG_INLINE value_type prelerp(value_type p, value_type q, value_type a)
{
return p + q - multiply(p, a);
}
//--------------------------------------------------------------------
// Interpolate p to q by a.
static AGG_INLINE value_type lerp(value_type p, value_type q, value_type a)
{
int t = (q - p) * a + base_MSB - (p > q);
return value_type(p + (((t >> base_shift) + t) >> base_shift));
}
//--------------------------------------------------------------------
self_type& clear()
{
r = g = b = a = 0;
return *this;
}
//--------------------------------------------------------------------
self_type& transparent()
{
a = 0;
return *this;
}
//--------------------------------------------------------------------
AGG_INLINE self_type& opacity(double a_)
{
if (a_ < 0) a = 0;
if (a_ > 1) a = 1;
a = value_type(uround(a_ * double(base_mask)));
return *this;
}
//--------------------------------------------------------------------
double opacity() const
{
return double(a) / double(base_mask);
}
//--------------------------------------------------------------------
AGG_INLINE self_type& premultiply()
{
if (a != base_mask)
{
if (a == 0)
{
r = g = b = 0;
}
else
{
r = multiply(r, a);
g = multiply(g, a);
b = multiply(b, a);
}
}
return *this;
}
//--------------------------------------------------------------------
AGG_INLINE self_type& premultiply(unsigned a_)
{
if (a < base_mask || a_ < base_mask)
{
if (a == 0 || a_ == 0)
{
r = g = b = a = 0;
}
else
{
calc_type r_ = (calc_type(r) * a_) / a;
calc_type g_ = (calc_type(g) * a_) / a;
calc_type b_ = (calc_type(b) * a_) / a;
r = value_type((r_ > a_) ? a_ : r_);
g = value_type((g_ > a_) ? a_ : g_);
b = value_type((b_ > a_) ? a_ : b_);
a = value_type(a_);
}
}
return *this;
}
//--------------------------------------------------------------------
AGG_INLINE self_type& demultiply()
{
if (a < base_mask)
{
if (a == 0)
{
r = g = b = 0;
}
else
{
calc_type r_ = (calc_type(r) * base_mask) / a;
calc_type g_ = (calc_type(g) * base_mask) / a;
calc_type b_ = (calc_type(b) * base_mask) / a;
r = value_type((r_ > calc_type(base_mask)) ? calc_type(base_mask) : r_);
g = value_type((g_ > calc_type(base_mask)) ? calc_type(base_mask) : g_);
b = value_type((b_ > calc_type(base_mask)) ? calc_type(base_mask) : b_);
}
}
return *this;
}
//--------------------------------------------------------------------
AGG_INLINE self_type gradient(const self_type& c, double k) const
{
self_type ret;
calc_type ik = uround(k * base_mask);
ret.r = lerp(r, c.r, ik);
ret.g = lerp(g, c.g, ik);
ret.b = lerp(b, c.b, ik);
ret.a = lerp(a, c.a, ik);
return ret;
}
//--------------------------------------------------------------------
AGG_INLINE void add(const self_type& c, unsigned cover)
{
calc_type cr, cg, cb, ca;
if (cover == cover_mask)
{
if (c.a == base_mask)
{
*this = c;
return;
}
else
{
cr = r + c.r;
cg = g + c.g;
cb = b + c.b;
ca = a + c.a;
}
}
else
{
cr = r + mult_cover(c.r, cover);
cg = g + mult_cover(c.g, cover);
cb = b + mult_cover(c.b, cover);
ca = a + mult_cover(c.a, cover);
}
r = (value_type)((cr > calc_type(base_mask)) ? calc_type(base_mask) : cr);
g = (value_type)((cg > calc_type(base_mask)) ? calc_type(base_mask) : cg);
b = (value_type)((cb > calc_type(base_mask)) ? calc_type(base_mask) : cb);
a = (value_type)((ca > calc_type(base_mask)) ? calc_type(base_mask) : ca);
}
//--------------------------------------------------------------------
template<class GammaLUT>
AGG_INLINE void apply_gamma_dir(const GammaLUT& gamma)
{
r = gamma.dir(r);
g = gamma.dir(g);
b = gamma.dir(b);
}
//--------------------------------------------------------------------
template<class GammaLUT>
AGG_INLINE void apply_gamma_inv(const GammaLUT& gamma)
{
r = gamma.inv(r);
g = gamma.inv(g);
b = gamma.inv(b);
}
//--------------------------------------------------------------------
static self_type no_color() { return self_type(0,0,0,0); }
//--------------------------------------------------------------------
static self_type from_wavelength(double wl, double gamma = 1.0)
{
return self_type(rgba::from_wavelength(wl, gamma));
}
};
//------------------------------------------------------rgba16_gamma_dir
template<class GammaLUT>
rgba16 rgba16_gamma_dir(rgba16 c, const GammaLUT& gamma)
{
return rgba16(gamma.dir(c.r), gamma.dir(c.g), gamma.dir(c.b), c.a);
}
//------------------------------------------------------rgba16_gamma_inv
template<class GammaLUT>
rgba16 rgba16_gamma_inv(rgba16 c, const GammaLUT& gamma)
{
return rgba16(gamma.inv(c.r), gamma.inv(c.g), gamma.inv(c.b), c.a);
}
//====================================================================rgba32
struct rgba32
{
typedef float value_type;
typedef double calc_type;
typedef double long_type;
typedef rgba32 self_type;
value_type r;
value_type g;
value_type b;
value_type a;
//--------------------------------------------------------------------
rgba32() {}
//--------------------------------------------------------------------
rgba32(value_type r_, value_type g_, value_type b_, value_type a_= 1) :
r(r_), g(g_), b(b_), a(a_) {}
//--------------------------------------------------------------------
rgba32(const self_type& c, float a_) :
r(c.r), g(c.g), b(c.b), a(a_) {}
//--------------------------------------------------------------------
rgba32(const rgba& c) :
r(value_type(c.r)), g(value_type(c.g)), b(value_type(c.b)), a(value_type(c.a)) {}
//--------------------------------------------------------------------
rgba32(const rgba8& c) :
r(value_type(c.r / 255.0)),
g(value_type(c.g / 255.0)),
b(value_type(c.b / 255.0)),
a(value_type(c.a / 255.0)) {}
//--------------------------------------------------------------------
rgba32(const srgba8& c) :
r(sRGB_conv<value_type>::rgb_from_sRGB(c.r)),
g(sRGB_conv<value_type>::rgb_from_sRGB(c.g)),
b(sRGB_conv<value_type>::rgb_from_sRGB(c.b)),
a(sRGB_conv<value_type>::alpha_from_sRGB(c.a)) {}
//--------------------------------------------------------------------
rgba32(const rgba16& c) :
r(value_type(c.r / 65535.0)),
g(value_type(c.g / 65535.0)),
b(value_type(c.b / 65535.0)),
a(value_type(c.a / 65535.0)) {}
//--------------------------------------------------------------------
operator rgba() const
{
return rgba(r, g, b, a);
}
//--------------------------------------------------------------------
operator rgba8() const
{
return rgba8(
uround(r * 255.0),
uround(g * 255.0),
uround(b * 255.0),
uround(a * 255.0));
}
//--------------------------------------------------------------------
operator srgba8() const
{
return srgba8(
sRGB_conv<value_type>::rgb_to_sRGB(r),
sRGB_conv<value_type>::rgb_to_sRGB(g),
sRGB_conv<value_type>::rgb_to_sRGB(b),
sRGB_conv<value_type>::alpha_to_sRGB(a));
}
//--------------------------------------------------------------------
operator rgba16() const
{
return rgba8(
uround(r * 65535.0),
uround(g * 65535.0),
uround(b * 65535.0),
uround(a * 65535.0));
}
//--------------------------------------------------------------------
static AGG_INLINE double to_double(value_type a)
{
return a;
}
//--------------------------------------------------------------------
static AGG_INLINE value_type from_double(double a)
{
return value_type(a);
}
//--------------------------------------------------------------------
static AGG_INLINE value_type empty_value()
{
return 0;
}
//--------------------------------------------------------------------
static AGG_INLINE value_type full_value()
{
return 1;
}
//--------------------------------------------------------------------
AGG_INLINE bool is_transparent() const
{
return a <= 0;
}
//--------------------------------------------------------------------
AGG_INLINE bool is_opaque() const
{
return a >= 1;
}
//--------------------------------------------------------------------
static AGG_INLINE value_type invert(value_type x)
{
return 1 - x;
}
//--------------------------------------------------------------------
static AGG_INLINE value_type multiply(value_type a, value_type b)
{
return value_type(a * b);
}
//--------------------------------------------------------------------
static AGG_INLINE value_type demultiply(value_type a, value_type b)
{
return (b == 0) ? 0 : value_type(a / b);
}
//--------------------------------------------------------------------
template<typename T>
static AGG_INLINE T downscale(T a)
{
return a;
}
//--------------------------------------------------------------------
template<typename T>
static AGG_INLINE T downshift(T a, unsigned n)
{
return n > 0 ? a / (1 << n) : a;
}
//--------------------------------------------------------------------
static AGG_INLINE value_type mult_cover(value_type a, cover_type b)
{
return value_type(a * b / cover_mask);
}
//--------------------------------------------------------------------
static AGG_INLINE cover_type scale_cover(cover_type a, value_type b)
{
return cover_type(uround(a * b));
}
//--------------------------------------------------------------------
// Interpolate p to q by a, assuming q is premultiplied by a.
static AGG_INLINE value_type prelerp(value_type p, value_type q, value_type a)
{
return (1 - a) * p + q; // more accurate than "p + q - p * a"
}
//--------------------------------------------------------------------
// Interpolate p to q by a.
static AGG_INLINE value_type lerp(value_type p, value_type q, value_type a)
{
// The form "p + a * (q - p)" avoids a multiplication, but may produce an
// inaccurate result. For example, "p + (q - p)" may not be exactly equal
// to q. Therefore, stick to the basic expression, which at least produces
// the correct result at either extreme.
return (1 - a) * p + a * q;
}
//--------------------------------------------------------------------
self_type& clear()
{
r = g = b = a = 0;
return *this;
}
//--------------------------------------------------------------------
self_type& transparent()
{
a = 0;
return *this;
}
//--------------------------------------------------------------------
AGG_INLINE self_type& opacity(double a_)
{
if (a_ < 0) a = 0;
else if (a_ > 1) a = 1;
else a = value_type(a_);
return *this;
}
//--------------------------------------------------------------------
double opacity() const
{
return a;
}
//--------------------------------------------------------------------
AGG_INLINE self_type& premultiply()
{
if (a < 1)
{
if (a <= 0)
{
r = g = b = 0;
}
else
{
r *= a;
g *= a;
b *= a;
}
}
return *this;
}
//--------------------------------------------------------------------
AGG_INLINE self_type& demultiply()
{
if (a < 1)
{
if (a <= 0)
{
r = g = b = 0;
}
else
{
r /= a;
g /= a;
b /= a;
}
}
return *this;
}
//--------------------------------------------------------------------
AGG_INLINE self_type gradient(const self_type& c, double k) const
{
self_type ret;
ret.r = value_type(r + (c.r - r) * k);
ret.g = value_type(g + (c.g - g) * k);
ret.b = value_type(b + (c.b - b) * k);
ret.a = value_type(a + (c.a - a) * k);
return ret;
}
//--------------------------------------------------------------------
AGG_INLINE void add(const self_type& c, unsigned cover)
{
if (cover == cover_mask)
{
if (c.is_opaque())
{
*this = c;
return;
}
else
{
r += c.r;
g += c.g;
b += c.b;
a += c.a;
}
}
else
{
r += mult_cover(c.r, cover);
g += mult_cover(c.g, cover);
b += mult_cover(c.b, cover);
a += mult_cover(c.a, cover);
}
if (a > 1) a = 1;
if (r > a) r = a;
if (g > a) g = a;
if (b > a) b = a;
}
//--------------------------------------------------------------------
template<class GammaLUT>
AGG_INLINE void apply_gamma_dir(const GammaLUT& gamma)
{
r = gamma.dir(r);
g = gamma.dir(g);
b = gamma.dir(b);
}
//--------------------------------------------------------------------
template<class GammaLUT>
AGG_INLINE void apply_gamma_inv(const GammaLUT& gamma)
{
r = gamma.inv(r);
g = gamma.inv(g);
b = gamma.inv(b);
}
//--------------------------------------------------------------------
static self_type no_color() { return self_type(0,0,0,0); }
//--------------------------------------------------------------------
static self_type from_wavelength(double wl, double gamma = 1)
{
return self_type(rgba::from_wavelength(wl, gamma));
}
};
}
#endif
| 0 |
D://workCode//uploadProject\awtk\3rd\agg | D://workCode//uploadProject\awtk\3rd\agg\include\agg_config.h | #ifndef AGG_CONFIG_INCLUDED
#define AGG_CONFIG_INCLUDED
// This file can be used to redefine certain data types.
//---------------------------------------
// 1. Default basic types such as:
//
// AGG_INT8
// AGG_INT8U
// AGG_INT16
// AGG_INT16U
// AGG_INT32
// AGG_INT32U
// AGG_INT64
// AGG_INT64U
//
// Just replace this file with new defines if necessary.
// For example, if your compiler doesn't have a 64 bit integer type
// you can still use AGG if you define the follows:
//
// #define AGG_INT64 int
// #define AGG_INT64U unsigned
//
// It will result in overflow in 16 bit-per-component image/pattern resampling
// but it won't result any crash and the rest of the library will remain
// fully functional.
//---------------------------------------
// 2. Default rendering_buffer type. Can be:
//
// Provides faster access for massive pixel operations,
// such as blur, image filtering:
// #define AGG_RENDERING_BUFFER row_ptr_cache<int8u>
//
// Provides cheaper creation and destruction (no mem allocs):
// #define AGG_RENDERING_BUFFER row_accessor<int8u>
//
// You can still use both of them simultaneously in your applications
// This #define is used only for default rendering_buffer type,
// in short hand typedefs like pixfmt_rgba32.
#endif
| 0 |
D://workCode//uploadProject\awtk\3rd\agg | D://workCode//uploadProject\awtk\3rd\agg\include\agg_conv_adaptor_vcgen.h | //----------------------------------------------------------------------------
// Anti-Grain Geometry - Version 2.4
// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
//
//----------------------------------------------------------------------------
// Contact: mcseem@antigrain.com
// mcseemagg@yahoo.com
// http://www.antigrain.com
//----------------------------------------------------------------------------
#ifndef AGG_CONV_ADAPTOR_VCGEN_INCLUDED
#define AGG_CONV_ADAPTOR_VCGEN_INCLUDED
#include "agg_basics.h"
namespace agg
{
//------------------------------------------------------------null_markers
struct null_markers
{
void remove_all() {}
void add_vertex(double, double, unsigned) {}
void prepare_src() {}
void rewind(unsigned) {}
unsigned vertex(double*, double*) { return path_cmd_stop; }
};
//------------------------------------------------------conv_adaptor_vcgen
template<class VertexSource,
class Generator,
class Markers=null_markers> class conv_adaptor_vcgen
{
enum status
{
initial,
accumulate,
generate
};
public:
explicit conv_adaptor_vcgen(VertexSource& source) :
m_source(&source),
m_status(initial)
{}
void attach(VertexSource& source) { m_source = &source; }
Generator& generator() { return m_generator; }
const Generator& generator() const { return m_generator; }
Markers& markers() { return m_markers; }
const Markers& markers() const { return m_markers; }
void rewind(unsigned path_id)
{
m_source->rewind(path_id);
m_status = initial;
}
unsigned vertex(double* x, double* y);
private:
// Prohibit copying
conv_adaptor_vcgen(const conv_adaptor_vcgen<VertexSource, Generator, Markers>&);
const conv_adaptor_vcgen<VertexSource, Generator, Markers>&
operator = (const conv_adaptor_vcgen<VertexSource, Generator, Markers>&);
VertexSource* m_source;
Generator m_generator;
Markers m_markers;
status m_status;
unsigned m_last_cmd;
double m_start_x;
double m_start_y;
};
//------------------------------------------------------------------------
template<class VertexSource, class Generator, class Markers>
unsigned conv_adaptor_vcgen<VertexSource, Generator, Markers>::vertex(double* x, double* y)
{
unsigned cmd = path_cmd_stop;
bool done = false;
while(!done)
{
switch(m_status)
{
case initial:
m_markers.remove_all();
m_last_cmd = m_source->vertex(&m_start_x, &m_start_y);
m_status = accumulate;
case accumulate:
if(is_stop(m_last_cmd)) return path_cmd_stop;
m_generator.remove_all();
m_generator.add_vertex(m_start_x, m_start_y, path_cmd_move_to);
m_markers.add_vertex(m_start_x, m_start_y, path_cmd_move_to);
for(;;)
{
cmd = m_source->vertex(x, y);
if(is_vertex(cmd))
{
m_last_cmd = cmd;
if(is_move_to(cmd))
{
m_start_x = *x;
m_start_y = *y;
break;
}
m_generator.add_vertex(*x, *y, cmd);
m_markers.add_vertex(*x, *y, path_cmd_line_to);
}
else
{
if(is_stop(cmd))
{
m_last_cmd = path_cmd_stop;
break;
}
if(is_end_poly(cmd))
{
m_generator.add_vertex(*x, *y, cmd);
break;
}
}
}
m_generator.rewind(0);
m_status = generate;
case generate:
cmd = m_generator.vertex(x, y);
if(is_stop(cmd))
{
m_status = accumulate;
break;
}
done = true;
break;
}
}
return cmd;
}
}
#endif
| 0 |
D://workCode//uploadProject\awtk\3rd\agg | D://workCode//uploadProject\awtk\3rd\agg\include\agg_conv_stroke.h | //----------------------------------------------------------------------------
// Anti-Grain Geometry - Version 2.4
// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
//
//----------------------------------------------------------------------------
// Contact: mcseem@antigrain.com
// mcseemagg@yahoo.com
// http://www.antigrain.com
//----------------------------------------------------------------------------
//
// conv_stroke
//
//----------------------------------------------------------------------------
#ifndef AGG_CONV_STROKE_INCLUDED
#define AGG_CONV_STROKE_INCLUDED
#include "agg_basics.h"
#include "agg_vcgen_stroke.h"
#include "agg_conv_adaptor_vcgen.h"
namespace agg
{
//-------------------------------------------------------------conv_stroke
template<class VertexSource, class Markers=null_markers>
struct conv_stroke :
public conv_adaptor_vcgen<VertexSource, vcgen_stroke, Markers>
{
typedef Markers marker_type;
typedef conv_adaptor_vcgen<VertexSource, vcgen_stroke, Markers> base_type;
conv_stroke(VertexSource& vs) :
conv_adaptor_vcgen<VertexSource, vcgen_stroke, Markers>(vs)
{
}
void line_cap(line_cap_e lc) { base_type::generator().line_cap(lc); }
void line_join(line_join_e lj) { base_type::generator().line_join(lj); }
void inner_join(inner_join_e ij) { base_type::generator().inner_join(ij); }
line_cap_e line_cap() const { return base_type::generator().line_cap(); }
line_join_e line_join() const { return base_type::generator().line_join(); }
inner_join_e inner_join() const { return base_type::generator().inner_join(); }
void width(double w) { base_type::generator().width(w); }
void miter_limit(double ml) { base_type::generator().miter_limit(ml); }
void miter_limit_theta(double t) { base_type::generator().miter_limit_theta(t); }
void inner_miter_limit(double ml) { base_type::generator().inner_miter_limit(ml); }
void approximation_scale(double as) { base_type::generator().approximation_scale(as); }
double width() const { return base_type::generator().width(); }
double miter_limit() const { return base_type::generator().miter_limit(); }
double inner_miter_limit() const { return base_type::generator().inner_miter_limit(); }
double approximation_scale() const { return base_type::generator().approximation_scale(); }
void shorten(double s) { base_type::generator().shorten(s); }
double shorten() const { return base_type::generator().shorten(); }
private:
conv_stroke(const conv_stroke<VertexSource, Markers>&);
const conv_stroke<VertexSource, Markers>&
operator = (const conv_stroke<VertexSource, Markers>&);
};
}
#endif
| 0 |
D://workCode//uploadProject\awtk\3rd\agg | D://workCode//uploadProject\awtk\3rd\agg\include\agg_dda_line.h | //----------------------------------------------------------------------------
// Anti-Grain Geometry - Version 2.4
// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
//
//----------------------------------------------------------------------------
// Contact: mcseem@antigrain.com
// mcseemagg@yahoo.com
// http://www.antigrain.com
//----------------------------------------------------------------------------
//
// classes dda_line_interpolator, dda2_line_interpolator
//
//----------------------------------------------------------------------------
#ifndef AGG_DDA_LINE_INCLUDED
#define AGG_DDA_LINE_INCLUDED
#include <stdlib.h>
#include "agg_basics.h"
namespace agg
{
//===================================================dda_line_interpolator
template<int FractionShift, int YShift=0> class dda_line_interpolator
{
public:
//--------------------------------------------------------------------
dda_line_interpolator() {}
//--------------------------------------------------------------------
dda_line_interpolator(int y1, int y2, unsigned count) :
m_y(y1),
m_inc(((y2 - y1) << FractionShift) / int(count)),
m_dy(0)
{
}
//--------------------------------------------------------------------
void operator ++ ()
{
m_dy += m_inc;
}
//--------------------------------------------------------------------
void operator -- ()
{
m_dy -= m_inc;
}
//--------------------------------------------------------------------
void operator += (unsigned n)
{
m_dy += m_inc * n;
}
//--------------------------------------------------------------------
void operator -= (unsigned n)
{
m_dy -= m_inc * n;
}
//--------------------------------------------------------------------
int y() const { return m_y + (m_dy >> (FractionShift-YShift)); }
int dy() const { return m_dy; }
private:
int m_y;
int m_inc;
int m_dy;
};
//=================================================dda2_line_interpolator
class dda2_line_interpolator
{
public:
typedef int save_data_type;
enum save_size_e { save_size = 2 };
//--------------------------------------------------------------------
dda2_line_interpolator() {}
//-------------------------------------------- Forward-adjusted line
dda2_line_interpolator(int y1, int y2, int count) :
m_cnt(count <= 0 ? 1 : count),
m_lft((y2 - y1) / m_cnt),
m_rem((y2 - y1) % m_cnt),
m_mod(m_rem),
m_y(y1)
{
if(m_mod <= 0)
{
m_mod += count;
m_rem += count;
m_lft--;
}
m_mod -= count;
}
//-------------------------------------------- Backward-adjusted line
dda2_line_interpolator(int y1, int y2, int count, int) :
m_cnt(count <= 0 ? 1 : count),
m_lft((y2 - y1) / m_cnt),
m_rem((y2 - y1) % m_cnt),
m_mod(m_rem),
m_y(y1)
{
if(m_mod <= 0)
{
m_mod += count;
m_rem += count;
m_lft--;
}
}
//-------------------------------------------- Backward-adjusted line
dda2_line_interpolator(int y, int count) :
m_cnt(count <= 0 ? 1 : count),
m_lft(y / m_cnt),
m_rem(y % m_cnt),
m_mod(m_rem),
m_y(0)
{
if(m_mod <= 0)
{
m_mod += count;
m_rem += count;
m_lft--;
}
}
//--------------------------------------------------------------------
void save(save_data_type* data) const
{
data[0] = m_mod;
data[1] = m_y;
}
//--------------------------------------------------------------------
void load(const save_data_type* data)
{
m_mod = data[0];
m_y = data[1];
}
//--------------------------------------------------------------------
void operator++()
{
m_mod += m_rem;
m_y += m_lft;
if(m_mod > 0)
{
m_mod -= m_cnt;
m_y++;
}
}
//--------------------------------------------------------------------
void operator--()
{
if(m_mod <= m_rem)
{
m_mod += m_cnt;
m_y--;
}
m_mod -= m_rem;
m_y -= m_lft;
}
//--------------------------------------------------------------------
void adjust_forward()
{
m_mod -= m_cnt;
}
//--------------------------------------------------------------------
void adjust_backward()
{
m_mod += m_cnt;
}
//--------------------------------------------------------------------
int mod() const { return m_mod; }
int rem() const { return m_rem; }
int lft() const { return m_lft; }
//--------------------------------------------------------------------
int y() const { return m_y; }
private:
int m_cnt;
int m_lft;
int m_rem;
int m_mod;
int m_y;
};
//---------------------------------------------line_bresenham_interpolator
class line_bresenham_interpolator
{
public:
enum subpixel_scale_e
{
subpixel_shift = 8,
subpixel_scale = 1 << subpixel_shift,
subpixel_mask = subpixel_scale - 1
};
//--------------------------------------------------------------------
static int line_lr(int v) { return v >> subpixel_shift; }
//--------------------------------------------------------------------
line_bresenham_interpolator(int x1, int y1, int x2, int y2) :
m_x1_lr(line_lr(x1)),
m_y1_lr(line_lr(y1)),
m_x2_lr(line_lr(x2)),
m_y2_lr(line_lr(y2)),
m_ver(abs(m_x2_lr - m_x1_lr) < abs(m_y2_lr - m_y1_lr)),
m_len(m_ver ? abs(m_y2_lr - m_y1_lr) :
abs(m_x2_lr - m_x1_lr)),
m_inc(m_ver ? ((y2 > y1) ? 1 : -1) : ((x2 > x1) ? 1 : -1)),
m_interpolator(m_ver ? x1 : y1,
m_ver ? x2 : y2,
m_len)
{
}
//--------------------------------------------------------------------
bool is_ver() const { return m_ver; }
unsigned len() const { return m_len; }
int inc() const { return m_inc; }
//--------------------------------------------------------------------
void hstep()
{
++m_interpolator;
m_x1_lr += m_inc;
}
//--------------------------------------------------------------------
void vstep()
{
++m_interpolator;
m_y1_lr += m_inc;
}
//--------------------------------------------------------------------
int x1() const { return m_x1_lr; }
int y1() const { return m_y1_lr; }
int x2() const { return line_lr(m_interpolator.y()); }
int y2() const { return line_lr(m_interpolator.y()); }
int x2_hr() const { return m_interpolator.y(); }
int y2_hr() const { return m_interpolator.y(); }
private:
int m_x1_lr;
int m_y1_lr;
int m_x2_lr;
int m_y2_lr;
bool m_ver;
unsigned m_len;
int m_inc;
dda2_line_interpolator m_interpolator;
};
}
#endif
| 0 |
D://workCode//uploadProject\awtk\3rd\agg | D://workCode//uploadProject\awtk\3rd\agg\include\agg_gamma_functions.h | //----------------------------------------------------------------------------
// Anti-Grain Geometry - Version 2.4
// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
//
//----------------------------------------------------------------------------
// Contact: mcseem@antigrain.com
// mcseemagg@yahoo.com
// http://www.antigrain.com
//----------------------------------------------------------------------------
#ifndef AGG_GAMMA_FUNCTIONS_INCLUDED
#define AGG_GAMMA_FUNCTIONS_INCLUDED
#include <math.h>
#include "agg_basics.h"
namespace agg
{
//===============================================================gamma_none
struct gamma_none
{
double operator()(double x) const { return x; }
};
//==============================================================gamma_power
class gamma_power
{
public:
gamma_power() : m_gamma(1.0) {}
gamma_power(double g) : m_gamma(g) {}
void gamma(double g) { m_gamma = g; }
double gamma() const { return m_gamma; }
double operator() (double x) const
{
return pow(x, m_gamma);
}
private:
double m_gamma;
};
//==========================================================gamma_threshold
class gamma_threshold
{
public:
gamma_threshold() : m_threshold(0.5) {}
gamma_threshold(double t) : m_threshold(t) {}
void threshold(double t) { m_threshold = t; }
double threshold() const { return m_threshold; }
double operator() (double x) const
{
return (x < m_threshold) ? 0.0 : 1.0;
}
private:
double m_threshold;
};
//============================================================gamma_linear
class gamma_linear
{
public:
gamma_linear() : m_start(0.0), m_end(1.0) {}
gamma_linear(double s, double e) : m_start(s), m_end(e) {}
void set(double s, double e) { m_start = s; m_end = e; }
void start(double s) { m_start = s; }
void end(double e) { m_end = e; }
double start() const { return m_start; }
double end() const { return m_end; }
double operator() (double x) const
{
if(x < m_start) return 0.0;
if(x > m_end) return 1.0;
return (x - m_start) / (m_end - m_start);
}
private:
double m_start;
double m_end;
};
//==========================================================gamma_multiply
class gamma_multiply
{
public:
gamma_multiply() : m_mul(1.0) {}
gamma_multiply(double v) : m_mul(v) {}
void value(double v) { m_mul = v; }
double value() const { return m_mul; }
double operator() (double x) const
{
double y = x * m_mul;
if(y > 1.0) y = 1.0;
return y;
}
private:
double m_mul;
};
inline double sRGB_to_linear(double x)
{
return (x <= 0.04045) ? (x / 12.92) : pow((x + 0.055) / (1.055), 2.4);
}
inline double linear_to_sRGB(double x)
{
return (x <= 0.0031308) ? (x * 12.92) : (1.055 * pow(x, 1 / 2.4) - 0.055);
}
}
#endif
| 0 |
D://workCode//uploadProject\awtk\3rd\agg | D://workCode//uploadProject\awtk\3rd\agg\include\agg_gamma_lut.h | //----------------------------------------------------------------------------
// Anti-Grain Geometry - Version 2.4
// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
//
//----------------------------------------------------------------------------
// Contact: mcseem@antigrain.com
// mcseemagg@yahoo.com
// http://www.antigrain.com
//----------------------------------------------------------------------------
#ifndef AGG_GAMMA_LUT_INCLUDED
#define AGG_GAMMA_LUT_INCLUDED
#include <math.h>
#include "agg_basics.h"
#include "agg_gamma_functions.h"
namespace agg
{
template<class LoResT=int8u,
class HiResT=int8u,
unsigned GammaShift=8,
unsigned HiResShift=8> class gamma_lut
{
public:
typedef gamma_lut<LoResT, HiResT, GammaShift, HiResShift> self_type;
enum gamma_scale_e
{
gamma_shift = GammaShift,
gamma_size = 1 << gamma_shift,
gamma_mask = gamma_size - 1
};
enum hi_res_scale_e
{
hi_res_shift = HiResShift,
hi_res_size = 1 << hi_res_shift,
hi_res_mask = hi_res_size - 1
};
~gamma_lut()
{
pod_allocator<LoResT>::deallocate(m_inv_gamma, hi_res_size);
pod_allocator<HiResT>::deallocate(m_dir_gamma, gamma_size);
}
gamma_lut() :
m_gamma(1.0),
m_dir_gamma(pod_allocator<HiResT>::allocate(gamma_size)),
m_inv_gamma(pod_allocator<LoResT>::allocate(hi_res_size))
{
unsigned i;
for(i = 0; i < gamma_size; i++)
{
m_dir_gamma[i] = HiResT(i << (hi_res_shift - gamma_shift));
}
for(i = 0; i < hi_res_size; i++)
{
m_inv_gamma[i] = LoResT(i >> (hi_res_shift - gamma_shift));
}
}
gamma_lut(double g) :
m_gamma(1.0),
m_dir_gamma(pod_allocator<HiResT>::allocate(gamma_size)),
m_inv_gamma(pod_allocator<LoResT>::allocate(hi_res_size))
{
gamma(g);
}
void gamma(double g)
{
m_gamma = g;
unsigned i;
for(i = 0; i < gamma_size; i++)
{
m_dir_gamma[i] = (HiResT)
uround(pow(i / double(gamma_mask), m_gamma) * double(hi_res_mask));
}
double inv_g = 1.0 / g;
for(i = 0; i < hi_res_size; i++)
{
m_inv_gamma[i] = (LoResT)
uround(pow(i / double(hi_res_mask), inv_g) * double(gamma_mask));
}
}
double gamma() const
{
return m_gamma;
}
HiResT dir(LoResT v) const
{
return m_dir_gamma[unsigned(v)];
}
LoResT inv(HiResT v) const
{
return m_inv_gamma[unsigned(v)];
}
private:
gamma_lut(const self_type&);
const self_type& operator = (const self_type&);
double m_gamma;
HiResT* m_dir_gamma;
LoResT* m_inv_gamma;
};
//
// sRGB support classes
//
// sRGB_lut - implements sRGB conversion for the various types.
// Base template is undefined, specializations are provided below.
template<class LinearType>
class sRGB_lut;
template<>
class sRGB_lut<float>
{
public:
sRGB_lut()
{
// Generate lookup tables.
for (int i = 0; i <= 255; ++i)
{
m_dir_table[i] = float(sRGB_to_linear(i / 255.0));
}
for (int i = 0; i <= 65535; ++i)
{
m_inv_table[i] = uround(255.0 * linear_to_sRGB(i / 65535.0));
}
}
float dir(int8u v) const
{
return m_dir_table[v];
}
int8u inv(float v) const
{
return m_inv_table[int16u(0.5 + v * 65535)];
}
private:
float m_dir_table[256];
int8u m_inv_table[65536];
};
template<>
class sRGB_lut<int16u>
{
public:
sRGB_lut()
{
// Generate lookup tables.
for (int i = 0; i <= 255; ++i)
{
m_dir_table[i] = uround(65535.0 * sRGB_to_linear(i / 255.0));
}
for (int i = 0; i <= 65535; ++i)
{
m_inv_table[i] = uround(255.0 * linear_to_sRGB(i / 65535.0));
}
}
int16u dir(int8u v) const
{
return m_dir_table[v];
}
int8u inv(int16u v) const
{
return m_inv_table[v];
}
private:
int16u m_dir_table[256];
int8u m_inv_table[65536];
};
template<>
class sRGB_lut<int8u>
{
public:
sRGB_lut()
{
// Generate lookup tables.
for (int i = 0; i <= 255; ++i)
{
m_dir_table[i] = uround(255.0 * sRGB_to_linear(i / 255.0));
m_inv_table[i] = uround(255.0 * linear_to_sRGB(i / 255.0));
}
}
int8u dir(int8u v) const
{
return m_dir_table[v];
}
int8u inv(int8u v) const
{
return m_inv_table[v];
}
private:
int8u m_dir_table[256];
int8u m_inv_table[256];
};
// Common base class for sRGB_conv objects. Defines an internal
// sRGB_lut object so that users don't have to.
template<class T>
class sRGB_conv_base
{
public:
static T rgb_from_sRGB(int8u x)
{
return lut.dir(x);
}
static int8u rgb_to_sRGB(T x)
{
return lut.inv(x);
}
private:
static sRGB_lut<T> lut;
};
// Definition of sRGB_conv_base::lut. Due to the fact that this a template,
// we don't need to place the definition in a cpp file. Hurrah.
template<class T>
sRGB_lut<T> sRGB_conv_base<T>::lut;
// Wrapper for sRGB-linear conversion.
// Base template is undefined, specializations are provided below.
template<class T>
class sRGB_conv;
template<>
class sRGB_conv<float> : public sRGB_conv_base<float>
{
public:
static float alpha_from_sRGB(int8u x)
{
static const double y = 1 / 255.0;
return float(x * y);
}
static int8u alpha_to_sRGB(float x)
{
return int8u(0.5 + x * 255);
}
};
template<>
class sRGB_conv<int16u> : public sRGB_conv_base<int16u>
{
public:
static int16u alpha_from_sRGB(int8u x)
{
return (x << 8) | x;
}
static int8u alpha_to_sRGB(int16u x)
{
return x >> 8;
}
};
template<>
class sRGB_conv<int8u> : public sRGB_conv_base<int8u>
{
public:
static int8u alpha_from_sRGB(int8u x)
{
return x;
}
static int8u alpha_to_sRGB(int8u x)
{
return x;
}
};
}
#endif
| 0 |
D://workCode//uploadProject\awtk\3rd\agg | D://workCode//uploadProject\awtk\3rd\agg\include\agg_image_accessors.h | //----------------------------------------------------------------------------
// Anti-Grain Geometry - Version 2.4
// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
//
//----------------------------------------------------------------------------
// Contact: mcseem@antigrain.com
// mcseemagg@yahoo.com
// http://www.antigrain.com
//----------------------------------------------------------------------------
#ifndef AGG_IMAGE_ACCESSORS_INCLUDED
#define AGG_IMAGE_ACCESSORS_INCLUDED
#include "agg_basics.h"
namespace agg
{
//-----------------------------------------------------image_accessor_clip
template<class PixFmt> class image_accessor_clip
{
public:
typedef PixFmt pixfmt_type;
typedef typename pixfmt_type::color_type color_type;
typedef typename pixfmt_type::order_type order_type;
typedef typename pixfmt_type::value_type value_type;
enum pix_width_e { pix_width = pixfmt_type::pix_width };
image_accessor_clip() {}
explicit image_accessor_clip(pixfmt_type& pixf,
const color_type& bk) :
m_pixf(&pixf)
{
pixfmt_type::make_pix(m_bk_buf, bk);
}
void attach(pixfmt_type& pixf)
{
m_pixf = &pixf;
}
void background_color(const color_type& bk)
{
pixfmt_type::make_pix(m_bk_buf, bk);
}
private:
AGG_INLINE const int8u* pixel() const
{
if(m_y >= 0 && m_y < (int)m_pixf->height() &&
m_x >= 0 && m_x < (int)m_pixf->width())
{
return m_pixf->pix_ptr(m_x, m_y);
}
return m_bk_buf;
}
public:
AGG_INLINE const int8u* span(int x, int y, unsigned len)
{
m_x = m_x0 = x;
m_y = y;
if(y >= 0 && y < (int)m_pixf->height() &&
x >= 0 && x+(int)len <= (int)m_pixf->width())
{
return m_pix_ptr = m_pixf->pix_ptr(x, y);
}
m_pix_ptr = 0;
return pixel();
}
AGG_INLINE const int8u* next_x()
{
if(m_pix_ptr) return m_pix_ptr += pix_width;
++m_x;
return pixel();
}
AGG_INLINE const int8u* next_y()
{
++m_y;
m_x = m_x0;
if(m_pix_ptr &&
m_y >= 0 && m_y < (int)m_pixf->height())
{
return m_pix_ptr = m_pixf->pix_ptr(m_x, m_y);
}
m_pix_ptr = 0;
return pixel();
}
private:
const pixfmt_type* m_pixf;
int8u m_bk_buf[pix_width];
int m_x, m_x0, m_y;
const int8u* m_pix_ptr;
};
//--------------------------------------------------image_accessor_no_clip
template<class PixFmt> class image_accessor_no_clip
{
public:
typedef PixFmt pixfmt_type;
typedef typename pixfmt_type::color_type color_type;
typedef typename pixfmt_type::order_type order_type;
typedef typename pixfmt_type::value_type value_type;
enum pix_width_e { pix_width = pixfmt_type::pix_width };
image_accessor_no_clip() {}
explicit image_accessor_no_clip(pixfmt_type& pixf) :
m_pixf(&pixf)
{}
void attach(pixfmt_type& pixf)
{
m_pixf = &pixf;
}
AGG_INLINE const int8u* span(int x, int y, unsigned)
{
m_x = x;
m_y = y;
return m_pix_ptr = m_pixf->pix_ptr(x, y);
}
AGG_INLINE const int8u* next_x()
{
return m_pix_ptr += pix_width;
}
AGG_INLINE const int8u* next_y()
{
++m_y;
return m_pix_ptr = m_pixf->pix_ptr(m_x, m_y);
}
private:
const pixfmt_type* m_pixf;
int m_x, m_y;
const int8u* m_pix_ptr;
};
//----------------------------------------------------image_accessor_clone
template<class PixFmt> class image_accessor_clone
{
public:
typedef PixFmt pixfmt_type;
typedef typename pixfmt_type::color_type color_type;
typedef typename pixfmt_type::order_type order_type;
typedef typename pixfmt_type::value_type value_type;
enum pix_width_e { pix_width = pixfmt_type::pix_width };
image_accessor_clone() {}
explicit image_accessor_clone(pixfmt_type& pixf) :
m_pixf(&pixf)
{}
void attach(pixfmt_type& pixf)
{
m_pixf = &pixf;
}
private:
AGG_INLINE const int8u* pixel() const
{
int x = m_x;
int y = m_y;
if(x < 0) x = 0;
if(y < 0) y = 0;
if(x >= (int)m_pixf->width()) x = m_pixf->width() - 1;
if(y >= (int)m_pixf->height()) y = m_pixf->height() - 1;
return m_pixf->pix_ptr(x, y);
}
public:
AGG_INLINE const int8u* span(int x, int y, unsigned len)
{
m_x = m_x0 = x;
m_y = y;
if(y >= 0 && y < (int)m_pixf->height() &&
x >= 0 && x+len <= (int)m_pixf->width())
{
return m_pix_ptr = m_pixf->pix_ptr(x, y);
}
m_pix_ptr = 0;
return pixel();
}
AGG_INLINE const int8u* next_x()
{
if(m_pix_ptr) return m_pix_ptr += pix_width;
++m_x;
return pixel();
}
AGG_INLINE const int8u* next_y()
{
++m_y;
m_x = m_x0;
if(m_pix_ptr &&
m_y >= 0 && m_y < (int)m_pixf->height())
{
return m_pix_ptr = m_pixf->pix_ptr(m_x, m_y);
}
m_pix_ptr = 0;
return pixel();
}
private:
const pixfmt_type* m_pixf;
int m_x, m_x0, m_y;
const int8u* m_pix_ptr;
};
//-----------------------------------------------------image_accessor_wrap
template<class PixFmt, class WrapX, class WrapY> class image_accessor_wrap
{
public:
typedef PixFmt pixfmt_type;
typedef typename pixfmt_type::color_type color_type;
typedef typename pixfmt_type::order_type order_type;
typedef typename pixfmt_type::value_type value_type;
enum pix_width_e { pix_width = pixfmt_type::pix_width };
image_accessor_wrap() {}
explicit image_accessor_wrap(pixfmt_type& pixf) :
m_pixf(&pixf),
m_wrap_x(pixf.width()),
m_wrap_y(pixf.height())
{}
void attach(pixfmt_type& pixf)
{
m_pixf = &pixf;
}
AGG_INLINE const int8u* span(int x, int y, unsigned)
{
m_x = x;
m_row_ptr = m_pixf->pix_ptr(0, m_wrap_y(y));
return m_row_ptr + m_wrap_x(x) * pix_width;
}
AGG_INLINE const int8u* next_x()
{
int x = ++m_wrap_x;
return m_row_ptr + x * pix_width;
}
AGG_INLINE const int8u* next_y()
{
m_row_ptr = m_pixf->pix_ptr(0, ++m_wrap_y);
return m_row_ptr + m_wrap_x(m_x) * pix_width;
}
private:
const pixfmt_type* m_pixf;
const int8u* m_row_ptr;
int m_x;
WrapX m_wrap_x;
WrapY m_wrap_y;
};
//--------------------------------------------------------wrap_mode_repeat
class wrap_mode_repeat
{
public:
wrap_mode_repeat() {}
wrap_mode_repeat(unsigned size) :
m_size(size),
m_add(size * (0x3FFFFFFF / size)),
m_value(0)
{}
AGG_INLINE unsigned operator() (int v)
{
return m_value = (unsigned(v) + m_add) % m_size;
}
AGG_INLINE unsigned operator++ ()
{
++m_value;
if(m_value >= m_size) m_value = 0;
return m_value;
}
private:
unsigned m_size;
unsigned m_add;
unsigned m_value;
};
//---------------------------------------------------wrap_mode_repeat_pow2
class wrap_mode_repeat_pow2
{
public:
wrap_mode_repeat_pow2() {}
wrap_mode_repeat_pow2(unsigned size) : m_value(0)
{
m_mask = 1;
while(m_mask < size) m_mask = (m_mask << 1) | 1;
m_mask >>= 1;
}
AGG_INLINE unsigned operator() (int v)
{
return m_value = unsigned(v) & m_mask;
}
AGG_INLINE unsigned operator++ ()
{
++m_value;
if(m_value > m_mask) m_value = 0;
return m_value;
}
private:
unsigned m_mask;
unsigned m_value;
};
//----------------------------------------------wrap_mode_repeat_auto_pow2
class wrap_mode_repeat_auto_pow2
{
public:
wrap_mode_repeat_auto_pow2() {}
wrap_mode_repeat_auto_pow2(unsigned size) :
m_size(size),
m_add(size * (0x3FFFFFFF / size)),
m_mask((m_size & (m_size-1)) ? 0 : m_size-1),
m_value(0)
{}
AGG_INLINE unsigned operator() (int v)
{
if(m_mask) return m_value = unsigned(v) & m_mask;
return m_value = (unsigned(v) + m_add) % m_size;
}
AGG_INLINE unsigned operator++ ()
{
++m_value;
if(m_value >= m_size) m_value = 0;
return m_value;
}
private:
unsigned m_size;
unsigned m_add;
unsigned m_mask;
unsigned m_value;
};
//-------------------------------------------------------wrap_mode_reflect
class wrap_mode_reflect
{
public:
wrap_mode_reflect() {}
wrap_mode_reflect(unsigned size) :
m_size(size),
m_size2(size * 2),
m_add(m_size2 * (0x3FFFFFFF / m_size2)),
m_value(0)
{}
AGG_INLINE unsigned operator() (int v)
{
m_value = (unsigned(v) + m_add) % m_size2;
if(m_value >= m_size) return m_size2 - m_value - 1;
return m_value;
}
AGG_INLINE unsigned operator++ ()
{
++m_value;
if(m_value >= m_size2) m_value = 0;
if(m_value >= m_size) return m_size2 - m_value - 1;
return m_value;
}
private:
unsigned m_size;
unsigned m_size2;
unsigned m_add;
unsigned m_value;
};
//--------------------------------------------------wrap_mode_reflect_pow2
class wrap_mode_reflect_pow2
{
public:
wrap_mode_reflect_pow2() {}
wrap_mode_reflect_pow2(unsigned size) : m_value(0)
{
m_mask = 1;
m_size = 1;
while(m_mask < size)
{
m_mask = (m_mask << 1) | 1;
m_size <<= 1;
}
}
AGG_INLINE unsigned operator() (int v)
{
m_value = unsigned(v) & m_mask;
if(m_value >= m_size) return m_mask - m_value;
return m_value;
}
AGG_INLINE unsigned operator++ ()
{
++m_value;
m_value &= m_mask;
if(m_value >= m_size) return m_mask - m_value;
return m_value;
}
private:
unsigned m_size;
unsigned m_mask;
unsigned m_value;
};
//---------------------------------------------wrap_mode_reflect_auto_pow2
class wrap_mode_reflect_auto_pow2
{
public:
wrap_mode_reflect_auto_pow2() {}
wrap_mode_reflect_auto_pow2(unsigned size) :
m_size(size),
m_size2(size * 2),
m_add(m_size2 * (0x3FFFFFFF / m_size2)),
m_mask((m_size2 & (m_size2-1)) ? 0 : m_size2-1),
m_value(0)
{}
AGG_INLINE unsigned operator() (int v)
{
m_value = m_mask ? unsigned(v) & m_mask :
(unsigned(v) + m_add) % m_size2;
if(m_value >= m_size) return m_size2 - m_value - 1;
return m_value;
}
AGG_INLINE unsigned operator++ ()
{
++m_value;
if(m_value >= m_size2) m_value = 0;
if(m_value >= m_size) return m_size2 - m_value - 1;
return m_value;
}
private:
unsigned m_size;
unsigned m_size2;
unsigned m_add;
unsigned m_mask;
unsigned m_value;
};
}
#endif
| 0 |
End of preview. Expand
in Dataset Viewer.
README.md exists but content is empty.
- Downloads last month
- 55