Refactor core libraries into their own library.

This commit is contained in:
David Given
2024-10-01 20:36:53 +02:00
parent fb6fa969a8
commit ca940d1599
425 changed files with 28872 additions and 20698 deletions

View File

@@ -2,33 +2,34 @@
#define ADF_NATIV_H
#ifdef __cplusplus
extern "C" {
extern "C"
{
#endif
#include "adf_str.h"
#define NATIVE_FILE 8001
struct nativeDevice
{
FILE* fd;
};
struct nativeDevice
{
FILE* fd;
};
struct nativeFunctions
{
/* called by adfMount() */
RETCODE (*adfInitDevice)(struct Device*, char*, BOOL);
/* called by adfReadBlock() */
RETCODE (*adfNativeReadSector)(struct Device*, int32_t, int, uint8_t*);
/* called by adfWriteBlock() */
RETCODE (*adfNativeWriteSector)(struct Device*, int32_t, int, uint8_t*);
/* called by adfMount() */
BOOL (*adfIsDevNative)(char*);
/* called by adfUnMount() */
RETCODE (*adfReleaseDevice)(struct Device*);
};
struct nativeFunctions
{
/* called by adfMount() */
RETCODE (*adfInitDevice)(struct Device*, char*, BOOL);
/* called by adfReadBlock() */
RETCODE (*adfNativeReadSector)(struct Device*, int32_t, int, uint8_t*);
/* called by adfWriteBlock() */
RETCODE (*adfNativeWriteSector)(struct Device*, int32_t, int, uint8_t*);
/* called by adfMount() */
BOOL (*adfIsDevNative)(char*);
/* called by adfUnMount() */
RETCODE (*adfReleaseDevice)(struct Device*);
};
extern void adfInitNativeFct();
extern void adfInitNativeFct();
#ifdef __cplusplus
}

View File

@@ -1,2 +1 @@
/* empty config.h to keep the source happy */

View File

@@ -27,25 +27,28 @@
*
*/
#include"adf_str.h"
#include"prefix.h"
#include "adf_str.h"
#include "prefix.h"
RETCODE adfReadBitmapBlock(struct Volume*, SECTNUM nSect, struct bBitmapBlock*);
RETCODE adfWriteBitmapBlock(struct Volume*, SECTNUM nSect, struct bBitmapBlock*);
RETCODE adfReadBitmapExtBlock(struct Volume*, SECTNUM nSect, struct bBitmapExtBlock*);
RETCODE adfWriteBitmapExtBlock(struct Volume*, SECTNUM, struct bBitmapExtBlock* );
RETCODE adfWriteBitmapBlock(
struct Volume*, SECTNUM nSect, struct bBitmapBlock*);
RETCODE adfReadBitmapExtBlock(
struct Volume*, SECTNUM nSect, struct bBitmapExtBlock*);
RETCODE adfWriteBitmapExtBlock(
struct Volume*, SECTNUM, struct bBitmapExtBlock*);
SECTNUM adfGet1FreeBlock(struct Volume *vol);
RETCODE adfUpdateBitmap(struct Volume *vol);
SECTNUM adfGet1FreeBlock(struct Volume* vol);
RETCODE adfUpdateBitmap(struct Volume* vol);
PREFIX int32_t adfCountFreeBlocks(struct Volume* vol);
RETCODE adfReadBitmap(struct Volume* , SECTNUM nBlock, struct bRootBlock* root);
RETCODE adfReadBitmap(struct Volume*, SECTNUM nBlock, struct bRootBlock* root);
BOOL adfIsBlockFree(struct Volume* vol, SECTNUM nSect);
void adfSetBlockFree(struct Volume* vol, SECTNUM nSect);
void adfSetBlockUsed(struct Volume* vol, SECTNUM nSect);
BOOL adfGetFreeBlocks(struct Volume* vol, int nbSect, SECTNUM* sectList);
RETCODE adfCreateBitmap(struct Volume *vol);
RETCODE adfWriteNewBitmap(struct Volume *vol);
void adfFreeBitmap(struct Volume *vol);
RETCODE adfCreateBitmap(struct Volume* vol);
RETCODE adfWriteNewBitmap(struct Volume* vol);
void adfFreeBitmap(struct Volume* vol);
#endif /* ADF_BITM_H */

View File

@@ -25,264 +25,255 @@
*
*/
#ifndef ADF_BLK_H
#define ADF_BLK_H 1
#define ULONG uint32_t
#define USHORT uint16_t
#define UCHAR uint8_t
#define ULONG uint32_t
#define USHORT uint16_t
#define UCHAR uint8_t
#define LOGICAL_BLOCK_SIZE 512
#define LOGICAL_BLOCK_SIZE 512
/* ----- FILE SYSTEM ----- */
#define FSMASK_FFS 1
#define FSMASK_INTL 2
#define FSMASK_DIRCACHE 4
#define isFFS(c) ((c)&FSMASK_FFS)
#define isOFS(c) (!((c)&FSMASK_FFS))
#define isINTL(c) ((c)&FSMASK_INTL)
#define isDIRCACHE(c) ((c)&FSMASK_DIRCACHE)
#define FSMASK_FFS 1
#define FSMASK_INTL 2
#define FSMASK_DIRCACHE 4
#define isFFS(c) ((c)&FSMASK_FFS)
#define isOFS(c) (!((c)&FSMASK_FFS))
#define isINTL(c) ((c)&FSMASK_INTL)
#define isDIRCACHE(c) ((c)&FSMASK_DIRCACHE)
/* ----- ENTRIES ----- */
/* access constants */
#define ACCMASK_D (1<<0)
#define ACCMASK_E (1<<1)
#define ACCMASK_W (1<<2)
#define ACCMASK_R (1<<3)
#define ACCMASK_A (1<<4)
#define ACCMASK_P (1<<5)
#define ACCMASK_S (1<<6)
#define ACCMASK_H (1<<7)
#define hasD(c) ((c)&ACCMASK_D)
#define hasE(c) ((c)&ACCMASK_E)
#define hasW(c) ((c)&ACCMASK_W)
#define hasR(c) ((c)&ACCMASK_R)
#define hasA(c) ((c)&ACCMASK_A)
#define hasP(c) ((c)&ACCMASK_P)
#define hasS(c) ((c)&ACCMASK_S)
#define hasH(c) ((c)&ACCMASK_H)
#define ACCMASK_D (1 << 0)
#define ACCMASK_E (1 << 1)
#define ACCMASK_W (1 << 2)
#define ACCMASK_R (1 << 3)
#define ACCMASK_A (1 << 4)
#define ACCMASK_P (1 << 5)
#define ACCMASK_S (1 << 6)
#define ACCMASK_H (1 << 7)
#define hasD(c) ((c)&ACCMASK_D)
#define hasE(c) ((c)&ACCMASK_E)
#define hasW(c) ((c)&ACCMASK_W)
#define hasR(c) ((c)&ACCMASK_R)
#define hasA(c) ((c)&ACCMASK_A)
#define hasP(c) ((c)&ACCMASK_P)
#define hasS(c) ((c)&ACCMASK_S)
#define hasH(c) ((c)&ACCMASK_H)
/* ----- BLOCKS ----- */
/* block constants */
#define BM_VALID -1
#define BM_INVALID 0
#define BM_VALID -1
#define BM_INVALID 0
#define HT_SIZE 72
#define BM_SIZE 25
#define MAX_DATABLK 72
#define MAXNAMELEN 30
#define MAXCMMTLEN 79
#define HT_SIZE 72
#define BM_SIZE 25
#define MAX_DATABLK 72
#define MAXNAMELEN 30
#define MAXCMMTLEN 79
/* block primary and secondary types */
#define T_HEADER 2
#define ST_ROOT 1
#define ST_DIR 2
#define ST_FILE -3
#define ST_LFILE -4
#define ST_LDIR 4
#define ST_LSOFT 3
#define T_LIST 16
#define T_DATA 8
#define T_DIRC 33
#define T_HEADER 2
#define ST_ROOT 1
#define ST_DIR 2
#define ST_FILE -3
#define ST_LFILE -4
#define ST_LDIR 4
#define ST_LSOFT 3
#define T_LIST 16
#define T_DATA 8
#define T_DIRC 33
/*--- blocks structures --- */
struct bBootBlock {
/*000*/ char dosType[4];
/*004*/ ULONG checkSum;
/*008*/ int32_t rootBlock;
/*00c*/ UCHAR data[500+512];
struct bBootBlock
{
/*000*/ char dosType[4];
/*004*/ ULONG checkSum;
/*008*/ int32_t rootBlock;
/*00c*/ UCHAR data[500 + 512];
};
struct bRootBlock {
/*000*/ int32_t type;
int32_t headerKey;
int32_t highSeq;
/*00c*/ int32_t hashTableSize;
int32_t firstData;
/*014*/ ULONG checkSum;
/*018*/ int32_t hashTable[HT_SIZE]; /* hash table */
/*138*/ int32_t bmFlag; /* bitmap flag, -1 means VALID */
/*13c*/ int32_t bmPages[BM_SIZE];
/*1a0*/ int32_t bmExt;
/*1a4*/ int32_t cDays; /* creation date FFS and OFS */
/*1a8*/ int32_t cMins;
/*1ac*/ int32_t cTicks;
/*1b0*/ char nameLen;
/*1b1*/ char diskName[MAXNAMELEN+1];
char r2[8];
/*1d8*/ int32_t days; /* last access : days after 1 jan 1978 */
/*1dc*/ int32_t mins; /* hours and minutes in minutes */
/*1e0*/ int32_t ticks; /* 1/50 seconds */
/*1e4*/ int32_t coDays; /* creation date OFS */
/*1e8*/ int32_t coMins;
/*1ec*/ int32_t coTicks;
int32_t nextSameHash; /* == 0 */
int32_t parent; /* == 0 */
/*1f8*/ int32_t extension; /* FFS: first directory cache block */
/*1fc*/ int32_t secType; /* == 1 */
struct bRootBlock
{
/*000*/ int32_t type;
int32_t headerKey;
int32_t highSeq;
/*00c*/ int32_t hashTableSize;
int32_t firstData;
/*014*/ ULONG checkSum;
/*018*/ int32_t hashTable[HT_SIZE]; /* hash table */
/*138*/ int32_t bmFlag; /* bitmap flag, -1 means VALID */
/*13c*/ int32_t bmPages[BM_SIZE];
/*1a0*/ int32_t bmExt;
/*1a4*/ int32_t cDays; /* creation date FFS and OFS */
/*1a8*/ int32_t cMins;
/*1ac*/ int32_t cTicks;
/*1b0*/ char nameLen;
/*1b1*/ char diskName[MAXNAMELEN + 1];
char r2[8];
/*1d8*/ int32_t days; /* last access : days after 1 jan 1978 */
/*1dc*/ int32_t mins; /* hours and minutes in minutes */
/*1e0*/ int32_t ticks; /* 1/50 seconds */
/*1e4*/ int32_t coDays; /* creation date OFS */
/*1e8*/ int32_t coMins;
/*1ec*/ int32_t coTicks;
int32_t nextSameHash; /* == 0 */
int32_t parent; /* == 0 */
/*1f8*/ int32_t extension; /* FFS: first directory cache block */
/*1fc*/ int32_t secType; /* == 1 */
};
struct bFileHeaderBlock {
/*000*/ int32_t type; /* == 2 */
/*004*/ int32_t headerKey; /* current block number */
/*008*/ int32_t highSeq; /* number of data block in this hdr block */
/*00c*/ int32_t dataSize; /* == 0 */
/*010*/ int32_t firstData;
/*014*/ ULONG checkSum;
/*018*/ int32_t dataBlocks[MAX_DATABLK];
/*138*/ int32_t r1;
/*13c*/ int32_t r2;
/*140*/ int32_t access; /* bit0=del, 1=modif, 2=write, 3=read */
/*144*/ uint32_t byteSize;
/*148*/ char commLen;
/*149*/ char comment[MAXCMMTLEN+1];
char r3[91-(MAXCMMTLEN+1)];
/*1a4*/ int32_t days;
/*1a8*/ int32_t mins;
/*1ac*/ int32_t ticks;
/*1b0*/ char nameLen;
/*1b1*/ char fileName[MAXNAMELEN+1];
int32_t r4;
/*1d4*/ int32_t real; /* unused == 0 */
/*1d8*/ int32_t nextLink; /* link chain */
int32_t r5[5];
/*1f0*/ int32_t nextSameHash; /* next entry with sane hash */
/*1f4*/ int32_t parent; /* parent directory */
/*1f8*/ int32_t extension; /* pointer to extension block */
/*1fc*/ int32_t secType; /* == -3 */
struct bFileHeaderBlock
{
/*000*/ int32_t type; /* == 2 */
/*004*/ int32_t headerKey; /* current block number */
/*008*/ int32_t highSeq; /* number of data block in this hdr block */
/*00c*/ int32_t dataSize; /* == 0 */
/*010*/ int32_t firstData;
/*014*/ ULONG checkSum;
/*018*/ int32_t dataBlocks[MAX_DATABLK];
/*138*/ int32_t r1;
/*13c*/ int32_t r2;
/*140*/ int32_t access; /* bit0=del, 1=modif, 2=write, 3=read */
/*144*/ uint32_t byteSize;
/*148*/ char commLen;
/*149*/ char comment[MAXCMMTLEN + 1];
char r3[91 - (MAXCMMTLEN + 1)];
/*1a4*/ int32_t days;
/*1a8*/ int32_t mins;
/*1ac*/ int32_t ticks;
/*1b0*/ char nameLen;
/*1b1*/ char fileName[MAXNAMELEN + 1];
int32_t r4;
/*1d4*/ int32_t real; /* unused == 0 */
/*1d8*/ int32_t nextLink; /* link chain */
int32_t r5[5];
/*1f0*/ int32_t nextSameHash; /* next entry with sane hash */
/*1f4*/ int32_t parent; /* parent directory */
/*1f8*/ int32_t extension; /* pointer to extension block */
/*1fc*/ int32_t secType; /* == -3 */
};
/*--- file header extension block structure ---*/
struct bFileExtBlock {
/*000*/ int32_t type; /* == 0x10 */
/*004*/ int32_t headerKey;
/*008*/ int32_t highSeq;
/*00c*/ int32_t dataSize; /* == 0 */
/*010*/ int32_t firstData; /* == 0 */
/*014*/ ULONG checkSum;
/*018*/ int32_t dataBlocks[MAX_DATABLK];
int32_t r[45];
int32_t info; /* == 0 */
int32_t nextSameHash; /* == 0 */
/*1f4*/ int32_t parent; /* header block */
/*1f8*/ int32_t extension; /* next header extension block */
/*1fc*/ int32_t secType; /* -3 */
struct bFileExtBlock
{
/*000*/ int32_t type; /* == 0x10 */
/*004*/ int32_t headerKey;
/*008*/ int32_t highSeq;
/*00c*/ int32_t dataSize; /* == 0 */
/*010*/ int32_t firstData; /* == 0 */
/*014*/ ULONG checkSum;
/*018*/ int32_t dataBlocks[MAX_DATABLK];
int32_t r[45];
int32_t info; /* == 0 */
int32_t nextSameHash; /* == 0 */
/*1f4*/ int32_t parent; /* header block */
/*1f8*/ int32_t extension; /* next header extension block */
/*1fc*/ int32_t secType; /* -3 */
};
struct bDirBlock {
/*000*/ int32_t type; /* == 2 */
/*004*/ int32_t headerKey;
/*008*/ int32_t highSeq; /* == 0 */
/*00c*/ int32_t hashTableSize; /* == 0 */
int32_t r1; /* == 0 */
/*014*/ ULONG checkSum;
/*018*/ int32_t hashTable[HT_SIZE]; /* hash table */
int32_t r2[2];
/*140*/ int32_t access;
int32_t r4; /* == 0 */
/*148*/ char commLen;
/*149*/ char comment[MAXCMMTLEN+1];
char r5[91-(MAXCMMTLEN+1)];
/*1a4*/ int32_t days; /* last access */
/*1a8*/ int32_t mins;
/*1ac*/ int32_t ticks;
/*1b0*/ char nameLen;
/*1b1*/ char dirName[MAXNAMELEN+1];
int32_t r6;
/*1d4*/ int32_t real; /* ==0 */
/*1d8*/ int32_t nextLink; /* link list */
int32_t r7[5];
/*1f0*/ int32_t nextSameHash;
/*1f4*/ int32_t parent;
/*1f8*/ int32_t extension; /* FFS : first directory cache */
/*1fc*/ int32_t secType; /* == 2 */
struct bDirBlock
{
/*000*/ int32_t type; /* == 2 */
/*004*/ int32_t headerKey;
/*008*/ int32_t highSeq; /* == 0 */
/*00c*/ int32_t hashTableSize; /* == 0 */
int32_t r1; /* == 0 */
/*014*/ ULONG checkSum;
/*018*/ int32_t hashTable[HT_SIZE]; /* hash table */
int32_t r2[2];
/*140*/ int32_t access;
int32_t r4; /* == 0 */
/*148*/ char commLen;
/*149*/ char comment[MAXCMMTLEN + 1];
char r5[91 - (MAXCMMTLEN + 1)];
/*1a4*/ int32_t days; /* last access */
/*1a8*/ int32_t mins;
/*1ac*/ int32_t ticks;
/*1b0*/ char nameLen;
/*1b1*/ char dirName[MAXNAMELEN + 1];
int32_t r6;
/*1d4*/ int32_t real; /* ==0 */
/*1d8*/ int32_t nextLink; /* link list */
int32_t r7[5];
/*1f0*/ int32_t nextSameHash;
/*1f4*/ int32_t parent;
/*1f8*/ int32_t extension; /* FFS : first directory cache */
/*1fc*/ int32_t secType; /* == 2 */
};
struct bOFSDataBlock{
/*000*/ int32_t type; /* == 8 */
/*004*/ int32_t headerKey; /* pointer to file_hdr block */
/*008*/ int32_t seqNum; /* file data block number */
/*00c*/ int32_t dataSize; /* <= 0x1e8 */
/*010*/ int32_t nextData; /* next data block */
/*014*/ ULONG checkSum;
/*018*/ UCHAR data[488];
struct bOFSDataBlock
{
/*000*/ int32_t type; /* == 8 */
/*004*/ int32_t headerKey; /* pointer to file_hdr block */
/*008*/ int32_t seqNum; /* file data block number */
/*00c*/ int32_t dataSize; /* <= 0x1e8 */
/*010*/ int32_t nextData; /* next data block */
/*014*/ ULONG checkSum;
/*018*/ UCHAR data[488];
/*200*/ };
/* --- bitmap --- */
struct bBitmapBlock {
/*000*/ ULONG checkSum;
/*004*/ ULONG map[127];
};
struct bBitmapExtBlock {
/*000*/ int32_t bmPages[127];
/*1fc*/ int32_t nextBlock;
};
struct bLinkBlock {
/*000*/ int32_t type; /* == 2 */
/*004*/ int32_t headerKey; /* self pointer */
int32_t r1[3];
/*014*/ ULONG checkSum;
/*018*/ char realName[64];
int32_t r2[83];
/*1a4*/ int32_t days; /* last access */
/*1a8*/ int32_t mins;
/*1ac*/ int32_t ticks;
/*1b0*/ char nameLen;
/*1b1*/ char name[MAXNAMELEN+1];
int32_t r3;
/*1d4*/ int32_t realEntry;
/*1d8*/ int32_t nextLink;
int32_t r4[5];
/*1f0*/ int32_t nextSameHash;
/*1f4*/ int32_t parent;
int32_t r5;
/*1fc*/ int32_t secType; /* == -4, 4, 3 */
};
struct bBitmapBlock
{
/*000*/ ULONG checkSum;
/*004*/ ULONG map[127];
};
struct bBitmapExtBlock
{
/*000*/ int32_t bmPages[127];
/*1fc*/ int32_t nextBlock;
};
struct bLinkBlock
{
/*000*/ int32_t type; /* == 2 */
/*004*/ int32_t headerKey; /* self pointer */
int32_t r1[3];
/*014*/ ULONG checkSum;
/*018*/ char realName[64];
int32_t r2[83];
/*1a4*/ int32_t days; /* last access */
/*1a8*/ int32_t mins;
/*1ac*/ int32_t ticks;
/*1b0*/ char nameLen;
/*1b1*/ char name[MAXNAMELEN + 1];
int32_t r3;
/*1d4*/ int32_t realEntry;
/*1d8*/ int32_t nextLink;
int32_t r4[5];
/*1f0*/ int32_t nextSameHash;
/*1f4*/ int32_t parent;
int32_t r5;
/*1fc*/ int32_t secType; /* == -4, 4, 3 */
};
/*--- directory cache block structure ---*/
struct bDirCacheBlock {
/*000*/ int32_t type; /* == 33 */
/*004*/ int32_t headerKey;
/*008*/ int32_t parent;
/*00c*/ int32_t recordsNb;
/*010*/ int32_t nextDirC;
/*014*/ ULONG checkSum;
/*018*/ uint8_t records[488];
};
struct bDirCacheBlock
{
/*000*/ int32_t type; /* == 33 */
/*004*/ int32_t headerKey;
/*008*/ int32_t parent;
/*00c*/ int32_t recordsNb;
/*010*/ int32_t nextDirC;
/*014*/ ULONG checkSum;
/*018*/ uint8_t records[488];
};
#endif /* ADF_BLK_H */
/*##########################################################################*/

View File

@@ -27,20 +27,28 @@
*
*/
#include "adf_str.h"
void adfGetCacheEntry(struct bDirCacheBlock *dirc, int *p, struct CacheEntry *cEntry);
int adfPutCacheEntry( struct bDirCacheBlock *dirc, int *p, struct CacheEntry *cEntry);
void adfGetCacheEntry(
struct bDirCacheBlock* dirc, int* p, struct CacheEntry* cEntry);
int adfPutCacheEntry(
struct bDirCacheBlock* dirc, int* p, struct CacheEntry* cEntry);
struct List* adfGetDirEntCache(struct Volume *vol, SECTNUM dir, BOOL recurs);
struct List* adfGetDirEntCache(struct Volume* vol, SECTNUM dir, BOOL recurs);
RETCODE adfCreateEmptyCache(struct Volume *vol, struct bEntryBlock *parent, SECTNUM nSect);
RETCODE adfAddInCache(struct Volume *vol, struct bEntryBlock *parent, struct bEntryBlock *entry);
RETCODE adfUpdateCache(struct Volume *vol, struct bEntryBlock *parent, struct bEntryBlock *entry, BOOL);
RETCODE adfDelFromCache(struct Volume *vol, struct bEntryBlock *parent, SECTNUM);
RETCODE adfCreateEmptyCache(
struct Volume* vol, struct bEntryBlock* parent, SECTNUM nSect);
RETCODE adfAddInCache(
struct Volume* vol, struct bEntryBlock* parent, struct bEntryBlock* entry);
RETCODE adfUpdateCache(struct Volume* vol,
struct bEntryBlock* parent,
struct bEntryBlock* entry,
BOOL);
RETCODE adfDelFromCache(
struct Volume* vol, struct bEntryBlock* parent, SECTNUM);
RETCODE adfReadDirCBlock(struct Volume *vol, SECTNUM nSect, struct bDirCacheBlock *dirc);
RETCODE adfReadDirCBlock(
struct Volume* vol, SECTNUM nSect, struct bDirCacheBlock* dirc);
RETCODE adfWriteDirCBlock(struct Volume*, int32_t, struct bDirCacheBlock* dirc);
#endif /* _ADF_CACHE_H */

View File

@@ -24,7 +24,6 @@
*
*/
#ifndef _ADF_DEFS_H
#define _ADF_DEFS_H 1
@@ -34,38 +33,33 @@
#define SECTNUM int32_t
#define RETCODE int32_t
#define TRUE 1
#define FALSE 0
#define TRUE 1
#define FALSE 0
#include <stdint.h>
#define ULONG uint32_t
#define USHORT uint16_t
#define UCHAR uint8_t
#define BOOL int
#define ULONG uint32_t
#define USHORT uint16_t
#define UCHAR uint8_t
#define BOOL int
/* defines max and min */
#ifndef max
#define max(a,b) (a)>(b) ? (a) : (b)
#define max(a, b) (a) > (b) ? (a) : (b)
#endif
#ifndef min
#define min(a,b) (a)<(b) ? (a) : (b)
#define min(a, b) (a) < (b) ? (a) : (b)
#endif
/* (*byte) to (*short) and (*byte) to (*long) conversion */
#define Short(p) ((p)[0]<<8 | (p)[1])
#define Long(p) (Short(p)<<16 | Short(p+2))
#define Short(p) ((p)[0] << 8 | (p)[1])
#define Long(p) (Short(p) << 16 | Short(p + 2))
/* swap short and swap long macros for little endian machines */
#define swapShort(p) ((p)[0]<<8 | (p)[1])
#define swapLong(p) (swapShort(p)<<16 | swapShort(p+2))
#define swapShort(p) ((p)[0] << 8 | (p)[1])
#define swapLong(p) (swapShort(p) << 16 | swapShort(p + 2))
#endif /* _ADF_DEFS_H */
/*##########################################################################*/

View File

@@ -26,45 +26,54 @@
*
*/
#include"adf_str.h"
#include"adf_err.h"
#include"adf_defs.h"
#include "adf_str.h"
#include "adf_err.h"
#include "adf_defs.h"
#include"prefix.h"
#include "prefix.h"
PREFIX RETCODE adfToRootDir(struct Volume *vol);
BOOL isDirEmpty(struct bDirBlock *dir);
PREFIX RETCODE adfRemoveEntry(struct Volume *vol, SECTNUM pSect, char *name);
PREFIX struct List* adfGetDirEnt(struct Volume* vol, SECTNUM nSect );
PREFIX struct List* adfGetRDirEnt(struct Volume* vol, SECTNUM nSect, BOOL recurs );
PREFIX RETCODE adfToRootDir(struct Volume* vol);
BOOL isDirEmpty(struct bDirBlock* dir);
PREFIX RETCODE adfRemoveEntry(struct Volume* vol, SECTNUM pSect, char* name);
PREFIX struct List* adfGetDirEnt(struct Volume* vol, SECTNUM nSect);
PREFIX struct List* adfGetRDirEnt(
struct Volume* vol, SECTNUM nSect, BOOL recurs);
PREFIX void adfFreeDirList(struct List* list);
RETCODE adfEntBlock2Entry(struct bEntryBlock *entryBlk, struct Entry *entry);
PREFIX void adfFreeEntry(struct Entry *entry);
RETCODE adfCreateFile(struct Volume* vol, SECTNUM parent, char *name,
struct bFileHeaderBlock *fhdr);
RETCODE adfEntBlock2Entry(struct bEntryBlock* entryBlk, struct Entry* entry);
PREFIX void adfFreeEntry(struct Entry* entry);
RETCODE adfCreateFile(struct Volume* vol,
SECTNUM parent,
char* name,
struct bFileHeaderBlock* fhdr);
PREFIX RETCODE adfCreateDir(struct Volume* vol, SECTNUM parent, char* name);
SECTNUM adfCreateEntry(struct Volume *vol, struct bEntryBlock *dir, char *name, SECTNUM );
PREFIX RETCODE adfRenameEntry(struct Volume *vol, SECTNUM, char *old,SECTNUM,char *new);
SECTNUM adfCreateEntry(
struct Volume* vol, struct bEntryBlock* dir, char* name, SECTNUM);
PREFIX RETCODE adfRenameEntry(
struct Volume* vol, SECTNUM, char* old, SECTNUM, char* new);
RETCODE adfReadEntryBlock(struct Volume* vol, SECTNUM nSect, struct bEntryBlock* ent);
RETCODE adfWriteDirBlock(struct Volume* vol, SECTNUM nSect, struct bDirBlock *dir);
RETCODE adfWriteEntryBlock(struct Volume* vol, SECTNUM nSect, struct bEntryBlock *ent);
RETCODE adfReadEntryBlock(
struct Volume* vol, SECTNUM nSect, struct bEntryBlock* ent);
RETCODE adfWriteDirBlock(
struct Volume* vol, SECTNUM nSect, struct bDirBlock* dir);
RETCODE adfWriteEntryBlock(
struct Volume* vol, SECTNUM nSect, struct bEntryBlock* ent);
char* adfAccess2String(int32_t acc);
uint8_t adfIntlToUpper(uint8_t c);
int adfGetHashValue(uint8_t *name, BOOL intl);
void myToUpper( uint8_t *ostr, uint8_t *nstr, int,BOOL intl );
PREFIX RETCODE adfChangeDir(struct Volume* vol, char *name);
int adfGetHashValue(uint8_t* name, BOOL intl);
void myToUpper(uint8_t* ostr, uint8_t* nstr, int, BOOL intl);
PREFIX RETCODE adfChangeDir(struct Volume* vol, char* name);
PREFIX RETCODE adfParentDir(struct Volume* vol);
PREFIX RETCODE adfSetEntryAccess(struct Volume*, SECTNUM, char*, int32_t);
PREFIX RETCODE adfSetEntryComment(struct Volume*, SECTNUM, char*, char*);
SECTNUM adfNameToEntryBlk(struct Volume *vol, int32_t ht[], char* name,
struct bEntryBlock *entry, SECTNUM *);
SECTNUM adfNameToEntryBlk(struct Volume* vol,
int32_t ht[],
char* name,
struct bEntryBlock* entry,
SECTNUM*);
PREFIX void printEntry(struct Entry* entry);
void adfFreeDirList(struct List* list);
#endif /* ADF_DIR_H */

View File

@@ -31,21 +31,21 @@
#include "adf_str.h"
#include "adf_defs.h"
PREFIX RETCODE adfInstallBootBlock(struct Volume *vol,uint8_t*);
PREFIX RETCODE adfInstallBootBlock(struct Volume* vol, uint8_t*);
PREFIX BOOL isSectNumValid(struct Volume *vol, SECTNUM nSect);
PREFIX BOOL isSectNumValid(struct Volume* vol, SECTNUM nSect);
PREFIX struct Volume* adfMount( struct Device *dev, int nPart, BOOL readOnly );
PREFIX void adfUnMount(struct Volume *vol);
PREFIX void adfVolumeInfo(struct Volume *vol);
struct Volume* adfCreateVol( struct Device* dev, int32_t start, int32_t len,
char* volName, int volType );
PREFIX struct Volume* adfMount(struct Device* dev, int nPart, BOOL readOnly);
PREFIX void adfUnMount(struct Volume* vol);
PREFIX void adfVolumeInfo(struct Volume* vol);
struct Volume* adfCreateVol(
struct Device* dev, int32_t start, int32_t len, char* volName, int volType);
/*void adfReadBitmap(struct Volume* , int32_t nBlock, struct bRootBlock* root);
void adfUpdateBitmap(struct Volume*);
*/
PREFIX RETCODE adfReadBlock(struct Volume* , int32_t nSect, uint8_t* buf);
PREFIX RETCODE adfWriteBlock(struct Volume* , int32_t nSect, uint8_t* buf);
PREFIX RETCODE adfReadBlock(struct Volume*, int32_t nSect, uint8_t* buf);
PREFIX RETCODE adfWriteBlock(struct Volume*, int32_t nSect, uint8_t* buf);
#endif /* _ADF_DISK_H */

View File

@@ -7,7 +7,7 @@
* adf_dump.h
*
* $Id$
*
*
* This file is part of ADFLib.
*
* ADFLib is free software; you can redistribute it and/or modify
@@ -26,14 +26,13 @@
*
*/
PREFIX struct Device*
adfCreateDumpDevice(char* filename, int32_t cyl, int32_t heads, int32_t sec);
PREFIX struct Device* adfCreateDumpDevice(
char* filename, int32_t cyl, int32_t heads, int32_t sec);
PREFIX RETCODE adfCreateHdFile(struct Device* dev, char* volName, int volType);
BOOL adfInitDumpDevice(struct Device* dev, char* name,BOOL);
BOOL adfReadDumpSector(struct Device *dev, int32_t n, int size, uint8_t* buf);
BOOL adfWriteDumpSector(struct Device *dev, int32_t n, int size, uint8_t* buf);
RETCODE adfReleaseDumpDevice(struct Device *dev);
BOOL adfInitDumpDevice(struct Device* dev, char* name, BOOL);
BOOL adfReadDumpSector(struct Device* dev, int32_t n, int size, uint8_t* buf);
BOOL adfWriteDumpSector(struct Device* dev, int32_t n, int size, uint8_t* buf);
RETCODE adfReleaseDumpDevice(struct Device* dev);
#endif /* ADF_DUMP_H */
/*##########################################################################*/

View File

@@ -7,7 +7,7 @@
* adf_env.h
*
* $Id$
*
*
* This file is part of ADFLib.
*
* ADFLib is free software; you can redistribute it and/or modify
@@ -26,13 +26,15 @@
*
*/
#include"prefix.h"
#include "prefix.h"
PREFIX void adfEnvInitDefault();
PREFIX void adfSetEnvFct( void(*e)(char*), void(*w)(char*), void(*v)(char*),
void(*n)(SECTNUM,int) );
PREFIX void adfSetEnvFct(void (*e)(char*),
void (*w)(char*),
void (*v)(char*),
void (*n)(SECTNUM, int));
PREFIX void adfEnvCleanUp();
PREFIX void adfChgEnvProp(int prop, void *new);
PREFIX void adfChgEnvProp(int prop, void* new);
PREFIX char* adfGetVersionNumber();
PREFIX char* adfGetVersionDate();

View File

@@ -26,39 +26,36 @@
*
*/
#define hasRC(rc, c) ((rc) & (c))
#define hasRC(rc,c) ((rc)&(c))
#define RC_OK 0
#define RC_ERROR -1
#define RC_OK 0
#define RC_ERROR -1
#define RC_MALLOC 1
#define RC_VOLFULL 2
#define RC_MALLOC 1
#define RC_VOLFULL 2
#define RC_FOPEN 1<<10
#define RC_NULLPTR 1<<12
#define RC_FOPEN 1 << 10
#define RC_NULLPTR 1 << 12
/* adfRead*Block() */
#define RC_BLOCKTYPE 1
#define RC_BLOCKSTYPE 1<<1
#define RC_BLOCKSUM 1<<2
#define RC_HEADERKEY 1<<3
#define RC_BLOCKREAD 1<<4
#define RC_BLOCKTYPE 1
#define RC_BLOCKSTYPE 1 << 1
#define RC_BLOCKSUM 1 << 2
#define RC_HEADERKEY 1 << 3
#define RC_BLOCKREAD 1 << 4
/* adfWrite*Block */
#define RC_BLOCKWRITE 1<<4
#define RC_BLOCKWRITE 1 << 4
/* adfReadBlock() */
#define RC_BLOCKOUTOFRANGE 1
#define RC_BLOCKNATREAD 1<<1
#define RC_BLOCKOUTOFRANGE 1
#define RC_BLOCKNATREAD 1 << 1
/* adfWriteBlock() */
/* RC_BLOCKOUTOFRANGE */
#define RC_BLOCKNATWRITE 1<<1
#define RC_BLOCKREADONLY 1<<2
#define RC_BLOCKNATWRITE 1 << 1
#define RC_BLOCKREADONLY 1 << 2
/* adfInitDumpDevice() */
/* RC_FOPEN */
@@ -66,17 +63,16 @@
/* adfNativeReadBlock(), adfReadDumpSector() */
#define RC_BLOCKSHORTREAD 1
#define RC_BLOCKFSEEK 1<<1
#define RC_BLOCKSHORTREAD 1
#define RC_BLOCKFSEEK 1 << 1
/* adfNativeWriteBlock(), adfWriteDumpSector() */
#define RC_BLOCKSHORTWRITE 1
#define RC_BLOCKSHORTWRITE 1
/* RC_BLOCKFSEEK */
/*-- adfReadRDSKblock --*/
#define RC_BLOCKID 1<<5
#define RC_BLOCKID 1 << 5
/*-- adfWriteRDSKblock() --*/
/*RC_BLOCKREADONLY*/

View File

@@ -26,35 +26,40 @@
*
*/
#include"prefix.h"
#include "prefix.h"
#include"adf_str.h"
#include "adf_str.h"
RETCODE adfGetFileBlocks(struct Volume* vol, struct bFileHeaderBlock* entry,
struct FileBlocks* );
RETCODE adfFreeFileBlocks(struct Volume* vol, struct bFileHeaderBlock *entry);
PREFIX int32_t adfFileRealSize(uint32_t size, int blockSize, int32_t *dataN, int32_t *extN);
RETCODE adfGetFileBlocks(
struct Volume* vol, struct bFileHeaderBlock* entry, struct FileBlocks*);
RETCODE adfFreeFileBlocks(struct Volume* vol, struct bFileHeaderBlock* entry);
PREFIX int32_t adfFileRealSize(
uint32_t size, int blockSize, int32_t* dataN, int32_t* extN);
int32_t adfPos2DataBlock(int32_t pos, int blockSize, int *posInExtBlk, int *posInDataBlk, int32_t *curDataN );
int32_t adfPos2DataBlock(int32_t pos,
int blockSize,
int* posInExtBlk,
int* posInDataBlk,
int32_t* curDataN);
RETCODE adfWriteFileHdrBlock(struct Volume *vol, SECTNUM nSect, struct bFileHeaderBlock* fhdr);
RETCODE adfWriteFileHdrBlock(
struct Volume* vol, SECTNUM nSect, struct bFileHeaderBlock* fhdr);
RETCODE adfReadDataBlock(struct Volume *vol, SECTNUM nSect, void *data);
RETCODE adfWriteDataBlock(struct Volume *vol, SECTNUM nSect, void *data);
RETCODE adfReadFileExtBlock(struct Volume *vol, SECTNUM nSect, struct bFileExtBlock* fext);
RETCODE adfWriteFileExtBlock(struct Volume *vol, SECTNUM nSect, struct bFileExtBlock* fext);
RETCODE adfReadDataBlock(struct Volume* vol, SECTNUM nSect, void* data);
RETCODE adfWriteDataBlock(struct Volume* vol, SECTNUM nSect, void* data);
RETCODE adfReadFileExtBlock(
struct Volume* vol, SECTNUM nSect, struct bFileExtBlock* fext);
RETCODE adfWriteFileExtBlock(
struct Volume* vol, SECTNUM nSect, struct bFileExtBlock* fext);
PREFIX struct File* adfOpenFile(struct Volume *vol, char* name, char *mode);
PREFIX void adfCloseFile(struct File *file);
PREFIX int32_t adfReadFile(struct File* file, int32_t n, uint8_t *buffer);
PREFIX struct File* adfOpenFile(struct Volume* vol, char* name, char* mode);
PREFIX void adfCloseFile(struct File* file);
PREFIX int32_t adfReadFile(struct File* file, int32_t n, uint8_t* buffer);
PREFIX BOOL adfEndOfFile(struct File* file);
PREFIX void adfFileSeek(struct File *file, uint32_t pos); /* BV */
PREFIX void adfFileSeek(struct File* file, uint32_t pos); /* BV */
RETCODE adfReadNextFileBlock(struct File* file);
PREFIX int32_t adfWriteFile(struct File *file, int32_t n, uint8_t *buffer);
PREFIX int32_t adfWriteFile(struct File* file, int32_t n, uint8_t* buffer);
SECTNUM adfCreateNextFileBlock(struct File* file);
PREFIX void adfFlushFile(struct File *file);
PREFIX void adfFlushFile(struct File* file);
#endif /* ADF_FILE_H */

View File

@@ -28,38 +28,48 @@
*
*/
#include"prefix.h"
#include "prefix.h"
#include "adf_str.h"
#include "hd_blk.h"
#include "adf_err.h"
int adfDevType(struct Device *dev);
PREFIX void adfDeviceInfo(struct Device *dev);
int adfDevType(struct Device* dev);
PREFIX void adfDeviceInfo(struct Device* dev);
RETCODE adfMountHd(struct Device *dev);
RETCODE adfMountHd(struct Device* dev);
RETCODE adfMountFlop(struct Device* dev);
PREFIX struct Device* adfMountDev( char* filename,BOOL);
PREFIX void adfUnMountDev( struct Device* dev);
PREFIX struct Device* adfMountDev(char* filename, BOOL);
PREFIX void adfUnMountDev(struct Device* dev);
RETCODE adfCreateHdHeader(struct Device* dev, int n, struct Partition** partList );
PREFIX RETCODE adfCreateFlop(struct Device* dev, char* volName, int volType );
PREFIX RETCODE adfCreateHd(struct Device* dev, int n, struct Partition** partList );
RETCODE adfCreateHdHeader(
struct Device* dev, int n, struct Partition** partList);
PREFIX RETCODE adfCreateFlop(struct Device* dev, char* volName, int volType);
PREFIX RETCODE adfCreateHd(
struct Device* dev, int n, struct Partition** partList);
PREFIX RETCODE adfCreateHdFile(struct Device* dev, char* volName, int volType);
struct Device* adfCreateDev(char* filename, int32_t cylinders, int32_t heads, int32_t sectors);
RETCODE adfReadBlockDev( struct Device* dev, int32_t nSect, int32_t size, uint8_t* buf );
RETCODE adfWriteBlockDev(struct Device* dev, int32_t nSect, int32_t size, uint8_t* buf );
RETCODE adfReadRDSKblock( struct Device* dev, struct bRDSKblock* blk );
RETCODE adfWriteRDSKblock(struct Device *dev, struct bRDSKblock* rdsk);
RETCODE adfReadPARTblock( struct Device* dev, int32_t nSect, struct bPARTblock* blk );
RETCODE adfWritePARTblock(struct Device *dev, int32_t nSect, struct bPARTblock* part);
RETCODE adfReadFSHDblock( struct Device* dev, int32_t nSect, struct bFSHDblock* blk);
RETCODE adfWriteFSHDblock(struct Device *dev, int32_t nSect, struct bFSHDblock* fshd);
RETCODE adfReadLSEGblock(struct Device* dev, int32_t nSect, struct bLSEGblock* blk);
RETCODE adfWriteLSEGblock(struct Device *dev, int32_t nSect, struct bLSEGblock* lseg);
struct Device* adfCreateDev(
char* filename, int32_t cylinders, int32_t heads, int32_t sectors);
RETCODE adfReadBlockDev(
struct Device* dev, int32_t nSect, int32_t size, uint8_t* buf);
RETCODE adfWriteBlockDev(
struct Device* dev, int32_t nSect, int32_t size, uint8_t* buf);
RETCODE adfReadRDSKblock(struct Device* dev, struct bRDSKblock* blk);
RETCODE adfWriteRDSKblock(struct Device* dev, struct bRDSKblock* rdsk);
RETCODE adfReadPARTblock(
struct Device* dev, int32_t nSect, struct bPARTblock* blk);
RETCODE adfWritePARTblock(
struct Device* dev, int32_t nSect, struct bPARTblock* part);
RETCODE adfReadFSHDblock(
struct Device* dev, int32_t nSect, struct bFSHDblock* blk);
RETCODE adfWriteFSHDblock(
struct Device* dev, int32_t nSect, struct bFSHDblock* fshd);
RETCODE adfReadLSEGblock(
struct Device* dev, int32_t nSect, struct bLSEGblock* blk);
RETCODE adfWriteLSEGblock(
struct Device* dev, int32_t nSect, struct bLSEGblock* lseg);
#endif /* _ADF_HD_H */

View File

@@ -7,7 +7,7 @@
* adf_link.h
*
* $Id$
*
*
* This file is part of ADFLib.
*
* ADFLib is free software; you can redistribute it and/or modify
@@ -26,11 +26,13 @@
*
*/
#include"prefix.h"
#include "prefix.h"
#include <stdint.h>
PREFIX RETCODE adfBlockPtr2EntryName(struct Volume *vol, SECTNUM nSect, SECTNUM lPar,
char **name, int32_t *size);
PREFIX RETCODE adfBlockPtr2EntryName(struct Volume* vol,
SECTNUM nSect,
SECTNUM lPar,
char** name,
int32_t* size);
#endif /* ADF_LINK_H */
/*##########################################################################*/

View File

@@ -30,38 +30,40 @@
#include "adf_str.h"
#define SW_LONG 4
#define SW_LONG 4
#define SW_SHORT 2
#define SW_CHAR 1
#define SW_CHAR 1
#define MAX_SWTYPE 11
#define SWBL_BOOT 0
#define SWBL_ROOT 1
#define SWBL_DATA 2
#define SWBL_FILE 3
#define SWBL_ENTRY 3
#define SWBL_DIR 3
#define SWBL_CACHE 4
#define SWBL_BITMAP 5
#define SWBL_FEXT 5
#define SWBL_LINK 6
#define SWBL_BITMAPE 5
#define SWBL_RDSK 7
#define SWBL_BADB 8
#define SWBL_PART 9
#define SWBL_FSHD 10
#define SWBL_LSEG 11
#define SWBL_BOOT 0
#define SWBL_ROOT 1
#define SWBL_DATA 2
#define SWBL_FILE 3
#define SWBL_ENTRY 3
#define SWBL_DIR 3
#define SWBL_CACHE 4
#define SWBL_BITMAP 5
#define SWBL_FEXT 5
#define SWBL_LINK 6
#define SWBL_BITMAPE 5
#define SWBL_RDSK 7
#define SWBL_BADB 8
#define SWBL_PART 9
#define SWBL_FSHD 10
#define SWBL_LSEG 11
RETCODE adfReadRootBlock(struct Volume*, int32_t nSect, struct bRootBlock* root);
RETCODE adfWriteRootBlock(struct Volume* vol, int32_t nSect, struct bRootBlock* root);
RETCODE adfReadRootBlock(
struct Volume*, int32_t nSect, struct bRootBlock* root);
RETCODE adfWriteRootBlock(
struct Volume* vol, int32_t nSect, struct bRootBlock* root);
RETCODE adfReadBootBlock(struct Volume*, struct bBootBlock* boot);
RETCODE adfWriteBootBlock(struct Volume* vol, struct bBootBlock* boot);
uint32_t adfBootSum(uint8_t *buf);
uint32_t adfNormalSum( uint8_t *buf, int offset, int bufLen );
uint32_t adfBootSum(uint8_t* buf);
uint32_t adfNormalSum(uint8_t* buf, int offset, int bufLen);
void swapEndian( uint8_t *buf, int type );
void swapEndian(uint8_t* buf, int type);
#endif /* _ADF_RAW_H */

View File

@@ -26,17 +26,16 @@
*
*/
#include"prefix.h"
#include "prefix.h"
#include "adf_str.h"
RETCODE adfReadGenBlock(struct Volume *vol, SECTNUM nSect, struct GenBlock *block);
RETCODE adfReadGenBlock(
struct Volume* vol, SECTNUM nSect, struct GenBlock* block);
PREFIX RETCODE adfCheckEntry(struct Volume* vol, SECTNUM nSect, int level);
PREFIX RETCODE adfUndelEntry(struct Volume* vol, SECTNUM parent, SECTNUM nSect);
PREFIX struct List* adfGetDelEnt(struct Volume *vol);
PREFIX struct List* adfGetDelEnt(struct Volume* vol);
PREFIX void adfFreeDelList(struct List* list);
/*##########################################################################*/
#endif /* _ADF_SALV_H */

View File

@@ -28,41 +28,43 @@
*
*/
#include<stdio.h>
#include <stdio.h>
#include"adf_defs.h"
#include"adf_blk.h"
#include"adf_err.h"
#include "adf_defs.h"
#include "adf_blk.h"
#include "adf_err.h"
/* ----- VOLUME ----- */
struct Volume {
struct Volume
{
struct Device* dev;
SECTNUM firstBlock; /* first block of data area (from beginning of device) */
SECTNUM lastBlock; /* last block of data area (from beginning of device) */
SECTNUM rootBlock; /* root block (from firstBlock) */
SECTNUM
firstBlock; /* first block of data area (from beginning of device) */
SECTNUM lastBlock; /* last block of data area (from beginning of device) */
SECTNUM rootBlock; /* root block (from firstBlock) */
char dosType; /* FFS/OFS, DIRCACHE, INTERNATIONAL */
char dosType; /* FFS/OFS, DIRCACHE, INTERNATIONAL */
BOOL bootCode;
BOOL readOnly;
int datablockSize; /* 488 or 512 */
int blockSize; /* 512 */
int datablockSize; /* 488 or 512 */
int blockSize; /* 512 */
char *volName;
char* volName;
BOOL mounted;
int32_t bitmapSize; /* in blocks */
SECTNUM *bitmapBlocks; /* bitmap blocks pointers */
struct bBitmapBlock **bitmapTable;
BOOL *bitmapBlocksChg;
int32_t bitmapSize; /* in blocks */
SECTNUM* bitmapBlocks; /* bitmap blocks pointers */
struct bBitmapBlock** bitmapTable;
BOOL* bitmapBlocksChg;
SECTNUM curDirPtr;
};
struct Partition {
struct Partition
{
int32_t startCyl;
int32_t lenCyl;
char* volName;
@@ -71,35 +73,36 @@ struct Partition {
/* ----- DEVICES ----- */
#define DEVTYPE_FLOPDD 1
#define DEVTYPE_FLOPHD 2
#define DEVTYPE_HARDDISK 3
#define DEVTYPE_HARDFILE 4
#define DEVTYPE_FLOPDD 1
#define DEVTYPE_FLOPHD 2
#define DEVTYPE_HARDDISK 3
#define DEVTYPE_HARDFILE 4
struct Device {
int devType; /* see below */
struct Device
{
int devType; /* see below */
BOOL readOnly;
int32_t size; /* in bytes */
int32_t size; /* in bytes */
int nVol; /* partitions */
struct Volume** volList;
int32_t cylinders; /* geometry */
int nVol; /* partitions */
struct Volume** volList;
int32_t cylinders; /* geometry */
int32_t heads;
int32_t sectors;
BOOL isNativeDev;
void *nativeDev;
void* nativeDev;
};
/* ----- FILE ----- */
struct File {
struct Volume *volume;
struct File
{
struct Volume* volume;
struct bFileHeaderBlock* fileHdr;
void *currentData;
void* currentData;
struct bFileExtBlock* currentExt;
int32_t nDataBlock;
@@ -109,12 +112,12 @@ struct File {
int posInDataBlk;
int posInExtBlk;
BOOL eof, writeMode;
};
};
/* ----- ENTRY ---- */
struct Entry{
struct Entry
{
int type;
char* name;
SECTNUM sector;
@@ -127,72 +130,72 @@ struct Entry{
int hour, mins, secs;
};
struct CacheEntry{
struct CacheEntry
{
int32_t header, size, protect;
short days, mins, ticks;
signed char type;
char nLen, cLen;
char name[MAXNAMELEN+1], comm[MAXCMMTLEN+1];
/* char *name, *comm;*/
char name[MAXNAMELEN + 1], comm[MAXCMMTLEN + 1];
/* char *name, *comm;*/
};
struct DateTime{
int year,mon,day,hour,min,sec;
struct DateTime
{
int year, mon, day, hour, min, sec;
};
/* ----- ENVIRONMENT ----- */
#define PR_VFCT 1
#define PR_WFCT 2
#define PR_EFCT 3
#define PR_NOTFCT 4
#define PR_USEDIRC 5
#define PR_USE_NOTFCT 6
#define PR_PROGBAR 7
#define PR_USE_PROGBAR 8
#define PR_RWACCESS 9
#define PR_VFCT 1
#define PR_WFCT 2
#define PR_EFCT 3
#define PR_NOTFCT 4
#define PR_USEDIRC 5
#define PR_USE_NOTFCT 6
#define PR_PROGBAR 7
#define PR_USE_PROGBAR 8
#define PR_RWACCESS 9
#define PR_USE_RWACCESS 10
struct Env{
void (*vFct)(char*); /* verbose callback function */
void (*wFct)(char*); /* warning callback function */
void (*eFct)(char*); /* error callback function */
struct Env
{
void (*vFct)(char*); /* verbose callback function */
void (*wFct)(char*); /* warning callback function */
void (*eFct)(char*); /* error callback function */
void (*notifyFct)(SECTNUM, int);
BOOL useNotify;
void (*rwhAccess)(SECTNUM,SECTNUM,BOOL);
void (*rwhAccess)(SECTNUM, SECTNUM, BOOL);
BOOL useRWAccess;
void (*progressBar)(int);
BOOL useProgressBar;
BOOL useDirCache;
void *nativeFct;
void* nativeFct;
};
struct List{ /* generic linked tree */
void *content;
struct List
{ /* generic linked tree */
void* content;
struct List* subdir;
struct List* next;
};
struct GenBlock{
struct GenBlock
{
SECTNUM sect;
SECTNUM parent;
int type;
int secType;
char *name; /* if (type == 2 and (secType==2 or secType==-3)) */
char* name; /* if (type == 2 and (secType==2 or secType==-3)) */
};
struct FileBlocks{
struct FileBlocks
{
SECTNUM header;
int32_t nbExtens;
SECTNUM* extens;
@@ -200,36 +203,35 @@ struct FileBlocks{
SECTNUM* data;
};
struct bEntryBlock {
/*000*/ int32_t type; /* T_HEADER == 2 */
/*004*/ int32_t headerKey; /* current block number */
int32_t r1[3];
/*014*/ uint32_t checkSum;
/*018*/ int32_t hashTable[HT_SIZE];
int32_t r2[2];
/*140*/ int32_t access; /* bit0=del, 1=modif, 2=write, 3=read */
/*144*/ int32_t byteSize;
/*148*/ char commLen;
/*149*/ char comment[MAXCMMTLEN+1];
char r3[91-(MAXCMMTLEN+1)];
/*1a4*/ int32_t days;
/*1a8*/ int32_t mins;
/*1ac*/ int32_t ticks;
/*1b0*/ char nameLen;
/*1b1*/ char name[MAXNAMELEN+1];
int32_t r4;
/*1d4*/ int32_t realEntry;
/*1d8*/ int32_t nextLink;
int32_t r5[5];
/*1f0*/ int32_t nextSameHash;
/*1f4*/ int32_t parent;
/*1f8*/ int32_t extension;
/*1fc*/ int32_t secType;
};
struct bEntryBlock
{
/*000*/ int32_t type; /* T_HEADER == 2 */
/*004*/ int32_t headerKey; /* current block number */
int32_t r1[3];
/*014*/ uint32_t checkSum;
/*018*/ int32_t hashTable[HT_SIZE];
int32_t r2[2];
/*140*/ int32_t access; /* bit0=del, 1=modif, 2=write, 3=read */
/*144*/ int32_t byteSize;
/*148*/ char commLen;
/*149*/ char comment[MAXCMMTLEN + 1];
char r3[91 - (MAXCMMTLEN + 1)];
/*1a4*/ int32_t days;
/*1a8*/ int32_t mins;
/*1ac*/ int32_t ticks;
/*1b0*/ char nameLen;
/*1b1*/ char name[MAXNAMELEN + 1];
int32_t r4;
/*1d4*/ int32_t realEntry;
/*1d8*/ int32_t nextLink;
int32_t r5[5];
/*1f0*/ int32_t nextSameHash;
/*1f4*/ int32_t parent;
/*1f8*/ int32_t extension;
/*1fc*/ int32_t secType;
};
#define ENV_DECLARATION struct Env adfEnv
#endif /* _ADF_STR_H */
/*##########################################################################*/

View File

@@ -26,25 +26,22 @@
*
*/
#include"prefix.h"
#include "prefix.h"
#include "adf_str.h"
void swLong(uint8_t* buf, uint32_t val);
void swShort(uint8_t* buf, uint16_t val);
PREFIX struct List* newCell(struct List* list, void* content);
PREFIX void freeList(struct List* list);
void adfDays2Date(int32_t days, int *yy, int *mm, int *dd);
void adfDays2Date(int32_t days, int* yy, int* mm, int* dd);
BOOL adfIsLeap(int y);
void
adfTime2AmigaTime(struct DateTime dt, int32_t *day, int32_t *min, int32_t *ticks );
struct DateTime
adfGiveCurrentTime( void );
void adfTime2AmigaTime(
struct DateTime dt, int32_t* day, int32_t* min, int32_t* ticks);
struct DateTime adfGiveCurrentTime(void);
void dumpBlock(uint8_t *buf);
void dumpBlock(uint8_t* buf);
/*##########################################################################*/
#endif /* _ADF_UTIL_H */

View File

@@ -29,96 +29,107 @@
*/
#ifdef __cplusplus
extern "C" {
extern "C"
{
#endif /* __cplusplus */
/* Visual C++ DLL specific, define WIN32DLL or not in the makefile */
/* Visual C++ DLL specific, define WIN32DLL or not in the makefile */
#ifdef WIN32DLL
#define PREFIX __declspec(dllimport)
#else
#define PREFIX
#define PREFIX
#endif /* WIN32DLL */
#include "adf_defs.h"
#include "adf_str.h"
/* util */
PREFIX struct List* newCell(struct List* list, void* content);
PREFIX void freeList(struct List* list);
/* util */
PREFIX struct List* newCell(struct List* list, void* content);
PREFIX void freeList(struct List* list);
/* dir */
PREFIX struct Entry* adfFindEntry(struct Volume *vol, char* name);
PREFIX RETCODE adfToRootDir(struct Volume *vol);
PREFIX RETCODE adfCreateDir(struct Volume* vol, SECTNUM parent, char* name);
PREFIX RETCODE adfChangeDir(struct Volume* vol, char *name);
PREFIX RETCODE adfParentDir(struct Volume* vol);
PREFIX RETCODE adfRemoveEntry(struct Volume *vol, SECTNUM pSect, char *name);
PREFIX struct List* adfGetDirEnt(struct Volume* vol, SECTNUM nSect );
PREFIX struct List* adfGetRDirEnt(struct Volume* vol, SECTNUM nSect, BOOL recurs );
PREFIX void printEntry(struct Entry* entry);
PREFIX void adfFreeDirList(struct List* list);
PREFIX void adfFreeEntry(struct Entry *);
PREFIX RETCODE adfRenameEntry(struct Volume *vol, SECTNUM, char *old,SECTNUM,char *pNew); /* BV */
PREFIX RETCODE adfSetEntryAccess(struct Volume*, SECTNUM, char*, int32_t);
PREFIX RETCODE adfSetEntryComment(struct Volume*, SECTNUM, char*, char*);
/* dir */
PREFIX struct Entry* adfFindEntry(struct Volume* vol, char* name);
PREFIX RETCODE adfToRootDir(struct Volume* vol);
PREFIX RETCODE adfCreateDir(struct Volume* vol, SECTNUM parent, char* name);
PREFIX RETCODE adfChangeDir(struct Volume* vol, char* name);
PREFIX RETCODE adfParentDir(struct Volume* vol);
PREFIX RETCODE adfRemoveEntry(
struct Volume* vol, SECTNUM pSect, char* name);
PREFIX struct List* adfGetDirEnt(struct Volume* vol, SECTNUM nSect);
PREFIX struct List* adfGetRDirEnt(
struct Volume* vol, SECTNUM nSect, BOOL recurs);
PREFIX void printEntry(struct Entry* entry);
PREFIX void adfFreeDirList(struct List* list);
PREFIX void adfFreeEntry(struct Entry*);
PREFIX RETCODE adfRenameEntry(
struct Volume* vol, SECTNUM, char* old, SECTNUM, char* pNew); /* BV */
PREFIX RETCODE adfSetEntryAccess(struct Volume*, SECTNUM, char*, int32_t);
PREFIX RETCODE adfSetEntryComment(struct Volume*, SECTNUM, char*, char*);
/* file */
PREFIX int32_t adfFileRealSize(uint32_t size, int blockSize, int32_t *dataN, int32_t *extN);
PREFIX struct File* adfOpenFile(struct Volume *vol, char* name, char *mode);
PREFIX void adfCloseFile(struct File *file);
PREFIX int32_t adfReadFile(struct File* file, int32_t n, uint8_t *buffer);
PREFIX BOOL adfEndOfFile(struct File* file);
PREFIX int32_t adfWriteFile(struct File *file, int32_t n, uint8_t *buffer);
PREFIX void adfFlushFile(struct File *file);
PREFIX void adfFileSeek(struct File *file, uint32_t pos);
/* file */
PREFIX int32_t adfFileRealSize(
uint32_t size, int blockSize, int32_t* dataN, int32_t* extN);
PREFIX struct File* adfOpenFile(struct Volume* vol, char* name, char* mode);
PREFIX void adfCloseFile(struct File* file);
PREFIX int32_t adfReadFile(struct File* file, int32_t n, uint8_t* buffer);
PREFIX BOOL adfEndOfFile(struct File* file);
PREFIX int32_t adfWriteFile(struct File* file, int32_t n, uint8_t* buffer);
PREFIX void adfFlushFile(struct File* file);
PREFIX void adfFileSeek(struct File* file, uint32_t pos);
/* volume */
PREFIX RETCODE adfInstallBootBlock(struct Volume *vol,uint8_t*);
PREFIX struct Volume* adfMount( struct Device *dev, int nPart, BOOL readOnly );
PREFIX void adfUnMount(struct Volume *vol);
PREFIX void adfVolumeInfo(struct Volume *vol);
/* volume */
PREFIX RETCODE adfInstallBootBlock(struct Volume* vol, uint8_t*);
PREFIX struct Volume* adfMount(
struct Device* dev, int nPart, BOOL readOnly);
PREFIX void adfUnMount(struct Volume* vol);
PREFIX void adfVolumeInfo(struct Volume* vol);
/* device */
PREFIX void adfDeviceInfo(struct Device *dev);
PREFIX struct Device* adfMountDev( char* filename,BOOL ro);
PREFIX void adfUnMountDev( struct Device* dev);
PREFIX RETCODE adfCreateHd(struct Device* dev, int n, struct Partition** partList );
PREFIX RETCODE adfCreateFlop(struct Device* dev, char* volName, int volType );
PREFIX RETCODE adfCreateHdFile(struct Device* dev, char* volName, int volType);
/* device */
PREFIX void adfDeviceInfo(struct Device* dev);
PREFIX struct Device* adfMountDev(char* filename, BOOL ro);
PREFIX void adfUnMountDev(struct Device* dev);
PREFIX RETCODE adfCreateHd(
struct Device* dev, int n, struct Partition** partList);
PREFIX RETCODE adfCreateFlop(
struct Device* dev, char* volName, int volType);
PREFIX RETCODE adfCreateHdFile(
struct Device* dev, char* volName, int volType);
/* dump device */
PREFIX struct Device* adfCreateDumpDevice(char* filename, int32_t cyl, int32_t heads, int32_t sec);
/* dump device */
PREFIX struct Device* adfCreateDumpDevice(
char* filename, int32_t cyl, int32_t heads, int32_t sec);
/* env */
PREFIX void adfEnvInitDefault();
PREFIX void adfEnvCleanUp();
PREFIX void adfChgEnvProp(int prop, void *pNew); /* BV */
PREFIX char* adfGetVersionNumber();
PREFIX char* adfGetVersionDate();
/* obsolete */
PREFIX void adfSetEnvFct( void(*e)(char*), void(*w)(char*), void(*v)(char*) );
/* env */
PREFIX void adfEnvInitDefault();
PREFIX void adfEnvCleanUp();
PREFIX void adfChgEnvProp(int prop, void* pNew); /* BV */
PREFIX char* adfGetVersionNumber();
PREFIX char* adfGetVersionDate();
/* obsolete */
PREFIX void adfSetEnvFct(
void (*e)(char*), void (*w)(char*), void (*v)(char*));
/* link */
PREFIX RETCODE adfBlockPtr2EntryName(struct Volume *, SECTNUM, SECTNUM,char **, int32_t *);
/* link */
PREFIX RETCODE adfBlockPtr2EntryName(
struct Volume*, SECTNUM, SECTNUM, char**, int32_t*);
/* salv */
PREFIX struct List* adfGetDelEnt(struct Volume *vol);
PREFIX RETCODE adfUndelEntry(struct Volume* vol, SECTNUM parent, SECTNUM nSect);
PREFIX void adfFreeDelList(struct List* list);
PREFIX RETCODE adfCheckEntry(struct Volume* vol, SECTNUM nSect, int level);
/* salv */
PREFIX struct List* adfGetDelEnt(struct Volume* vol);
PREFIX RETCODE adfUndelEntry(
struct Volume* vol, SECTNUM parent, SECTNUM nSect);
PREFIX void adfFreeDelList(struct List* list);
PREFIX RETCODE adfCheckEntry(struct Volume* vol, SECTNUM nSect, int level);
/* middle level API */
/* middle level API */
PREFIX BOOL isSectNumValid(struct Volume *vol, SECTNUM nSect);
PREFIX BOOL isSectNumValid(struct Volume* vol, SECTNUM nSect);
/* low level API */
PREFIX RETCODE adfReadBlock(struct Volume* , int32_t nSect, uint8_t* buf);
PREFIX RETCODE adfWriteBlock(struct Volume* , int32_t nSect, uint8_t* buf);
PREFIX int32_t adfCountFreeBlocks(struct Volume* vol);
/* low level API */
PREFIX RETCODE adfReadBlock(struct Volume*, int32_t nSect, uint8_t* buf);
PREFIX RETCODE adfWriteBlock(struct Volume*, int32_t nSect, uint8_t* buf);
PREFIX int32_t adfCountFreeBlocks(struct Volume* vol);
#ifdef __cplusplus
}

View File

@@ -1,13 +1,11 @@
#include "config.h"
#ifndef LITT_ENDIAN
#if defined(__hppa__) || \
defined(__m68k__) || defined(mc68000) || defined(_M_M68K) || \
(defined(__MIPS__) && defined(__MISPEB__)) || \
defined(__ppc__) || defined(__POWERPC__) || defined(_M_PPC) || \
defined(__sparc__)
#else
#define LITT_ENDIAN 1
#endif
#if defined(__hppa__) || defined(__m68k__) || defined(mc68000) || \
defined(_M_M68K) || (defined(__MIPS__) && defined(__MISPEB__)) || \
defined(__ppc__) || defined(__POWERPC__) || defined(_M_PPC) || \
defined(__sparc__)
#else
#define LITT_ENDIAN 1
#endif
#endif

View File

@@ -25,7 +25,6 @@
*
*/
#ifndef _HD_BLK_H
#define _HD_BLK_H 1
@@ -33,135 +32,134 @@
/* ------- RDSK ---------*/
struct bRDSKblock {
/*000*/ char id[4]; /* RDSK */
/*004*/ int32_t size; /* 64 int32_ts */
/*008*/ ULONG checksum;
/*00c*/ int32_t hostID; /* 7 */
/*010*/ int32_t blockSize; /* 512 bytes */
/*014*/ int32_t flags; /* 0x17 */
/*018*/ int32_t badBlockList;
/*01c*/ int32_t partitionList;
/*020*/ int32_t fileSysHdrList;
/*024*/ int32_t driveInit;
/*028*/ int32_t r1[6]; /* -1 */
/*040*/ int32_t cylinders;
/*044*/ int32_t sectors;
/*048*/ int32_t heads;
/*04c*/ int32_t interleave;
/*050*/ int32_t parkingZone;
/*054*/ int32_t r2[3]; /* 0 */
/*060*/ int32_t writePreComp;
/*064*/ int32_t reducedWrite;
/*068*/ int32_t stepRate;
/*06c*/ int32_t r3[5]; /* 0 */
/*080*/ int32_t rdbBlockLo;
/*084*/ int32_t rdbBlockHi;
/*088*/ int32_t loCylinder;
/*08c*/ int32_t hiCylinder;
/*090*/ int32_t cylBlocks;
/*094*/ int32_t autoParkSeconds;
/*098*/ int32_t highRDSKBlock;
/*09c*/ int32_t r4; /* 0 */
/*0a0*/ char diskVendor[8];
/*0a8*/ char diskProduct[16];
/*0b8*/ char diskRevision[4];
/*0bc*/ char controllerVendor[8];
/*0c4*/ char controllerProduct[16];
/*0d4*/ char controllerRevision[4];
/*0d8*/ int32_t r5[10]; /* 0 */
/*100*/
struct bRDSKblock
{
/*000*/ char id[4]; /* RDSK */
/*004*/ int32_t size; /* 64 int32_ts */
/*008*/ ULONG checksum;
/*00c*/ int32_t hostID; /* 7 */
/*010*/ int32_t blockSize; /* 512 bytes */
/*014*/ int32_t flags; /* 0x17 */
/*018*/ int32_t badBlockList;
/*01c*/ int32_t partitionList;
/*020*/ int32_t fileSysHdrList;
/*024*/ int32_t driveInit;
/*028*/ int32_t r1[6]; /* -1 */
/*040*/ int32_t cylinders;
/*044*/ int32_t sectors;
/*048*/ int32_t heads;
/*04c*/ int32_t interleave;
/*050*/ int32_t parkingZone;
/*054*/ int32_t r2[3]; /* 0 */
/*060*/ int32_t writePreComp;
/*064*/ int32_t reducedWrite;
/*068*/ int32_t stepRate;
/*06c*/ int32_t r3[5]; /* 0 */
/*080*/ int32_t rdbBlockLo;
/*084*/ int32_t rdbBlockHi;
/*088*/ int32_t loCylinder;
/*08c*/ int32_t hiCylinder;
/*090*/ int32_t cylBlocks;
/*094*/ int32_t autoParkSeconds;
/*098*/ int32_t highRDSKBlock;
/*09c*/ int32_t r4; /* 0 */
/*0a0*/ char diskVendor[8];
/*0a8*/ char diskProduct[16];
/*0b8*/ char diskRevision[4];
/*0bc*/ char controllerVendor[8];
/*0c4*/ char controllerProduct[16];
/*0d4*/ char controllerRevision[4];
/*0d8*/ int32_t r5[10]; /* 0 */
/*100*/
};
struct bBADBentry {
/*000*/ int32_t badBlock;
/*004*/ int32_t goodBlock;
struct bBADBentry
{
/*000*/ int32_t badBlock;
/*004*/ int32_t goodBlock;
};
struct bBADBblock {
/*000*/ char id[4]; /* BADB */
/*004*/ int32_t size; /* 128 int32_ts */
/*008*/ ULONG checksum;
/*00c*/ int32_t hostID; /* 7 */
/*010*/ int32_t next;
/*014*/ int32_t r1;
/*018*/ struct bBADBentry blockPairs[61];
struct bBADBblock
{
/*000*/ char id[4]; /* BADB */
/*004*/ int32_t size; /* 128 int32_ts */
/*008*/ ULONG checksum;
/*00c*/ int32_t hostID; /* 7 */
/*010*/ int32_t next;
/*014*/ int32_t r1;
/*018*/ struct bBADBentry blockPairs[61];
};
struct bPARTblock
{
/*000*/ char id[4]; /* PART */
/*004*/ int32_t size; /* 64 int32_ts */
/*008*/ ULONG checksum;
/*00c*/ int32_t hostID; /* 7 */
/*010*/ int32_t next;
/*014*/ int32_t flags;
/*018*/ int32_t r1[2];
/*020*/ int32_t devFlags;
/*024*/ char nameLen;
/*025*/ char name[31];
/*044*/ int32_t r2[15];
struct bPARTblock {
/*000*/ char id[4]; /* PART */
/*004*/ int32_t size; /* 64 int32_ts */
/*008*/ ULONG checksum;
/*00c*/ int32_t hostID; /* 7 */
/*010*/ int32_t next;
/*014*/ int32_t flags;
/*018*/ int32_t r1[2];
/*020*/ int32_t devFlags;
/*024*/ char nameLen;
/*025*/ char name[31];
/*044*/ int32_t r2[15];
/*080*/ int32_t vectorSize; /* often 16 int32_ts */
/*084*/ int32_t blockSize; /* 128 int32_ts */
/*088*/ int32_t secOrg;
/*08c*/ int32_t surfaces;
/*090*/ int32_t sectorsPerBlock; /* == 1 */
/*094*/ int32_t blocksPerTrack;
/*098*/ int32_t dosReserved;
/*09c*/ int32_t dosPreAlloc;
/*0a0*/ int32_t interleave;
/*0a4*/ int32_t lowCyl;
/*0a8*/ int32_t highCyl;
/*0ac*/ int32_t numBuffer;
/*0b0*/ int32_t bufMemType;
/*0b4*/ int32_t maxTransfer;
/*0b8*/ int32_t mask;
/*0bc*/ int32_t bootPri;
/*0c0*/ char dosType[4];
/*0c4*/ int32_t r3[15];
/*080*/ int32_t vectorSize; /* often 16 int32_ts */
/*084*/ int32_t blockSize; /* 128 int32_ts */
/*088*/ int32_t secOrg;
/*08c*/ int32_t surfaces;
/*090*/ int32_t sectorsPerBlock; /* == 1 */
/*094*/ int32_t blocksPerTrack;
/*098*/ int32_t dosReserved;
/*09c*/ int32_t dosPreAlloc;
/*0a0*/ int32_t interleave;
/*0a4*/ int32_t lowCyl;
/*0a8*/ int32_t highCyl;
/*0ac*/ int32_t numBuffer;
/*0b0*/ int32_t bufMemType;
/*0b4*/ int32_t maxTransfer;
/*0b8*/ int32_t mask;
/*0bc*/ int32_t bootPri;
/*0c0*/ char dosType[4];
/*0c4*/ int32_t r3[15];
};
struct bLSEGblock {
/*000*/ char id[4]; /* LSEG */
/*004*/ int32_t size; /* 128 int32_ts */
/*008*/ ULONG checksum;
/*00c*/ int32_t hostID; /* 7 */
/*010*/ int32_t next;
/*014*/ char loadData[123*4];
struct bLSEGblock
{
/*000*/ char id[4]; /* LSEG */
/*004*/ int32_t size; /* 128 int32_ts */
/*008*/ ULONG checksum;
/*00c*/ int32_t hostID; /* 7 */
/*010*/ int32_t next;
/*014*/ char loadData[123 * 4];
};
struct bFSHDblock
{
/*000*/ char id[4]; /* FSHD */
/*004*/ int32_t size; /* 64 */
/*008*/ ULONG checksum;
/*00c*/ int32_t hostID; /* 7 */
/*010*/ int32_t next;
/*014*/ int32_t flags;
/*018*/ int32_t r1[2];
/*020*/ char dosType[4];
/*024*/ short majVersion;
/*026*/ short minVersion;
/*028*/ int32_t patchFlags;
struct bFSHDblock {
/*000*/ char id[4]; /* FSHD */
/*004*/ int32_t size; /* 64 */
/*008*/ ULONG checksum;
/*00c*/ int32_t hostID; /* 7 */
/*010*/ int32_t next;
/*014*/ int32_t flags;
/*018*/ int32_t r1[2];
/*020*/ char dosType[4];
/*024*/ short majVersion;
/*026*/ short minVersion;
/*028*/ int32_t patchFlags;
/*02c*/ int32_t type;
/*030*/ int32_t task;
/*034*/ int32_t lock;
/*038*/ int32_t handler;
/*03c*/ int32_t stackSize;
/*040*/ int32_t priority;
/*044*/ int32_t startup;
/*048*/ int32_t segListBlock;
/*04c*/ int32_t globalVec;
/*050*/ int32_t r2[23];
/*0ac*/ int32_t r3[21];
/*02c*/ int32_t type;
/*030*/ int32_t task;
/*034*/ int32_t lock;
/*038*/ int32_t handler;
/*03c*/ int32_t stackSize;
/*040*/ int32_t priority;
/*044*/ int32_t startup;
/*048*/ int32_t segListBlock;
/*04c*/ int32_t globalVec;
/*050*/ int32_t r2[23];
/*0ac*/ int32_t r3[21];
};
#endif /* _HD_BLK_H */
/*##########################################################################*/

View File

@@ -25,12 +25,12 @@
* along with Foobar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
*/
#ifdef WIN32DLL
#define PREFIX __declspec(dllexport)
#else
#define PREFIX
#define PREFIX
#endif /* WIN32DLL */
#endif /* _PREFIX_H */

View File

@@ -23,7 +23,7 @@
#define AGG2D_INCLUDED
// With this define uncommented you can use floating-point pixel format
//#define AGG2D_USE_FLOAT_FORMAT
// #define AGG2D_USE_FLOAT_FORMAT
#include "agg_basics.h"
#include "agg_trans_affine.h"
@@ -56,37 +56,50 @@ class Agg2D
#ifdef AGG2D_USE_FLOAT_FORMAT
typedef agg::rgba32 ColorType;
#else
typedef agg::rgba8 ColorType;
typedef agg::rgba8 ColorType;
#endif
typedef agg::order_bgra ComponentOrder; // Platform dependent!
typedef agg::blender_rgba<ColorType, ComponentOrder> Blender;
typedef agg::comp_op_adaptor_rgba<ColorType, ComponentOrder> BlenderComp;
typedef agg::blender_rgba_pre<ColorType, ComponentOrder> BlenderPre;
typedef agg::comp_op_adaptor_rgba_pre<ColorType, ComponentOrder> BlenderCompPre;
typedef agg::blender_rgba<ColorType, ComponentOrder> Blender;
typedef agg::comp_op_adaptor_rgba<ColorType, ComponentOrder> BlenderComp;
typedef agg::blender_rgba_pre<ColorType, ComponentOrder> BlenderPre;
typedef agg::comp_op_adaptor_rgba_pre<ColorType, ComponentOrder>
BlenderCompPre;
typedef agg::pixfmt_alpha_blend_rgba<Blender, agg::rendering_buffer> PixFormat;
typedef agg::pixfmt_custom_blend_rgba<BlenderComp, agg::rendering_buffer> PixFormatComp;
typedef agg::pixfmt_alpha_blend_rgba<BlenderPre, agg::rendering_buffer> PixFormatPre;
typedef agg::pixfmt_custom_blend_rgba<BlenderCompPre, agg::rendering_buffer> PixFormatCompPre;
typedef agg::pixfmt_alpha_blend_rgba<Blender, agg::rendering_buffer>
PixFormat;
typedef agg::pixfmt_custom_blend_rgba<BlenderComp, agg::rendering_buffer>
PixFormatComp;
typedef agg::pixfmt_alpha_blend_rgba<BlenderPre, agg::rendering_buffer>
PixFormatPre;
typedef agg::pixfmt_custom_blend_rgba<BlenderCompPre, agg::rendering_buffer>
PixFormatCompPre;
typedef agg::renderer_base<PixFormat> RendererBase;
typedef agg::renderer_base<PixFormatComp> RendererBaseComp;
typedef agg::renderer_base<PixFormatPre> RendererBasePre;
typedef agg::renderer_base<PixFormat> RendererBase;
typedef agg::renderer_base<PixFormatComp> RendererBaseComp;
typedef agg::renderer_base<PixFormatPre> RendererBasePre;
typedef agg::renderer_base<PixFormatCompPre> RendererBaseCompPre;
typedef agg::renderer_scanline_aa_solid<RendererBase> RendererSolid;
typedef agg::renderer_scanline_aa_solid<RendererBase> RendererSolid;
typedef agg::renderer_scanline_aa_solid<RendererBaseComp> RendererSolidComp;
typedef agg::span_allocator<ColorType> SpanAllocator;
typedef agg::pod_auto_array<ColorType, 256> GradientArray;
typedef agg::span_gradient<ColorType, agg::span_interpolator_linear<>, agg::gradient_x, GradientArray> LinearGradientSpan;
typedef agg::span_gradient<ColorType, agg::span_interpolator_linear<>, agg::gradient_circle, GradientArray> RadialGradientSpan;
typedef agg::span_gradient<ColorType,
agg::span_interpolator_linear<>,
agg::gradient_x,
GradientArray>
LinearGradientSpan;
typedef agg::span_gradient<ColorType,
agg::span_interpolator_linear<>,
agg::gradient_circle,
GradientArray>
RadialGradientSpan;
typedef agg::conv_curve<agg::path_storage> ConvCurve;
typedef agg::conv_stroke<ConvCurve> ConvStroke;
typedef agg::conv_transform<ConvCurve> PathTransform;
typedef agg::conv_transform<ConvStroke> StrokeTransform;
typedef agg::conv_curve<agg::path_storage> ConvCurve;
typedef agg::conv_stroke<ConvCurve> ConvStroke;
typedef agg::conv_transform<ConvCurve> PathTransform;
typedef agg::conv_transform<ConvStroke> StrokeTransform;
enum Gradient
{
@@ -98,12 +111,12 @@ class Agg2D
public:
friend class Agg2DRenderer;
// Use srgba8 as the "user" color type, even though the underlying color type
// might be something else, such as rgba32. This allows code based on
// Use srgba8 as the "user" color type, even though the underlying color
// type might be something else, such as rgba32. This allows code based on
// 8-bit sRGB values to carry on working as before.
typedef agg::srgba8 Color;
typedef agg::rect_i Rect;
typedef agg::rect_d RectD;
typedef agg::srgba8 Color;
typedef agg::rect_i Rect;
typedef agg::rect_d RectD;
typedef agg::trans_affine Affine;
enum LineJoin
@@ -115,9 +128,9 @@ public:
enum LineCap
{
CapButt = agg::butt_cap,
CapButt = agg::butt_cap,
CapSquare = agg::square_cap,
CapRound = agg::round_cap
CapRound = agg::round_cap
};
enum TextAlignment
@@ -127,7 +140,6 @@ public:
AlignCenter,
};
enum DrawPathFlag
{
FillOnly,
@@ -155,20 +167,28 @@ public:
double affineMatrix[6];
};
struct Image
{
agg::rendering_buffer renBuf;
Image() {}
Image(unsigned char* buf, unsigned width, unsigned height, int stride) :
renBuf(buf, width, height, stride) {}
void attach(unsigned char* buf, unsigned width, unsigned height, int stride)
Image(unsigned char* buf, unsigned width, unsigned height, int stride):
renBuf(buf, width, height, stride)
{
}
void attach(
unsigned char* buf, unsigned width, unsigned height, int stride)
{
renBuf.attach(buf, width, height, stride);
}
int width() const { return renBuf.width(); }
int height() const { return renBuf.height(); }
int width() const
{
return renBuf.width();
}
int height() const
{
return renBuf.height();
}
void premultiply();
void demultiply();
};
@@ -202,36 +222,37 @@ public:
enum BlendMode
{
BlendAlpha = agg::end_of_comp_op_e,
BlendClear = agg::comp_op_clear,
BlendSrc = agg::comp_op_src,
BlendDst = agg::comp_op_dst,
BlendSrcOver = agg::comp_op_src_over,
BlendDstOver = agg::comp_op_dst_over,
BlendSrcIn = agg::comp_op_src_in,
BlendDstIn = agg::comp_op_dst_in,
BlendSrcOut = agg::comp_op_src_out,
BlendDstOut = agg::comp_op_dst_out,
BlendSrcAtop = agg::comp_op_src_atop,
BlendDstAtop = agg::comp_op_dst_atop,
BlendXor = agg::comp_op_xor,
BlendAdd = agg::comp_op_plus,
BlendMultiply = agg::comp_op_multiply,
BlendScreen = agg::comp_op_screen,
BlendOverlay = agg::comp_op_overlay,
BlendDarken = agg::comp_op_darken,
BlendLighten = agg::comp_op_lighten,
BlendAlpha = agg::end_of_comp_op_e,
BlendClear = agg::comp_op_clear,
BlendSrc = agg::comp_op_src,
BlendDst = agg::comp_op_dst,
BlendSrcOver = agg::comp_op_src_over,
BlendDstOver = agg::comp_op_dst_over,
BlendSrcIn = agg::comp_op_src_in,
BlendDstIn = agg::comp_op_dst_in,
BlendSrcOut = agg::comp_op_src_out,
BlendDstOut = agg::comp_op_dst_out,
BlendSrcAtop = agg::comp_op_src_atop,
BlendDstAtop = agg::comp_op_dst_atop,
BlendXor = agg::comp_op_xor,
BlendAdd = agg::comp_op_plus,
BlendMultiply = agg::comp_op_multiply,
BlendScreen = agg::comp_op_screen,
BlendOverlay = agg::comp_op_overlay,
BlendDarken = agg::comp_op_darken,
BlendLighten = agg::comp_op_lighten,
BlendColorDodge = agg::comp_op_color_dodge,
BlendColorBurn = agg::comp_op_color_burn,
BlendHardLight = agg::comp_op_hard_light,
BlendSoftLight = agg::comp_op_soft_light,
BlendColorBurn = agg::comp_op_color_burn,
BlendHardLight = agg::comp_op_hard_light,
BlendSoftLight = agg::comp_op_soft_light,
BlendDifference = agg::comp_op_difference,
BlendExclusion = agg::comp_op_exclusion,
BlendExclusion = agg::comp_op_exclusion,
};
enum Direction
{
CW, CCW
CW,
CCW
};
~Agg2D();
@@ -239,26 +260,27 @@ public:
// Setup
//-----------------------
void attach(unsigned char* buf, unsigned width, unsigned height, int stride);
void attach(Image& img);
void attach(
unsigned char* buf, unsigned width, unsigned height, int stride);
void attach(Image& img);
void clipBox(double x1, double y1, double x2, double y2);
void clipBox(double x1, double y1, double x2, double y2);
RectD clipBox() const;
void clearAll(Color c);
void clearAll(unsigned r, unsigned g, unsigned b, unsigned a = 255);
void clearAll(Color c);
void clearAll(unsigned r, unsigned g, unsigned b, unsigned a = 255);
void clearClipBox(Color c);
void clearClipBox(unsigned r, unsigned g, unsigned b, unsigned a = 255);
void clearClipBox(Color c);
void clearClipBox(unsigned r, unsigned g, unsigned b, unsigned a = 255);
// Conversions
//-----------------------
void worldToScreen(double& x, double& y) const;
void screenToWorld(double& x, double& y) const;
void worldToScreen(double& x, double& y) const;
void screenToWorld(double& x, double& y) const;
double worldToScreen(double scalar) const;
double screenToWorld(double scalar) const;
void alignPoint(double& x, double& y) const;
bool inBox(double worldX, double worldY) const;
void alignPoint(double& x, double& y) const;
bool inBox(double worldX, double worldY) const;
// General Attributes
//-----------------------
@@ -289,14 +311,30 @@ public:
Color fillColor() const;
Color lineColor() const;
void fillLinearGradient(double x1, double y1, double x2, double y2, Color c1, Color c2, double profile=1.0);
void lineLinearGradient(double x1, double y1, double x2, double y2, Color c1, Color c2, double profile=1.0);
void fillLinearGradient(double x1,
double y1,
double x2,
double y2,
Color c1,
Color c2,
double profile = 1.0);
void lineLinearGradient(double x1,
double y1,
double x2,
double y2,
Color c1,
Color c2,
double profile = 1.0);
void fillRadialGradient(double x, double y, double r, Color c1, Color c2, double profile=1.0);
void lineRadialGradient(double x, double y, double r, Color c1, Color c2, double profile=1.0);
void fillRadialGradient(
double x, double y, double r, Color c1, Color c2, double profile = 1.0);
void lineRadialGradient(
double x, double y, double r, Color c1, Color c2, double profile = 1.0);
void fillRadialGradient(double x, double y, double r, Color c1, Color c2, Color c3);
void lineRadialGradient(double x, double y, double r, Color c1, Color c2, Color c3);
void fillRadialGradient(
double x, double y, double r, Color c1, Color c2, Color c3);
void lineRadialGradient(
double x, double y, double r, Color c1, Color c2, Color c3);
void fillRadialGradient(double x, double y, double r);
void lineRadialGradient(double x, double y, double r);
@@ -313,9 +351,12 @@ public:
void fillEvenOdd(bool evenOddFlag);
bool fillEvenOdd() const;
void textAlignment(TextAlignment alignment);
void textSize(double sizeX, double sizeY);
inline void textSize(double size) { textSize(size, size); }
void textAlignment(TextAlignment alignment);
void textSize(double sizeX, double sizeY);
inline void textSize(double size)
{
textSize(size, size);
}
// Transformations
//-----------------------
@@ -328,26 +369,54 @@ public:
void scale(double sx, double sy);
void skew(double sx, double sy);
void translate(double x, double y);
void parallelogram(double x1, double y1, double x2, double y2, const double* para);
void viewport(double worldX1, double worldY1, double worldX2, double worldY2,
double screenX1, double screenY1, double screenX2, double screenY2,
ViewportOption opt=XMidYMid);
void parallelogram(
double x1, double y1, double x2, double y2, const double* para);
void viewport(double worldX1,
double worldY1,
double worldX2,
double worldY2,
double screenX1,
double screenY1,
double screenX2,
double screenY2,
ViewportOption opt = XMidYMid);
// Basic Shapes
//-----------------------
void line(double x1, double y1, double x2, double y2);
void triangle(double x1, double y1, double x2, double y2, double x3, double y3);
void triangle(
double x1, double y1, double x2, double y2, double x3, double y3);
void rectangle(double x1, double y1, double x2, double y2);
void roundedRect(double x1, double y1, double x2, double y2, double r);
void roundedRect(double x1, double y1, double x2, double y2, double rx, double ry);
void roundedRect(double x1, double y1, double x2, double y2,
double rxBottom, double ryBottom,
double rxTop, double ryTop);
void roundedRect(
double x1, double y1, double x2, double y2, double rx, double ry);
void roundedRect(double x1,
double y1,
double x2,
double y2,
double rxBottom,
double ryBottom,
double rxTop,
double ryTop);
void ellipse(double cx, double cy, double rx, double ry);
void arc(double cx, double cy, double rx, double ry, double start, double sweep);
void star(double cx, double cy, double r1, double r2, double startAngle, int numRays);
void curve(double x1, double y1, double x2, double y2, double x3, double y3);
void curve(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4);
void arc(
double cx, double cy, double rx, double ry, double start, double sweep);
void star(double cx,
double cy,
double r1,
double r2,
double startAngle,
int numRays);
void curve(
double x1, double y1, double x2, double y2, double x3, double y3);
void curve(double x1,
double y1,
double x2,
double y2,
double x3,
double y3,
double x4,
double y4);
void polygon(double* xy, int numPoints);
void polyline(double* xy, int numPoints);
@@ -367,47 +436,53 @@ public:
void verLineTo(double y);
void verLineRel(double dy);
void arcTo(double rx, double ry,
double angle,
bool largeArcFlag,
bool sweepFlag,
double x, double y);
void arcTo(double rx,
double ry,
double angle,
bool largeArcFlag,
bool sweepFlag,
double x,
double y);
void arcRel(double rx, double ry,
double angle,
bool largeArcFlag,
bool sweepFlag,
double dx, double dy);
void arcRel(double rx,
double ry,
double angle,
bool largeArcFlag,
bool sweepFlag,
double dx,
double dy);
void quadricCurveTo(double xCtrl, double yCtrl,
double xTo, double yTo);
void quadricCurveRel(double dxCtrl, double dyCtrl,
double dxTo, double dyTo);
void quadricCurveTo(double xCtrl, double yCtrl, double xTo, double yTo);
void quadricCurveRel(
double dxCtrl, double dyCtrl, double dxTo, double dyTo);
void quadricCurveTo(double xTo, double yTo);
void quadricCurveRel(double dxTo, double dyTo);
void cubicCurveTo(double xCtrl1, double yCtrl1,
double xCtrl2, double yCtrl2,
double xTo, double yTo);
void cubicCurveTo(double xCtrl1,
double yCtrl1,
double xCtrl2,
double yCtrl2,
double xTo,
double yTo);
void cubicCurveRel(double dxCtrl1, double dyCtrl1,
double dxCtrl2, double dyCtrl2,
double dxTo, double dyTo);
void cubicCurveRel(double dxCtrl1,
double dyCtrl1,
double dxCtrl2,
double dyCtrl2,
double dxTo,
double dyTo);
void cubicCurveTo(double xCtrl2, double yCtrl2,
double xTo, double yTo);
void cubicCurveTo(double xCtrl2, double yCtrl2, double xTo, double yTo);
void cubicCurveRel(double xCtrl2, double yCtrl2,
double xTo, double yTo);
void cubicCurveRel(double xCtrl2, double yCtrl2, double xTo, double yTo);
void addEllipse(double cx, double cy, double rx, double ry, Direction dir);
void text(double x, double y, const std::string& text);
void text(double x, double y, const std::string& text);
void closePolygon();
void drawPath(DrawPathFlag flag = FillAndStroke);
void drawPathNoTransform(DrawPathFlag flag = FillAndStroke);
// Image Transformations
//-----------------------
void imageFilter(ImageFilter f);
@@ -417,52 +492,90 @@ public:
ImageResample imageResample() const;
void transformImage(const Image& img,
int imgX1, int imgY1, int imgX2, int imgY2,
double dstX1, double dstY1, double dstX2, double dstY2);
int imgX1,
int imgY1,
int imgX2,
int imgY2,
double dstX1,
double dstY1,
double dstX2,
double dstY2);
void transformImage(const Image& img,
double dstX1, double dstY1, double dstX2, double dstY2);
double dstX1,
double dstY1,
double dstX2,
double dstY2);
void transformImage(const Image& img,
int imgX1, int imgY1, int imgX2, int imgY2,
const double* parallelogram);
int imgX1,
int imgY1,
int imgX2,
int imgY2,
const double* parallelogram);
void transformImage(const Image& img, const double* parallelogram);
void transformImagePath(const Image& img,
int imgX1,
int imgY1,
int imgX2,
int imgY2,
double dstX1,
double dstY1,
double dstX2,
double dstY2);
void transformImagePath(const Image& img,
int imgX1, int imgY1, int imgX2, int imgY2,
double dstX1, double dstY1, double dstX2, double dstY2);
double dstX1,
double dstY1,
double dstX2,
double dstY2);
void transformImagePath(const Image& img,
double dstX1, double dstY1, double dstX2, double dstY2);
void transformImagePath(const Image& img,
int imgX1, int imgY1, int imgX2, int imgY2,
const double* parallelogram);
int imgX1,
int imgY1,
int imgX2,
int imgY2,
const double* parallelogram);
void transformImagePath(const Image& img, const double* parallelogram);
// Image Blending (no transformations available)
void blendImage(Image& img,
int imgX1, int imgY1, int imgX2, int imgY2,
double dstX, double dstY, unsigned alpha=255);
void blendImage(Image& img, double dstX, double dstY, unsigned alpha=255);
int imgX1,
int imgY1,
int imgX2,
int imgY2,
double dstX,
double dstY,
unsigned alpha = 255);
void blendImage(Image& img, double dstX, double dstY, unsigned alpha = 255);
// Copy image directly, together with alpha-channel
void copyImage(Image& img,
int imgX1, int imgY1, int imgX2, int imgY2,
double dstX, double dstY);
int imgX1,
int imgY1,
int imgX2,
int imgY2,
double dstX,
double dstY);
void copyImage(Image& img, double dstX, double dstY);
// Auxiliary
//-----------------------
static double pi() { return agg::pi; }
static double deg2Rad(double v) { return v * agg::pi / 180.0; }
static double rad2Deg(double v) { return v * 180.0 / agg::pi; }
static double pi()
{
return agg::pi;
}
static double deg2Rad(double v)
{
return v * agg::pi / 180.0;
}
static double rad2Deg(double v)
{
return v * 180.0 / agg::pi;
}
private:
void render(bool fillColor);
@@ -472,97 +585,94 @@ private:
void addLine(double x1, double y1, double x2, double y2);
void updateRasterizerGamma();
void renderImage(const Image& img, int x1, int y1, int x2, int y2, const double* parl);
void renderImage(
const Image& img, int x1, int y1, int x2, int y2, const double* parl);
agg::rendering_buffer m_rbuf;
PixFormat m_pixFormat;
PixFormatComp m_pixFormatComp;
PixFormatPre m_pixFormatPre;
PixFormatCompPre m_pixFormatCompPre;
RendererBase m_renBase;
RendererBaseComp m_renBaseComp;
RendererBasePre m_renBasePre;
RendererBaseCompPre m_renBaseCompPre;
RendererSolid m_renSolid;
RendererSolidComp m_renSolidComp;
agg::rendering_buffer m_rbuf;
PixFormat m_pixFormat;
PixFormatComp m_pixFormatComp;
PixFormatPre m_pixFormatPre;
PixFormatCompPre m_pixFormatCompPre;
RendererBase m_renBase;
RendererBaseComp m_renBaseComp;
RendererBasePre m_renBasePre;
RendererBaseCompPre m_renBaseCompPre;
RendererSolid m_renSolid;
RendererSolidComp m_renSolidComp;
SpanAllocator m_allocator;
RectD m_clipBox;
SpanAllocator m_allocator;
RectD m_clipBox;
BlendMode m_blendMode;
BlendMode m_imageBlendMode;
Color m_imageBlendColor;
BlendMode m_blendMode;
BlendMode m_imageBlendMode;
Color m_imageBlendColor;
agg::scanline_u8 m_scanline;
agg::rasterizer_scanline_aa<> m_rasterizer;
agg::scanline_u8 m_scanline;
agg::rasterizer_scanline_aa<> m_rasterizer;
double m_masterAlpha;
double m_antiAliasGamma;
double m_masterAlpha;
double m_antiAliasGamma;
Color m_fillColor;
Color m_lineColor;
GradientArray m_fillGradient;
GradientArray m_lineGradient;
Color m_fillColor;
Color m_lineColor;
GradientArray m_fillGradient;
GradientArray m_lineGradient;
LineCap m_lineCap;
LineJoin m_lineJoin;
LineCap m_lineCap;
LineJoin m_lineJoin;
Gradient m_fillGradientFlag;
Gradient m_lineGradientFlag;
agg::trans_affine m_fillGradientMatrix;
agg::trans_affine m_lineGradientMatrix;
double m_fillGradientD1;
double m_lineGradientD1;
double m_fillGradientD2;
double m_lineGradientD2;
Gradient m_fillGradientFlag;
Gradient m_lineGradientFlag;
agg::trans_affine m_fillGradientMatrix;
agg::trans_affine m_lineGradientMatrix;
double m_fillGradientD1;
double m_lineGradientD1;
double m_fillGradientD2;
double m_lineGradientD2;
TextAlignment m_textAlignment;
double m_textSizeX;
double m_textSizeY;
TextAlignment m_textAlignment;
double m_textSizeX;
double m_textSizeY;
ImageFilter m_imageFilter;
ImageResample m_imageResample;
agg::image_filter_lut m_imageFilterLut;
ImageFilter m_imageFilter;
ImageResample m_imageResample;
agg::image_filter_lut m_imageFilterLut;
agg::span_interpolator_linear<> m_fillGradientInterpolator;
agg::span_interpolator_linear<> m_lineGradientInterpolator;
agg::gradient_x m_linearGradientFunction;
agg::gradient_circle m_radialGradientFunction;
agg::gradient_x m_linearGradientFunction;
agg::gradient_circle m_radialGradientFunction;
double m_lineWidth;
bool m_evenOddFlag;
double m_lineWidth;
bool m_evenOddFlag;
agg::path_storage m_path;
agg::trans_affine m_transform;
agg::path_storage m_path;
agg::trans_affine m_transform;
ConvCurve m_convCurve;
ConvStroke m_convStroke;
ConvCurve m_convCurve;
ConvStroke m_convStroke;
PathTransform m_pathTransform;
StrokeTransform m_strokeTransform;
PathTransform m_pathTransform;
StrokeTransform m_strokeTransform;
#ifdef AGG_USE_FONTS
#ifndef AGG2D_USE_FREETYPE
HDC m_fontDC;
HDC m_fontDC;
#endif
FontEngine m_fontEngine;
FontCacheManager m_fontCacheManager;
FontEngine m_fontEngine;
FontCacheManager m_fontCacheManager;
#endif
};
inline bool operator == (const Agg2D::Color& c1, const Agg2D::Color& c2)
inline bool operator==(const Agg2D::Color& c1, const Agg2D::Color& c2)
{
return c1.r == c2.r && c1.g == c2.g && c1.b == c2.b && c1.a == c2.a;
return c1.r == c2.r && c1.g == c2.g && c1.b == c2.b && c1.a == c2.a;
}
inline bool operator != (const Agg2D::Color& c1, const Agg2D::Color& c2)
inline bool operator!=(const Agg2D::Color& c1, const Agg2D::Color& c2)
{
return !(c1 == c2);
return !(c1 == c2);
}
#endif

View File

@@ -2,8 +2,8 @@
// 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.
// 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.
//
@@ -28,52 +28,63 @@ namespace agg
//===================================================one_component_mask_u8
struct one_component_mask_u8
{
static unsigned calculate(const int8u* p) { return *p; }
static unsigned calculate(const int8u* p)
{
return *p;
}
};
//=====================================================rgb_to_gray_mask_u8
template<unsigned R, unsigned G, unsigned B>
template <unsigned R, unsigned G, unsigned B>
struct rgb_to_gray_mask_u8
{
static unsigned calculate(const int8u* p)
{
return (p[R]*77 + p[G]*150 + p[B]*29) >> 8;
static unsigned calculate(const int8u* p)
{
return (p[R] * 77 + p[G] * 150 + p[B] * 29) >> 8;
}
};
//==========================================================alpha_mask_u8
template<unsigned Step=1, unsigned Offset=0, class MaskF=one_component_mask_u8>
template <unsigned Step = 1,
unsigned Offset = 0,
class MaskF = one_component_mask_u8>
class alpha_mask_u8
{
public:
typedef int8u cover_type;
typedef alpha_mask_u8<Step, Offset, MaskF> self_type;
enum cover_scale_e
{
{
cover_shift = 8,
cover_none = 0,
cover_full = 255
cover_none = 0,
cover_full = 255
};
alpha_mask_u8() : m_rbuf(0) {}
explicit alpha_mask_u8(rendering_buffer& rbuf) : m_rbuf(&rbuf) {}
alpha_mask_u8(): m_rbuf(0) {}
explicit alpha_mask_u8(rendering_buffer& rbuf): m_rbuf(&rbuf) {}
void attach(rendering_buffer& rbuf) { m_rbuf = &rbuf; }
void attach(rendering_buffer& rbuf)
{
m_rbuf = &rbuf;
}
MaskF& mask_function() { return m_mask_function; }
const MaskF& mask_function() const { return m_mask_function; }
MaskF& mask_function()
{
return m_mask_function;
}
const MaskF& mask_function() const
{
return m_mask_function;
}
//--------------------------------------------------------------------
cover_type pixel(int x, int y) const
{
if(x >= 0 && y >= 0 &&
x < (int)m_rbuf->width() &&
y < (int)m_rbuf->height())
if (x >= 0 && y >= 0 && x < (int)m_rbuf->width() &&
y < (int)m_rbuf->height())
{
return (cover_type)m_mask_function.calculate(
m_rbuf->row_ptr(y) + x * Step + Offset);
m_rbuf->row_ptr(y) + x * Step + Offset);
}
return 0;
}
@@ -81,19 +92,18 @@ namespace agg
//--------------------------------------------------------------------
cover_type combine_pixel(int x, int y, cover_type val) const
{
if(x >= 0 && y >= 0 &&
x < (int)m_rbuf->width() &&
y < (int)m_rbuf->height())
if (x >= 0 && y >= 0 && x < (int)m_rbuf->width() &&
y < (int)m_rbuf->height())
{
return (cover_type)((cover_full + val *
m_mask_function.calculate(
m_rbuf->row_ptr(y) + x * Step + Offset)) >>
cover_shift);
return (
cover_type)((cover_full + val * m_mask_function.calculate(
m_rbuf->row_ptr(y) +
x * Step + Offset)) >>
cover_shift);
}
return 0;
}
//--------------------------------------------------------------------
void fill_hspan(int x, int y, cover_type* dst, int num_pix) const
{
@@ -103,16 +113,16 @@ namespace agg
int count = num_pix;
cover_type* covers = dst;
if(y < 0 || y > ymax)
if (y < 0 || y > ymax)
{
std::memset(dst, 0, num_pix * sizeof(cover_type));
return;
}
if(x < 0)
if (x < 0)
{
count += x;
if(count <= 0)
if (count <= 0)
{
std::memset(dst, 0, num_pix * sizeof(cover_type));
return;
@@ -122,11 +132,11 @@ namespace agg
x = 0;
}
if(x + count > xmax)
if (x + count > xmax)
{
int rest = x + count - xmax - 1;
count -= rest;
if(count <= 0)
if (count <= 0)
{
std::memset(dst, 0, num_pix * sizeof(cover_type));
return;
@@ -139,11 +149,9 @@ namespace agg
{
*covers++ = (cover_type)m_mask_function.calculate(mask);
mask += Step;
}
while(--count);
} while (--count);
}
//--------------------------------------------------------------------
void combine_hspan(int x, int y, cover_type* dst, int num_pix) const
{
@@ -153,16 +161,16 @@ namespace agg
int count = num_pix;
cover_type* covers = dst;
if(y < 0 || y > ymax)
if (y < 0 || y > ymax)
{
std::memset(dst, 0, num_pix * sizeof(cover_type));
return;
}
if(x < 0)
if (x < 0)
{
count += x;
if(count <= 0)
if (count <= 0)
{
std::memset(dst, 0, num_pix * sizeof(cover_type));
return;
@@ -172,11 +180,11 @@ namespace agg
x = 0;
}
if(x + count > xmax)
if (x + count > xmax)
{
int rest = x + count - xmax - 1;
count -= rest;
if(count <= 0)
if (count <= 0)
{
std::memset(dst, 0, num_pix * sizeof(cover_type));
return;
@@ -187,13 +195,14 @@ namespace agg
const int8u* mask = m_rbuf->row_ptr(y) + x * Step + Offset;
do
{
*covers = (cover_type)((cover_full + (*covers) *
m_mask_function.calculate(mask)) >>
cover_shift);
*covers =
(cover_type)((cover_full +
(*covers) *
m_mask_function.calculate(mask)) >>
cover_shift);
++covers;
mask += Step;
}
while(--count);
} while (--count);
}
//--------------------------------------------------------------------
@@ -205,16 +214,16 @@ namespace agg
int count = num_pix;
cover_type* covers = dst;
if(x < 0 || x > xmax)
if (x < 0 || x > xmax)
{
std::memset(dst, 0, num_pix * sizeof(cover_type));
return;
}
if(y < 0)
if (y < 0)
{
count += y;
if(count <= 0)
if (count <= 0)
{
std::memset(dst, 0, num_pix * sizeof(cover_type));
return;
@@ -224,11 +233,11 @@ namespace agg
y = 0;
}
if(y + count > ymax)
if (y + count > ymax)
{
int rest = y + count - ymax - 1;
count -= rest;
if(count <= 0)
if (count <= 0)
{
std::memset(dst, 0, num_pix * sizeof(cover_type));
return;
@@ -241,8 +250,7 @@ namespace agg
{
*covers++ = (cover_type)m_mask_function.calculate(mask);
mask += m_rbuf->stride();
}
while(--count);
} while (--count);
}
//--------------------------------------------------------------------
@@ -254,16 +262,16 @@ namespace agg
int count = num_pix;
cover_type* covers = dst;
if(x < 0 || x > xmax)
if (x < 0 || x > xmax)
{
std::memset(dst, 0, num_pix * sizeof(cover_type));
return;
}
if(y < 0)
if (y < 0)
{
count += y;
if(count <= 0)
if (count <= 0)
{
std::memset(dst, 0, num_pix * sizeof(cover_type));
return;
@@ -273,11 +281,11 @@ namespace agg
y = 0;
}
if(y + count > ymax)
if (y + count > ymax)
{
int rest = y + count - ymax - 1;
count -= rest;
if(count <= 0)
if (count <= 0)
{
std::memset(dst, 0, num_pix * sizeof(cover_type));
return;
@@ -288,34 +296,33 @@ namespace agg
const int8u* mask = m_rbuf->row_ptr(y) + x * Step + Offset;
do
{
*covers = (cover_type)((cover_full + (*covers) *
m_mask_function.calculate(mask)) >>
cover_shift);
*covers =
(cover_type)((cover_full +
(*covers) *
m_mask_function.calculate(mask)) >>
cover_shift);
++covers;
mask += m_rbuf->stride();
}
while(--count);
} while (--count);
}
private:
alpha_mask_u8(const self_type&);
const self_type& operator = (const self_type&);
const self_type& operator=(const self_type&);
rendering_buffer* m_rbuf;
MaskF m_mask_function;
MaskF m_mask_function;
};
typedef alpha_mask_u8<1, 0> alpha_mask_gray8; //----alpha_mask_gray8
typedef alpha_mask_u8<1, 0> alpha_mask_gray8; //----alpha_mask_gray8
typedef alpha_mask_u8<3, 0> alpha_mask_rgb24r; //----alpha_mask_rgb24r
typedef alpha_mask_u8<3, 1> alpha_mask_rgb24g; //----alpha_mask_rgb24g
typedef alpha_mask_u8<3, 2> alpha_mask_rgb24b; //----alpha_mask_rgb24b
typedef alpha_mask_u8<3, 0> alpha_mask_rgb24r; //----alpha_mask_rgb24r
typedef alpha_mask_u8<3, 1> alpha_mask_rgb24g; //----alpha_mask_rgb24g
typedef alpha_mask_u8<3, 2> alpha_mask_rgb24b; //----alpha_mask_rgb24b
typedef alpha_mask_u8<3, 2> alpha_mask_bgr24r; //----alpha_mask_bgr24r
typedef alpha_mask_u8<3, 1> alpha_mask_bgr24g; //----alpha_mask_bgr24g
typedef alpha_mask_u8<3, 0> alpha_mask_bgr24b; //----alpha_mask_bgr24b
typedef alpha_mask_u8<3, 2> alpha_mask_bgr24r; //----alpha_mask_bgr24r
typedef alpha_mask_u8<3, 1> alpha_mask_bgr24g; //----alpha_mask_bgr24g
typedef alpha_mask_u8<3, 0> alpha_mask_bgr24b; //----alpha_mask_bgr24b
typedef alpha_mask_u8<4, 0> alpha_mask_rgba32r; //----alpha_mask_rgba32r
typedef alpha_mask_u8<4, 1> alpha_mask_rgba32g; //----alpha_mask_rgba32g
@@ -337,56 +344,68 @@ namespace agg
typedef alpha_mask_u8<4, 1> alpha_mask_abgr32b; //----alpha_mask_abgr32b
typedef alpha_mask_u8<4, 0> alpha_mask_abgr32a; //----alpha_mask_abgr32a
typedef alpha_mask_u8<3, 0, rgb_to_gray_mask_u8<0, 1, 2> > alpha_mask_rgb24gray; //----alpha_mask_rgb24gray
typedef alpha_mask_u8<3, 0, rgb_to_gray_mask_u8<2, 1, 0> > alpha_mask_bgr24gray; //----alpha_mask_bgr24gray
typedef alpha_mask_u8<4, 0, rgb_to_gray_mask_u8<0, 1, 2> > alpha_mask_rgba32gray; //----alpha_mask_rgba32gray
typedef alpha_mask_u8<4, 1, rgb_to_gray_mask_u8<0, 1, 2> > alpha_mask_argb32gray; //----alpha_mask_argb32gray
typedef alpha_mask_u8<4, 0, rgb_to_gray_mask_u8<2, 1, 0> > alpha_mask_bgra32gray; //----alpha_mask_bgra32gray
typedef alpha_mask_u8<4, 1, rgb_to_gray_mask_u8<2, 1, 0> > alpha_mask_abgr32gray; //----alpha_mask_abgr32gray
typedef alpha_mask_u8<3, 0, rgb_to_gray_mask_u8<0, 1, 2>>
alpha_mask_rgb24gray; //----alpha_mask_rgb24gray
typedef alpha_mask_u8<3, 0, rgb_to_gray_mask_u8<2, 1, 0>>
alpha_mask_bgr24gray; //----alpha_mask_bgr24gray
typedef alpha_mask_u8<4, 0, rgb_to_gray_mask_u8<0, 1, 2>>
alpha_mask_rgba32gray; //----alpha_mask_rgba32gray
typedef alpha_mask_u8<4, 1, rgb_to_gray_mask_u8<0, 1, 2>>
alpha_mask_argb32gray; //----alpha_mask_argb32gray
typedef alpha_mask_u8<4, 0, rgb_to_gray_mask_u8<2, 1, 0>>
alpha_mask_bgra32gray; //----alpha_mask_bgra32gray
typedef alpha_mask_u8<4, 1, rgb_to_gray_mask_u8<2, 1, 0>>
alpha_mask_abgr32gray; //----alpha_mask_abgr32gray
//==========================================================amask_no_clip_u8
template<unsigned Step=1, unsigned Offset=0, class MaskF=one_component_mask_u8>
template <unsigned Step = 1,
unsigned Offset = 0,
class MaskF = one_component_mask_u8>
class amask_no_clip_u8
{
public:
typedef int8u cover_type;
typedef amask_no_clip_u8<Step, Offset, MaskF> self_type;
enum cover_scale_e
{
{
cover_shift = 8,
cover_none = 0,
cover_full = 255
cover_none = 0,
cover_full = 255
};
amask_no_clip_u8() : m_rbuf(0) {}
explicit amask_no_clip_u8(rendering_buffer& rbuf) : m_rbuf(&rbuf) {}
amask_no_clip_u8(): m_rbuf(0) {}
explicit amask_no_clip_u8(rendering_buffer& rbuf): m_rbuf(&rbuf) {}
void attach(rendering_buffer& rbuf) { m_rbuf = &rbuf; }
MaskF& mask_function() { return m_mask_function; }
const MaskF& mask_function() const { return m_mask_function; }
void attach(rendering_buffer& rbuf)
{
m_rbuf = &rbuf;
}
MaskF& mask_function()
{
return m_mask_function;
}
const MaskF& mask_function() const
{
return m_mask_function;
}
//--------------------------------------------------------------------
cover_type pixel(int x, int y) const
{
return (cover_type)m_mask_function.calculate(
m_rbuf->row_ptr(y) + x * Step + Offset);
m_rbuf->row_ptr(y) + x * Step + Offset);
}
//--------------------------------------------------------------------
cover_type combine_pixel(int x, int y, cover_type val) const
{
return (cover_type)((cover_full + val *
m_mask_function.calculate(
m_rbuf->row_ptr(y) + x * Step + Offset)) >>
cover_shift);
return (cover_type)((cover_full + val * m_mask_function.calculate(
m_rbuf->row_ptr(y) +
x * Step + Offset)) >>
cover_shift);
}
//--------------------------------------------------------------------
void fill_hspan(int x, int y, cover_type* dst, int num_pix) const
{
@@ -395,28 +414,24 @@ namespace agg
{
*dst++ = (cover_type)m_mask_function.calculate(mask);
mask += Step;
}
while(--num_pix);
} while (--num_pix);
}
//--------------------------------------------------------------------
void combine_hspan(int x, int y, cover_type* dst, int num_pix) const
{
const int8u* mask = m_rbuf->row_ptr(y) + x * Step + Offset;
do
{
*dst = (cover_type)((cover_full + (*dst) *
m_mask_function.calculate(mask)) >>
*dst = (cover_type)((cover_full +
(*dst) *
m_mask_function.calculate(mask)) >>
cover_shift);
++dst;
mask += Step;
}
while(--num_pix);
} while (--num_pix);
}
//--------------------------------------------------------------------
void fill_vspan(int x, int y, cover_type* dst, int num_pix) const
{
@@ -425,75 +440,98 @@ namespace agg
{
*dst++ = (cover_type)m_mask_function.calculate(mask);
mask += m_rbuf->stride();
}
while(--num_pix);
} while (--num_pix);
}
//--------------------------------------------------------------------
void combine_vspan(int x, int y, cover_type* dst, int num_pix) const
{
const int8u* mask = m_rbuf->row_ptr(y) + x * Step + Offset;
do
{
*dst = (cover_type)((cover_full + (*dst) *
m_mask_function.calculate(mask)) >>
*dst = (cover_type)((cover_full +
(*dst) *
m_mask_function.calculate(mask)) >>
cover_shift);
++dst;
mask += m_rbuf->stride();
}
while(--num_pix);
} while (--num_pix);
}
private:
amask_no_clip_u8(const self_type&);
const self_type& operator = (const self_type&);
const self_type& operator=(const self_type&);
rendering_buffer* m_rbuf;
MaskF m_mask_function;
MaskF m_mask_function;
};
typedef amask_no_clip_u8<1, 0> amask_no_clip_gray8; //----amask_no_clip_gray8
typedef amask_no_clip_u8<1, 0>
amask_no_clip_gray8; //----amask_no_clip_gray8
typedef amask_no_clip_u8<3, 0> amask_no_clip_rgb24r; //----amask_no_clip_rgb24r
typedef amask_no_clip_u8<3, 1> amask_no_clip_rgb24g; //----amask_no_clip_rgb24g
typedef amask_no_clip_u8<3, 2> amask_no_clip_rgb24b; //----amask_no_clip_rgb24b
typedef amask_no_clip_u8<3, 0>
amask_no_clip_rgb24r; //----amask_no_clip_rgb24r
typedef amask_no_clip_u8<3, 1>
amask_no_clip_rgb24g; //----amask_no_clip_rgb24g
typedef amask_no_clip_u8<3, 2>
amask_no_clip_rgb24b; //----amask_no_clip_rgb24b
typedef amask_no_clip_u8<3, 2> amask_no_clip_bgr24r; //----amask_no_clip_bgr24r
typedef amask_no_clip_u8<3, 1> amask_no_clip_bgr24g; //----amask_no_clip_bgr24g
typedef amask_no_clip_u8<3, 0> amask_no_clip_bgr24b; //----amask_no_clip_bgr24b
typedef amask_no_clip_u8<3, 2>
amask_no_clip_bgr24r; //----amask_no_clip_bgr24r
typedef amask_no_clip_u8<3, 1>
amask_no_clip_bgr24g; //----amask_no_clip_bgr24g
typedef amask_no_clip_u8<3, 0>
amask_no_clip_bgr24b; //----amask_no_clip_bgr24b
typedef amask_no_clip_u8<4, 0> amask_no_clip_rgba32r; //----amask_no_clip_rgba32r
typedef amask_no_clip_u8<4, 1> amask_no_clip_rgba32g; //----amask_no_clip_rgba32g
typedef amask_no_clip_u8<4, 2> amask_no_clip_rgba32b; //----amask_no_clip_rgba32b
typedef amask_no_clip_u8<4, 3> amask_no_clip_rgba32a; //----amask_no_clip_rgba32a
typedef amask_no_clip_u8<4, 0>
amask_no_clip_rgba32r; //----amask_no_clip_rgba32r
typedef amask_no_clip_u8<4, 1>
amask_no_clip_rgba32g; //----amask_no_clip_rgba32g
typedef amask_no_clip_u8<4, 2>
amask_no_clip_rgba32b; //----amask_no_clip_rgba32b
typedef amask_no_clip_u8<4, 3>
amask_no_clip_rgba32a; //----amask_no_clip_rgba32a
typedef amask_no_clip_u8<4, 1> amask_no_clip_argb32r; //----amask_no_clip_argb32r
typedef amask_no_clip_u8<4, 2> amask_no_clip_argb32g; //----amask_no_clip_argb32g
typedef amask_no_clip_u8<4, 3> amask_no_clip_argb32b; //----amask_no_clip_argb32b
typedef amask_no_clip_u8<4, 0> amask_no_clip_argb32a; //----amask_no_clip_argb32a
typedef amask_no_clip_u8<4, 1>
amask_no_clip_argb32r; //----amask_no_clip_argb32r
typedef amask_no_clip_u8<4, 2>
amask_no_clip_argb32g; //----amask_no_clip_argb32g
typedef amask_no_clip_u8<4, 3>
amask_no_clip_argb32b; //----amask_no_clip_argb32b
typedef amask_no_clip_u8<4, 0>
amask_no_clip_argb32a; //----amask_no_clip_argb32a
typedef amask_no_clip_u8<4, 2> amask_no_clip_bgra32r; //----amask_no_clip_bgra32r
typedef amask_no_clip_u8<4, 1> amask_no_clip_bgra32g; //----amask_no_clip_bgra32g
typedef amask_no_clip_u8<4, 0> amask_no_clip_bgra32b; //----amask_no_clip_bgra32b
typedef amask_no_clip_u8<4, 3> amask_no_clip_bgra32a; //----amask_no_clip_bgra32a
typedef amask_no_clip_u8<4, 2>
amask_no_clip_bgra32r; //----amask_no_clip_bgra32r
typedef amask_no_clip_u8<4, 1>
amask_no_clip_bgra32g; //----amask_no_clip_bgra32g
typedef amask_no_clip_u8<4, 0>
amask_no_clip_bgra32b; //----amask_no_clip_bgra32b
typedef amask_no_clip_u8<4, 3>
amask_no_clip_bgra32a; //----amask_no_clip_bgra32a
typedef amask_no_clip_u8<4, 3> amask_no_clip_abgr32r; //----amask_no_clip_abgr32r
typedef amask_no_clip_u8<4, 2> amask_no_clip_abgr32g; //----amask_no_clip_abgr32g
typedef amask_no_clip_u8<4, 1> amask_no_clip_abgr32b; //----amask_no_clip_abgr32b
typedef amask_no_clip_u8<4, 0> amask_no_clip_abgr32a; //----amask_no_clip_abgr32a
typedef amask_no_clip_u8<3, 0, rgb_to_gray_mask_u8<0, 1, 2> > amask_no_clip_rgb24gray; //----amask_no_clip_rgb24gray
typedef amask_no_clip_u8<3, 0, rgb_to_gray_mask_u8<2, 1, 0> > amask_no_clip_bgr24gray; //----amask_no_clip_bgr24gray
typedef amask_no_clip_u8<4, 0, rgb_to_gray_mask_u8<0, 1, 2> > amask_no_clip_rgba32gray; //----amask_no_clip_rgba32gray
typedef amask_no_clip_u8<4, 1, rgb_to_gray_mask_u8<0, 1, 2> > amask_no_clip_argb32gray; //----amask_no_clip_argb32gray
typedef amask_no_clip_u8<4, 0, rgb_to_gray_mask_u8<2, 1, 0> > amask_no_clip_bgra32gray; //----amask_no_clip_bgra32gray
typedef amask_no_clip_u8<4, 1, rgb_to_gray_mask_u8<2, 1, 0> > amask_no_clip_abgr32gray; //----amask_no_clip_abgr32gray
typedef amask_no_clip_u8<4, 3>
amask_no_clip_abgr32r; //----amask_no_clip_abgr32r
typedef amask_no_clip_u8<4, 2>
amask_no_clip_abgr32g; //----amask_no_clip_abgr32g
typedef amask_no_clip_u8<4, 1>
amask_no_clip_abgr32b; //----amask_no_clip_abgr32b
typedef amask_no_clip_u8<4, 0>
amask_no_clip_abgr32a; //----amask_no_clip_abgr32a
typedef amask_no_clip_u8<3, 0, rgb_to_gray_mask_u8<0, 1, 2>>
amask_no_clip_rgb24gray; //----amask_no_clip_rgb24gray
typedef amask_no_clip_u8<3, 0, rgb_to_gray_mask_u8<2, 1, 0>>
amask_no_clip_bgr24gray; //----amask_no_clip_bgr24gray
typedef amask_no_clip_u8<4, 0, rgb_to_gray_mask_u8<0, 1, 2>>
amask_no_clip_rgba32gray; //----amask_no_clip_rgba32gray
typedef amask_no_clip_u8<4, 1, rgb_to_gray_mask_u8<0, 1, 2>>
amask_no_clip_argb32gray; //----amask_no_clip_argb32gray
typedef amask_no_clip_u8<4, 0, rgb_to_gray_mask_u8<2, 1, 0>>
amask_no_clip_bgra32gray; //----amask_no_clip_bgra32gray
typedef amask_no_clip_u8<4, 1, rgb_to_gray_mask_u8<2, 1, 0>>
amask_no_clip_abgr32gray; //----amask_no_clip_abgr32gray
}
#endif

View File

@@ -2,8 +2,8 @@
// 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.
// 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.
//
@@ -27,24 +27,33 @@ namespace agg
//=====================================================================arc
//
// See Implementation agg_arc.cpp
// See Implementation agg_arc.cpp
//
class arc
{
public:
arc() : m_scale(1.0), m_initialized(false) {}
arc(double x, double y,
double rx, double ry,
double a1, double a2,
bool ccw=true);
arc(): m_scale(1.0), m_initialized(false) {}
arc(double x,
double y,
double rx,
double ry,
double a1,
double a2,
bool ccw = true);
void init(double x, double y,
double rx, double ry,
double a1, double a2,
bool ccw=true);
void init(double x,
double y,
double rx,
double ry,
double a1,
double a2,
bool ccw = true);
void approximation_scale(double s);
double approximation_scale() const { return m_scale; }
double approximation_scale() const
{
return m_scale;
}
void rewind(unsigned);
unsigned vertex(double* x, double* y);
@@ -52,22 +61,20 @@ namespace agg
private:
void normalize(double a1, double a2, bool ccw);
double m_x;
double m_y;
double m_rx;
double m_ry;
double m_angle;
double m_start;
double m_end;
double m_scale;
double m_da;
bool m_ccw;
bool m_initialized;
double m_x;
double m_y;
double m_rx;
double m_ry;
double m_angle;
double m_start;
double m_end;
double m_scale;
double m_da;
bool m_ccw;
bool m_initialized;
unsigned m_path_cmd;
};
}
#endif

View File

File diff suppressed because it is too large Load Diff

View File

@@ -2,8 +2,8 @@
// 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.
// 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.
//
@@ -13,7 +13,7 @@
// http://www.antigrain.com
//----------------------------------------------------------------------------
//
// Simple arrowhead/arrowtail generator
// Simple arrowhead/arrowtail generator
//
//----------------------------------------------------------------------------
#ifndef AGG_ARROWHEAD_INCLUDED
@@ -26,7 +26,7 @@ namespace agg
//===============================================================arrowhead
//
// See implementation agg_arrowhead.cpp
// See implementation agg_arrowhead.cpp
//
class arrowhead
{
@@ -42,8 +42,14 @@ namespace agg
m_head_flag = true;
}
void head() { m_head_flag = true; }
void no_head() { m_head_flag = false; }
void head()
{
m_head_flag = true;
}
void no_head()
{
m_head_flag = false;
}
void tail(double d1, double d2, double d3, double d4)
{
@@ -54,24 +60,30 @@ namespace agg
m_tail_flag = true;
}
void tail() { m_tail_flag = true; }
void no_tail() { m_tail_flag = false; }
void tail()
{
m_tail_flag = true;
}
void no_tail()
{
m_tail_flag = false;
}
void rewind(unsigned path_id);
unsigned vertex(double* x, double* y);
private:
double m_head_d1;
double m_head_d2;
double m_head_d3;
double m_head_d4;
double m_tail_d1;
double m_tail_d2;
double m_tail_d3;
double m_tail_d4;
bool m_head_flag;
bool m_tail_flag;
double m_coord[16];
double m_head_d1;
double m_head_d2;
double m_head_d3;
double m_head_d4;
double m_tail_d1;
double m_tail_d2;
double m_tail_d3;
double m_tail_d4;
bool m_head_flag;
bool m_tail_flag;
double m_coord[16];
unsigned m_cmd[8];
unsigned m_curr_id;
unsigned m_curr_coord;

View File

@@ -2,8 +2,8 @@
// 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.
// 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.
//
@@ -25,37 +25,50 @@
#else
namespace agg
{
// The policy of all AGG containers and memory allocation strategy
// 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
// 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
template <class T>
struct pod_allocator
{
static T* allocate(unsigned num) { return new T [num]; }
static void deallocate(T* ptr, unsigned) { delete [] ptr; }
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.
// 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
template <class T>
struct obj_allocator
{
static T* allocate() { return new T; }
static void deallocate(T* ptr) { delete ptr; }
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
@@ -104,7 +117,7 @@ namespace agg
//------------------------------------------------ Some fixes for MS Visual C++
#if defined(_MSC_VER)
#pragma warning(disable:4786) // Identifier was truncated...
#pragma warning(disable : 4786) // Identifier was truncated...
#endif
#if defined(_MSC_VER)
@@ -116,38 +129,36 @@ namespace agg
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
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
#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]
__asm fld qword ptr[v] __asm fistp dword ptr[t] __asm mov eax,
dword ptr[t]
}
AGG_INLINE unsigned uround(double v) //-------uround
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]
__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
AGG_INLINE unsigned ufloor(double v) //-------ufloor
{
return unsigned(floor(v));
}
@@ -155,7 +166,7 @@ namespace agg
{
return int(ceil(v));
}
AGG_INLINE unsigned uceil(double v) //--------uceil
AGG_INLINE unsigned uceil(double v) //--------uceil
{
return unsigned(ceil(v));
}
@@ -213,48 +224,53 @@ namespace agg
#endif
//---------------------------------------------------------------saturation
template<int Limit> struct 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;
if (v < double(-Limit))
return -Limit;
if (v > double(Limit))
return Limit;
return agg::iround(v);
}
};
//------------------------------------------------------------------mul_one
template<unsigned Shift> struct mul_one
template <unsigned Shift>
struct mul_one
{
AGG_INLINE static unsigned mul(unsigned a, unsigned b)
{
unsigned q = a * b + (1 << (Shift-1));
unsigned q = a * b + (1 << (Shift - 1));
return (q + (q >> Shift)) >> Shift;
}
};
//-------------------------------------------------------------------------
typedef unsigned char cover_type; //----cover_type
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
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.
// 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
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
@@ -278,37 +294,60 @@ namespace agg
{
return rad * 180.0 / pi;
}
//----------------------------------------------------------------rect_base
template<class T> struct rect_base
template <class T>
struct rect_base
{
typedef T value_type;
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_)
rect_base(T x1_, T y1_, T x2_, T y2_):
x1(x1_),
y1(y1_),
x2(x2_),
y2(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; }
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;
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;
}
@@ -321,72 +360,78 @@ namespace agg
{
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);
return !(r.x1 > x2 || r.x2 < x1 || r.y1 > y2 || r.y2 < y1);
}
};
//-----------------------------------------------------intersect_rectangles
template<class Rect>
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
// 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;
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>
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;
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<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_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
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
@@ -403,7 +448,7 @@ namespace agg
//-----------------------------------------------------------------is_stop
inline bool is_stop(unsigned c)
{
{
return c == path_cmd_stop;
}
@@ -447,7 +492,7 @@ namespace agg
inline bool is_close(unsigned c)
{
return (c & ~(path_flags_cw | path_flags_ccw)) ==
(path_cmd_end_poly | path_flags_close);
(path_cmd_end_poly | path_flags_close);
}
//------------------------------------------------------------is_next_poly
@@ -471,19 +516,19 @@ namespace agg
//-------------------------------------------------------------is_oriented
inline bool is_oriented(unsigned c)
{
return (c & (path_flags_cw | path_flags_ccw)) != 0;
return (c & (path_flags_cw | path_flags_ccw)) != 0;
}
//---------------------------------------------------------------is_closed
inline bool is_closed(unsigned c)
{
return (c & path_flags_close) != 0;
return (c & path_flags_close) != 0;
}
//----------------------------------------------------------get_close_flag
inline unsigned get_close_flag(unsigned c)
{
return c & path_flags_close;
return c & path_flags_close;
}
//-------------------------------------------------------clear_orientation
@@ -505,70 +550,77 @@ namespace agg
}
//--------------------------------------------------------------point_base
template<class T> struct point_base
template <class T>
struct point_base
{
typedef T value_type;
T x,y;
T x, y;
point_base() {}
point_base(T x_, T y_) : x(x_), y(y_) {}
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<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
template <class T>
struct vertex_base
{
typedef T value_type;
T x,y;
T x, y;
unsigned cmd;
vertex_base() {}
vertex_base(T x_, T y_, unsigned cmd_) : x(x_), y(y_), cmd(cmd_) {}
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<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
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_) {}
row_info(int x1_, int x2_, T* ptr_): x1(x1_), x2(x2_), ptr(ptr_) {}
};
//----------------------------------------------------------const_row_info
template<class T> struct 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_) {}
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)
template <class T>
inline bool is_equal_eps(T v1, T v2, T epsilon)
{
bool neg1 = v1 < 0.0;
bool neg2 = v2 < 0.0;
bool neg1 = v1 < 0.0;
bool neg2 = v2 < 0.0;
if (neg1 != neg2)
return std::fabs(v1) < epsilon && std::fabs(v2) < epsilon;
if (neg1 != neg2)
return std::fabs(v1) < epsilon && std::fabs(v2) < epsilon;
int int1, int2;
std::frexp(v1, &int1);
std::frexp(v2, &int2);
int min12 = int1 < int2 ? int1 : int2;
std::frexp(v1, &int1);
std::frexp(v2, &int2);
int min12 = int1 < int2 ? int1 : int2;
v1 = std::ldexp(v1, -min12);
v2 = std::ldexp(v2, -min12);
v1 = std::ldexp(v1, -min12);
v2 = std::ldexp(v2, -min12);
return std::fabs(v1 - v2) < epsilon;
return std::fabs(v1 - v2) < epsilon;
}
}
#endif

View File

@@ -2,8 +2,8 @@
// 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.
// 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.
//
@@ -13,7 +13,7 @@
// http://www.antigrain.com
//----------------------------------------------------------------------------
//
// Arc generator. Produces at most 4 consecutive cubic bezier curves, i.e.,
// Arc generator. Produces at most 4 consecutive cubic bezier curves, i.e.,
// 4, 7, 10, or 13 vertices.
//
//----------------------------------------------------------------------------
@@ -27,33 +27,42 @@ namespace agg
{
//-----------------------------------------------------------------------
void arc_to_bezier(double cx, double cy, double rx, double ry,
double start_angle, double sweep_angle,
double* curve);
void arc_to_bezier(double cx,
double cy,
double rx,
double ry,
double start_angle,
double sweep_angle,
double* curve);
//==============================================================bezier_arc
//
//
// See implemantaion agg_bezier_arc.cpp
//
class bezier_arc
{
public:
//--------------------------------------------------------------------
bezier_arc() : m_vertex(26), m_num_vertices(0), m_cmd(path_cmd_line_to) {}
bezier_arc(double x, double y,
double rx, double ry,
double start_angle,
double sweep_angle)
bezier_arc(): m_vertex(26), m_num_vertices(0), m_cmd(path_cmd_line_to)
{
}
bezier_arc(double x,
double y,
double rx,
double ry,
double start_angle,
double sweep_angle)
{
init(x, y, rx, ry, start_angle, sweep_angle);
}
//--------------------------------------------------------------------
void init(double x, double y,
double rx, double ry,
double start_angle,
double sweep_angle);
void init(double x,
double y,
double rx,
double ry,
double start_angle,
double sweep_angle);
//--------------------------------------------------------------------
void rewind(unsigned)
@@ -64,67 +73,85 @@ namespace agg
//--------------------------------------------------------------------
unsigned vertex(double* x, double* y)
{
if(m_vertex >= m_num_vertices) return path_cmd_stop;
if (m_vertex >= m_num_vertices)
return path_cmd_stop;
*x = m_vertices[m_vertex];
*y = m_vertices[m_vertex + 1];
m_vertex += 2;
return (m_vertex == 2) ? unsigned(path_cmd_move_to) : m_cmd;
}
// Supplemantary functions. num_vertices() actually returns doubled
// Supplemantary functions. num_vertices() actually returns doubled
// number of vertices. That is, for 1 vertex it returns 2.
//--------------------------------------------------------------------
unsigned num_vertices() const { return m_num_vertices; }
const double* vertices() const { return m_vertices; }
double* vertices() { return m_vertices; }
unsigned num_vertices() const
{
return m_num_vertices;
}
const double* vertices() const
{
return m_vertices;
}
double* vertices()
{
return m_vertices;
}
private:
unsigned m_vertex;
unsigned m_num_vertices;
double m_vertices[26];
double m_vertices[26];
unsigned m_cmd;
};
//==========================================================bezier_arc_svg
// Compute an SVG-style bezier arc.
// Compute an SVG-style bezier arc.
//
// Computes an elliptical arc from (x1, y1) to (x2, y2). The size and
// orientation of the ellipse are defined by two radii (rx, ry)
// and an x-axis-rotation, which indicates how the ellipse as a whole
// is rotated relative to the current coordinate system. The center
// (cx, cy) of the ellipse is calculated automatically to satisfy the
// constraints imposed by the other parameters.
// large-arc-flag and sweep-flag contribute to the automatic calculations
// Computes an elliptical arc from (x1, y1) to (x2, y2). The size and
// orientation of the ellipse are defined by two radii (rx, ry)
// and an x-axis-rotation, which indicates how the ellipse as a whole
// is rotated relative to the current coordinate system. The center
// (cx, cy) of the ellipse is calculated automatically to satisfy the
// constraints imposed by the other parameters.
// large-arc-flag and sweep-flag contribute to the automatic calculations
// and help determine how the arc is drawn.
class bezier_arc_svg
{
public:
//--------------------------------------------------------------------
bezier_arc_svg() : m_arc(), m_radii_ok(false) {}
bezier_arc_svg(): m_arc(), m_radii_ok(false) {}
bezier_arc_svg(double x1, double y1,
double rx, double ry,
double angle,
bool large_arc_flag,
bool sweep_flag,
double x2, double y2) :
m_arc(), m_radii_ok(false)
bezier_arc_svg(double x1,
double y1,
double rx,
double ry,
double angle,
bool large_arc_flag,
bool sweep_flag,
double x2,
double y2):
m_arc(),
m_radii_ok(false)
{
init(x1, y1, rx, ry, angle, large_arc_flag, sweep_flag, x2, y2);
}
//--------------------------------------------------------------------
void init(double x1, double y1,
double rx, double ry,
double angle,
bool large_arc_flag,
bool sweep_flag,
double x2, double y2);
void init(double x1,
double y1,
double rx,
double ry,
double angle,
bool large_arc_flag,
bool sweep_flag,
double x2,
double y2);
//--------------------------------------------------------------------
bool radii_ok() const { return m_radii_ok; }
bool radii_ok() const
{
return m_radii_ok;
}
//--------------------------------------------------------------------
void rewind(unsigned)
@@ -138,22 +165,27 @@ namespace agg
return m_arc.vertex(x, y);
}
// Supplemantary functions. num_vertices() actually returns doubled
// Supplemantary functions. num_vertices() actually returns doubled
// number of vertices. That is, for 1 vertex it returns 2.
//--------------------------------------------------------------------
unsigned num_vertices() const { return m_arc.num_vertices(); }
const double* vertices() const { return m_arc.vertices(); }
double* vertices() { return m_arc.vertices(); }
unsigned num_vertices() const
{
return m_arc.num_vertices();
}
const double* vertices() const
{
return m_arc.vertices();
}
double* vertices()
{
return m_arc.vertices();
}
private:
bezier_arc m_arc;
bool m_radii_ok;
bool m_radii_ok;
};
}
#endif

View File

@@ -2,8 +2,8 @@
// 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.
// 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.
//
@@ -20,19 +20,20 @@
namespace agg
{
class bitset_iterator
{
public:
bitset_iterator(const int8u* bits, unsigned offset = 0) :
bitset_iterator(const int8u* bits, unsigned offset = 0):
m_bits(bits + (offset >> 3)),
m_mask(0x80 >> (offset & 7))
{}
{
}
void operator ++ ()
void operator++()
{
m_mask >>= 1;
if(m_mask == 0)
if (m_mask == 0)
{
++m_bits;
m_mask = 0x80;
@@ -46,7 +47,7 @@ namespace agg
private:
const int8u* m_bits;
int8u m_mask;
int8u m_mask;
};
}

View File

File diff suppressed because it is too large Load Diff

View File

@@ -2,8 +2,8 @@
// 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.
// 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.
//
@@ -25,10 +25,15 @@ namespace agg
{
//-----------------------------------------------------------bounding_rect
template<class VertexSource, class GetId, class CoordT>
bool bounding_rect(VertexSource& vs, GetId& gi,
unsigned start, unsigned num,
CoordT* x1, CoordT* y1, CoordT* x2, CoordT* y2)
template <class VertexSource, class GetId, class CoordT>
bool bounding_rect(VertexSource& vs,
GetId& gi,
unsigned start,
unsigned num,
CoordT* x1,
CoordT* y1,
CoordT* x2,
CoordT* y2)
{
unsigned i;
double x;
@@ -40,15 +45,15 @@ namespace agg
*x2 = CoordT(0);
*y2 = CoordT(0);
for(i = 0; i < num; i++)
for (i = 0; i < num; i++)
{
vs.rewind(gi[start + i]);
unsigned cmd;
while(!is_stop(cmd = vs.vertex(&x, &y)))
while (!is_stop(cmd = vs.vertex(&x, &y)))
{
if(is_vertex(cmd))
if (is_vertex(cmd))
{
if(first)
if (first)
{
*x1 = CoordT(x);
*y1 = CoordT(y);
@@ -58,10 +63,14 @@ namespace agg
}
else
{
if(CoordT(x) < *x1) *x1 = CoordT(x);
if(CoordT(y) < *y1) *y1 = CoordT(y);
if(CoordT(x) > *x2) *x2 = CoordT(x);
if(CoordT(y) > *y2) *y2 = CoordT(y);
if (CoordT(x) < *x1)
*x1 = CoordT(x);
if (CoordT(y) < *y1)
*y1 = CoordT(y);
if (CoordT(x) > *x2)
*x2 = CoordT(x);
if (CoordT(y) > *y2)
*y2 = CoordT(y);
}
}
}
@@ -69,11 +78,14 @@ namespace agg
return *x1 <= *x2 && *y1 <= *y2;
}
//-----------------------------------------------------bounding_rect_single
template<class VertexSource, class CoordT>
bool bounding_rect_single(VertexSource& vs, unsigned path_id,
CoordT* x1, CoordT* y1, CoordT* x2, CoordT* y2)
template <class VertexSource, class CoordT>
bool bounding_rect_single(VertexSource& vs,
unsigned path_id,
CoordT* x1,
CoordT* y1,
CoordT* x2,
CoordT* y2)
{
double x;
double y;
@@ -86,11 +98,11 @@ namespace agg
vs.rewind(path_id);
unsigned cmd;
while(!is_stop(cmd = vs.vertex(&x, &y)))
while (!is_stop(cmd = vs.vertex(&x, &y)))
{
if(is_vertex(cmd))
if (is_vertex(cmd))
{
if(first)
if (first)
{
*x1 = CoordT(x);
*y1 = CoordT(y);
@@ -100,17 +112,20 @@ namespace agg
}
else
{
if(CoordT(x) < *x1) *x1 = CoordT(x);
if(CoordT(y) < *y1) *y1 = CoordT(y);
if(CoordT(x) > *x2) *x2 = CoordT(x);
if(CoordT(y) > *y2) *y2 = CoordT(y);
if (CoordT(x) < *x1)
*x1 = CoordT(x);
if (CoordT(y) < *y1)
*y1 = CoordT(y);
if (CoordT(x) > *x2)
*x2 = CoordT(x);
if (CoordT(y) > *y2)
*y2 = CoordT(y);
}
}
}
return *x1 <= *x2 && *y1 <= *y2;
}
}
#endif

View File

@@ -2,8 +2,8 @@
// 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.
// 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.
//
@@ -26,51 +26,49 @@ namespace agg
{
//----------------------------------------------------------------bspline
// A very simple class of Bi-cubic Spline interpolation.
// First call init(num, x[], y[]) where num - number of source points,
// x, y - arrays of X and Y values respectively. Here Y must be a function
// of X. It means that all the X-coordinates must be arranged in the ascending
// order.
// Then call get(x) that calculates a value Y for the respective X.
// The class supports extrapolation, i.e. you can call get(x) where x is
// outside the given with init() X-range. Extrapolation is a simple linear
// function.
// First call init(num, x[], y[]) where num - number of source points,
// x, y - arrays of X and Y values respectively. Here Y must be a function
// of X. It means that all the X-coordinates must be arranged in the
// ascending order. Then call get(x) that calculates a value Y for the
// respective X. The class supports extrapolation, i.e. you can call get(x)
// where x is outside the given with init() X-range. Extrapolation is a
// simple linear function.
//
// See Implementation agg_bspline.cpp
//------------------------------------------------------------------------
class bspline
class bspline
{
public:
bspline();
bspline(int num);
bspline(int num, const double* x, const double* y);
void init(int num);
void add_point(double x, double y);
void prepare();
void init(int num);
void add_point(double x, double y);
void prepare();
void init(int num, const double* x, const double* y);
void init(int num, const double* x, const double* y);
double get(double x) const;
double get_stateful(double x) const;
private:
bspline(const bspline&);
const bspline& operator = (const bspline&);
const bspline& operator=(const bspline&);
static void bsearch(int n, const double *x, double x0, int *i);
static void bsearch(int n, const double* x, double x0, int* i);
double extrapolation_left(double x) const;
double extrapolation_right(double x) const;
double interpolation(double x, int i) const;
int m_max;
int m_num;
double* m_x;
double* m_y;
int m_max;
int m_num;
double* m_x;
double* m_y;
pod_array<double> m_am;
mutable int m_last_idx;
mutable int m_last_idx;
};
}
#endif

View File

@@ -2,8 +2,8 @@
// 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.
// 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.
//
@@ -13,7 +13,7 @@
// http://www.antigrain.com
//----------------------------------------------------------------------------
//
// Liang-Barsky clipping
// Liang-Barsky clipping
//
//----------------------------------------------------------------------------
#ifndef AGG_CLIP_LIANG_BARSKY_INCLUDED
@@ -31,12 +31,14 @@ namespace agg
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_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
// Determine the clipping code of the vertex according to the
// Cyrus-Beck line clipping algorithm
//
// | |
@@ -52,42 +54,37 @@ namespace agg
// | |
// clip_box.x1 clip_box.x2
//
//
template<class T>
//
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);
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>
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);
return (x > clip_box.x2) | ((x < clip_box.x1) << 2);
}
//--------------------------------------------------------clipping_flags_y
template<class T>
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)
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 deltay = y2 - y1;
double xin;
double xout;
double yin;
@@ -95,52 +92,52 @@ namespace agg
double tinx;
double tiny;
double toutx;
double touty;
double touty;
double tin1;
double tin2;
double tout1;
unsigned np = 0;
if(deltax == 0.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
if (deltay == 0.0)
{
// bump off of the horizontal
deltay = (y1 > clip_box.y1) ? -nearzero : nearzero;
}
if(deltax > 0.0)
{
if (deltax > 0.0)
{
// points to right
xin = clip_box.x1;
xin = clip_box.x1;
xout = clip_box.x2;
}
else
else
{
xin = clip_box.x2;
xin = clip_box.x2;
xout = clip_box.x1;
}
if(deltay > 0.0)
if (deltay > 0.0)
{
// points up
yin = clip_box.y1;
yin = clip_box.y1;
yout = clip_box.y2;
}
else
else
{
yin = clip_box.y2;
yin = clip_box.y2;
yout = clip_box.y1;
}
tinx = (xin - x1) / deltax;
tiny = (yin - y1) / deltay;
if (tinx < tiny)
if (tinx < tiny)
{
// hits x first
tin1 = tinx;
@@ -152,35 +149,35 @@ namespace agg
tin1 = tiny;
tin2 = tinx;
}
if(tin1 <= 1.0)
if (tin1 <= 1.0)
{
if(0.0 < tin1)
if (0.0 < tin1)
{
*x++ = (T)xin;
*y++ = (T)yin;
++np;
}
if(tin2 <= 1.0)
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 > 0.0 || tout1 > 0.0)
{
if(tin2 <= tout1)
if (tin2 <= tout1)
{
if(tin2 > 0.0)
if (tin2 > 0.0)
{
if(tinx > tiny)
if (tinx > tiny)
{
*x++ = (T)xin;
*y++ = (T)(y1 + tinx * deltay);
}
else
else
{
*x++ = (T)(x1 + tiny * deltax);
*y++ = (T)yin;
@@ -188,34 +185,34 @@ namespace agg
++np;
}
if(tout1 < 1.0)
if (tout1 < 1.0)
{
if(toutx < touty)
if (toutx < touty)
{
*x++ = (T)xout;
*y++ = (T)(y1 + toutx * deltay);
}
else
else
{
*x++ = (T)(x1 + touty * deltax);
*y++ = (T)yout;
}
}
else
else
{
*x++ = x2;
*y++ = y2;
}
++np;
}
else
else
{
if(tinx > tiny)
if (tinx > tiny)
{
*x++ = (T)xin;
*y++ = (T)yout;
}
else
else
{
*x++ = (T)xout;
*y++ = (T)yin;
@@ -228,38 +225,44 @@ namespace agg
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)
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;
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;
}
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;
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
@@ -267,29 +270,29 @@ namespace agg
// (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)
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)
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))
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))
if ((f1 & clipping_flags_y_clipped) != 0 &&
(f1 & clipping_flags_y_clipped) == (f2 & clipping_flags_y_clipped))
{
// Fully clipped
return 4;
@@ -299,25 +302,25 @@ namespace agg
T ty1 = *y1;
T tx2 = *x2;
T ty2 = *y2;
if(f1)
{
if(!clip_move_point(tx1, ty1, tx2, ty2, clip_box, x1, y1, f1))
if (f1)
{
if (!clip_move_point(tx1, ty1, tx2, ty2, clip_box, x1, y1, f1))
{
return 4;
}
if(*x1 == *x2 && *y1 == *y2)
if (*x1 == *x2 && *y1 == *y2)
{
return 4;
}
ret |= 1;
}
if(f2)
if (f2)
{
if(!clip_move_point(tx1, ty1, tx2, ty2, clip_box, x2, y2, f2))
if (!clip_move_point(tx1, ty1, tx2, ty2, clip_box, x2, y2, f2))
{
return 4;
}
if(*x1 == *x2 && *y1 == *y2)
if (*x1 == *x2 && *y1 == *y2)
{
return 4;
}
@@ -326,8 +329,6 @@ namespace agg
return ret;
}
}
#endif

View File

File diff suppressed because it is too large Load Diff

View File

File diff suppressed because it is too large Load Diff

View File

@@ -5,7 +5,7 @@
//---------------------------------------
// 1. Default basic types such as:
//
//
// AGG_INT8
// AGG_INT8U
// AGG_INT16
@@ -15,7 +15,7 @@
// AGG_INT64
// AGG_INT64U
//
// Just replace this file with new defines if necessary.
// 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:
//
@@ -23,21 +23,20 @@
// #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
// 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,
// 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
// 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.

View File

@@ -2,8 +2,8 @@
// 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.
// 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.
//
@@ -28,14 +28,15 @@ namespace agg
void prepare_src() {}
void rewind(unsigned) {}
unsigned vertex(double*, double*) { return path_cmd_stop; }
unsigned vertex(double*, double*)
{
return path_cmd_stop;
}
};
//------------------------------------------------------conv_adaptor_vcgen
template<class VertexSource,
class Generator,
class Markers=null_markers> class conv_adaptor_vcgen
template <class VertexSource, class Generator, class Markers = null_markers>
class conv_adaptor_vcgen
{
enum status
{
@@ -45,21 +46,37 @@ namespace agg
};
public:
explicit conv_adaptor_vcgen(VertexSource& source) :
m_source(&source),
explicit conv_adaptor_vcgen(VertexSource& source):
m_source(&source),
m_status(initial)
{}
void attach(VertexSource& source) { m_source = &source; }
{
}
void attach(VertexSource& source)
{
m_source = &source;
}
Generator& generator() { return m_generator; }
const Generator& generator() const { return m_generator; }
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);
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;
}
@@ -67,86 +84,87 @@ namespace agg
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>&);
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;
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)
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)
while (!done)
{
switch(m_status)
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))
{
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;
}
done = true;
break;
}
}
return cmd;

View File

@@ -2,8 +2,8 @@
// 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.
// 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.
//
@@ -22,57 +22,66 @@ namespace agg
{
//======================================================conv_adaptor_vpgen
template<class VertexSource, class VPGen> class conv_adaptor_vpgen
template <class VertexSource, class VPGen>
class conv_adaptor_vpgen
{
public:
explicit conv_adaptor_vpgen(VertexSource& source) : m_source(&source) {}
void attach(VertexSource& source) { m_source = &source; }
explicit conv_adaptor_vpgen(VertexSource& source): m_source(&source) {}
void attach(VertexSource& source)
{
m_source = &source;
}
VPGen& vpgen() { return m_vpgen; }
const VPGen& vpgen() const { return m_vpgen; }
VPGen& vpgen()
{
return m_vpgen;
}
const VPGen& vpgen() const
{
return m_vpgen;
}
void rewind(unsigned path_id);
unsigned vertex(double* x, double* y);
private:
conv_adaptor_vpgen(const conv_adaptor_vpgen<VertexSource, VPGen>&);
const conv_adaptor_vpgen<VertexSource, VPGen>&
operator = (const conv_adaptor_vpgen<VertexSource, VPGen>&);
const conv_adaptor_vpgen<VertexSource, VPGen>& operator=(
const conv_adaptor_vpgen<VertexSource, VPGen>&);
VertexSource* m_source;
VPGen m_vpgen;
double m_start_x;
double m_start_y;
unsigned m_poly_flags;
int m_vertices;
VPGen m_vpgen;
double m_start_x;
double m_start_y;
unsigned m_poly_flags;
int m_vertices;
};
//------------------------------------------------------------------------
template<class VertexSource, class VPGen>
void conv_adaptor_vpgen<VertexSource, VPGen>::rewind(unsigned path_id)
{
template <class VertexSource, class VPGen>
void conv_adaptor_vpgen<VertexSource, VPGen>::rewind(unsigned path_id)
{
m_source->rewind(path_id);
m_vpgen.reset();
m_start_x = 0;
m_start_y = 0;
m_start_x = 0;
m_start_y = 0;
m_poly_flags = 0;
m_vertices = 0;
m_vertices = 0;
}
//------------------------------------------------------------------------
template<class VertexSource, class VPGen>
unsigned conv_adaptor_vpgen<VertexSource, VPGen>::vertex(double* x, double* y)
template <class VertexSource, class VPGen>
unsigned conv_adaptor_vpgen<VertexSource, VPGen>::vertex(
double* x, double* y)
{
unsigned cmd = path_cmd_stop;
for(;;)
for (;;)
{
cmd = m_vpgen.vertex(x, y);
if(!is_stop(cmd)) break;
if (!is_stop(cmd))
break;
if(m_poly_flags && !m_vpgen.auto_unclose())
if (m_poly_flags && !m_vpgen.auto_unclose())
{
*x = 0.0;
*y = 0.0;
@@ -81,9 +90,9 @@ namespace agg
break;
}
if(m_vertices < 0)
if (m_vertices < 0)
{
if(m_vertices < -1)
if (m_vertices < -1)
{
m_vertices = 0;
return path_cmd_stop;
@@ -95,25 +104,25 @@ namespace agg
double tx, ty;
cmd = m_source->vertex(&tx, &ty);
if(is_vertex(cmd))
if (is_vertex(cmd))
{
if(is_move_to(cmd))
if (is_move_to(cmd))
{
if(m_vpgen.auto_close() && m_vertices > 2)
if (m_vpgen.auto_close() && m_vertices > 2)
{
m_vpgen.line_to(m_start_x, m_start_y);
m_poly_flags = path_cmd_end_poly | path_flags_close;
m_start_x = tx;
m_start_y = ty;
m_vertices = -1;
m_start_x = tx;
m_start_y = ty;
m_vertices = -1;
continue;
}
m_vpgen.move_to(tx, ty);
m_start_x = tx;
m_start_y = ty;
m_start_x = tx;
m_start_y = ty;
m_vertices = 1;
}
else
else
{
m_vpgen.line_to(tx, ty);
++m_vertices;
@@ -121,13 +130,14 @@ namespace agg
}
else
{
if(is_end_poly(cmd))
if (is_end_poly(cmd))
{
m_poly_flags = cmd;
if(is_closed(cmd) || m_vpgen.auto_close())
if (is_closed(cmd) || m_vpgen.auto_close())
{
if(m_vpgen.auto_close()) m_poly_flags |= path_flags_close;
if(m_vertices > 2)
if (m_vpgen.auto_close())
m_poly_flags |= path_flags_close;
if (m_vertices > 2)
{
m_vpgen.line_to(m_start_x, m_start_y);
}
@@ -137,11 +147,11 @@ namespace agg
else
{
// path_cmd_stop
if(m_vpgen.auto_close() && m_vertices > 2)
if (m_vpgen.auto_close() && m_vertices > 2)
{
m_vpgen.line_to(m_start_x, m_start_y);
m_poly_flags = path_cmd_end_poly | path_flags_close;
m_vertices = -2;
m_vertices = -2;
continue;
}
break;
@@ -151,9 +161,6 @@ namespace agg
return cmd;
}
}
#endif

View File

@@ -2,8 +2,8 @@
// 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.
// 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.
//
@@ -19,30 +19,35 @@
#include "agg_vcgen_bspline.h"
#include "agg_conv_adaptor_vcgen.h"
namespace agg
{
//---------------------------------------------------------conv_bspline
template<class VertexSource>
template <class VertexSource>
struct conv_bspline : public conv_adaptor_vcgen<VertexSource, vcgen_bspline>
{
typedef conv_adaptor_vcgen<VertexSource, vcgen_bspline> base_type;
conv_bspline(VertexSource& vs) :
conv_adaptor_vcgen<VertexSource, vcgen_bspline>(vs) {}
conv_bspline(VertexSource& vs):
conv_adaptor_vcgen<VertexSource, vcgen_bspline>(vs)
{
}
void interpolation_step(double v) { base_type::generator().interpolation_step(v); }
double interpolation_step() const { return base_type::generator().interpolation_step(); }
void interpolation_step(double v)
{
base_type::generator().interpolation_step(v);
}
double interpolation_step() const
{
return base_type::generator().interpolation_step();
}
private:
conv_bspline(const conv_bspline<VertexSource>&);
const conv_bspline<VertexSource>&
operator = (const conv_bspline<VertexSource>&);
const conv_bspline<VertexSource>& operator=(
const conv_bspline<VertexSource>&);
};
}
#endif

View File

@@ -2,8 +2,8 @@
// 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.
// 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.
//
@@ -14,12 +14,12 @@
//----------------------------------------------------------------------------
//
// Polygon clipping converter
// There an optimized Liang-Basky algorithm is used.
// There an optimized Liang-Basky algorithm is used.
// The algorithm doesn't optimize the degenerate edges, i.e. it will never
// break a closed polygon into two or more ones, instead, there will be
// break a closed polygon into two or more ones, instead, there will be
// degenerate edges coinciding with the respective clipping boundaries.
// This is a sub-optimal solution, because that optimization would require
// extra, rather expensive math while the rasterizer tolerates it quite well,
// This is a sub-optimal solution, because that optimization would require
// extra, rather expensive math while the rasterizer tolerates it quite well,
// without any considerable overhead.
//
//----------------------------------------------------------------------------
@@ -34,28 +34,43 @@ namespace agg
{
//=======================================================conv_clip_polygon
template<class VertexSource>
struct conv_clip_polygon : public conv_adaptor_vpgen<VertexSource, vpgen_clip_polygon>
template <class VertexSource>
struct conv_clip_polygon :
public conv_adaptor_vpgen<VertexSource, vpgen_clip_polygon>
{
typedef conv_adaptor_vpgen<VertexSource, vpgen_clip_polygon> base_type;
conv_clip_polygon(VertexSource& vs) :
conv_adaptor_vpgen<VertexSource, vpgen_clip_polygon>(vs) {}
conv_clip_polygon(VertexSource& vs):
conv_adaptor_vpgen<VertexSource, vpgen_clip_polygon>(vs)
{
}
void clip_box(double x1, double y1, double x2, double y2)
{
base_type::vpgen().clip_box(x1, y1, x2, y2);
}
double x1() const { return base_type::vpgen().x1(); }
double y1() const { return base_type::vpgen().y1(); }
double x2() const { return base_type::vpgen().x2(); }
double y2() const { return base_type::vpgen().y2(); }
double x1() const
{
return base_type::vpgen().x1();
}
double y1() const
{
return base_type::vpgen().y1();
}
double x2() const
{
return base_type::vpgen().x2();
}
double y2() const
{
return base_type::vpgen().y2();
}
private:
conv_clip_polygon(const conv_clip_polygon<VertexSource>&);
const conv_clip_polygon<VertexSource>&
operator = (const conv_clip_polygon<VertexSource>&);
const conv_clip_polygon<VertexSource>& operator=(
const conv_clip_polygon<VertexSource>&);
};
}

View File

@@ -2,8 +2,8 @@
// 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.
// 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.
//
@@ -14,12 +14,12 @@
//----------------------------------------------------------------------------
//
// polyline clipping converter
// There an optimized Liang-Basky algorithm is used.
// There an optimized Liang-Basky algorithm is used.
// The algorithm doesn't optimize the degenerate edges, i.e. it will never
// break a closed polyline into two or more ones, instead, there will be
// break a closed polyline into two or more ones, instead, there will be
// degenerate edges coinciding with the respective clipping boundaries.
// This is a sub-optimal solution, because that optimization would require
// extra, rather expensive math while the rasterizer tolerates it quite well,
// This is a sub-optimal solution, because that optimization would require
// extra, rather expensive math while the rasterizer tolerates it quite well,
// without any considerable overhead.
//
//----------------------------------------------------------------------------
@@ -34,28 +34,43 @@ namespace agg
{
//=======================================================conv_clip_polyline
template<class VertexSource>
struct conv_clip_polyline : public conv_adaptor_vpgen<VertexSource, vpgen_clip_polyline>
template <class VertexSource>
struct conv_clip_polyline :
public conv_adaptor_vpgen<VertexSource, vpgen_clip_polyline>
{
typedef conv_adaptor_vpgen<VertexSource, vpgen_clip_polyline> base_type;
conv_clip_polyline(VertexSource& vs) :
conv_adaptor_vpgen<VertexSource, vpgen_clip_polyline>(vs) {}
conv_clip_polyline(VertexSource& vs):
conv_adaptor_vpgen<VertexSource, vpgen_clip_polyline>(vs)
{
}
void clip_box(double x1, double y1, double x2, double y2)
{
base_type::vpgen().clip_box(x1, y1, x2, y2);
}
double x1() const { return base_type::vpgen().x1(); }
double y1() const { return base_type::vpgen().y1(); }
double x2() const { return base_type::vpgen().x2(); }
double y2() const { return base_type::vpgen().y2(); }
double x1() const
{
return base_type::vpgen().x1();
}
double y1() const
{
return base_type::vpgen().y1();
}
double x2() const
{
return base_type::vpgen().x2();
}
double y2() const
{
return base_type::vpgen().y2();
}
private:
conv_clip_polyline(const conv_clip_polyline<VertexSource>&);
const conv_clip_polyline<VertexSource>&
operator = (const conv_clip_polyline<VertexSource>&);
const conv_clip_polyline<VertexSource>& operator=(
const conv_clip_polyline<VertexSource>&);
};
}

View File

@@ -2,8 +2,8 @@
// 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.
// 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.
//
@@ -22,32 +22,34 @@ namespace agg
{
//======================================================conv_close_polygon
template<class VertexSource> class conv_close_polygon
template <class VertexSource>
class conv_close_polygon
{
public:
explicit conv_close_polygon(VertexSource& vs) : m_source(&vs) {}
void attach(VertexSource& source) { m_source = &source; }
explicit conv_close_polygon(VertexSource& vs): m_source(&vs) {}
void attach(VertexSource& source)
{
m_source = &source;
}
void rewind(unsigned path_id);
unsigned vertex(double* x, double* y);
private:
conv_close_polygon(const conv_close_polygon<VertexSource>&);
const conv_close_polygon<VertexSource>&
operator = (const conv_close_polygon<VertexSource>&);
const conv_close_polygon<VertexSource>& operator=(
const conv_close_polygon<VertexSource>&);
VertexSource* m_source;
unsigned m_cmd[2];
double m_x[2];
double m_y[2];
unsigned m_vertex;
bool m_line_to;
unsigned m_cmd[2];
double m_x[2];
double m_y[2];
unsigned m_vertex;
bool m_line_to;
};
//------------------------------------------------------------------------
template<class VertexSource>
template <class VertexSource>
void conv_close_polygon<VertexSource>::rewind(unsigned path_id)
{
m_source->rewind(path_id);
@@ -55,16 +57,14 @@ namespace agg
m_line_to = false;
}
//------------------------------------------------------------------------
template<class VertexSource>
template <class VertexSource>
unsigned conv_close_polygon<VertexSource>::vertex(double* x, double* y)
{
unsigned cmd = path_cmd_stop;
for(;;)
for (;;)
{
if(m_vertex < 2)
if (m_vertex < 2)
{
*x = m_x[m_vertex];
*y = m_y[m_vertex];
@@ -75,43 +75,43 @@ namespace agg
cmd = m_source->vertex(x, y);
if(is_end_poly(cmd))
if (is_end_poly(cmd))
{
cmd |= path_flags_close;
break;
}
if(is_stop(cmd))
if (is_stop(cmd))
{
if(m_line_to)
if (m_line_to)
{
m_cmd[0] = path_cmd_end_poly | path_flags_close;
m_cmd[1] = path_cmd_stop;
m_vertex = 0;
m_cmd[0] = path_cmd_end_poly | path_flags_close;
m_cmd[1] = path_cmd_stop;
m_vertex = 0;
m_line_to = false;
continue;
}
break;
}
if(is_move_to(cmd))
if (is_move_to(cmd))
{
if(m_line_to)
if (m_line_to)
{
m_x[0] = 0.0;
m_y[0] = 0.0;
m_cmd[0] = path_cmd_end_poly | path_flags_close;
m_x[1] = *x;
m_y[1] = *y;
m_cmd[1] = cmd;
m_vertex = 0;
m_x[0] = 0.0;
m_y[0] = 0.0;
m_cmd[0] = path_cmd_end_poly | path_flags_close;
m_x[1] = *x;
m_y[1] = *y;
m_cmd[1] = cmd;
m_vertex = 0;
m_line_to = false;
continue;
}
break;
}
if(is_vertex(cmd))
if (is_vertex(cmd))
{
m_line_to = true;
break;

View File

@@ -2,8 +2,8 @@
// 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.
// 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.
//
@@ -21,19 +21,29 @@
namespace agg
{
//=============================================================conv_concat
// Concatenation of two paths. Usually used to combine lines or curves
// Concatenation of two paths. Usually used to combine lines or curves
// with markers such as arrowheads
template<class VS1, class VS2> class conv_concat
template <class VS1, class VS2>
class conv_concat
{
public:
conv_concat(VS1& source1, VS2& source2) :
m_source1(&source1), m_source2(&source2), m_status(2) {}
void attach1(VS1& source) { m_source1 = &source; }
void attach2(VS2& source) { m_source2 = &source; }
conv_concat(VS1& source1, VS2& source2):
m_source1(&source1),
m_source2(&source2),
m_status(2)
{
}
void attach1(VS1& source)
{
m_source1 = &source;
}
void attach2(VS2& source)
{
m_source2 = &source;
}
void rewind(unsigned path_id)
{
{
m_source1->rewind(path_id);
m_source2->rewind(0);
m_status = 0;
@@ -42,16 +52,18 @@ namespace agg
unsigned vertex(double* x, double* y)
{
unsigned cmd;
if(m_status == 0)
if (m_status == 0)
{
cmd = m_source1->vertex(x, y);
if(!is_stop(cmd)) return cmd;
if (!is_stop(cmd))
return cmd;
m_status = 1;
}
if(m_status == 1)
if (m_status == 1)
{
cmd = m_source2->vertex(x, y);
if(!is_stop(cmd)) return cmd;
if (!is_stop(cmd))
return cmd;
m_status = 2;
}
return path_cmd_stop;
@@ -59,15 +71,12 @@ namespace agg
private:
conv_concat(const conv_concat<VS1, VS2>&);
const conv_concat<VS1, VS2>&
operator = (const conv_concat<VS1, VS2>&);
const conv_concat<VS1, VS2>& operator=(const conv_concat<VS1, VS2>&);
VS1* m_source1;
VS2* m_source2;
int m_status;
int m_status;
};
}
#endif

View File

@@ -2,8 +2,8 @@
// 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.
// 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.
//
@@ -27,37 +27,82 @@ namespace agg
{
//-----------------------------------------------------------conv_contour
template<class VertexSource>
template <class VertexSource>
struct conv_contour : public conv_adaptor_vcgen<VertexSource, vcgen_contour>
{
typedef conv_adaptor_vcgen<VertexSource, vcgen_contour> base_type;
conv_contour(VertexSource& vs) :
conv_contour(VertexSource& vs):
conv_adaptor_vcgen<VertexSource, vcgen_contour>(vs)
{
}
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); }
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); }
void auto_detect_orientation(bool v) { base_type::generator().auto_detect_orientation(v); }
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);
}
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);
}
void auto_detect_orientation(bool v)
{
base_type::generator().auto_detect_orientation(v);
}
line_join_e line_join() const { return base_type::generator().line_join(); }
inner_join_e inner_join() const { return base_type::generator().inner_join(); }
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(); }
bool auto_detect_orientation() const { return base_type::generator().auto_detect_orientation(); }
line_join_e line_join() const
{
return base_type::generator().line_join();
}
inner_join_e inner_join() const
{
return base_type::generator().inner_join();
}
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();
}
bool auto_detect_orientation() const
{
return base_type::generator().auto_detect_orientation();
}
private:
conv_contour(const conv_contour<VertexSource>&);
const conv_contour<VertexSource>&
operator = (const conv_contour<VertexSource>&);
const conv_contour<VertexSource>& operator=(
const conv_contour<VertexSource>&);
};
}

View File

@@ -2,8 +2,8 @@
// 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.
// 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.
//
@@ -26,106 +26,109 @@
namespace agg
{
//---------------------------------------------------------------conv_curve
// Curve converter class. Any path storage can have Bezier curves defined
// by their control points. There're two types of curves supported: curve3
// Curve converter class. Any path storage can have Bezier curves defined
// by their control points. There're two types of curves supported: curve3
// and curve4. Curve3 is a conic Bezier curve with 2 endpoints and 1 control
// point. Curve4 has 2 control points (4 points in total) and can be used
// to interpolate more complicated curves. Curve4, unlike curve3 can be used
// to approximate arcs, both circular and elliptical. Curves are approximated
// with straight lines and one of the approaches is just to store the whole
// sequence of vertices that approximate our curve. It takes additional
// memory, and at the same time the consecutive vertices can be calculated
// on demand.
// to interpolate more complicated curves. Curve4, unlike curve3 can be used
// to approximate arcs, both circular and elliptical. Curves are
// approximated with straight lines and one of the approaches is just to
// store the whole sequence of vertices that approximate our curve. It takes
// additional memory, and at the same time the consecutive vertices can be
// calculated on demand.
//
// Initially, path storages are not suppose to keep all the vertices of the
// curves (although, nothing prevents us from doing so). Instead, path_storage
// keeps only vertices, needed to calculate a curve on demand. Those vertices
// are marked with special commands. So, if the path_storage contains curves
// (which are not real curves yet), and we render this storage directly,
// all we will see is only 2 or 3 straight line segments (for curve3 and
// curve4 respectively). If we need to see real curves drawn we need to
// include this class into the conversion pipeline.
// curves (although, nothing prevents us from doing so). Instead,
// path_storage keeps only vertices, needed to calculate a curve on demand.
// Those vertices are marked with special commands. So, if the path_storage
// contains curves (which are not real curves yet), and we render this
// storage directly, all we will see is only 2 or 3 straight line segments
// (for curve3 and curve4 respectively). If we need to see real curves drawn
// we need to include this class into the conversion pipeline.
//
// Class conv_curve recognizes commands path_cmd_curve3 and path_cmd_curve4
// and converts these vertices into a move_to/line_to sequence.
// Class conv_curve recognizes commands path_cmd_curve3 and path_cmd_curve4
// and converts these vertices into a move_to/line_to sequence.
//-----------------------------------------------------------------------
template<class VertexSource,
class Curve3=curve3,
class Curve4=curve4> class conv_curve
template <class VertexSource, class Curve3 = curve3, class Curve4 = curve4>
class conv_curve
{
public:
typedef Curve3 curve3_type;
typedef Curve4 curve4_type;
typedef conv_curve<VertexSource, Curve3, Curve4> self_type;
explicit conv_curve(VertexSource& source) :
m_source(&source), m_last_x(0.0), m_last_y(0.0) {}
void attach(VertexSource& source) { m_source = &source; }
explicit conv_curve(VertexSource& source):
m_source(&source),
m_last_x(0.0),
m_last_y(0.0)
{
}
void attach(VertexSource& source)
{
m_source = &source;
}
void approximation_method(curve_approximation_method_e v)
{
void approximation_method(curve_approximation_method_e v)
{
m_curve3.approximation_method(v);
m_curve4.approximation_method(v);
}
curve_approximation_method_e approximation_method() const
{
curve_approximation_method_e approximation_method() const
{
return m_curve4.approximation_method();
}
void approximation_scale(double s)
{
m_curve3.approximation_scale(s);
m_curve4.approximation_scale(s);
void approximation_scale(double s)
{
m_curve3.approximation_scale(s);
m_curve4.approximation_scale(s);
}
double approximation_scale() const
{
return m_curve4.approximation_scale();
double approximation_scale() const
{
return m_curve4.approximation_scale();
}
void angle_tolerance(double v)
{
m_curve3.angle_tolerance(v);
m_curve4.angle_tolerance(v);
void angle_tolerance(double v)
{
m_curve3.angle_tolerance(v);
m_curve4.angle_tolerance(v);
}
double angle_tolerance() const
{
return m_curve4.angle_tolerance();
double angle_tolerance() const
{
return m_curve4.angle_tolerance();
}
void cusp_limit(double v)
{
m_curve3.cusp_limit(v);
m_curve4.cusp_limit(v);
void cusp_limit(double v)
{
m_curve3.cusp_limit(v);
m_curve4.cusp_limit(v);
}
double cusp_limit() const
{
return m_curve4.cusp_limit();
double cusp_limit() const
{
return m_curve4.cusp_limit();
}
void rewind(unsigned path_id);
void rewind(unsigned path_id);
unsigned vertex(double* x, double* y);
private:
conv_curve(const self_type&);
const self_type& operator = (const self_type&);
const self_type& operator=(const self_type&);
VertexSource* m_source;
double m_last_x;
double m_last_y;
curve3_type m_curve3;
curve4_type m_curve4;
double m_last_x;
double m_last_y;
curve3_type m_curve3;
curve4_type m_curve4;
};
//------------------------------------------------------------------------
template<class VertexSource, class Curve3, class Curve4>
template <class VertexSource, class Curve3, class Curve4>
void conv_curve<VertexSource, Curve3, Curve4>::rewind(unsigned path_id)
{
m_source->rewind(path_id);
@@ -135,19 +138,19 @@ namespace agg
m_curve4.reset();
}
//------------------------------------------------------------------------
template<class VertexSource, class Curve3, class Curve4>
unsigned conv_curve<VertexSource, Curve3, Curve4>::vertex(double* x, double* y)
template <class VertexSource, class Curve3, class Curve4>
unsigned conv_curve<VertexSource, Curve3, Curve4>::vertex(
double* x, double* y)
{
if(!is_stop(m_curve3.vertex(x, y)))
if (!is_stop(m_curve3.vertex(x, y)))
{
m_last_x = *x;
m_last_y = *y;
return path_cmd_line_to;
}
if(!is_stop(m_curve4.vertex(x, y)))
if (!is_stop(m_curve4.vertex(x, y)))
{
m_last_x = *x;
m_last_y = *y;
@@ -160,42 +163,35 @@ namespace agg
double end_y = 0;
unsigned cmd = m_source->vertex(x, y);
switch(cmd)
switch (cmd)
{
case path_cmd_curve3:
m_source->vertex(&end_x, &end_y);
case path_cmd_curve3:
m_source->vertex(&end_x, &end_y);
m_curve3.init(m_last_x, m_last_y,
*x, *y,
end_x, end_y);
m_curve3.init(m_last_x, m_last_y, *x, *y, end_x, end_y);
m_curve3.vertex(x, y); // First call returns path_cmd_move_to
m_curve3.vertex(x, y); // This is the first vertex of the curve
cmd = path_cmd_line_to;
break;
m_curve3.vertex(x, y); // First call returns path_cmd_move_to
m_curve3.vertex(x, y); // This is the first vertex of the curve
cmd = path_cmd_line_to;
break;
case path_cmd_curve4:
m_source->vertex(&ct2_x, &ct2_y);
m_source->vertex(&end_x, &end_y);
case path_cmd_curve4:
m_source->vertex(&ct2_x, &ct2_y);
m_source->vertex(&end_x, &end_y);
m_curve4.init(m_last_x, m_last_y,
*x, *y,
ct2_x, ct2_y,
end_x, end_y);
m_curve4.init(
m_last_x, m_last_y, *x, *y, ct2_x, ct2_y, end_x, end_y);
m_curve4.vertex(x, y); // First call returns path_cmd_move_to
m_curve4.vertex(x, y); // This is the first vertex of the curve
cmd = path_cmd_line_to;
break;
m_curve4.vertex(x, y); // First call returns path_cmd_move_to
m_curve4.vertex(x, y); // This is the first vertex of the curve
cmd = path_cmd_line_to;
break;
}
m_last_x = *x;
m_last_y = *y;
return cmd;
}
}
#endif

View File

@@ -2,8 +2,8 @@
// 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.
// 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.
//
@@ -27,42 +27,48 @@ namespace agg
{
//---------------------------------------------------------------conv_dash
template<class VertexSource, class Markers=null_markers>
struct conv_dash : public conv_adaptor_vcgen<VertexSource, vcgen_dash, Markers>
template <class VertexSource, class Markers = null_markers>
struct conv_dash :
public conv_adaptor_vcgen<VertexSource, vcgen_dash, Markers>
{
typedef Markers marker_type;
typedef conv_adaptor_vcgen<VertexSource, vcgen_dash, Markers> base_type;
conv_dash(VertexSource& vs) :
conv_dash(VertexSource& vs):
conv_adaptor_vcgen<VertexSource, vcgen_dash, Markers>(vs)
{
}
void remove_all_dashes()
{
base_type::generator().remove_all_dashes();
void remove_all_dashes()
{
base_type::generator().remove_all_dashes();
}
void add_dash(double dash_len, double gap_len)
{
base_type::generator().add_dash(dash_len, gap_len);
void add_dash(double dash_len, double gap_len)
{
base_type::generator().add_dash(dash_len, gap_len);
}
void dash_start(double ds)
{
base_type::generator().dash_start(ds);
void dash_start(double ds)
{
base_type::generator().dash_start(ds);
}
void shorten(double s) { base_type::generator().shorten(s); }
double shorten() const { return base_type::generator().shorten(); }
void shorten(double s)
{
base_type::generator().shorten(s);
}
double shorten() const
{
return base_type::generator().shorten();
}
private:
conv_dash(const conv_dash<VertexSource, Markers>&);
const conv_dash<VertexSource, Markers>&
operator = (const conv_dash<VertexSource, Markers>&);
const conv_dash<VertexSource, Markers>& operator=(
const conv_dash<VertexSource, Markers>&);
};
}
#endif

View File

@@ -2,8 +2,8 @@
// 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.
// 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.
//
@@ -13,7 +13,7 @@
// http://www.antigrain.com
//----------------------------------------------------------------------------
//
// General Polygon Clipper based on the GPC library by Alan Murta
// General Polygon Clipper based on the GPC library by Alan Murta
// Union, Intersection, XOR, A-B, B-A
// Contact the author if you intend to use it in commercial applications!
// http://www.cs.man.ac.uk/aig/staff/alan/software/
@@ -28,9 +28,9 @@
#include "agg_basics.h"
#include "agg_array.h"
extern "C"
{
#include "gpc.h"
extern "C"
{
#include "gpc.h"
}
namespace agg
@@ -44,9 +44,9 @@ namespace agg
gpc_b_minus_a
};
//================================================================conv_gpc
template<class VSA, class VSB> class conv_gpc
template <class VSA, class VSB>
class conv_gpc
{
enum status
{
@@ -62,10 +62,9 @@ namespace agg
gpc_vertex* vertices;
};
typedef pod_bvector<gpc_vertex, 8> vertex_array_type;
typedef pod_bvector<gpc_vertex, 8> vertex_array_type;
typedef pod_bvector<contour_header_type, 6> contour_header_array_type;
public:
typedef VSA source_a_type;
typedef VSB source_b_type;
@@ -76,7 +75,7 @@ namespace agg
free_gpc_data();
}
conv_gpc(source_a_type& a, source_b_type& b, gpc_op_e op = gpc_or) :
conv_gpc(source_a_type& a, source_b_type& b, gpc_op_e op = gpc_or):
m_src_a(&a),
m_src_b(&b),
m_status(status_move_to),
@@ -89,18 +88,27 @@ namespace agg
std::memset(&m_result, 0, sizeof(m_result));
}
void attach1(VSA& source) { m_src_a = &source; }
void attach2(VSB& source) { m_src_b = &source; }
void attach1(VSA& source)
{
m_src_a = &source;
}
void attach2(VSB& source)
{
m_src_b = &source;
}
void operation(gpc_op_e v) { m_operation = v; }
void operation(gpc_op_e v)
{
m_operation = v;
}
// Vertex Source Interface
void rewind(unsigned path_id);
void rewind(unsigned path_id);
unsigned vertex(double* x, double* y);
private:
conv_gpc(const conv_gpc<VSA, VSB>&);
const conv_gpc<VSA, VSB>& operator = (const conv_gpc<VSA, VSB>&);
const conv_gpc<VSA, VSB>& operator=(const conv_gpc<VSA, VSB>&);
//--------------------------------------------------------------------
void free_polygon(gpc_polygon& p);
@@ -114,9 +122,9 @@ namespace agg
bool next_contour();
bool next_vertex(double* x, double* y);
//--------------------------------------------------------------------
template<class VS> void add(VS& src, gpc_polygon& p)
template <class VS>
void add(VS& src, gpc_polygon& p)
{
unsigned cmd;
double x, y;
@@ -127,13 +135,13 @@ namespace agg
m_contour_accumulator.remove_all();
while(!is_stop(cmd = src.vertex(&x, &y)))
while (!is_stop(cmd = src.vertex(&x, &y)))
{
if(is_vertex(cmd))
if (is_vertex(cmd))
{
if(is_move_to(cmd))
if (is_move_to(cmd))
{
if(line_to)
if (line_to)
{
end_contour(orientation);
orientation = 0;
@@ -147,72 +155,65 @@ namespace agg
}
else
{
if(is_end_poly(cmd))
if (is_end_poly(cmd))
{
orientation = get_orientation(cmd);
if(line_to && is_closed(cmd))
if (line_to && is_closed(cmd))
{
add_vertex(start_x, start_y);
}
}
}
}
if(line_to)
if (line_to)
{
end_contour(orientation);
}
make_polygon(p);
}
private:
//--------------------------------------------------------------------
source_a_type* m_src_a;
source_b_type* m_src_b;
status m_status;
int m_vertex;
int m_contour;
gpc_op_e m_operation;
vertex_array_type m_vertex_accumulator;
contour_header_array_type m_contour_accumulator;
gpc_polygon m_poly_a;
gpc_polygon m_poly_b;
gpc_polygon m_result;
source_a_type* m_src_a;
source_b_type* m_src_b;
status m_status;
int m_vertex;
int m_contour;
gpc_op_e m_operation;
vertex_array_type m_vertex_accumulator;
contour_header_array_type m_contour_accumulator;
gpc_polygon m_poly_a;
gpc_polygon m_poly_b;
gpc_polygon m_result;
};
//------------------------------------------------------------------------
template<class VSA, class VSB>
template <class VSA, class VSB>
void conv_gpc<VSA, VSB>::free_polygon(gpc_polygon& p)
{
int i;
for(i = 0; i < p.num_contours; i++)
for (i = 0; i < p.num_contours; i++)
{
pod_allocator<gpc_vertex>::deallocate(p.contour[i].vertex,
p.contour[i].num_vertices);
pod_allocator<gpc_vertex>::deallocate(
p.contour[i].vertex, p.contour[i].num_vertices);
}
pod_allocator<gpc_vertex_list>::deallocate(p.contour, p.num_contours);
std::memset(&p, 0, sizeof(gpc_polygon));
}
//------------------------------------------------------------------------
template<class VSA, class VSB>
template <class VSA, class VSB>
void conv_gpc<VSA, VSB>::free_result()
{
if(m_result.contour)
if (m_result.contour)
{
gpc_free_polygon(&m_result);
}
std::memset(&m_result, 0, sizeof(m_result));
}
//------------------------------------------------------------------------
template<class VSA, class VSB>
template <class VSA, class VSB>
void conv_gpc<VSA, VSB>::free_gpc_data()
{
free_polygon(m_poly_a);
@@ -220,9 +221,8 @@ namespace agg
free_result();
}
//------------------------------------------------------------------------
template<class VSA, class VSB>
template <class VSA, class VSB>
void conv_gpc<VSA, VSB>::start_contour()
{
contour_header_type h;
@@ -231,9 +231,8 @@ namespace agg
m_vertex_accumulator.remove_all();
}
//------------------------------------------------------------------------
template<class VSA, class VSB>
template <class VSA, class VSB>
inline void conv_gpc<VSA, VSB>::add_vertex(double x, double y)
{
gpc_vertex v;
@@ -242,28 +241,28 @@ namespace agg
m_vertex_accumulator.add(v);
}
//------------------------------------------------------------------------
template<class VSA, class VSB>
template <class VSA, class VSB>
void conv_gpc<VSA, VSB>::end_contour(unsigned /*orientation*/)
{
if(m_contour_accumulator.size())
if (m_contour_accumulator.size())
{
if(m_vertex_accumulator.size() > 2)
if (m_vertex_accumulator.size() > 2)
{
contour_header_type& h =
contour_header_type& h =
m_contour_accumulator[m_contour_accumulator.size() - 1];
h.num_vertices = m_vertex_accumulator.size();
h.hole_flag = 0;
// TO DO: Clarify the "holes"
//if(is_cw(orientation)) h.hole_flag = 1;
// if(is_cw(orientation)) h.hole_flag = 1;
h.vertices = pod_allocator<gpc_vertex>::allocate(h.num_vertices);
h.vertices =
pod_allocator<gpc_vertex>::allocate(h.num_vertices);
gpc_vertex* d = h.vertices;
int i;
for(i = 0; i < h.num_vertices; i++)
for (i = 0; i < h.num_vertices; i++)
{
const gpc_vertex& s = m_vertex_accumulator[i];
d->x = s.x;
@@ -278,22 +277,22 @@ namespace agg
}
}
//------------------------------------------------------------------------
template<class VSA, class VSB>
template <class VSA, class VSB>
void conv_gpc<VSA, VSB>::make_polygon(gpc_polygon& p)
{
free_polygon(p);
if(m_contour_accumulator.size())
if (m_contour_accumulator.size())
{
p.num_contours = m_contour_accumulator.size();
p.hole = 0;
p.contour = pod_allocator<gpc_vertex_list>::allocate(p.num_contours);
p.contour =
pod_allocator<gpc_vertex_list>::allocate(p.num_contours);
int i;
gpc_vertex_list* pv = p.contour;
for(i = 0; i < p.num_contours; i++)
for (i = 0; i < p.num_contours; i++)
{
const contour_header_type& h = m_contour_accumulator[i];
pv->num_vertices = h.num_vertices;
@@ -303,9 +302,8 @@ namespace agg
}
}
//------------------------------------------------------------------------
template<class VSA, class VSB>
template <class VSA, class VSB>
void conv_gpc<VSA, VSB>::start_extracting()
{
m_status = status_move_to;
@@ -313,12 +311,11 @@ namespace agg
m_vertex = -1;
}
//------------------------------------------------------------------------
template<class VSA, class VSB>
template <class VSA, class VSB>
bool conv_gpc<VSA, VSB>::next_contour()
{
if(++m_contour < m_result.num_contours)
if (++m_contour < m_result.num_contours)
{
m_vertex = -1;
return true;
@@ -326,13 +323,12 @@ namespace agg
return false;
}
//------------------------------------------------------------------------
template<class VSA, class VSB>
template <class VSA, class VSB>
inline bool conv_gpc<VSA, VSB>::next_vertex(double* x, double* y)
{
const gpc_vertex_list& vlist = m_result.contour[m_contour];
if(++m_vertex < vlist.num_vertices)
if (++m_vertex < vlist.num_vertices)
{
const gpc_vertex& v = vlist.vertex[m_vertex];
*x = v.x;
@@ -342,9 +338,8 @@ namespace agg
return false;
}
//------------------------------------------------------------------------
template<class VSA, class VSB>
template <class VSA, class VSB>
void conv_gpc<VSA, VSB>::rewind(unsigned path_id)
{
free_result();
@@ -352,56 +347,40 @@ namespace agg
m_src_b->rewind(path_id);
add(*m_src_a, m_poly_a);
add(*m_src_b, m_poly_b);
switch(m_operation)
switch (m_operation)
{
case gpc_or:
gpc_polygon_clip(GPC_UNION,
&m_poly_a,
&m_poly_b,
&m_result);
break;
case gpc_or:
gpc_polygon_clip(GPC_UNION, &m_poly_a, &m_poly_b, &m_result);
break;
case gpc_and:
gpc_polygon_clip(GPC_INT,
&m_poly_a,
&m_poly_b,
&m_result);
break;
case gpc_and:
gpc_polygon_clip(GPC_INT, &m_poly_a, &m_poly_b, &m_result);
break;
case gpc_xor:
gpc_polygon_clip(GPC_XOR,
&m_poly_a,
&m_poly_b,
&m_result);
break;
case gpc_xor:
gpc_polygon_clip(GPC_XOR, &m_poly_a, &m_poly_b, &m_result);
break;
case gpc_a_minus_b:
gpc_polygon_clip(GPC_DIFF,
&m_poly_a,
&m_poly_b,
&m_result);
break;
case gpc_a_minus_b:
gpc_polygon_clip(GPC_DIFF, &m_poly_a, &m_poly_b, &m_result);
break;
case gpc_b_minus_a:
gpc_polygon_clip(GPC_DIFF,
&m_poly_b,
&m_poly_a,
&m_result);
break;
case gpc_b_minus_a:
gpc_polygon_clip(GPC_DIFF, &m_poly_b, &m_poly_a, &m_result);
break;
}
start_extracting();
}
//------------------------------------------------------------------------
template<class VSA, class VSB>
template <class VSA, class VSB>
unsigned conv_gpc<VSA, VSB>::vertex(double* x, double* y)
{
if(m_status == status_move_to)
if (m_status == status_move_to)
{
if(next_contour())
if (next_contour())
{
if(next_vertex(x, y))
if (next_vertex(x, y))
{
m_status = status_line_to;
return path_cmd_move_to;
@@ -412,7 +391,7 @@ namespace agg
}
else
{
if(next_vertex(x, y))
if (next_vertex(x, y))
{
return path_cmd_line_to;
}
@@ -425,8 +404,6 @@ namespace agg
return path_cmd_stop;
}
}
#endif

View File

@@ -2,8 +2,8 @@
// 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.
// 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.
//
@@ -26,24 +26,30 @@
namespace agg
{
//-------------------------------------------------------------conv_marker
template<class MarkerLocator, class MarkerShapes>
template <class MarkerLocator, class MarkerShapes>
class conv_marker
{
public:
conv_marker(MarkerLocator& ml, MarkerShapes& ms);
trans_affine& transform() { return m_transform; }
const trans_affine& transform() const { return m_transform; }
trans_affine& transform()
{
return m_transform;
}
const trans_affine& transform() const
{
return m_transform;
}
void rewind(unsigned path_id);
unsigned vertex(double* x, double* y);
private:
conv_marker(const conv_marker<MarkerLocator, MarkerShapes>&);
const conv_marker<MarkerLocator, MarkerShapes>&
operator = (const conv_marker<MarkerLocator, MarkerShapes>&);
const conv_marker<MarkerLocator, MarkerShapes>& operator=(
const conv_marker<MarkerLocator, MarkerShapes>&);
enum status_e
enum status_e
{
initial,
markers,
@@ -52,18 +58,18 @@ namespace agg
};
MarkerLocator* m_marker_locator;
MarkerShapes* m_marker_shapes;
trans_affine m_transform;
trans_affine m_mtx;
status_e m_status;
unsigned m_marker;
unsigned m_num_markers;
MarkerShapes* m_marker_shapes;
trans_affine m_transform;
trans_affine m_mtx;
status_e m_status;
unsigned m_marker;
unsigned m_num_markers;
};
//------------------------------------------------------------------------
template<class MarkerLocator, class MarkerShapes>
conv_marker<MarkerLocator, MarkerShapes>::conv_marker(MarkerLocator& ml, MarkerShapes& ms) :
template <class MarkerLocator, class MarkerShapes>
conv_marker<MarkerLocator, MarkerShapes>::conv_marker(
MarkerLocator& ml, MarkerShapes& ms):
m_marker_locator(&ml),
m_marker_shapes(&ms),
m_status(initial),
@@ -72,9 +78,8 @@ namespace agg
{
}
//------------------------------------------------------------------------
template<class MarkerLocator, class MarkerShapes>
template <class MarkerLocator, class MarkerShapes>
void conv_marker<MarkerLocator, MarkerShapes>::rewind(unsigned)
{
m_status = initial;
@@ -82,61 +87,62 @@ namespace agg
m_num_markers = 1;
}
//------------------------------------------------------------------------
template<class MarkerLocator, class MarkerShapes>
unsigned conv_marker<MarkerLocator, MarkerShapes>::vertex(double* x, double* y)
template <class MarkerLocator, class MarkerShapes>
unsigned conv_marker<MarkerLocator, MarkerShapes>::vertex(
double* x, double* y)
{
unsigned cmd = path_cmd_move_to;
double x1, y1, x2, y2;
while(!is_stop(cmd))
while (!is_stop(cmd))
{
switch(m_status)
switch (m_status)
{
case initial:
if(m_num_markers == 0)
{
cmd = path_cmd_stop;
break;
}
m_marker_locator->rewind(m_marker);
++m_marker;
m_num_markers = 0;
m_status = markers;
case markers:
if(is_stop(m_marker_locator->vertex(&x1, &y1)))
{
m_status = initial;
break;
}
if(is_stop(m_marker_locator->vertex(&x2, &y2)))
{
m_status = initial;
break;
}
++m_num_markers;
m_mtx = m_transform;
m_mtx *= trans_affine_rotation(std::atan2(y2 - y1, x2 - x1));
m_mtx *= trans_affine_translation(x1, y1);
m_marker_shapes->rewind(m_marker - 1);
m_status = polygon;
case polygon:
cmd = m_marker_shapes->vertex(x, y);
if(is_stop(cmd))
{
cmd = path_cmd_move_to;
case initial:
if (m_num_markers == 0)
{
cmd = path_cmd_stop;
break;
}
m_marker_locator->rewind(m_marker);
++m_marker;
m_num_markers = 0;
m_status = markers;
break;
}
m_mtx.transform(x, y);
return cmd;
case stop:
cmd = path_cmd_stop;
break;
case markers:
if (is_stop(m_marker_locator->vertex(&x1, &y1)))
{
m_status = initial;
break;
}
if (is_stop(m_marker_locator->vertex(&x2, &y2)))
{
m_status = initial;
break;
}
++m_num_markers;
m_mtx = m_transform;
m_mtx *=
trans_affine_rotation(std::atan2(y2 - y1, x2 - x1));
m_mtx *= trans_affine_translation(x1, y1);
m_marker_shapes->rewind(m_marker - 1);
m_status = polygon;
case polygon:
cmd = m_marker_shapes->vertex(x, y);
if (is_stop(cmd))
{
cmd = path_cmd_move_to;
m_status = markers;
break;
}
m_mtx.transform(x, y);
return cmd;
case stop:
cmd = path_cmd_stop;
break;
}
}
return cmd;
@@ -144,6 +150,4 @@ namespace agg
}
#endif

View File

@@ -2,8 +2,8 @@
// 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.
// 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.
//
@@ -24,28 +24,34 @@ namespace agg
{
//=====================================================conv_marker_adaptor
template<class VertexSource, class Markers=null_markers>
struct conv_marker_adaptor :
public conv_adaptor_vcgen<VertexSource, vcgen_vertex_sequence, Markers>
template <class VertexSource, class Markers = null_markers>
struct conv_marker_adaptor :
public conv_adaptor_vcgen<VertexSource, vcgen_vertex_sequence, Markers>
{
typedef Markers marker_type;
typedef conv_adaptor_vcgen<VertexSource, vcgen_vertex_sequence, Markers> base_type;
typedef conv_adaptor_vcgen<VertexSource, vcgen_vertex_sequence, Markers>
base_type;
conv_marker_adaptor(VertexSource& vs) :
conv_marker_adaptor(VertexSource& vs):
conv_adaptor_vcgen<VertexSource, vcgen_vertex_sequence, Markers>(vs)
{
}
void shorten(double s) { base_type::generator().shorten(s); }
double shorten() const { return base_type::generator().shorten(); }
void shorten(double s)
{
base_type::generator().shorten(s);
}
double shorten() const
{
return base_type::generator().shorten();
}
private:
conv_marker_adaptor(const conv_marker_adaptor<VertexSource, Markers>&);
const conv_marker_adaptor<VertexSource, Markers>&
operator = (const conv_marker_adaptor<VertexSource, Markers>&);
const conv_marker_adaptor<VertexSource, Markers>& operator=(
const conv_marker_adaptor<VertexSource, Markers>&);
};
}
#endif

View File

@@ -2,8 +2,8 @@
// 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.
// 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.
//
@@ -24,25 +24,32 @@ namespace agg
{
//========================================================conv_segmentator
template<class VertexSource>
struct conv_segmentator : public conv_adaptor_vpgen<VertexSource, vpgen_segmentator>
template <class VertexSource>
struct conv_segmentator :
public conv_adaptor_vpgen<VertexSource, vpgen_segmentator>
{
typedef conv_adaptor_vpgen<VertexSource, vpgen_segmentator> base_type;
conv_segmentator(VertexSource& vs) :
conv_adaptor_vpgen<VertexSource, vpgen_segmentator>(vs) {}
conv_segmentator(VertexSource& vs):
conv_adaptor_vpgen<VertexSource, vpgen_segmentator>(vs)
{
}
void approximation_scale(double s) { base_type::vpgen().approximation_scale(s); }
double approximation_scale() const { return base_type::vpgen().approximation_scale(); }
void approximation_scale(double s)
{
base_type::vpgen().approximation_scale(s);
}
double approximation_scale() const
{
return base_type::vpgen().approximation_scale();
}
private:
conv_segmentator(const conv_segmentator<VertexSource>&);
const conv_segmentator<VertexSource>&
operator = (const conv_segmentator<VertexSource>&);
const conv_segmentator<VertexSource>& operator=(
const conv_segmentator<VertexSource>&);
};
}
#endif

View File

@@ -2,8 +2,8 @@
// 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.
// 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.
//
@@ -24,27 +24,34 @@ namespace agg
{
//=======================================================conv_shorten_path
template<class VertexSource> class conv_shorten_path :
public conv_adaptor_vcgen<VertexSource, vcgen_vertex_sequence>
template <class VertexSource>
class conv_shorten_path :
public conv_adaptor_vcgen<VertexSource, vcgen_vertex_sequence>
{
public:
typedef conv_adaptor_vcgen<VertexSource, vcgen_vertex_sequence> base_type;
typedef conv_adaptor_vcgen<VertexSource, vcgen_vertex_sequence>
base_type;
conv_shorten_path(VertexSource& vs) :
conv_shorten_path(VertexSource& vs):
conv_adaptor_vcgen<VertexSource, vcgen_vertex_sequence>(vs)
{
}
void shorten(double s) { base_type::generator().shorten(s); }
double shorten() const { return base_type::generator().shorten(); }
void shorten(double s)
{
base_type::generator().shorten(s);
}
double shorten() const
{
return base_type::generator().shorten();
}
private:
conv_shorten_path(const conv_shorten_path<VertexSource>&);
const conv_shorten_path<VertexSource>&
operator = (const conv_shorten_path<VertexSource>&);
const conv_shorten_path<VertexSource>& operator=(
const conv_shorten_path<VertexSource>&);
};
}
#endif

View File

@@ -2,8 +2,8 @@
// 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.
// 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.
//
@@ -24,57 +24,64 @@
#include "agg_conv_adaptor_vcgen.h"
#include "agg_conv_curve.h"
namespace agg
{
//-------------------------------------------------------conv_smooth_poly1
template<class VertexSource>
struct conv_smooth_poly1 :
public conv_adaptor_vcgen<VertexSource, vcgen_smooth_poly1>
template <class VertexSource>
struct conv_smooth_poly1 :
public conv_adaptor_vcgen<VertexSource, vcgen_smooth_poly1>
{
typedef conv_adaptor_vcgen<VertexSource, vcgen_smooth_poly1> base_type;
conv_smooth_poly1(VertexSource& vs) :
conv_smooth_poly1(VertexSource& vs):
conv_adaptor_vcgen<VertexSource, vcgen_smooth_poly1>(vs)
{
}
void smooth_value(double v) { base_type::generator().smooth_value(v); }
double smooth_value() const { return base_type::generator().smooth_value(); }
void smooth_value(double v)
{
base_type::generator().smooth_value(v);
}
double smooth_value() const
{
return base_type::generator().smooth_value();
}
private:
conv_smooth_poly1(const conv_smooth_poly1<VertexSource>&);
const conv_smooth_poly1<VertexSource>&
operator = (const conv_smooth_poly1<VertexSource>&);
const conv_smooth_poly1<VertexSource>& operator=(
const conv_smooth_poly1<VertexSource>&);
};
//-------------------------------------------------conv_smooth_poly1_curve
template<class VertexSource>
struct conv_smooth_poly1_curve :
public conv_curve<conv_smooth_poly1<VertexSource> >
template <class VertexSource>
struct conv_smooth_poly1_curve :
public conv_curve<conv_smooth_poly1<VertexSource>>
{
conv_smooth_poly1_curve(VertexSource& vs) :
conv_curve<conv_smooth_poly1<VertexSource> >(m_smooth),
conv_smooth_poly1_curve(VertexSource& vs):
conv_curve<conv_smooth_poly1<VertexSource>>(m_smooth),
m_smooth(vs)
{
}
void smooth_value(double v) { m_smooth.generator().smooth_value(v); }
double smooth_value() const { return m_smooth.generator().smooth_value(); }
void smooth_value(double v)
{
m_smooth.generator().smooth_value(v);
}
double smooth_value() const
{
return m_smooth.generator().smooth_value();
}
private:
conv_smooth_poly1_curve(const conv_smooth_poly1_curve<VertexSource>&);
const conv_smooth_poly1_curve<VertexSource>&
operator = (const conv_smooth_poly1_curve<VertexSource>&);
const conv_smooth_poly1_curve<VertexSource>& operator=(
const conv_smooth_poly1_curve<VertexSource>&);
conv_smooth_poly1<VertexSource> m_smooth;
};
}
#endif

View File

@@ -2,8 +2,8 @@
// 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.
// 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.
//
@@ -27,45 +27,96 @@ namespace agg
{
//-------------------------------------------------------------conv_stroke
template<class VertexSource, class Markers=null_markers>
struct conv_stroke :
public conv_adaptor_vcgen<VertexSource, vcgen_stroke, Markers>
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;
typedef conv_adaptor_vcgen<VertexSource, vcgen_stroke, Markers>
base_type;
conv_stroke(VertexSource& vs) :
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); }
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(); }
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); }
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(); }
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(); }
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>&);
conv_stroke(const conv_stroke<VertexSource, Markers>&);
const conv_stroke<VertexSource, Markers>& operator=(
const conv_stroke<VertexSource, Markers>&);
};
}

View File

@@ -2,8 +2,8 @@
// 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.
// 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.
//
@@ -26,22 +26,29 @@ namespace agg
{
//----------------------------------------------------------conv_transform
template<class VertexSource, class Transformer=trans_affine> class conv_transform
template <class VertexSource, class Transformer = trans_affine>
class conv_transform
{
public:
conv_transform(VertexSource& source, Transformer& tr) :
m_source(&source), m_trans(&tr) {}
void attach(VertexSource& source) { m_source = &source; }
conv_transform(VertexSource& source, Transformer& tr):
m_source(&source),
m_trans(&tr)
{
}
void attach(VertexSource& source)
{
m_source = &source;
}
void rewind(unsigned path_id)
{
m_source->rewind(path_id);
void rewind(unsigned path_id)
{
m_source->rewind(path_id);
}
unsigned vertex(double* x, double* y)
{
unsigned cmd = m_source->vertex(x, y);
if(is_vertex(cmd))
if (is_vertex(cmd))
{
m_trans->transform(x, y);
}
@@ -55,14 +62,13 @@ namespace agg
private:
conv_transform(const conv_transform<VertexSource>&);
const conv_transform<VertexSource>&
operator = (const conv_transform<VertexSource>&);
const conv_transform<VertexSource>& operator=(
const conv_transform<VertexSource>&);
VertexSource* m_source;
VertexSource* m_source;
Transformer* m_trans;
};
}
#endif

View File

@@ -2,8 +2,8 @@
// 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.
// 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.
//
@@ -21,11 +21,15 @@
namespace agg
{
//====================================================conv_unclose_polygon
template<class VertexSource> class conv_unclose_polygon
template <class VertexSource>
class conv_unclose_polygon
{
public:
explicit conv_unclose_polygon(VertexSource& vs) : m_source(&vs) {}
void attach(VertexSource& source) { m_source = &source; }
explicit conv_unclose_polygon(VertexSource& vs): m_source(&vs) {}
void attach(VertexSource& source)
{
m_source = &source;
}
void rewind(unsigned path_id)
{
@@ -35,14 +39,15 @@ namespace agg
unsigned vertex(double* x, double* y)
{
unsigned cmd = m_source->vertex(x, y);
if(is_end_poly(cmd)) cmd &= ~path_flags_close;
if (is_end_poly(cmd))
cmd &= ~path_flags_close;
return cmd;
}
private:
conv_unclose_polygon(const conv_unclose_polygon<VertexSource>&);
const conv_unclose_polygon<VertexSource>&
operator = (const conv_unclose_polygon<VertexSource>&);
const conv_unclose_polygon<VertexSource>& operator=(
const conv_unclose_polygon<VertexSource>&);
VertexSource* m_source;
};

View File

File diff suppressed because it is too large Load Diff

View File

@@ -2,8 +2,8 @@
// 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.
// 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.
//
@@ -27,14 +27,15 @@ namespace agg
{
//===================================================dda_line_interpolator
template<int FractionShift, int YShift=0> class 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) :
dda_line_interpolator(int y1, int y2, unsigned count):
m_y(y1),
m_inc(((y2 - y1) << FractionShift) / int(count)),
m_dy(0)
@@ -42,34 +43,38 @@ namespace agg
}
//--------------------------------------------------------------------
void operator ++ ()
void operator++()
{
m_dy += m_inc;
}
//--------------------------------------------------------------------
void operator -- ()
void operator--()
{
m_dy -= m_inc;
}
//--------------------------------------------------------------------
void operator += (unsigned n)
void operator+=(unsigned n)
{
m_dy += m_inc * n;
}
//--------------------------------------------------------------------
void operator -= (unsigned 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; }
int y() const
{
return m_y + (m_dy >> (FractionShift - YShift));
}
int dy() const
{
return m_dy;
}
private:
int m_y;
@@ -77,29 +82,28 @@ namespace agg
int m_dy;
};
//=================================================dda2_line_interpolator
class dda2_line_interpolator
{
public:
typedef int save_data_type;
enum save_size_e { save_size = 2 };
enum save_size_e
{
save_size = 2
};
//--------------------------------------------------------------------
dda2_line_interpolator() {}
//-------------------------------------------- Forward-adjusted line
dda2_line_interpolator(int y1, int y2, int count) :
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)
if (m_mod <= 0)
{
m_mod += count;
m_rem += count;
@@ -109,14 +113,14 @@ namespace agg
}
//-------------------------------------------- Backward-adjusted line
dda2_line_interpolator(int y1, int y2, int count, int) :
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)
if (m_mod <= 0)
{
m_mod += count;
m_rem += count;
@@ -125,14 +129,14 @@ namespace agg
}
//-------------------------------------------- Backward-adjusted line
dda2_line_interpolator(int y, int count) :
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)
if (m_mod <= 0)
{
m_mod += count;
m_rem += count;
@@ -140,7 +144,6 @@ namespace agg
}
}
//--------------------------------------------------------------------
void save(save_data_type* data) const
{
@@ -152,7 +155,7 @@ namespace agg
void load(const save_data_type* data)
{
m_mod = data[0];
m_y = data[1];
m_y = data[1];
}
//--------------------------------------------------------------------
@@ -160,7 +163,7 @@ namespace agg
{
m_mod += m_rem;
m_y += m_lft;
if(m_mod > 0)
if (m_mod > 0)
{
m_mod -= m_cnt;
m_y++;
@@ -170,7 +173,7 @@ namespace agg
//--------------------------------------------------------------------
void operator--()
{
if(m_mod <= m_rem)
if (m_mod <= m_rem)
{
m_mod += m_cnt;
m_y--;
@@ -192,12 +195,24 @@ namespace agg
}
//--------------------------------------------------------------------
int mod() const { return m_mod; }
int rem() const { return m_rem; }
int lft() const { return m_lft; }
int mod() const
{
return m_mod;
}
int rem() const
{
return m_rem;
}
int lft() const
{
return m_lft;
}
//--------------------------------------------------------------------
int y() const { return m_y; }
int y() const
{
return m_y;
}
private:
int m_cnt;
@@ -207,12 +222,6 @@ namespace agg
int m_y;
};
//---------------------------------------------line_bresenham_interpolator
class line_bresenham_interpolator
{
@@ -221,32 +230,42 @@ namespace agg
{
subpixel_shift = 8,
subpixel_scale = 1 << subpixel_shift,
subpixel_mask = subpixel_scale - 1
subpixel_mask = subpixel_scale - 1
};
//--------------------------------------------------------------------
static int line_lr(int v) { return v >> subpixel_shift; }
static int line_lr(int v)
{
return v >> subpixel_shift;
}
//--------------------------------------------------------------------
line_bresenham_interpolator(int x1, int y1, int x2, int y2) :
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(std::abs(m_x2_lr - m_x1_lr) < std::abs(m_y2_lr - m_y1_lr)),
m_len(m_ver ? std::abs(m_y2_lr - m_y1_lr) :
std::abs(m_x2_lr - m_x1_lr)),
m_len(m_ver ? std::abs(m_y2_lr - m_y1_lr)
: std::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)
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; }
bool is_ver() const
{
return m_ver;
}
unsigned len() const
{
return m_len;
}
int inc() const
{
return m_inc;
}
//--------------------------------------------------------------------
void hstep()
@@ -263,28 +282,42 @@ namespace agg
}
//--------------------------------------------------------------------
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(); }
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;
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

View File

@@ -2,8 +2,8 @@
// 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.
// 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.
//
@@ -30,20 +30,43 @@ namespace agg
class ellipse
{
public:
ellipse() :
m_x(0.0), m_y(0.0), m_rx(1.0), m_ry(1.0), m_scale(1.0),
m_num(4), m_step(0), m_cw(false) {}
ellipse(double x, double y, double rx, double ry,
unsigned num_steps=0, bool cw=false) :
m_x(x), m_y(y), m_rx(rx), m_ry(ry), m_scale(1.0),
m_num(num_steps), m_step(0), m_cw(cw)
ellipse():
m_x(0.0),
m_y(0.0),
m_rx(1.0),
m_ry(1.0),
m_scale(1.0),
m_num(4),
m_step(0),
m_cw(false)
{
if(m_num == 0) calc_num_steps();
}
void init(double x, double y, double rx, double ry,
unsigned num_steps=0, bool cw=false);
ellipse(double x,
double y,
double rx,
double ry,
unsigned num_steps = 0,
bool cw = false):
m_x(x),
m_y(y),
m_rx(rx),
m_ry(ry),
m_scale(1.0),
m_num(num_steps),
m_step(0),
m_cw(cw)
{
if (m_num == 0)
calc_num_steps();
}
void init(double x,
double y,
double rx,
double ry,
unsigned num_steps = 0,
bool cw = false);
void approximation_scale(double scale);
void rewind(unsigned path_id);
@@ -63,8 +86,8 @@ namespace agg
};
//------------------------------------------------------------------------
inline void ellipse::init(double x, double y, double rx, double ry,
unsigned num_steps, bool cw)
inline void ellipse::init(
double x, double y, double rx, double ry, unsigned num_steps, bool cw)
{
m_x = x;
m_y = y;
@@ -73,12 +96,13 @@ namespace agg
m_num = num_steps;
m_step = 0;
m_cw = cw;
if(m_num == 0) calc_num_steps();
if (m_num == 0)
calc_num_steps();
}
//------------------------------------------------------------------------
inline void ellipse::approximation_scale(double scale)
{
{
m_scale = scale;
calc_num_steps();
}
@@ -88,7 +112,7 @@ namespace agg
{
double ra = (std::fabs(m_rx) + std::fabs(m_ry)) / 2;
double da = std::acos(ra / (ra + 0.125 / m_scale)) * 2;
m_num = uround(2*pi / da);
m_num = uround(2 * pi / da);
}
//------------------------------------------------------------------------
@@ -100,14 +124,16 @@ namespace agg
//------------------------------------------------------------------------
inline unsigned ellipse::vertex(double* x, double* y)
{
if(m_step == m_num)
if (m_step == m_num)
{
++m_step;
return path_cmd_end_poly | path_flags_close | path_flags_ccw;
}
if(m_step > m_num) return path_cmd_stop;
if (m_step > m_num)
return path_cmd_stop;
double angle = double(m_step) / double(m_num) * 2.0 * pi;
if(m_cw) angle = 2.0 * pi - angle;
if (m_cw)
angle = 2.0 * pi - angle;
*x = m_x + std::cos(angle) * m_rx;
*y = m_y + std::sin(angle) * m_ry;
m_step++;
@@ -116,8 +142,4 @@ namespace agg
}
#endif

View File

@@ -2,8 +2,8 @@
// 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.
// 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.
//
@@ -20,10 +20,8 @@
#ifndef AGG_ELLIPSE_BRESENHAM_INCLUDED
#define AGG_ELLIPSE_BRESENHAM_INCLUDED
#include "agg_basics.h"
namespace agg
{
@@ -31,7 +29,7 @@ namespace agg
class ellipse_bresenham_interpolator
{
public:
ellipse_bresenham_interpolator(int rx, int ry) :
ellipse_bresenham_interpolator(int rx, int ry):
m_rx2(rx * rx),
m_ry2(ry * ry),
m_two_rx2(m_rx2 << 1),
@@ -41,47 +39,57 @@ namespace agg
m_inc_x(0),
m_inc_y(-ry * m_two_rx2),
m_cur_f(0)
{}
int dx() const { return m_dx; }
int dy() const { return m_dy; }
void operator++ ()
{
int mx, my, mxy, min_m;
int fx, fy, fxy;
}
int dx() const
{
return m_dx;
}
int dy() const
{
return m_dy;
}
void operator++()
{
int mx, my, mxy, min_m;
int fx, fy, fxy;
mx = fx = m_cur_f + m_inc_x + m_ry2;
if(mx < 0) mx = -mx;
if (mx < 0)
mx = -mx;
my = fy = m_cur_f + m_inc_y + m_rx2;
if(my < 0) my = -my;
if (my < 0)
my = -my;
mxy = fxy = m_cur_f + m_inc_x + m_ry2 + m_inc_y + m_rx2;
if(mxy < 0) mxy = -mxy;
if (mxy < 0)
mxy = -mxy;
min_m = mx;
min_m = mx;
bool flag = true;
if(min_m > my)
{
min_m = my;
flag = false;
if (min_m > my)
{
min_m = my;
flag = false;
}
m_dx = m_dy = 0;
if(min_m > mxy)
{
if (min_m > mxy)
{
m_inc_x += m_two_ry2;
m_inc_y += m_two_rx2;
m_cur_f = fxy;
m_dx = 1;
m_dx = 1;
m_dy = 1;
return;
}
if(flag)
if (flag)
{
m_inc_x += m_two_ry2;
m_cur_f = fx;
@@ -104,10 +112,8 @@ namespace agg
int m_inc_x;
int m_inc_y;
int m_cur_f;
};
}
#endif

View File

@@ -2,8 +2,8 @@
// 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.
// 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.
//

View File

@@ -2,8 +2,8 @@
// 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.
// 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.
//
@@ -26,41 +26,40 @@ namespace agg
enum glyph_data_type
{
glyph_data_invalid = 0,
glyph_data_mono = 1,
glyph_data_gray8 = 2,
glyph_data_mono = 1,
glyph_data_gray8 = 2,
glyph_data_outline = 3
};
//-------------------------------------------------------------glyph_cache
struct glyph_cache
{
unsigned glyph_index;
int8u* data;
unsigned data_size;
unsigned glyph_index;
int8u* data;
unsigned data_size;
glyph_data_type data_type;
rect_i bounds;
double advance_x;
double advance_y;
rect_i bounds;
double advance_x;
double advance_y;
};
//--------------------------------------------------------------font_cache
class font_cache
{
public:
enum block_size_e { block_size = 16384-16 };
enum block_size_e
{
block_size = 16384 - 16
};
//--------------------------------------------------------------------
font_cache() :
m_allocator(block_size),
m_font_signature(0)
{}
font_cache(): m_allocator(block_size), m_font_signature(0) {}
//--------------------------------------------------------------------
void signature(const char* font_signature)
{
m_font_signature = (char*)m_allocator.allocate(std::strlen(font_signature) + 1);
m_font_signature =
(char*)m_allocator.allocate(std::strlen(font_signature) + 1);
std::strcpy(m_font_signature, font_signature);
std::memset(m_glyphs, 0, sizeof(m_glyphs));
}
@@ -75,7 +74,7 @@ namespace agg
const glyph_cache* find_glyph(unsigned glyph_code) const
{
unsigned msb = (glyph_code >> 8) & 0xFF;
if(m_glyphs[msb])
if (m_glyphs[msb])
{
return m_glyphs[msb][glyph_code & 0xFF];
}
@@ -83,52 +82,45 @@ namespace agg
}
//--------------------------------------------------------------------
glyph_cache* cache_glyph(unsigned glyph_code,
unsigned glyph_index,
unsigned data_size,
glyph_data_type data_type,
const rect_i& bounds,
double advance_x,
double advance_y)
glyph_cache* cache_glyph(unsigned glyph_code,
unsigned glyph_index,
unsigned data_size,
glyph_data_type data_type,
const rect_i& bounds,
double advance_x,
double advance_y)
{
unsigned msb = (glyph_code >> 8) & 0xFF;
if(m_glyphs[msb] == 0)
if (m_glyphs[msb] == 0)
{
m_glyphs[msb] =
(glyph_cache**)m_allocator.allocate(sizeof(glyph_cache*) * 256,
sizeof(glyph_cache*));
m_glyphs[msb] = (glyph_cache**)m_allocator.allocate(
sizeof(glyph_cache*) * 256, sizeof(glyph_cache*));
std::memset(m_glyphs[msb], 0, sizeof(glyph_cache*) * 256);
}
unsigned lsb = glyph_code & 0xFF;
if(m_glyphs[msb][lsb]) return 0; // Already exists, do not overwrite
if (m_glyphs[msb][lsb])
return 0; // Already exists, do not overwrite
glyph_cache* glyph =
(glyph_cache*)m_allocator.allocate(sizeof(glyph_cache),
sizeof(double));
glyph_cache* glyph = (glyph_cache*)m_allocator.allocate(
sizeof(glyph_cache), sizeof(double));
glyph->glyph_index = glyph_index;
glyph->data = m_allocator.allocate(data_size);
glyph->data_size = data_size;
glyph->data_type = data_type;
glyph->bounds = bounds;
glyph->advance_x = advance_x;
glyph->advance_y = advance_y;
glyph->glyph_index = glyph_index;
glyph->data = m_allocator.allocate(data_size);
glyph->data_size = data_size;
glyph->data_type = data_type;
glyph->bounds = bounds;
glyph->advance_x = advance_x;
glyph->advance_y = advance_y;
return m_glyphs[msb][lsb] = glyph;
}
private:
block_allocator m_allocator;
glyph_cache** m_glyphs[256];
char* m_font_signature;
glyph_cache** m_glyphs[256];
char* m_font_signature;
};
//---------------------------------------------------------font_cache_pool
class font_cache_pool
{
@@ -137,7 +129,7 @@ namespace agg
~font_cache_pool()
{
unsigned i;
for(i = 0; i < m_num_fonts; ++i)
for (i = 0; i < m_num_fonts; ++i)
{
obj_allocator<font_cache>::deallocate(m_fonts[i]);
}
@@ -145,21 +137,21 @@ namespace agg
}
//--------------------------------------------------------------------
font_cache_pool(unsigned max_fonts=32) :
font_cache_pool(unsigned max_fonts = 32):
m_fonts(pod_allocator<font_cache*>::allocate(max_fonts)),
m_max_fonts(max_fonts),
m_num_fonts(0),
m_cur_font(0)
{}
{
}
//--------------------------------------------------------------------
void font(const char* font_signature, bool reset_cache = false)
{
int idx = find_font(font_signature);
if(idx >= 0)
if (idx >= 0)
{
if(reset_cache)
if (reset_cache)
{
obj_allocator<font_cache>::deallocate(m_fonts[idx]);
m_fonts[idx] = obj_allocator<font_cache>::allocate();
@@ -169,12 +161,12 @@ namespace agg
}
else
{
if(m_num_fonts >= m_max_fonts)
if (m_num_fonts >= m_max_fonts)
{
obj_allocator<font_cache>::deallocate(m_fonts[0]);
std::memcpy(m_fonts,
m_fonts + 1,
(m_max_fonts - 1) * sizeof(font_cache*));
std::memcpy(m_fonts,
m_fonts + 1,
(m_max_fonts - 1) * sizeof(font_cache*));
m_num_fonts = m_max_fonts - 1;
}
m_fonts[m_num_fonts] = obj_allocator<font_cache>::allocate();
@@ -193,54 +185,52 @@ namespace agg
//--------------------------------------------------------------------
const glyph_cache* find_glyph(unsigned glyph_code) const
{
if(m_cur_font) return m_cur_font->find_glyph(glyph_code);
if (m_cur_font)
return m_cur_font->find_glyph(glyph_code);
return 0;
}
//--------------------------------------------------------------------
glyph_cache* cache_glyph(unsigned glyph_code,
unsigned glyph_index,
unsigned data_size,
glyph_data_type data_type,
const rect_i& bounds,
double advance_x,
double advance_y)
glyph_cache* cache_glyph(unsigned glyph_code,
unsigned glyph_index,
unsigned data_size,
glyph_data_type data_type,
const rect_i& bounds,
double advance_x,
double advance_y)
{
if(m_cur_font)
if (m_cur_font)
{
return m_cur_font->cache_glyph(glyph_code,
glyph_index,
data_size,
data_type,
bounds,
advance_x,
advance_y);
glyph_index,
data_size,
data_type,
bounds,
advance_x,
advance_y);
}
return 0;
}
//--------------------------------------------------------------------
int find_font(const char* font_signature)
{
unsigned i;
for(i = 0; i < m_num_fonts; i++)
for (i = 0; i < m_num_fonts; i++)
{
if(m_fonts[i]->font_is(font_signature)) return int(i);
if (m_fonts[i]->font_is(font_signature))
return int(i);
}
return -1;
}
private:
font_cache** m_fonts;
unsigned m_max_fonts;
unsigned m_num_fonts;
font_cache* m_cur_font;
unsigned m_max_fonts;
unsigned m_num_fonts;
font_cache* m_cur_font;
};
//------------------------------------------------------------------------
enum glyph_rendering
{
@@ -251,29 +241,31 @@ namespace agg
glyph_ren_agg_gray8
};
//------------------------------------------------------font_cache_manager
template<class FontEngine> class font_cache_manager
template <class FontEngine>
class font_cache_manager
{
public:
typedef FontEngine font_engine_type;
typedef font_cache_manager<FontEngine> self_type;
typedef typename font_engine_type::path_adaptor_type path_adaptor_type;
typedef typename font_engine_type::gray8_adaptor_type gray8_adaptor_type;
typedef typename gray8_adaptor_type::embedded_scanline gray8_scanline_type;
typedef typename font_engine_type::mono_adaptor_type mono_adaptor_type;
typedef typename mono_adaptor_type::embedded_scanline mono_scanline_type;
typedef typename font_engine_type::path_adaptor_type path_adaptor_type;
typedef
typename font_engine_type::gray8_adaptor_type gray8_adaptor_type;
typedef
typename gray8_adaptor_type::embedded_scanline gray8_scanline_type;
typedef typename font_engine_type::mono_adaptor_type mono_adaptor_type;
typedef
typename mono_adaptor_type::embedded_scanline mono_scanline_type;
//--------------------------------------------------------------------
font_cache_manager(font_engine_type& engine, unsigned max_fonts=32) :
font_cache_manager(font_engine_type& engine, unsigned max_fonts = 32):
m_fonts(max_fonts),
m_engine(engine),
m_change_stamp(-1),
m_prev_glyph(0),
m_last_glyph(0)
{}
{
}
//--------------------------------------------------------------------
void reset_last_glyph()
@@ -286,23 +278,23 @@ namespace agg
{
synchronize();
const glyph_cache* gl = m_fonts.find_glyph(glyph_code);
if(gl)
if (gl)
{
m_prev_glyph = m_last_glyph;
return m_last_glyph = gl;
}
else
{
if(m_engine.prepare_glyph(glyph_code))
if (m_engine.prepare_glyph(glyph_code))
{
m_prev_glyph = m_last_glyph;
m_last_glyph = m_fonts.cache_glyph(glyph_code,
m_engine.glyph_index(),
m_engine.data_size(),
m_engine.data_type(),
m_engine.bounds(),
m_engine.advance_x(),
m_engine.advance_y());
m_last_glyph = m_fonts.cache_glyph(glyph_code,
m_engine.glyph_index(),
m_engine.data_size(),
m_engine.data_type(),
m_engine.bounds(),
m_engine.advance_x(),
m_engine.advance_y());
m_engine.write_glyph_to(m_last_glyph->data);
return m_last_glyph;
}
@@ -311,50 +303,70 @@ namespace agg
}
//--------------------------------------------------------------------
void init_embedded_adaptors(const glyph_cache* gl,
double x, double y,
double scale=1.0)
void init_embedded_adaptors(
const glyph_cache* gl, double x, double y, double scale = 1.0)
{
if(gl)
if (gl)
{
switch(gl->data_type)
switch (gl->data_type)
{
default: return;
case glyph_data_mono:
m_mono_adaptor.init(gl->data, gl->data_size, x, y);
break;
default:
return;
case glyph_data_mono:
m_mono_adaptor.init(gl->data, gl->data_size, x, y);
break;
case glyph_data_gray8:
m_gray8_adaptor.init(gl->data, gl->data_size, x, y);
break;
case glyph_data_gray8:
m_gray8_adaptor.init(gl->data, gl->data_size, x, y);
break;
case glyph_data_outline:
m_path_adaptor.init(gl->data, gl->data_size, x, y, scale);
break;
case glyph_data_outline:
m_path_adaptor.init(
gl->data, gl->data_size, x, y, scale);
break;
}
}
}
//--------------------------------------------------------------------
path_adaptor_type& path_adaptor()
{
return m_path_adaptor;
}
gray8_adaptor_type& gray8_adaptor()
{
return m_gray8_adaptor;
}
gray8_scanline_type& gray8_scanline()
{
return m_gray8_scanline;
}
mono_adaptor_type& mono_adaptor()
{
return m_mono_adaptor;
}
mono_scanline_type& mono_scanline()
{
return m_mono_scanline;
}
//--------------------------------------------------------------------
path_adaptor_type& path_adaptor() { return m_path_adaptor; }
gray8_adaptor_type& gray8_adaptor() { return m_gray8_adaptor; }
gray8_scanline_type& gray8_scanline() { return m_gray8_scanline; }
mono_adaptor_type& mono_adaptor() { return m_mono_adaptor; }
mono_scanline_type& mono_scanline() { return m_mono_scanline; }
//--------------------------------------------------------------------
const glyph_cache* perv_glyph() const { return m_prev_glyph; }
const glyph_cache* last_glyph() const { return m_last_glyph; }
const glyph_cache* perv_glyph() const
{
return m_prev_glyph;
}
const glyph_cache* last_glyph() const
{
return m_last_glyph;
}
//--------------------------------------------------------------------
bool add_kerning(double* x, double* y)
{
if(m_prev_glyph && m_last_glyph)
if (m_prev_glyph && m_last_glyph)
{
return m_engine.add_kerning(m_prev_glyph->glyph_index,
m_last_glyph->glyph_index,
x, y);
return m_engine.add_kerning(
m_prev_glyph->glyph_index, m_last_glyph->glyph_index, x, y);
}
return false;
}
@@ -362,7 +374,8 @@ namespace agg
//--------------------------------------------------------------------
void precache(unsigned from, unsigned to)
{
for(; from <= to; ++from) glyph(from);
for (; from <= to; ++from)
glyph(from);
}
//--------------------------------------------------------------------
@@ -376,12 +389,12 @@ namespace agg
private:
//--------------------------------------------------------------------
font_cache_manager(const self_type&);
const self_type& operator = (const self_type&);
const self_type& operator=(const self_type&);
//--------------------------------------------------------------------
void synchronize()
{
if(m_change_stamp != m_engine.change_stamp())
if (m_change_stamp != m_engine.change_stamp())
{
m_fonts.font(m_engine.font_signature());
m_change_stamp = m_engine.change_stamp();
@@ -389,21 +402,20 @@ namespace agg
}
}
font_cache_pool m_fonts;
font_engine_type& m_engine;
int m_change_stamp;
double m_dx;
double m_dy;
const glyph_cache* m_prev_glyph;
const glyph_cache* m_last_glyph;
path_adaptor_type m_path_adaptor;
gray8_adaptor_type m_gray8_adaptor;
font_cache_pool m_fonts;
font_engine_type& m_engine;
int m_change_stamp;
double m_dx;
double m_dy;
const glyph_cache* m_prev_glyph;
const glyph_cache* m_last_glyph;
path_adaptor_type m_path_adaptor;
gray8_adaptor_type m_gray8_adaptor;
gray8_scanline_type m_gray8_scanline;
mono_adaptor_type m_mono_adaptor;
mono_scanline_type m_mono_scanline;
mono_adaptor_type m_mono_adaptor;
mono_scanline_type m_mono_scanline;
};
}
#endif

View File

@@ -21,291 +21,311 @@
#include <cstring>
#include "agg_array.h"
namespace agg {
namespace agg
{
namespace fman {
//---------------------------------------------------------glyph_data_type
enum glyph_data_type
{
glyph_data_invalid = 0,
glyph_data_mono = 1,
glyph_data_gray8 = 2,
glyph_data_outline = 3
};
//-------------------------------------------------------------cached_glyph
struct cached_glyph
{
void * cached_font;
unsigned glyph_code;
unsigned glyph_index;
int8u* data;
unsigned data_size;
glyph_data_type data_type;
rect_i bounds;
double advance_x;
double advance_y;
};
//--------------------------------------------------------------cached_glyphs
class cached_glyphs
{
public:
enum block_size_e { block_size = 16384-16 };
//--------------------------------------------------------------------
cached_glyphs()
: m_allocator(block_size)
{ std::memset(m_glyphs, 0, sizeof(m_glyphs)); }
//--------------------------------------------------------------------
const cached_glyph* find_glyph(unsigned glyph_code) const
namespace fman
{
unsigned msb = (glyph_code >> 8) & 0xFF;
if(m_glyphs[msb])
{
return m_glyphs[msb][glyph_code & 0xFF];
}
return 0;
}
//--------------------------------------------------------------------
cached_glyph* cache_glyph(
void * cached_font,
unsigned glyph_code,
unsigned glyph_index,
unsigned data_size,
glyph_data_type data_type,
const rect_i& bounds,
double advance_x,
double advance_y)
{
unsigned msb = (glyph_code >> 8) & 0xFF;
if(m_glyphs[msb] == 0)
{
m_glyphs[msb] =
(cached_glyph**)m_allocator.allocate(sizeof(cached_glyph*) * 256,
sizeof(cached_glyph*));
std::memset(m_glyphs[msb], 0, sizeof(cached_glyph*) * 256);
}
unsigned lsb = glyph_code & 0xFF;
if(m_glyphs[msb][lsb]) return 0; // Already exists, do not overwrite
cached_glyph* glyph =
(cached_glyph*)m_allocator.allocate(sizeof(cached_glyph),
sizeof(double));
glyph->cached_font = cached_font;
glyph->glyph_code = glyph_code;
glyph->glyph_index = glyph_index;
glyph->data = m_allocator.allocate(data_size);
glyph->data_size = data_size;
glyph->data_type = data_type;
glyph->bounds = bounds;
glyph->advance_x = advance_x;
glyph->advance_y = advance_y;
return m_glyphs[msb][lsb] = glyph;
}
private:
block_allocator m_allocator;
cached_glyph** m_glyphs[256];
};
//------------------------------------------------------------------------
enum glyph_rendering
{
glyph_ren_native_mono,
glyph_ren_native_gray8,
glyph_ren_outline,
glyph_ren_agg_mono,
glyph_ren_agg_gray8
};
//------------------------------------------------------font_cache_manager
template<class FontEngine> class font_cache_manager
{
public:
typedef FontEngine font_engine_type;
typedef font_cache_manager<FontEngine> self_type;
typedef typename font_engine_type::path_adaptor_type path_adaptor_type;
typedef typename font_engine_type::gray8_adaptor_type gray8_adaptor_type;
typedef typename gray8_adaptor_type::embedded_scanline gray8_scanline_type;
typedef typename font_engine_type::mono_adaptor_type mono_adaptor_type;
typedef typename mono_adaptor_type::embedded_scanline mono_scanline_type;
struct cached_font
{
cached_font(
font_engine_type& engine,
typename FontEngine::loaded_face *face,
double height,
double width,
bool hinting,
glyph_rendering rendering )
: m_engine( engine )
, m_face( face )
, m_height( height )
, m_width( width )
, m_hinting( hinting )
, m_rendering( rendering )
{
select_face();
m_face_height=m_face->height();
m_face_width=m_face->width();
m_face_ascent=m_face->ascent();
m_face_descent=m_face->descent();
m_face_ascent_b=m_face->ascent_b();
m_face_descent_b=m_face->descent_b();
}
double height() const
{
return m_face_height;
}
double width() const
{
return m_face_width;
}
double ascent() const
{
return m_face_ascent;
}
double descent() const
{
return m_face_descent;
}
double ascent_b() const
{
return m_face_ascent_b;
}
double descent_b() const
{
return m_face_descent_b;
}
bool add_kerning( const cached_glyph *first, const cached_glyph *second, double* x, double* y)
{
if( !first || !second )
return false;
select_face();
return m_face->add_kerning(
first->glyph_index, second->glyph_index, x, y );
}
void select_face()
{
m_face->select_instance( m_height, m_width, m_hinting, m_rendering );
}
const cached_glyph *get_glyph(unsigned cp)
{
const cached_glyph *glyph=m_glyphs.find_glyph(cp);
if( glyph==0 )
//---------------------------------------------------------glyph_data_type
enum glyph_data_type
{
typename FontEngine::prepared_glyph prepared;
select_face();
bool success=m_face->prepare_glyph(cp, &prepared);
if( success )
{
glyph=m_glyphs.cache_glyph(
this,
prepared.glyph_code,
prepared.glyph_index,
prepared.data_size,
prepared.data_type,
prepared.bounds,
prepared.advance_x,
prepared.advance_y );
assert( glyph!=0 );
m_face->write_glyph_to(&prepared,glyph->data);
}
}
return glyph;
}
glyph_data_invalid = 0,
glyph_data_mono = 1,
glyph_data_gray8 = 2,
glyph_data_outline = 3
};
font_engine_type& m_engine;
typename FontEngine::loaded_face *m_face;
double m_height;
double m_width;
bool m_hinting;
glyph_rendering m_rendering;
double m_face_height;
double m_face_width;
double m_face_ascent;
double m_face_descent;
double m_face_ascent_b;
double m_face_descent_b;
cached_glyphs m_glyphs;
};
//--------------------------------------------------------------------
font_cache_manager(font_engine_type& engine, unsigned max_fonts=32)
:m_engine(engine)
{ }
//--------------------------------------------------------------------
void init_embedded_adaptors(const cached_glyph* gl,
double x, double y,
double scale=1.0)
{
if(gl)
{
switch(gl->data_type)
//-------------------------------------------------------------cached_glyph
struct cached_glyph
{
default: return;
case glyph_data_mono:
m_mono_adaptor.init(gl->data, gl->data_size, x, y);
break;
void* cached_font;
unsigned glyph_code;
unsigned glyph_index;
int8u* data;
unsigned data_size;
glyph_data_type data_type;
rect_i bounds;
double advance_x;
double advance_y;
};
case glyph_data_gray8:
m_gray8_adaptor.init(gl->data, gl->data_size, x, y);
break;
//--------------------------------------------------------------cached_glyphs
class cached_glyphs
{
public:
enum block_size_e
{
block_size = 16384 - 16
};
//--------------------------------------------------------------------
cached_glyphs(): m_allocator(block_size)
{
std::memset(m_glyphs, 0, sizeof(m_glyphs));
}
//--------------------------------------------------------------------
const cached_glyph* find_glyph(unsigned glyph_code) const
{
unsigned msb = (glyph_code >> 8) & 0xFF;
if (m_glyphs[msb])
{
return m_glyphs[msb][glyph_code & 0xFF];
}
return 0;
}
//--------------------------------------------------------------------
cached_glyph* cache_glyph(void* cached_font,
unsigned glyph_code,
unsigned glyph_index,
unsigned data_size,
glyph_data_type data_type,
const rect_i& bounds,
double advance_x,
double advance_y)
{
unsigned msb = (glyph_code >> 8) & 0xFF;
if (m_glyphs[msb] == 0)
{
m_glyphs[msb] = (cached_glyph**)m_allocator.allocate(
sizeof(cached_glyph*) * 256, sizeof(cached_glyph*));
std::memset(m_glyphs[msb], 0, sizeof(cached_glyph*) * 256);
}
unsigned lsb = glyph_code & 0xFF;
if (m_glyphs[msb][lsb])
return 0; // Already exists, do not overwrite
cached_glyph* glyph = (cached_glyph*)m_allocator.allocate(
sizeof(cached_glyph), sizeof(double));
glyph->cached_font = cached_font;
glyph->glyph_code = glyph_code;
glyph->glyph_index = glyph_index;
glyph->data = m_allocator.allocate(data_size);
glyph->data_size = data_size;
glyph->data_type = data_type;
glyph->bounds = bounds;
glyph->advance_x = advance_x;
glyph->advance_y = advance_y;
return m_glyphs[msb][lsb] = glyph;
}
private:
block_allocator m_allocator;
cached_glyph** m_glyphs[256];
};
//------------------------------------------------------------------------
enum glyph_rendering
{
glyph_ren_native_mono,
glyph_ren_native_gray8,
glyph_ren_outline,
glyph_ren_agg_mono,
glyph_ren_agg_gray8
};
//------------------------------------------------------font_cache_manager
template <class FontEngine>
class font_cache_manager
{
public:
typedef FontEngine font_engine_type;
typedef font_cache_manager<FontEngine> self_type;
typedef
typename font_engine_type::path_adaptor_type path_adaptor_type;
typedef typename font_engine_type::gray8_adaptor_type
gray8_adaptor_type;
typedef typename gray8_adaptor_type::embedded_scanline
gray8_scanline_type;
typedef
typename font_engine_type::mono_adaptor_type mono_adaptor_type;
typedef typename mono_adaptor_type::embedded_scanline
mono_scanline_type;
struct cached_font
{
cached_font(font_engine_type& engine,
typename FontEngine::loaded_face* face,
double height,
double width,
bool hinting,
glyph_rendering rendering):
m_engine(engine),
m_face(face),
m_height(height),
m_width(width),
m_hinting(hinting),
m_rendering(rendering)
{
select_face();
m_face_height = m_face->height();
m_face_width = m_face->width();
m_face_ascent = m_face->ascent();
m_face_descent = m_face->descent();
m_face_ascent_b = m_face->ascent_b();
m_face_descent_b = m_face->descent_b();
}
double height() const
{
return m_face_height;
}
double width() const
{
return m_face_width;
}
double ascent() const
{
return m_face_ascent;
}
double descent() const
{
return m_face_descent;
}
double ascent_b() const
{
return m_face_ascent_b;
}
double descent_b() const
{
return m_face_descent_b;
}
bool add_kerning(const cached_glyph* first,
const cached_glyph* second,
double* x,
double* y)
{
if (!first || !second)
return false;
select_face();
return m_face->add_kerning(
first->glyph_index, second->glyph_index, x, y);
}
void select_face()
{
m_face->select_instance(
m_height, m_width, m_hinting, m_rendering);
}
const cached_glyph* get_glyph(unsigned cp)
{
const cached_glyph* glyph = m_glyphs.find_glyph(cp);
if (glyph == 0)
{
typename FontEngine::prepared_glyph prepared;
select_face();
bool success = m_face->prepare_glyph(cp, &prepared);
if (success)
{
glyph = m_glyphs.cache_glyph(this,
prepared.glyph_code,
prepared.glyph_index,
prepared.data_size,
prepared.data_type,
prepared.bounds,
prepared.advance_x,
prepared.advance_y);
assert(glyph != 0);
m_face->write_glyph_to(&prepared, glyph->data);
}
}
return glyph;
}
font_engine_type& m_engine;
typename FontEngine::loaded_face* m_face;
double m_height;
double m_width;
bool m_hinting;
glyph_rendering m_rendering;
double m_face_height;
double m_face_width;
double m_face_ascent;
double m_face_descent;
double m_face_ascent_b;
double m_face_descent_b;
cached_glyphs m_glyphs;
};
//--------------------------------------------------------------------
font_cache_manager(
font_engine_type& engine, unsigned max_fonts = 32):
m_engine(engine)
{
}
//--------------------------------------------------------------------
void init_embedded_adaptors(
const cached_glyph* gl, double x, double y, double scale = 1.0)
{
if (gl)
{
switch (gl->data_type)
{
default:
return;
case glyph_data_mono:
m_mono_adaptor.init(gl->data, gl->data_size, x, y);
break;
case glyph_data_gray8:
m_gray8_adaptor.init(gl->data, gl->data_size, x, y);
break;
case glyph_data_outline:
m_path_adaptor.init(
gl->data, gl->data_size, x, y, scale);
break;
}
}
}
//--------------------------------------------------------------------
path_adaptor_type& path_adaptor()
{
return m_path_adaptor;
}
gray8_adaptor_type& gray8_adaptor()
{
return m_gray8_adaptor;
}
gray8_scanline_type& gray8_scanline()
{
return m_gray8_scanline;
}
mono_adaptor_type& mono_adaptor()
{
return m_mono_adaptor;
}
mono_scanline_type& mono_scanline()
{
return m_mono_scanline;
}
private:
//--------------------------------------------------------------------
font_cache_manager(const self_type&);
const self_type& operator=(const self_type&);
font_engine_type& m_engine;
path_adaptor_type m_path_adaptor;
gray8_adaptor_type m_gray8_adaptor;
gray8_scanline_type m_gray8_scanline;
mono_adaptor_type m_mono_adaptor;
mono_scanline_type m_mono_scanline;
};
case glyph_data_outline:
m_path_adaptor.init(gl->data, gl->data_size, x, y, scale);
break;
}
}
}
//--------------------------------------------------------------------
path_adaptor_type& path_adaptor() { return m_path_adaptor; }
gray8_adaptor_type& gray8_adaptor() { return m_gray8_adaptor; }
gray8_scanline_type& gray8_scanline() { return m_gray8_scanline; }
mono_adaptor_type& mono_adaptor() { return m_mono_adaptor; }
mono_scanline_type& mono_scanline() { return m_mono_scanline; }
private:
//--------------------------------------------------------------------
font_cache_manager(const self_type&);
const self_type& operator = (const self_type&);
font_engine_type& m_engine;
path_adaptor_type m_path_adaptor;
gray8_adaptor_type m_gray8_adaptor;
gray8_scanline_type m_gray8_scanline;
mono_adaptor_type m_mono_adaptor;
mono_scanline_type m_mono_scanline;
};
}
}
#endif

View File

@@ -2,8 +2,8 @@
// 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.
// 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.
//
@@ -23,21 +23,29 @@ namespace agg
//===============================================================gamma_none
struct gamma_none
{
double operator()(double x) const { return x; }
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) {}
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; }
void gamma(double g)
{
m_gamma = g;
}
double gamma() const
{
return m_gamma;
}
double operator() (double x) const
double operator()(double x) const
{
return pow(x, m_gamma);
}
@@ -46,18 +54,23 @@ namespace agg
double m_gamma;
};
//==========================================================gamma_threshold
class gamma_threshold
{
public:
gamma_threshold() : m_threshold(0.5) {}
gamma_threshold(double t) : m_threshold(t) {}
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; }
void threshold(double t)
{
m_threshold = t;
}
double threshold() const
{
return m_threshold;
}
double operator() (double x) const
double operator()(double x) const
{
return (x < m_threshold) ? 0.0 : 1.0;
}
@@ -66,24 +79,41 @@ namespace agg
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) {}
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
void set(double s, double e)
{
if(x < m_start) return 0.0;
if(x > m_end) return 1.0;
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);
}
@@ -92,21 +122,27 @@ namespace agg
double m_end;
};
//==========================================================gamma_multiply
class gamma_multiply
{
public:
gamma_multiply() : m_mul(1.0) {}
gamma_multiply(double v) : m_mul(v) {}
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; }
void value(double v)
{
m_mul = v;
}
double value() const
{
return m_mul;
}
double operator() (double x) const
double operator()(double x) const
{
double y = x * m_mul;
if(y > 1.0) y = 1.0;
if (y > 1.0)
y = 1.0;
return y;
}
@@ -121,11 +157,9 @@ namespace agg
inline double linear_to_sRGB(double x)
{
return (x <= 0.0031308) ? (x * 12.92) : (1.055 * pow(x, 1 / 2.4) - 0.055);
return (x <= 0.0031308) ? (x * 12.92)
: (1.055 * pow(x, 1 / 2.4) - 0.055);
}
}
#endif

View File

@@ -2,8 +2,8 @@
// 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.
// 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.
//
@@ -22,10 +22,11 @@
namespace agg
{
template<class LoResT=int8u,
class HiResT=int8u,
unsigned GammaShift=8,
unsigned HiResShift=8> class gamma_lut
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;
@@ -33,15 +34,15 @@ namespace agg
enum gamma_scale_e
{
gamma_shift = GammaShift,
gamma_size = 1 << gamma_shift,
gamma_mask = gamma_size - 1
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
hi_res_size = 1 << hi_res_shift,
hi_res_mask = hi_res_size - 1
};
~gamma_lut()
@@ -50,47 +51,49 @@ namespace agg
pod_allocator<HiResT>::deallocate(m_dir_gamma, gamma_size);
}
gamma_lut() :
m_gamma(1.0),
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++)
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++)
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),
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)
void gamma(double g)
{
m_gamma = g;
unsigned i;
for(i = 0; i < gamma_size; i++)
for (i = 0; i < gamma_size; i++)
{
m_dir_gamma[i] = (HiResT)
uround(std::pow(i / double(gamma_mask), m_gamma) * double(hi_res_mask));
m_dir_gamma[i] =
(HiResT)uround(std::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++)
for (i = 0; i < hi_res_size; i++)
{
m_inv_gamma[i] = (LoResT)
uround(std::pow(i / double(hi_res_mask), inv_g) * double(gamma_mask));
m_inv_gamma[i] =
(LoResT)uround(std::pow(i / double(hi_res_mask), inv_g) *
double(gamma_mask));
}
}
@@ -99,19 +102,19 @@ namespace agg
return m_gamma;
}
HiResT dir(LoResT v) const
{
return m_dir_gamma[unsigned(v)];
HiResT dir(LoResT v) const
{
return m_dir_gamma[unsigned(v)];
}
LoResT inv(HiResT v) const
{
LoResT inv(HiResT v) const
{
return m_inv_gamma[unsigned(v)];
}
private:
gamma_lut(const self_type&);
const self_type& operator = (const self_type&);
const self_type& operator=(const self_type&);
double m_gamma;
HiResT* m_dir_gamma;
@@ -122,10 +125,10 @@ namespace agg
// sRGB support classes
//
// Optimized sRGB lookup table. The direct conversion (sRGB to linear)
// is a straightforward lookup. The inverse conversion (linear to sRGB)
// Optimized sRGB lookup table. The direct conversion (sRGB to linear)
// is a straightforward lookup. The inverse conversion (linear to sRGB)
// is implemented using binary search.
template<class LinearType>
template <class LinearType>
class sRGB_lut_base
{
public:
@@ -138,14 +141,22 @@ namespace agg
{
// Unrolled binary search.
int8u x = 0;
if (v > m_inv_table[128]) x = 128;
if (v > m_inv_table[x + 64]) x += 64;
if (v > m_inv_table[x + 32]) x += 32;
if (v > m_inv_table[x + 16]) x += 16;
if (v > m_inv_table[x + 8]) x += 8;
if (v > m_inv_table[x + 4]) x += 4;
if (v > m_inv_table[x + 2]) x += 2;
if (v > m_inv_table[x + 1]) x += 1;
if (v > m_inv_table[128])
x = 128;
if (v > m_inv_table[x + 64])
x += 64;
if (v > m_inv_table[x + 32])
x += 32;
if (v > m_inv_table[x + 16])
x += 16;
if (v > m_inv_table[x + 8])
x += 8;
if (v > m_inv_table[x + 4])
x += 4;
if (v > m_inv_table[x + 2])
x += 2;
if (v > m_inv_table[x + 1])
x += 1;
return x;
}
@@ -154,36 +165,33 @@ namespace agg
LinearType m_inv_table[256];
// Only derived classes may instantiate.
sRGB_lut_base()
{
}
sRGB_lut_base() {}
};
// sRGB_lut - implements sRGB conversion for the various types.
// Base template is undefined, specializations are provided below.
template<class LinearType>
template <class LinearType>
class sRGB_lut;
template<>
template <>
class sRGB_lut<float> : public sRGB_lut_base<float>
{
public:
sRGB_lut()
{
// Generate lookup tables.
m_dir_table[0] = 0;
m_inv_table[0] = 0;
for (unsigned i = 1; i <= 255; ++i)
{
// Floating-point RGB is in range [0,1].
m_dir_table[i] = float(sRGB_to_linear(i / 255.0));
m_inv_table[i] = float(sRGB_to_linear((i - 0.5) / 255.0));
}
}
sRGB_lut()
{
// Generate lookup tables.
m_dir_table[0] = 0;
m_inv_table[0] = 0;
for (unsigned i = 1; i <= 255; ++i)
{
// Floating-point RGB is in range [0,1].
m_dir_table[i] = float(sRGB_to_linear(i / 255.0));
m_inv_table[i] = float(sRGB_to_linear((i - 0.5) / 255.0));
}
}
};
template<>
template <>
class sRGB_lut<int16u> : public sRGB_lut_base<int16u>
{
public:
@@ -196,18 +204,19 @@ namespace agg
{
// 16-bit RGB is in range [0,65535].
m_dir_table[i] = uround(65535.0 * sRGB_to_linear(i / 255.0));
m_inv_table[i] = uround(65535.0 * sRGB_to_linear((i - 0.5) / 255.0));
m_inv_table[i] =
uround(65535.0 * sRGB_to_linear((i - 0.5) / 255.0));
}
}
};
template<>
template <>
class sRGB_lut<int8u> : public sRGB_lut_base<int8u>
{
public:
sRGB_lut()
{
// Generate lookup tables.
// Generate lookup tables.
m_dir_table[0] = 0;
m_inv_table[0] = 0;
for (int i = 1; i <= 255; ++i)
@@ -225,9 +234,9 @@ namespace agg
}
};
// Common base class for sRGB_conv objects. Defines an internal
// Common base class for sRGB_conv objects. Defines an internal
// sRGB_lut object so that users don't have to.
template<class T>
template <class T>
class sRGB_conv_base
{
public:
@@ -245,17 +254,17 @@ namespace agg
static sRGB_lut<T> lut;
};
// Definition of sRGB_conv_base::lut. Due to the fact that this a template,
// 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>
template <class T>
sRGB_lut<T> sRGB_conv_base<T>::lut;
// Wrapper for sRGB-linear conversion.
// Wrapper for sRGB-linear conversion.
// Base template is undefined, specializations are provided below.
template<class T>
template <class T>
class sRGB_conv;
template<>
template <>
class sRGB_conv<float> : public sRGB_conv_base<float>
{
public:
@@ -267,13 +276,15 @@ namespace agg
static int8u alpha_to_sRGB(float x)
{
if (x < 0) return 0;
if (x > 1) return 255;
if (x < 0)
return 0;
if (x > 1)
return 255;
return int8u(0.5 + x * 255);
}
};
template<>
template <>
class sRGB_conv<int16u> : public sRGB_conv_base<int16u>
{
public:
@@ -288,7 +299,7 @@ namespace agg
}
};
template<>
template <>
class sRGB_conv<int8u> : public sRGB_conv_base<int8u>
{
public:

View File

@@ -2,8 +2,8 @@
// 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.
// 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.
//
@@ -23,7 +23,8 @@ namespace agg
{
//========================================================glyph_raster_bin
template<class ColorT> class glyph_raster_bin
template <class ColorT>
class glyph_raster_bin
{
public:
typedef ColorT color_type;
@@ -31,41 +32,53 @@ namespace agg
//--------------------------------------------------------------------
struct glyph_rect
{
int x1,y1,x2,y2;
int x1, y1, x2, y2;
double dx, dy;
};
//--------------------------------------------------------------------
glyph_raster_bin(const int8u* font) :
m_font(font),
m_big_endian(false)
glyph_raster_bin(const int8u* font): m_font(font), m_big_endian(false)
{
int t = 1;
if(*(char*)&t == 0) m_big_endian = true;
if (*(char*)&t == 0)
m_big_endian = true;
std::memset(m_span, 0, sizeof(m_span));
}
//--------------------------------------------------------------------
const int8u* font() const { return m_font; }
void font(const int8u* f) { m_font = f; }
const int8u* font() const
{
return m_font;
}
void font(const int8u* f)
{
m_font = f;
}
//--------------------------------------------------------------------
double height() const { return m_font[0]; }
double base_line() const { return m_font[1]; }
double height() const
{
return m_font[0];
}
double base_line() const
{
return m_font[1];
}
//--------------------------------------------------------------------
template<class CharT>
template <class CharT>
double width(const CharT* str) const
{
unsigned start_char = m_font[2];
unsigned num_chars = m_font[3];
unsigned w = 0;
while(*str)
while (*str)
{
unsigned glyph = *str;
const int8u* bits = m_font + 4 + num_chars * 2 +
value(m_font + 4 + (glyph - start_char) * 2);
const int8u* bits =
m_font + 4 + num_chars * 2 +
value(m_font + 4 + (glyph - start_char) * 2);
w += *bits;
++str;
}
@@ -73,12 +86,13 @@ namespace agg
}
//--------------------------------------------------------------------
void prepare(glyph_rect* r, double x, double y, unsigned glyph, bool flip)
void prepare(
glyph_rect* r, double x, double y, unsigned glyph, bool flip)
{
unsigned start_char = m_font[2];
unsigned num_chars = m_font[3];
m_bits = m_font + 4 + num_chars * 2 +
m_bits = m_font + 4 + num_chars * 2 +
value(m_font + 4 + (glyph - start_char) * 2);
m_glyph_width = *m_bits++;
@@ -86,7 +100,7 @@ namespace agg
r->x1 = int(x);
r->x2 = r->x1 + m_glyph_width - 1;
if(flip)
if (flip)
{
r->y1 = int(y) - m_font[0] + m_font[1];
r->y2 = r->y1 + m_font[0] - 1;
@@ -96,7 +110,7 @@ namespace agg
r->y1 = int(y) - m_font[1] + 1;
r->y2 = r->y1 + m_font[0] - 1;
}
r->dx = m_glyph_width;
r->dx = m_glyph_width;
r->dy = 0;
}
@@ -108,11 +122,12 @@ namespace agg
unsigned j;
unsigned val = *bits;
unsigned nb = 0;
for(j = 0; j < m_glyph_width; ++j)
for (j = 0; j < m_glyph_width; ++j)
{
m_span[j] = (cover_type)((val & 0x80) ? cover_full : cover_none);
m_span[j] =
(cover_type)((val & 0x80) ? cover_full : cover_none);
val <<= 1;
if(++nb >= 8)
if (++nb >= 8)
{
val = *++bits;
nb = 0;
@@ -126,20 +141,19 @@ namespace agg
int16u value(const int8u* p) const
{
int16u v;
if(m_big_endian)
if (m_big_endian)
{
*(int8u*)&v = p[1];
*(int8u*)&v = p[1];
*((int8u*)&v + 1) = p[0];
}
else
{
*(int8u*)&v = p[0];
*(int8u*)&v = p[0];
*((int8u*)&v + 1) = p[1];
}
return v;
}
//--------------------------------------------------------------------
const int8u* m_font;
bool m_big_endian;
@@ -149,7 +163,6 @@ namespace agg
unsigned m_glyph_byte_width;
};
}
#endif

View File

@@ -2,8 +2,8 @@
// 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.
// 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.
//
@@ -25,21 +25,22 @@ namespace agg
{
//======================================================color_interpolator
template<class ColorT> struct color_interpolator
template <class ColorT>
struct color_interpolator
{
public:
typedef ColorT color_type;
color_interpolator(const color_type& c1,
const color_type& c2,
unsigned len) :
color_interpolator(
const color_type& c1, const color_type& c2, unsigned len):
m_c1(c1),
m_c2(c2),
m_len(len),
m_count(0)
{}
{
}
void operator ++ ()
void operator++()
{
++m_count;
}
@@ -52,29 +53,33 @@ namespace agg
private:
color_type m_c1;
color_type m_c2;
unsigned m_len;
unsigned m_count;
unsigned m_len;
unsigned m_count;
};
//========================================================================
// Fast specialization for rgba8
template<> struct color_interpolator<rgba8>
template <>
struct color_interpolator<rgba8>
{
public:
typedef rgba8 color_type;
color_interpolator(const color_type& c1,
const color_type& c2,
unsigned len) :
color_interpolator(
const color_type& c1, const color_type& c2, unsigned len):
r(c1.r, c2.r, len),
g(c1.g, c2.g, len),
b(c1.b, c2.b, len),
a(c1.a, c2.a, len)
{}
void operator ++ ()
{
++r; ++g; ++b; ++a;
}
void operator++()
{
++r;
++g;
++b;
++a;
}
color_type color() const
@@ -88,21 +93,23 @@ namespace agg
//========================================================================
// Fast specialization for gray8
template<> struct color_interpolator<gray8>
template <>
struct color_interpolator<gray8>
{
public:
typedef gray8 color_type;
color_interpolator(const color_type& c1,
const color_type& c2,
unsigned len) :
color_interpolator(
const color_type& c1, const color_type& c2, unsigned len):
v(c1.v, c2.v, len),
a(c1.a, c2.a, len)
{}
void operator ++ ()
{
++v; ++a;
}
void operator++()
{
++v;
++a;
}
color_type color() const
@@ -111,26 +118,29 @@ namespace agg
}
private:
agg::dda_line_interpolator<14> v,a;
agg::dda_line_interpolator<14> v, a;
};
//============================================================gradient_lut
template<class ColorInterpolator,
unsigned ColorLutSize=256> class gradient_lut
template <class ColorInterpolator, unsigned ColorLutSize = 256>
class gradient_lut
{
public:
typedef ColorInterpolator interpolator_type;
typedef typename interpolator_type::color_type color_type;
enum { color_lut_size = ColorLutSize };
enum
{
color_lut_size = ColorLutSize
};
//--------------------------------------------------------------------
gradient_lut() : m_color_lut(color_lut_size) {}
gradient_lut(): m_color_lut(color_lut_size) {}
// Build Gradient Lut
// First, call remove_all(), then add_color() at least twice,
// then build_lut(). Argument "offset" in add_color must be
// in range [0...1] and defines a color stop as it is described
// in SVG specification, section Gradients and Patterns.
// First, call remove_all(), then add_color() at least twice,
// then build_lut(). Argument "offset" in add_color must be
// in range [0...1] and defines a color stop as it is described
// in SVG specification, section Gradients and Patterns.
// The simplest linear gradient is:
// gradient_lut.add_color(0.0, start_color);
// gradient_lut.add_color(1.0, end_color);
@@ -139,36 +149,37 @@ namespace agg
void add_color(double offset, const color_type& color);
void build_lut();
// Size-index Interface. This class can be used directly as the
// ColorF in span_gradient. All it needs is two access methods
// Size-index Interface. This class can be used directly as the
// ColorF in span_gradient. All it needs is two access methods
// size() and operator [].
//--------------------------------------------------------------------
static unsigned size()
{
return color_lut_size;
static unsigned size()
{
return color_lut_size;
}
const color_type& operator [] (unsigned i) const
{
return m_color_lut[i];
const color_type& operator[](unsigned i) const
{
return m_color_lut[i];
}
private:
//--------------------------------------------------------------------
struct color_point
{
double offset;
double offset;
color_type color;
color_point() {}
color_point(double off, const color_type& c) :
offset(off), color(c)
color_point(double off, const color_type& c): offset(off), color(c)
{
if(offset < 0.0) offset = 0.0;
if(offset > 1.0) offset = 1.0;
if (offset < 0.0)
offset = 0.0;
if (offset > 1.0)
offset = 1.0;
}
};
typedef agg::pod_bvector<color_point, 4> color_profile_type;
typedef agg::pod_array<color_type> color_lut_type;
typedef agg::pod_array<color_type> color_lut_type;
static bool offset_less(const color_point& a, const color_point& b)
{
@@ -180,49 +191,48 @@ namespace agg
}
//--------------------------------------------------------------------
color_profile_type m_color_profile;
color_lut_type m_color_lut;
color_profile_type m_color_profile;
color_lut_type m_color_lut;
};
//------------------------------------------------------------------------
template<class T, unsigned S>
void gradient_lut<T,S>::remove_all()
{
m_color_profile.remove_all();
template <class T, unsigned S>
void gradient_lut<T, S>::remove_all()
{
m_color_profile.remove_all();
}
//------------------------------------------------------------------------
template<class T, unsigned S>
void gradient_lut<T,S>::add_color(double offset, const color_type& color)
template <class T, unsigned S>
void gradient_lut<T, S>::add_color(double offset, const color_type& color)
{
m_color_profile.add(color_point(offset, color));
}
//------------------------------------------------------------------------
template<class T, unsigned S>
void gradient_lut<T,S>::build_lut()
template <class T, unsigned S>
void gradient_lut<T, S>::build_lut()
{
quick_sort(m_color_profile, offset_less);
m_color_profile.cut_at(remove_duplicates(m_color_profile, offset_equal));
if(m_color_profile.size() >= 2)
m_color_profile.cut_at(
remove_duplicates(m_color_profile, offset_equal));
if (m_color_profile.size() >= 2)
{
unsigned i;
unsigned start = uround(m_color_profile[0].offset * color_lut_size);
unsigned end;
color_type c = m_color_profile[0].color;
for(i = 0; i < start; i++)
for (i = 0; i < start; i++)
{
m_color_lut[i] = c;
}
for(i = 1; i < m_color_profile.size(); i++)
for (i = 1; i < m_color_profile.size(); i++)
{
end = uround(m_color_profile[i].offset * color_lut_size);
interpolator_type ci(m_color_profile[i-1].color,
m_color_profile[i ].color,
end - start + 1);
while(start < end)
end = uround(m_color_profile[i].offset * color_lut_size);
interpolator_type ci(m_color_profile[i - 1].color,
m_color_profile[i].color,
end - start + 1);
while (start < end)
{
m_color_lut[start] = ci.color();
++ci;
@@ -230,7 +240,7 @@ namespace agg
}
}
c = m_color_profile.last().color;
for(; end < m_color_lut.size(); end++)
for (; end < m_color_lut.size(); end++)
{
m_color_lut[end] = c;
}
@@ -238,7 +248,4 @@ namespace agg
}
}
#endif

View File

@@ -2,8 +2,8 @@
// 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.
// 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.
//
@@ -27,10 +27,9 @@
namespace agg
{
//---------------------------------------------------------------gsv_text
//
// See Implementation agg_gsv_text.cpp
// See Implementation agg_gsv_text.cpp
//
class gsv_text
{
@@ -46,14 +45,17 @@ namespace agg
gsv_text();
void font(const void* font);
void flip(bool flip_y) { m_flip = flip_y; }
void flip(bool flip_y)
{
m_flip = flip_y;
}
void load_font(const char* file);
void size(double height, double width=0.0);
void size(double height, double width = 0.0);
void space(double space);
void line_space(double line_space);
void start_point(double x, double y);
void text(const char* text);
double text_width();
void rewind(unsigned path_id);
@@ -62,75 +64,73 @@ namespace agg
private:
// not supposed to be copied
gsv_text(const gsv_text&);
const gsv_text& operator = (const gsv_text&);
const gsv_text& operator=(const gsv_text&);
int16u value(const int8u* p) const
{
int16u v;
if(m_big_endian)
if (m_big_endian)
{
*(int8u*)&v = p[1];
*(int8u*)&v = p[1];
*((int8u*)&v + 1) = p[0];
}
else
{
*(int8u*)&v = p[0];
*(int8u*)&v = p[0];
*((int8u*)&v + 1) = p[1];
}
return v;
}
private:
double m_x;
double m_y;
double m_start_x;
double m_width;
double m_height;
double m_space;
double m_line_space;
char m_chr[2];
char* m_text;
double m_x;
double m_y;
double m_start_x;
double m_width;
double m_height;
double m_space;
double m_line_space;
char m_chr[2];
char* m_text;
pod_array<char> m_text_buf;
char* m_cur_chr;
const void* m_font;
char* m_cur_chr;
const void* m_font;
pod_array<char> m_loaded_font;
status m_status;
bool m_big_endian;
bool m_flip;
int8u* m_indices;
int8* m_glyphs;
int8* m_bglyph;
int8* m_eglyph;
double m_w;
double m_h;
status m_status;
bool m_big_endian;
bool m_flip;
int8u* m_indices;
int8* m_glyphs;
int8* m_bglyph;
int8* m_eglyph;
double m_w;
double m_h;
};
//--------------------------------------------------------gsv_text_outline
template<class Transformer = trans_affine> class gsv_text_outline
template <class Transformer = trans_affine>
class gsv_text_outline
{
public:
gsv_text_outline(gsv_text& text, Transformer& trans) :
m_polyline(text),
m_trans(m_polyline, trans)
gsv_text_outline(gsv_text& text, Transformer& trans):
m_polyline(text),
m_trans(m_polyline, trans)
{
}
void width(double w)
{
m_polyline.width(w);
void width(double w)
{
m_polyline.width(w);
}
void transformer(const Transformer* trans)
void transformer(const Transformer* trans)
{
m_trans->transformer(trans);
}
void rewind(unsigned path_id)
{
m_trans.rewind(path_id);
void rewind(unsigned path_id)
{
m_trans.rewind(path_id);
m_polyline.line_join(round_join);
m_polyline.line_cap(round_cap);
}
@@ -145,9 +145,6 @@ namespace agg
conv_transform<conv_stroke<gsv_text>, Transformer> m_trans;
};
}
#endif

View File

@@ -2,8 +2,8 @@
// 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.
// 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.
//
@@ -22,18 +22,21 @@ namespace agg
{
//-----------------------------------------------------image_accessor_clip
template<class PixFmt> class image_accessor_clip
template <class PixFmt>
class image_accessor_clip
{
public:
typedef PixFmt pixfmt_type;
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 };
enum pix_width_e
{
pix_width = pixfmt_type::pix_width
};
image_accessor_clip() {}
explicit image_accessor_clip(pixfmt_type& pixf,
const color_type& bk) :
explicit image_accessor_clip(pixfmt_type& pixf, const color_type& bk):
m_pixf(&pixf)
{
pixfmt_type::make_pix(m_bk_buf, bk);
@@ -52,8 +55,8 @@ namespace agg
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())
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);
}
@@ -65,8 +68,8 @@ namespace agg
{
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())
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);
}
@@ -76,7 +79,8 @@ namespace agg
AGG_INLINE const int8u* next_x()
{
if(m_pix_ptr) return m_pix_ptr += pix_width;
if (m_pix_ptr)
return m_pix_ptr += pix_width;
++m_x;
return pixel();
}
@@ -85,8 +89,7 @@ namespace agg
{
++m_y;
m_x = m_x0;
if(m_pix_ptr &&
m_y >= 0 && m_y < (int)m_pixf->height())
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);
}
@@ -96,28 +99,27 @@ namespace agg
private:
const pixfmt_type* m_pixf;
int8u m_bk_buf[pix_width];
int m_x, m_x0, m_y;
const int8u* m_pix_ptr;
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
template <class PixFmt>
class image_accessor_no_clip
{
public:
typedef PixFmt pixfmt_type;
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 };
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)
{}
explicit image_accessor_no_clip(pixfmt_type& pixf): m_pixf(&pixf) {}
void attach(pixfmt_type& pixf)
{
@@ -144,27 +146,26 @@ namespace agg
private:
const pixfmt_type* m_pixf;
int m_x, m_y;
const int8u* m_pix_ptr;
int m_x, m_y;
const int8u* m_pix_ptr;
};
//----------------------------------------------------image_accessor_clone
template<class PixFmt> class image_accessor_clone
template <class PixFmt>
class image_accessor_clone
{
public:
typedef PixFmt pixfmt_type;
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 };
enum pix_width_e
{
pix_width = pixfmt_type::pix_width
};
image_accessor_clone() {}
explicit image_accessor_clone(pixfmt_type& pixf) :
m_pixf(&pixf)
{}
explicit image_accessor_clone(pixfmt_type& pixf): m_pixf(&pixf) {}
void attach(pixfmt_type& pixf)
{
@@ -176,10 +177,14 @@ namespace agg
{
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;
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);
}
@@ -188,8 +193,8 @@ namespace agg
{
m_x = m_x0 = x;
m_y = y;
if(y >= 0 && y < (int)m_pixf->height() &&
x >= 0 && x+len <= (int)m_pixf->width())
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);
}
@@ -199,7 +204,8 @@ namespace agg
AGG_INLINE const int8u* next_x()
{
if(m_pix_ptr) return m_pix_ptr += pix_width;
if (m_pix_ptr)
return m_pix_ptr += pix_width;
++m_x;
return pixel();
}
@@ -208,8 +214,7 @@ namespace agg
{
++m_y;
m_x = m_x0;
if(m_pix_ptr &&
m_y >= 0 && m_y < (int)m_pixf->height())
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);
}
@@ -219,30 +224,31 @@ namespace agg
private:
const pixfmt_type* m_pixf;
int m_x, m_x0, m_y;
const int8u* m_pix_ptr;
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
template <class PixFmt, class WrapX, class WrapY>
class image_accessor_wrap
{
public:
typedef PixFmt pixfmt_type;
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 };
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()),
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)
{
@@ -270,92 +276,96 @@ namespace agg
private:
const pixfmt_type* m_pixf;
const int8u* m_row_ptr;
int m_x;
WrapX m_wrap_x;
WrapY m_wrap_y;
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),
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++ ()
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;
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)
wrap_mode_repeat_pow2(unsigned size): m_value(0)
{
m_mask = 1;
while(m_mask < size) m_mask = (m_mask << 1) | 1;
while (m_mask < size)
m_mask = (m_mask << 1) | 1;
m_mask >>= 1;
}
AGG_INLINE unsigned operator() (int v)
{
AGG_INLINE unsigned operator()(int v)
{
return m_value = unsigned(v) & m_mask;
}
AGG_INLINE unsigned operator++ ()
AGG_INLINE unsigned operator++()
{
++m_value;
if(m_value > m_mask) m_value = 0;
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) :
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_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;
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++ ()
AGG_INLINE unsigned operator++()
{
++m_value;
if(m_value >= m_size) m_value = 0;
if (m_value >= m_size)
m_value = 0;
return m_value;
}
@@ -366,33 +376,37 @@ namespace agg
unsigned m_value;
};
//-------------------------------------------------------wrap_mode_reflect
class wrap_mode_reflect
{
public:
wrap_mode_reflect() {}
wrap_mode_reflect(unsigned size) :
m_size(size),
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)
{
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;
if (m_value >= m_size)
return m_size2 - m_value - 1;
return m_value;
}
AGG_INLINE unsigned operator++ ()
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;
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;
@@ -400,69 +414,72 @@ namespace agg
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)
wrap_mode_reflect_pow2(unsigned size): m_value(0)
{
m_mask = 1;
m_size = 1;
while(m_mask < size)
while (m_mask < size)
{
m_mask = (m_mask << 1) | 1;
m_size <<= 1;
}
}
AGG_INLINE unsigned operator() (int v)
{
AGG_INLINE unsigned operator()(int v)
{
m_value = unsigned(v) & m_mask;
if(m_value >= m_size) return m_mask - m_value;
if (m_value >= m_size)
return m_mask - m_value;
return m_value;
}
AGG_INLINE unsigned operator++ ()
AGG_INLINE unsigned operator++()
{
++m_value;
m_value &= m_mask;
if(m_value >= m_size) return m_mask - m_value;
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) :
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_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++ ()
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;
if (m_value >= m_size2)
m_value = 0;
if (m_value >= m_size)
return m_size2 - m_value - 1;
return m_value;
}
@@ -474,8 +491,6 @@ namespace agg
unsigned m_value;
};
}
#endif

View File

@@ -2,8 +2,8 @@
// 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.
// 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.
//
@@ -26,116 +26,134 @@
namespace agg
{
// See Implementation agg_image_filters.cpp
// See Implementation agg_image_filters.cpp
enum image_filter_scale_e
{
image_filter_shift = 14, //----image_filter_shift
image_filter_scale = 1 << image_filter_shift, //----image_filter_scale
image_filter_mask = image_filter_scale - 1 //----image_filter_mask
image_filter_scale = 1 << image_filter_shift, //----image_filter_scale
image_filter_mask = image_filter_scale - 1 //----image_filter_mask
};
enum image_subpixel_scale_e
{
image_subpixel_shift = 8, //----image_subpixel_shift
image_subpixel_scale = 1 << image_subpixel_shift, //----image_subpixel_scale
image_subpixel_mask = image_subpixel_scale - 1 //----image_subpixel_mask
image_subpixel_shift = 8, //----image_subpixel_shift
image_subpixel_scale =
1 << image_subpixel_shift, //----image_subpixel_scale
image_subpixel_mask = image_subpixel_scale - 1 //----image_subpixel_mask
};
//-----------------------------------------------------image_filter_lut
class image_filter_lut
{
public:
template<class FilterF> void calculate(const FilterF& filter,
bool normalization=true)
template <class FilterF>
void calculate(const FilterF& filter, bool normalization = true)
{
(void)filter; // prevent erroneous C4100 in MSVC
(void)filter; // prevent erroneous C4100 in MSVC
double r = filter.radius();
realloc_lut(r);
unsigned i;
unsigned pivot = diameter() << (image_subpixel_shift - 1);
for(i = 0; i < pivot; i++)
for (i = 0; i < pivot; i++)
{
double x = double(i) / double(image_subpixel_scale);
double y = filter.calc_weight(x);
m_weight_array[pivot + i] =
m_weight_array[pivot - i] = (int16)iround(y * image_filter_scale);
m_weight_array[pivot + i] = m_weight_array[pivot - i] =
(int16)iround(y * image_filter_scale);
}
unsigned end = (diameter() << image_subpixel_shift) - 1;
m_weight_array[0] = m_weight_array[end];
if(normalization)
if (normalization)
{
normalize();
}
}
image_filter_lut() : m_radius(0), m_diameter(0), m_start(0) {}
image_filter_lut(): m_radius(0), m_diameter(0), m_start(0) {}
template<class FilterF> image_filter_lut(const FilterF& filter,
bool normalization=true)
template <class FilterF>
image_filter_lut(const FilterF& filter, bool normalization = true)
{
calculate(filter, normalization);
}
double radius() const { return m_radius; }
unsigned diameter() const { return m_diameter; }
int start() const { return m_start; }
const int16* weight_array() const { return &m_weight_array[0]; }
void normalize();
double radius() const
{
return m_radius;
}
unsigned diameter() const
{
return m_diameter;
}
int start() const
{
return m_start;
}
const int16* weight_array() const
{
return &m_weight_array[0];
}
void normalize();
private:
void realloc_lut(double radius);
image_filter_lut(const image_filter_lut&);
const image_filter_lut& operator = (const image_filter_lut&);
const image_filter_lut& operator=(const image_filter_lut&);
double m_radius;
unsigned m_diameter;
int m_start;
double m_radius;
unsigned m_diameter;
int m_start;
pod_array<int16> m_weight_array;
};
//--------------------------------------------------------image_filter
template<class FilterF> class image_filter : public image_filter_lut
template <class FilterF>
class image_filter : public image_filter_lut
{
public:
image_filter()
{
calculate(m_filter_function);
}
private:
FilterF m_filter_function;
};
//-----------------------------------------------image_filter_bilinear
struct image_filter_bilinear
{
static double radius() { return 1.0; }
static double radius()
{
return 1.0;
}
static double calc_weight(double x)
{
return 1.0 - x;
}
};
//-----------------------------------------------image_filter_hanning
struct image_filter_hanning
{
static double radius() { return 1.0; }
static double radius()
{
return 1.0;
}
static double calc_weight(double x)
{
return 0.5 + 0.5 * std::cos(pi * x);
}
};
//-----------------------------------------------image_filter_hamming
struct image_filter_hamming
{
static double radius() { return 1.0; }
static double radius()
{
return 1.0;
}
static double calc_weight(double x)
{
return 0.54 + 0.46 * std::cos(pi * x);
@@ -145,22 +163,33 @@ namespace agg
//-----------------------------------------------image_filter_hermite
struct image_filter_hermite
{
static double radius() { return 1.0; }
static double radius()
{
return 1.0;
}
static double calc_weight(double x)
{
return (2.0 * x - 3.0) * x * x + 1.0;
}
};
//------------------------------------------------image_filter_quadric
struct image_filter_quadric
{
static double radius() { return 1.5; }
static double radius()
{
return 1.5;
}
static double calc_weight(double x)
{
double t;
if(x < 0.5) return 0.75 - x * x;
if(x < 1.5) {t = x - 1.5; return 0.5 * t * t;}
if (x < 0.5)
return 0.75 - x * x;
if (x < 1.5)
{
t = x - 1.5;
return 0.5 * t * t;
}
return 0.0;
}
};
@@ -174,12 +203,14 @@ namespace agg
}
public:
static double radius() { return 2.0; }
static double radius()
{
return 2.0;
}
static double calc_weight(double x)
{
return
(1.0/6.0) *
(pow3(x + 2) - 4 * pow3(x + 1) + 6 * pow3(x) - 4 * pow3(x - 1));
return (1.0 / 6.0) * (pow3(x + 2) - 4 * pow3(x + 1) + 6 * pow3(x) -
4 * pow3(x - 1));
}
};
@@ -191,13 +222,15 @@ namespace agg
double epsilon;
public:
image_filter_kaiser(double b = 6.33) :
a(b), epsilon(1e-12)
image_filter_kaiser(double b = 6.33): a(b), epsilon(1e-12)
{
i0a = 1.0 / bessel_i0(b);
}
static double radius() { return 1.0; }
static double radius()
{
return 1.0;
}
double calc_weight(double x) const
{
return bessel_i0(a * std::sqrt(1. - x * x)) * i0a;
@@ -212,8 +245,8 @@ namespace agg
sum = 1.;
y = x * x / 4.;
t = y;
for(i = 2; t > epsilon; i++)
for (i = 2; t > epsilon; i++)
{
sum += t;
t *= (double)y / (i * i);
@@ -225,11 +258,16 @@ namespace agg
//----------------------------------------------image_filter_catrom
struct image_filter_catrom
{
static double radius() { return 2.0; }
static double radius()
{
return 2.0;
}
static double calc_weight(double x)
{
if(x < 1.0) return 0.5 * (2.0 + x * x * (-5.0 + x * 3.0));
if(x < 2.0) return 0.5 * (4.0 + x * (-8.0 + x * (5.0 - x)));
if (x < 1.0)
return 0.5 * (2.0 + x * x * (-5.0 + x * 3.0));
if (x < 2.0)
return 0.5 * (4.0 + x * (-8.0 + x * (5.0 - x)));
return 0.;
}
};
@@ -241,7 +279,7 @@ namespace agg
double q0, q1, q2, q3;
public:
image_filter_mitchell(double b = 1.0/3.0, double c = 1.0/3.0) :
image_filter_mitchell(double b = 1.0 / 3.0, double c = 1.0 / 3.0):
p0((6.0 - 2.0 * b) / 6.0),
p2((-18.0 + 12.0 * b + 6.0 * c) / 6.0),
p3((12.0 - 9.0 * b - 6.0 * c) / 6.0),
@@ -249,200 +287,289 @@ namespace agg
q1((-12.0 * b - 48.0 * c) / 6.0),
q2((6.0 * b + 30.0 * c) / 6.0),
q3((-b - 6.0 * c) / 6.0)
{}
{
}
static double radius() { return 2.0; }
static double radius()
{
return 2.0;
}
double calc_weight(double x) const
{
if(x < 1.0) return p0 + x * x * (p2 + x * p3);
if(x < 2.0) return q0 + x * (q1 + x * (q2 + x * q3));
if (x < 1.0)
return p0 + x * x * (p2 + x * p3);
if (x < 2.0)
return q0 + x * (q1 + x * (q2 + x * q3));
return 0.0;
}
};
//----------------------------------------------image_filter_spline16
struct image_filter_spline16
{
static double radius() { return 2.0; }
static double radius()
{
return 2.0;
}
static double calc_weight(double x)
{
if(x < 1.0)
if (x < 1.0)
{
return ((x - 9.0/5.0 ) * x - 1.0/5.0 ) * x + 1.0;
return ((x - 9.0 / 5.0) * x - 1.0 / 5.0) * x + 1.0;
}
return ((-1.0/3.0 * (x-1) + 4.0/5.0) * (x-1) - 7.0/15.0 ) * (x-1);
return ((-1.0 / 3.0 * (x - 1) + 4.0 / 5.0) * (x - 1) - 7.0 / 15.0) *
(x - 1);
}
};
//---------------------------------------------image_filter_spline36
struct image_filter_spline36
{
static double radius() { return 3.0; }
static double radius()
{
return 3.0;
}
static double calc_weight(double x)
{
if(x < 1.0)
{
return ((13.0/11.0 * x - 453.0/209.0) * x - 3.0/209.0) * x + 1.0;
}
if(x < 2.0)
{
return ((-6.0/11.0 * (x-1) + 270.0/209.0) * (x-1) - 156.0/ 209.0) * (x-1);
}
return ((1.0/11.0 * (x-2) - 45.0/209.0) * (x-2) + 26.0/209.0) * (x-2);
if (x < 1.0)
{
return ((13.0 / 11.0 * x - 453.0 / 209.0) * x - 3.0 / 209.0) *
x +
1.0;
}
if (x < 2.0)
{
return ((-6.0 / 11.0 * (x - 1) + 270.0 / 209.0) * (x - 1) -
156.0 / 209.0) *
(x - 1);
}
return ((1.0 / 11.0 * (x - 2) - 45.0 / 209.0) * (x - 2) +
26.0 / 209.0) *
(x - 2);
}
};
//----------------------------------------------image_filter_gaussian
struct image_filter_gaussian
{
static double radius() { return 2.0; }
static double calc_weight(double x)
static double radius()
{
return 2.0;
}
static double calc_weight(double x)
{
return std::exp(-2.0 * x * x) * std::sqrt(2.0 / pi);
}
};
//------------------------------------------------image_filter_bessel
struct image_filter_bessel
{
static double radius() { return 3.2383; }
static double radius()
{
return 3.2383;
}
static double calc_weight(double x)
{
return (x == 0.0) ? pi / 4.0 : besj(pi * x, 1) / (2.0 * x);
}
};
//-------------------------------------------------image_filter_sinc
class image_filter_sinc
{
public:
image_filter_sinc(double r) : m_radius(r < 2.0 ? 2.0 : r) {}
double radius() const { return m_radius; }
image_filter_sinc(double r): m_radius(r < 2.0 ? 2.0 : r) {}
double radius() const
{
return m_radius;
}
double calc_weight(double x) const
{
if(x == 0.0) return 1.0;
if (x == 0.0)
return 1.0;
x *= pi;
return std::sin(x) / x;
}
private:
double m_radius;
};
//-----------------------------------------------image_filter_lanczos
class image_filter_lanczos
{
public:
image_filter_lanczos(double r) : m_radius(r < 2.0 ? 2.0 : r) {}
double radius() const { return m_radius; }
image_filter_lanczos(double r): m_radius(r < 2.0 ? 2.0 : r) {}
double radius() const
{
return m_radius;
}
double calc_weight(double x) const
{
if(x == 0.0) return 1.0;
if(x > m_radius) return 0.0;
x *= pi;
double xr = x / m_radius;
return (std::sin(x) / x) * (std::sin(xr) / xr);
if (x == 0.0)
return 1.0;
if (x > m_radius)
return 0.0;
x *= pi;
double xr = x / m_radius;
return (std::sin(x) / x) * (std::sin(xr) / xr);
}
private:
double m_radius;
};
//----------------------------------------------image_filter_blackman
class image_filter_blackman
{
public:
image_filter_blackman(double r) : m_radius(r < 2.0 ? 2.0 : r) {}
double radius() const { return m_radius; }
image_filter_blackman(double r): m_radius(r < 2.0 ? 2.0 : r) {}
double radius() const
{
return m_radius;
}
double calc_weight(double x) const
{
if(x == 0.0) return 1.0;
if(x > m_radius) return 0.0;
x *= pi;
double xr = x / m_radius;
return (std::sin(x) / x) * (0.42 + 0.5*std::cos(xr) + 0.08*std::cos(2*xr));
if (x == 0.0)
return 1.0;
if (x > m_radius)
return 0.0;
x *= pi;
double xr = x / m_radius;
return (std::sin(x) / x) *
(0.42 + 0.5 * std::cos(xr) + 0.08 * std::cos(2 * xr));
}
private:
double m_radius;
};
//------------------------------------------------image_filter_sinc36
class image_filter_sinc36 : public image_filter_sinc
{ public: image_filter_sinc36() : image_filter_sinc(3.0){} };
{
public:
image_filter_sinc36(): image_filter_sinc(3.0) {}
};
//------------------------------------------------image_filter_sinc64
class image_filter_sinc64 : public image_filter_sinc
{ public: image_filter_sinc64() : image_filter_sinc(4.0){} };
{
public:
image_filter_sinc64(): image_filter_sinc(4.0) {}
};
//-----------------------------------------------image_filter_sinc100
class image_filter_sinc100 : public image_filter_sinc
{ public: image_filter_sinc100() : image_filter_sinc(5.0){} };
{
public:
image_filter_sinc100(): image_filter_sinc(5.0) {}
};
//-----------------------------------------------image_filter_sinc144
class image_filter_sinc144 : public image_filter_sinc
{ public: image_filter_sinc144() : image_filter_sinc(6.0){} };
{
public:
image_filter_sinc144(): image_filter_sinc(6.0) {}
};
//-----------------------------------------------image_filter_sinc196
class image_filter_sinc196 : public image_filter_sinc
{ public: image_filter_sinc196() : image_filter_sinc(7.0){} };
{
public:
image_filter_sinc196(): image_filter_sinc(7.0) {}
};
//-----------------------------------------------image_filter_sinc256
class image_filter_sinc256 : public image_filter_sinc
{ public: image_filter_sinc256() : image_filter_sinc(8.0){} };
{
public:
image_filter_sinc256(): image_filter_sinc(8.0) {}
};
//---------------------------------------------image_filter_lanczos36
class image_filter_lanczos36 : public image_filter_lanczos
{ public: image_filter_lanczos36() : image_filter_lanczos(3.0){} };
{
public:
image_filter_lanczos36(): image_filter_lanczos(3.0) {}
};
//---------------------------------------------image_filter_lanczos64
class image_filter_lanczos64 : public image_filter_lanczos
{ public: image_filter_lanczos64() : image_filter_lanczos(4.0){} };
{
public:
image_filter_lanczos64(): image_filter_lanczos(4.0) {}
};
//--------------------------------------------image_filter_lanczos100
class image_filter_lanczos100 : public image_filter_lanczos
{ public: image_filter_lanczos100() : image_filter_lanczos(5.0){} };
{
public:
image_filter_lanczos100(): image_filter_lanczos(5.0) {}
};
//--------------------------------------------image_filter_lanczos144
class image_filter_lanczos144 : public image_filter_lanczos
{ public: image_filter_lanczos144() : image_filter_lanczos(6.0){} };
{
public:
image_filter_lanczos144(): image_filter_lanczos(6.0) {}
};
//--------------------------------------------image_filter_lanczos196
class image_filter_lanczos196 : public image_filter_lanczos
{ public: image_filter_lanczos196() : image_filter_lanczos(7.0){} };
{
public:
image_filter_lanczos196(): image_filter_lanczos(7.0) {}
};
//--------------------------------------------image_filter_lanczos256
class image_filter_lanczos256 : public image_filter_lanczos
{ public: image_filter_lanczos256() : image_filter_lanczos(8.0){} };
{
public:
image_filter_lanczos256(): image_filter_lanczos(8.0) {}
};
//--------------------------------------------image_filter_blackman36
class image_filter_blackman36 : public image_filter_blackman
{ public: image_filter_blackman36() : image_filter_blackman(3.0){} };
{
public:
image_filter_blackman36(): image_filter_blackman(3.0) {}
};
//--------------------------------------------image_filter_blackman64
class image_filter_blackman64 : public image_filter_blackman
{ public: image_filter_blackman64() : image_filter_blackman(4.0){} };
{
public:
image_filter_blackman64(): image_filter_blackman(4.0) {}
};
//-------------------------------------------image_filter_blackman100
class image_filter_blackman100 : public image_filter_blackman
{ public: image_filter_blackman100() : image_filter_blackman(5.0){} };
{
public:
image_filter_blackman100(): image_filter_blackman(5.0) {}
};
//-------------------------------------------image_filter_blackman144
class image_filter_blackman144 : public image_filter_blackman
{ public: image_filter_blackman144() : image_filter_blackman(6.0){} };
{
public:
image_filter_blackman144(): image_filter_blackman(6.0) {}
};
//-------------------------------------------image_filter_blackman196
class image_filter_blackman196 : public image_filter_blackman
{ public: image_filter_blackman196() : image_filter_blackman(7.0){} };
{
public:
image_filter_blackman196(): image_filter_blackman(7.0) {}
};
//-------------------------------------------image_filter_blackman256
class image_filter_blackman256 : public image_filter_blackman
{ public: image_filter_blackman256() : image_filter_blackman(8.0){} };
{
public:
image_filter_blackman256(): image_filter_blackman(8.0) {}
};
}

View File

@@ -2,8 +2,8 @@
// 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.
// 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.
//
@@ -21,41 +21,44 @@
namespace agg
{
// See Implementation agg_line_aa_basics.cpp
// See Implementation agg_line_aa_basics.cpp
//-------------------------------------------------------------------------
enum line_subpixel_scale_e
{
line_subpixel_shift = 8, //----line_subpixel_shift
line_subpixel_scale = 1 << line_subpixel_shift, //----line_subpixel_scale
line_subpixel_mask = line_subpixel_scale - 1, //----line_subpixel_mask
line_max_coord = (1 << 28) - 1, //----line_max_coord
line_subpixel_shift = 8, //----line_subpixel_shift
line_subpixel_scale = 1
<< line_subpixel_shift, //----line_subpixel_scale
line_subpixel_mask = line_subpixel_scale - 1, //----line_subpixel_mask
line_max_coord = (1 << 28) - 1, //----line_max_coord
line_max_length = 1 << (line_subpixel_shift + 10) //----line_max_length
};
//-------------------------------------------------------------------------
enum line_mr_subpixel_scale_e
{
line_mr_subpixel_shift = 4, //----line_mr_subpixel_shift
line_mr_subpixel_scale = 1 << line_mr_subpixel_shift, //----line_mr_subpixel_scale
line_mr_subpixel_mask = line_mr_subpixel_scale - 1 //----line_mr_subpixel_mask
line_mr_subpixel_shift = 4, //----line_mr_subpixel_shift
line_mr_subpixel_scale =
1 << line_mr_subpixel_shift, //----line_mr_subpixel_scale
line_mr_subpixel_mask =
line_mr_subpixel_scale - 1 //----line_mr_subpixel_mask
};
//------------------------------------------------------------------line_mr
AGG_INLINE int line_mr(int x)
{
return x >> (line_subpixel_shift - line_mr_subpixel_shift);
AGG_INLINE int line_mr(int x)
{
return x >> (line_subpixel_shift - line_mr_subpixel_shift);
}
//-------------------------------------------------------------------line_hr
AGG_INLINE int line_hr(int x)
{
return x << (line_subpixel_shift - line_mr_subpixel_shift);
AGG_INLINE int line_hr(int x)
{
return x << (line_subpixel_shift - line_mr_subpixel_shift);
}
//---------------------------------------------------------------line_dbl_hr
AGG_INLINE int line_dbl_hr(int x)
{
AGG_INLINE int line_dbl_hr(int x)
{
return x << line_subpixel_shift;
}
@@ -82,8 +85,11 @@ namespace agg
{
//---------------------------------------------------------------------
line_parameters() {}
line_parameters(int x1_, int y1_, int x2_, int y2_, int len_) :
x1(x1_), y1(y1_), x2(x2_), y2(y2_),
line_parameters(int x1_, int y1_, int x2_, int y2_, int len_):
x1(x1_),
y1(y1_),
x2(x2_),
y2(y2_),
dx(std::abs(x2_ - x1_)),
dy(std::abs(y2_ - y1_)),
sx((x2_ > x1_) ? 1 : -1),
@@ -96,19 +102,27 @@ namespace agg
}
//---------------------------------------------------------------------
unsigned orthogonal_quadrant() const { return s_orthogonal_quadrant[octant]; }
unsigned diagonal_quadrant() const { return s_diagonal_quadrant[octant]; }
unsigned orthogonal_quadrant() const
{
return s_orthogonal_quadrant[octant];
}
unsigned diagonal_quadrant() const
{
return s_diagonal_quadrant[octant];
}
//---------------------------------------------------------------------
bool same_orthogonal_quadrant(const line_parameters& lp) const
{
return s_orthogonal_quadrant[octant] == s_orthogonal_quadrant[lp.octant];
return s_orthogonal_quadrant[octant] ==
s_orthogonal_quadrant[lp.octant];
}
//---------------------------------------------------------------------
bool same_diagonal_quadrant(const line_parameters& lp) const
{
return s_diagonal_quadrant[octant] == s_diagonal_quadrant[lp.octant];
return s_diagonal_quadrant[octant] ==
s_diagonal_quadrant[lp.octant];
}
//---------------------------------------------------------------------
@@ -121,19 +135,19 @@ namespace agg
lp1 = *this;
lp2 = *this;
lp1.x2 = xmid;
lp1.y2 = ymid;
lp1.x2 = xmid;
lp1.y2 = ymid;
lp1.len = len2;
lp1.dx = std::abs(lp1.x2 - lp1.x1);
lp1.dy = std::abs(lp1.y2 - lp1.y1);
lp1.dx = std::abs(lp1.x2 - lp1.x1);
lp1.dy = std::abs(lp1.y2 - lp1.y1);
lp2.x1 = xmid;
lp2.y1 = ymid;
lp2.x1 = xmid;
lp2.y1 = ymid;
lp2.len = len2;
lp2.dx = std::abs(lp2.x2 - lp2.x1);
lp2.dy = std::abs(lp2.y2 - lp2.y1);
lp2.dx = std::abs(lp2.x2 - lp2.x1);
lp2.dy = std::abs(lp2.y2 - lp2.y1);
}
//---------------------------------------------------------------------
int x1, y1, x2, y2, dx, dy, sx, sy;
bool vertical;
@@ -146,44 +160,40 @@ namespace agg
static const int8u s_diagonal_quadrant[8];
};
// See Implementation agg_line_aa_basics.cpp
// See Implementation agg_line_aa_basics.cpp
//----------------------------------------------------------------bisectrix
void bisectrix(const line_parameters& l1,
const line_parameters& l2,
int* x, int* y);
void bisectrix(
const line_parameters& l1, const line_parameters& l2, int* x, int* y);
//-------------------------------------------fix_degenerate_bisectrix_start
void inline fix_degenerate_bisectrix_start(const line_parameters& lp,
int* x, int* y)
void inline fix_degenerate_bisectrix_start(
const line_parameters& lp, int* x, int* y)
{
int d = iround((double(*x - lp.x2) * double(lp.y2 - lp.y1) -
double(*y - lp.y2) * double(lp.x2 - lp.x1)) / lp.len);
if(d < line_subpixel_scale/2)
int d = iround((double(*x - lp.x2) * double(lp.y2 - lp.y1) -
double(*y - lp.y2) * double(lp.x2 - lp.x1)) /
lp.len);
if (d < line_subpixel_scale / 2)
{
*x = lp.x1 + (lp.y2 - lp.y1);
*y = lp.y1 - (lp.x2 - lp.x1);
}
}
//---------------------------------------------fix_degenerate_bisectrix_end
void inline fix_degenerate_bisectrix_end(const line_parameters& lp,
int* x, int* y)
void inline fix_degenerate_bisectrix_end(
const line_parameters& lp, int* x, int* y)
{
int d = iround((double(*x - lp.x2) * double(lp.y2 - lp.y1) -
double(*y - lp.y2) * double(lp.x2 - lp.x1)) / lp.len);
if(d < line_subpixel_scale/2)
int d = iround((double(*x - lp.x2) * double(lp.y2 - lp.y1) -
double(*y - lp.y2) * double(lp.x2 - lp.x1)) /
lp.len);
if (d < line_subpixel_scale / 2)
{
*x = lp.x2 + (lp.y2 - lp.y1);
*y = lp.y2 - (lp.x2 - lp.x1);
}
}
}
#endif

View File

@@ -2,8 +2,8 @@
// 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.
// 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.
//
@@ -12,7 +12,7 @@
// mcseemagg@yahoo.com
// http://www.antigrain.com
//----------------------------------------------------------------------------
// Bessel function (besj) was adapted for use in AGG library by Andy Wilk
// Bessel function (besj) was adapted for use in AGG library by Andy Wilk
// Contact: castor.vulgaris@gmail.com
//----------------------------------------------------------------------------
@@ -34,18 +34,21 @@ namespace agg
const double intersection_epsilon = 1.0e-30;
//------------------------------------------------------------cross_product
AGG_INLINE double cross_product(double x1, double y1,
double x2, double y2,
double x, double y)
AGG_INLINE double cross_product(
double x1, double y1, double x2, double y2, double x, double y)
{
return (x - x2) * (y2 - y1) - (y - y2) * (x2 - x1);
}
//--------------------------------------------------------point_in_triangle
AGG_INLINE bool point_in_triangle(double x1, double y1,
double x2, double y2,
double x3, double y3,
double x, double y)
AGG_INLINE bool point_in_triangle(double x1,
double y1,
double x2,
double y2,
double x3,
double y3,
double x,
double y)
{
bool cp1 = cross_product(x1, y1, x2, y2, x, y) < 0.0;
bool cp2 = cross_product(x2, y2, x3, y3, x, y) < 0.0;
@@ -56,28 +59,28 @@ namespace agg
//-----------------------------------------------------------calc_distance
AGG_INLINE double calc_distance(double x1, double y1, double x2, double y2)
{
double dx = x2-x1;
double dy = y2-y1;
double dx = x2 - x1;
double dy = y2 - y1;
return std::sqrt(dx * dx + dy * dy);
}
//--------------------------------------------------------calc_sq_distance
AGG_INLINE double calc_sq_distance(double x1, double y1, double x2, double y2)
AGG_INLINE double calc_sq_distance(
double x1, double y1, double x2, double y2)
{
double dx = x2-x1;
double dy = y2-y1;
double dx = x2 - x1;
double dy = y2 - y1;
return dx * dx + dy * dy;
}
//------------------------------------------------calc_line_point_distance
AGG_INLINE double calc_line_point_distance(double x1, double y1,
double x2, double y2,
double x, double y)
AGG_INLINE double calc_line_point_distance(
double x1, double y1, double x2, double y2, double x, double y)
{
double dx = x2-x1;
double dy = y2-y1;
double dx = x2 - x1;
double dy = y2 - y1;
double d = std::sqrt(dx * dx + dy * dy);
if(d < vertex_dist_epsilon)
if (d < vertex_dist_epsilon)
{
return calc_distance(x1, y1, x, y);
}
@@ -85,16 +88,15 @@ namespace agg
}
//-------------------------------------------------------calc_line_point_u
AGG_INLINE double calc_segment_point_u(double x1, double y1,
double x2, double y2,
double x, double y)
AGG_INLINE double calc_segment_point_u(
double x1, double y1, double x2, double y2, double x, double y)
{
double dx = x2 - x1;
double dy = y2 - y1;
if(dx == 0 && dy == 0)
if (dx == 0 && dy == 0)
{
return 0;
return 0;
}
double pdx = x - x1;
@@ -104,105 +106,125 @@ namespace agg
}
//---------------------------------------------calc_line_point_sq_distance
AGG_INLINE double calc_segment_point_sq_distance(double x1, double y1,
double x2, double y2,
double x, double y,
double u)
AGG_INLINE double calc_segment_point_sq_distance(double x1,
double y1,
double x2,
double y2,
double x,
double y,
double u)
{
if(u <= 0)
if (u <= 0)
{
return calc_sq_distance(x, y, x1, y1);
return calc_sq_distance(x, y, x1, y1);
}
else
if(u >= 1)
else if (u >= 1)
{
return calc_sq_distance(x, y, x2, y2);
return calc_sq_distance(x, y, x2, y2);
}
return calc_sq_distance(x, y, x1 + u * (x2 - x1), y1 + u * (y2 - y1));
}
//---------------------------------------------calc_line_point_sq_distance
AGG_INLINE double calc_segment_point_sq_distance(double x1, double y1,
double x2, double y2,
double x, double y)
AGG_INLINE double calc_segment_point_sq_distance(
double x1, double y1, double x2, double y2, double x, double y)
{
return
calc_segment_point_sq_distance(
x1, y1, x2, y2, x, y,
calc_segment_point_u(x1, y1, x2, y2, x, y));
return calc_segment_point_sq_distance(
x1, y1, x2, y2, x, y, calc_segment_point_u(x1, y1, x2, y2, x, y));
}
//-------------------------------------------------------calc_intersection
AGG_INLINE bool calc_intersection(double ax, double ay, double bx, double by,
double cx, double cy, double dx, double dy,
double* x, double* y)
AGG_INLINE bool calc_intersection(double ax,
double ay,
double bx,
double by,
double cx,
double cy,
double dx,
double dy,
double* x,
double* y)
{
double num = (ay-cy) * (dx-cx) - (ax-cx) * (dy-cy);
double den = (bx-ax) * (dy-cy) - (by-ay) * (dx-cx);
if(std::fabs(den) < intersection_epsilon) return false;
double num = (ay - cy) * (dx - cx) - (ax - cx) * (dy - cy);
double den = (bx - ax) * (dy - cy) - (by - ay) * (dx - cx);
if (std::fabs(den) < intersection_epsilon)
return false;
double r = num / den;
*x = ax + r * (bx-ax);
*y = ay + r * (by-ay);
*x = ax + r * (bx - ax);
*y = ay + r * (by - ay);
return true;
}
//-----------------------------------------------------intersection_exists
AGG_INLINE bool intersection_exists(double x1, double y1, double x2, double y2,
double x3, double y3, double x4, double y4)
AGG_INLINE bool intersection_exists(double x1,
double y1,
double x2,
double y2,
double x3,
double y3,
double x4,
double y4)
{
// It's less expensive but you can't control the
// It's less expensive but you can't control the
// boundary conditions: Less or LessEqual
double dx1 = x2 - x1;
double dy1 = y2 - y1;
double dx2 = x4 - x3;
double dy2 = y4 - y3;
return ((x3 - x2) * dy1 - (y3 - y2) * dx1 < 0.0) !=
((x4 - x2) * dy1 - (y4 - y2) * dx1 < 0.0) &&
return ((x3 - x2) * dy1 - (y3 - y2) * dx1 < 0.0) !=
((x4 - x2) * dy1 - (y4 - y2) * dx1 < 0.0) &&
((x1 - x4) * dy2 - (y1 - y4) * dx2 < 0.0) !=
((x2 - x4) * dy2 - (y2 - y4) * dx2 < 0.0);
((x2 - x4) * dy2 - (y2 - y4) * dx2 < 0.0);
// It's is more expensive but more flexible
// It's is more expensive but more flexible
// in terms of boundary conditions.
//--------------------
//double den = (x2-x1) * (y4-y3) - (y2-y1) * (x4-x3);
//if(fabs(den) < intersection_epsilon) return false;
//double nom1 = (x4-x3) * (y1-y3) - (y4-y3) * (x1-x3);
//double nom2 = (x2-x1) * (y1-y3) - (y2-y1) * (x1-x3);
//double ua = nom1 / den;
//double ub = nom2 / den;
//return ua >= 0.0 && ua <= 1.0 && ub >= 0.0 && ub <= 1.0;
// double den = (x2-x1) * (y4-y3) - (y2-y1) * (x4-x3);
// if(fabs(den) < intersection_epsilon) return false;
// double nom1 = (x4-x3) * (y1-y3) - (y4-y3) * (x1-x3);
// double nom2 = (x2-x1) * (y1-y3) - (y2-y1) * (x1-x3);
// double ua = nom1 / den;
// double ub = nom2 / den;
// return ua >= 0.0 && ua <= 1.0 && ub >= 0.0 && ub <= 1.0;
}
//--------------------------------------------------------calc_orthogonal
AGG_INLINE void calc_orthogonal(double thickness,
double x1, double y1,
double x2, double y2,
double* x, double* y)
double x1,
double y1,
double x2,
double y2,
double* x,
double* y)
{
double dx = x2 - x1;
double dy = y2 - y1;
double d = std::sqrt(dx*dx + dy*dy);
*x = thickness * dy / d;
double d = std::sqrt(dx * dx + dy * dy);
*x = thickness * dy / d;
*y = -thickness * dx / d;
}
//--------------------------------------------------------dilate_triangle
AGG_INLINE void dilate_triangle(double x1, double y1,
double x2, double y2,
double x3, double y3,
double *x, double* y,
double d)
AGG_INLINE void dilate_triangle(double x1,
double y1,
double x2,
double y2,
double x3,
double y3,
double* x,
double* y,
double d)
{
double dx1=0.0;
double dy1=0.0;
double dx2=0.0;
double dy2=0.0;
double dx3=0.0;
double dy3=0.0;
double dx1 = 0.0;
double dy1 = 0.0;
double dx2 = 0.0;
double dy2 = 0.0;
double dx3 = 0.0;
double dy3 = 0.0;
double loc = cross_product(x1, y1, x2, y2, x3, y3);
if(std::fabs(loc) > intersection_epsilon)
if (std::fabs(loc) > intersection_epsilon)
{
if(cross_product(x1, y1, x2, y2, x3, y3) > 0.0)
if (cross_product(x1, y1, x2, y2, x3, y3) > 0.0)
{
d = -d;
}
@@ -210,33 +232,40 @@ namespace agg
calc_orthogonal(d, x2, y2, x3, y3, &dx2, &dy2);
calc_orthogonal(d, x3, y3, x1, y1, &dx3, &dy3);
}
*x++ = x1 + dx1; *y++ = y1 + dy1;
*x++ = x2 + dx1; *y++ = y2 + dy1;
*x++ = x2 + dx2; *y++ = y2 + dy2;
*x++ = x3 + dx2; *y++ = y3 + dy2;
*x++ = x3 + dx3; *y++ = y3 + dy3;
*x++ = x1 + dx3; *y++ = y1 + dy3;
*x++ = x1 + dx1;
*y++ = y1 + dy1;
*x++ = x2 + dx1;
*y++ = y2 + dy1;
*x++ = x2 + dx2;
*y++ = y2 + dy2;
*x++ = x3 + dx2;
*y++ = y3 + dy2;
*x++ = x3 + dx3;
*y++ = y3 + dy3;
*x++ = x1 + dx3;
*y++ = y1 + dy3;
}
//------------------------------------------------------calc_triangle_area
AGG_INLINE double calc_triangle_area(double x1, double y1,
double x2, double y2,
double x3, double y3)
AGG_INLINE double calc_triangle_area(
double x1, double y1, double x2, double y2, double x3, double y3)
{
return (x1*y2 - x2*y1 + x2*y3 - x3*y2 + x3*y1 - x1*y3) * 0.5;
return (x1 * y2 - x2 * y1 + x2 * y3 - x3 * y2 + x3 * y1 - x1 * y3) *
0.5;
}
//-------------------------------------------------------calc_polygon_area
template<class Storage> double calc_polygon_area(const Storage& st)
template <class Storage>
double calc_polygon_area(const Storage& st)
{
unsigned i;
double sum = 0.0;
double x = st[0].x;
double y = st[0].y;
double x = st[0].x;
double y = st[0].y;
double xs = x;
double ys = y;
for(i = 1; i < st.size(); i++)
for (i = 1; i < st.size(); i++)
{
const typename Storage::value_type& v = st[i];
sum += x * v.y - y * v.x;
@@ -249,21 +278,20 @@ namespace agg
//------------------------------------------------------------------------
// Tables for fast sqrt
extern int16u g_sqrt_table[1024];
extern int8 g_elder_bit_table[256];
extern int8 g_elder_bit_table[256];
//---------------------------------------------------------------fast_sqrt
//Fast integer Sqrt - really fast: no cycles, divisions or multiplications
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable : 4035) //Disable warning "no return value"
#endif
//---------------------------------------------------------------fast_sqrt
// Fast integer Sqrt - really fast: no cycles, divisions or multiplications
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable : 4035) // Disable warning "no return value"
#endif
AGG_INLINE unsigned fast_sqrt(unsigned val)
{
#if defined(_M_IX86) && defined(_MSC_VER) && !defined(AGG_NO_ASM)
//For Ix86 family processors this assembler code is used.
//The key command here is bsr - determination the number of the most
//significant bit of the value. For other processors
#if defined(_M_IX86) && defined(_MSC_VER) && !defined(AGG_NO_ASM)
// For Ix86 family processors this assembler code is used.
// The key command here is bsr - determination the number of the most
// significant bit of the value. For other processors
//(and maybe compilers) the pure C "#else" section is used.
__asm
{
@@ -283,35 +311,35 @@ namespace agg
mov ecx, edx
shr eax, cl
}
#else
#else
//This code is actually pure C and portable to most
//arcitectures including 64bit ones.
// This code is actually pure C and portable to most
// arcitectures including 64bit ones.
unsigned t = val;
int bit=0;
int bit = 0;
unsigned shift = 11;
//The following piece of code is just an emulation of the
//Ix86 assembler command "bsr" (see above). However on old
//Intels (like Intel MMX 233MHz) this code is about twice
//faster (sic!) then just one "bsr". On PIII and PIV the
//bsr is optimized quite well.
// The following piece of code is just an emulation of the
// Ix86 assembler command "bsr" (see above). However on old
// Intels (like Intel MMX 233MHz) this code is about twice
// faster (sic!) then just one "bsr". On PIII and PIV the
// bsr is optimized quite well.
bit = t >> 24;
if(bit)
if (bit)
{
bit = g_elder_bit_table[bit] + 24;
}
else
{
bit = (t >> 16) & 0xFF;
if(bit)
if (bit)
{
bit = g_elder_bit_table[bit] + 16;
}
else
{
bit = (t >> 8) & 0xFF;
if(bit)
if (bit)
{
bit = g_elder_bit_table[bit] + 8;
}
@@ -322,23 +350,20 @@ namespace agg
}
}
//This code calculates the sqrt.
// This code calculates the sqrt.
bit -= 9;
if(bit > 0)
if (bit > 0)
{
bit = (bit >> 1) + (bit & 1);
shift -= bit;
val >>= (bit << 1);
}
return g_sqrt_table[val] >> shift;
#endif
#endif
}
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
//--------------------------------------------------------------------besj
// Function BESJ calculates Bessel function of first kind of order n
@@ -364,48 +389,49 @@ namespace agg
//------------------------------------------------------------------------
inline double besj(double x, int n)
{
if(n < 0)
if (n < 0)
{
return 0;
}
double d = 1E-6;
double b = 0;
if(std::fabs(x) <= d)
if (std::fabs(x) <= d)
{
if(n != 0) return 0;
if (n != 0)
return 0;
return 1;
}
double b1 = 0; // b1 is the value from the previous iteration
// Set up a starting order for recurrence
int m1 = (int)std::fabs(x) + 6;
if(std::fabs(x) > 5)
if (std::fabs(x) > 5)
{
m1 = (int)(std::fabs(1.4 * x + 60 / x));
}
int m2 = (int)(n + 2 + std::fabs(x) / 4);
if (m1 > m2)
if (m1 > m2)
{
m2 = m1;
}
// Apply recurrence down from curent max order
for(;;)
for (;;)
{
double c3 = 0;
double c2 = 1E-30;
double c4 = 0;
int m8 = 1;
if (m2 / 2 * 2 == m2)
if (m2 / 2 * 2 == m2)
{
m8 = -1;
}
int imax = m2 - 2;
for (int i = 1; i <= imax; i++)
for (int i = 1; i <= imax; i++)
{
double c6 = 2 * (m2 - i) * c2 / x - c3;
c3 = c2;
c2 = c6;
if(m2 - i - 1 == n)
if (m2 - i - 1 == n)
{
b = c6;
}
@@ -416,13 +442,13 @@ namespace agg
}
}
double c6 = 2 * c2 / x - c3;
if(n == 0)
if (n == 0)
{
b = c6;
}
c4 += c6;
b /= c4;
if(std::fabs(b - b1) < d)
if (std::fabs(b - b1) < d)
{
return b;
}
@@ -433,5 +459,4 @@ namespace agg
}
#endif

View File

@@ -2,8 +2,8 @@
// 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.
// 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.
//
@@ -36,14 +36,13 @@ namespace agg
//------------------------------------------------------------line_join_e
enum line_join_e
{
miter_join = 0,
miter_join_revert = 1,
round_join = 2,
bevel_join = 3,
miter_join_round = 4
miter_join = 0,
miter_join_revert = 1,
round_join = 2,
bevel_join = 3,
miter_join_round = 4
};
//-----------------------------------------------------------inner_join_e
enum inner_join_e
{
@@ -54,43 +53,83 @@ namespace agg
};
//------------------------------------------------------------math_stroke
template<class VertexConsumer> class math_stroke
template <class VertexConsumer>
class math_stroke
{
public:
typedef typename VertexConsumer::value_type coord_type;
math_stroke();
void line_cap(line_cap_e lc) { m_line_cap = lc; }
void line_join(line_join_e lj) { m_line_join = lj; }
void inner_join(inner_join_e ij) { m_inner_join = ij; }
void line_cap(line_cap_e lc)
{
m_line_cap = lc;
}
void line_join(line_join_e lj)
{
m_line_join = lj;
}
void inner_join(inner_join_e ij)
{
m_inner_join = ij;
}
line_cap_e line_cap() const { return m_line_cap; }
line_join_e line_join() const { return m_line_join; }
inner_join_e inner_join() const { return m_inner_join; }
line_cap_e line_cap() const
{
return m_line_cap;
}
line_join_e line_join() const
{
return m_line_join;
}
inner_join_e inner_join() const
{
return m_inner_join;
}
void width(double w);
void miter_limit(double ml) { m_miter_limit = ml; }
void miter_limit(double ml)
{
m_miter_limit = ml;
}
void miter_limit_theta(double t);
void inner_miter_limit(double ml) { m_inner_miter_limit = ml; }
void approximation_scale(double as) { m_approx_scale = as; }
void inner_miter_limit(double ml)
{
m_inner_miter_limit = ml;
}
void approximation_scale(double as)
{
m_approx_scale = as;
}
double width() const { return m_width * 2.0; }
double miter_limit() const { return m_miter_limit; }
double inner_miter_limit() const { return m_inner_miter_limit; }
double approximation_scale() const { return m_approx_scale; }
double width() const
{
return m_width * 2.0;
}
double miter_limit() const
{
return m_miter_limit;
}
double inner_miter_limit() const
{
return m_inner_miter_limit;
}
double approximation_scale() const
{
return m_approx_scale;
}
void calc_cap(VertexConsumer& vc,
const vertex_dist& v0,
const vertex_dist& v1,
double len);
const vertex_dist& v0,
const vertex_dist& v1,
double len);
void calc_join(VertexConsumer& vc,
const vertex_dist& v0,
const vertex_dist& v1,
const vertex_dist& v2,
double len1,
double len2);
const vertex_dist& v0,
const vertex_dist& v1,
const vertex_dist& v2,
double len1,
double len2);
private:
AGG_INLINE void add_vertex(VertexConsumer& vc, double x, double y)
@@ -99,37 +138,43 @@ namespace agg
}
void calc_arc(VertexConsumer& vc,
double x, double y,
double dx1, double dy1,
double dx2, double dy2);
double x,
double y,
double dx1,
double dy1,
double dx2,
double dy2);
void calc_miter(VertexConsumer& vc,
const vertex_dist& v0,
const vertex_dist& v1,
const vertex_dist& v2,
double dx1, double dy1,
double dx2, double dy2,
line_join_e lj,
double mlimit,
double dbevel);
const vertex_dist& v0,
const vertex_dist& v1,
const vertex_dist& v2,
double dx1,
double dy1,
double dx2,
double dy2,
line_join_e lj,
double mlimit,
double dbevel);
double m_width;
double m_width_abs;
double m_width_eps;
int m_width_sign;
double m_miter_limit;
double m_inner_miter_limit;
double m_approx_scale;
line_cap_e m_line_cap;
line_join_e m_line_join;
double m_width;
double m_width_abs;
double m_width_eps;
int m_width_sign;
double m_miter_limit;
double m_inner_miter_limit;
double m_approx_scale;
line_cap_e m_line_cap;
line_join_e m_line_join;
inner_join_e m_inner_join;
};
//-----------------------------------------------------------------------
template<class VC> math_stroke<VC>::math_stroke() :
template <class VC>
math_stroke<VC>::math_stroke():
m_width(0.5),
m_width_abs(0.5),
m_width_eps(0.5/1024.0),
m_width_eps(0.5 / 1024.0),
m_width_sign(1),
m_miter_limit(4.0),
m_inner_miter_limit(1.01),
@@ -141,64 +186,74 @@ namespace agg
}
//-----------------------------------------------------------------------
template<class VC> void math_stroke<VC>::width(double w)
{
m_width = w * 0.5;
if(m_width < 0)
template <class VC>
void math_stroke<VC>::width(double w)
{
m_width = w * 0.5;
if (m_width < 0)
{
m_width_abs = -m_width;
m_width_abs = -m_width;
m_width_sign = -1;
}
else
{
m_width_abs = m_width;
m_width_abs = m_width;
m_width_sign = 1;
}
m_width_eps = m_width / 1024.0;
}
//-----------------------------------------------------------------------
template<class VC> void math_stroke<VC>::miter_limit_theta(double t)
{
m_miter_limit = 1.0 / std::sin(t * 0.5) ;
template <class VC>
void math_stroke<VC>::miter_limit_theta(double t)
{
m_miter_limit = 1.0 / std::sin(t * 0.5);
}
//-----------------------------------------------------------------------
template<class VC>
template <class VC>
void math_stroke<VC>::calc_arc(VC& vc,
double x, double y,
double dx1, double dy1,
double dx2, double dy2)
double x,
double y,
double dx1,
double dy1,
double dx2,
double dy2)
{
double a1 = std::atan2(dy1 * m_width_sign, dx1 * m_width_sign);
double a2 = std::atan2(dy2 * m_width_sign, dx2 * m_width_sign);
double da = a1 - a2;
int i, n;
da = std::acos(m_width_abs / (m_width_abs + 0.125 / m_approx_scale)) * 2;
da =
std::acos(m_width_abs / (m_width_abs + 0.125 / m_approx_scale)) * 2;
add_vertex(vc, x + dx1, y + dy1);
if(m_width_sign > 0)
if (m_width_sign > 0)
{
if(a1 > a2) a2 += 2 * pi;
if (a1 > a2)
a2 += 2 * pi;
n = int((a2 - a1) / da);
da = (a2 - a1) / (n + 1);
a1 += da;
for(i = 0; i < n; i++)
for (i = 0; i < n; i++)
{
add_vertex(vc, x + std::cos(a1) * m_width, y + std::sin(a1) * m_width);
add_vertex(
vc, x + std::cos(a1) * m_width, y + std::sin(a1) * m_width);
a1 += da;
}
}
else
{
if(a1 < a2) a2 -= 2 * pi;
if (a1 < a2)
a2 -= 2 * pi;
n = int((a1 - a2) / da);
da = (a1 - a2) / (n + 1);
a1 -= da;
for(i = 0; i < n; i++)
for (i = 0; i < n; i++)
{
add_vertex(vc, x + std::cos(a1) * m_width, y + std::sin(a1) * m_width);
add_vertex(
vc, x + std::cos(a1) * m_width, y + std::sin(a1) * m_width);
a1 -= da;
}
}
@@ -206,34 +261,41 @@ namespace agg
}
//-----------------------------------------------------------------------
template<class VC>
template <class VC>
void math_stroke<VC>::calc_miter(VC& vc,
const vertex_dist& v0,
const vertex_dist& v1,
const vertex_dist& v2,
double dx1, double dy1,
double dx2, double dy2,
line_join_e lj,
double mlimit,
double dbevel)
const vertex_dist& v0,
const vertex_dist& v1,
const vertex_dist& v2,
double dx1,
double dy1,
double dx2,
double dy2,
line_join_e lj,
double mlimit,
double dbevel)
{
double xi = v1.x;
double yi = v1.y;
double di = 1;
double xi = v1.x;
double yi = v1.y;
double di = 1;
double lim = m_width_abs * mlimit;
bool miter_limit_exceeded = true; // Assume the worst
bool intersection_failed = true; // Assume the worst
bool intersection_failed = true; // Assume the worst
if(calc_intersection(v0.x + dx1, v0.y - dy1,
v1.x + dx1, v1.y - dy1,
v1.x + dx2, v1.y - dy2,
v2.x + dx2, v2.y - dy2,
&xi, &yi))
if (calc_intersection(v0.x + dx1,
v0.y - dy1,
v1.x + dx1,
v1.y - dy1,
v1.x + dx2,
v1.y - dy2,
v2.x + dx2,
v2.y - dy2,
&xi,
&yi))
{
// Calculation of the intersection succeeded
//---------------------
di = calc_distance(v1.x, v1.y, xi, yi);
if(di <= lim)
if (di <= lim)
{
// Inside the miter limit
//---------------------
@@ -245,19 +307,19 @@ namespace agg
else
{
// Calculation of the intersection failed, most probably
// the three points lie one straight line.
// First check if v0 and v2 lie on the opposite sides of vector:
// the three points lie one straight line.
// First check if v0 and v2 lie on the opposite sides of vector:
// (v1.x, v1.y) -> (v1.x+dx1, v1.y-dy1), that is, the perpendicular
// to the line determined by vertices v0 and v1.
// This condition determines whether the next line segments continues
// the previous one or goes back.
// This condition determines whether the next line segments
// continues the previous one or goes back.
//----------------
double x2 = v1.x + dx1;
double y2 = v1.y - dy1;
if((cross_product(v0.x, v0.y, v1.x, v1.y, x2, y2) < 0.0) ==
(cross_product(v1.x, v1.y, v2.x, v2.y, x2, y2) < 0.0))
if ((cross_product(v0.x, v0.y, v1.x, v1.y, x2, y2) < 0.0) ==
(cross_product(v1.x, v1.y, v2.x, v2.y, x2, y2) < 0.0))
{
// This case means that the next segment continues
// This case means that the next segment continues
// the previous one (straight line)
//-----------------
add_vertex(vc, v1.x + dx1, v1.y - dy1);
@@ -265,59 +327,59 @@ namespace agg
}
}
if(miter_limit_exceeded)
if (miter_limit_exceeded)
{
// Miter limit exceeded
//------------------------
switch(lj)
switch (lj)
{
case miter_join_revert:
// For the compatibility with SVG, PDF, etc,
// we use a simple bevel join instead of
// "smart" bevel
//-------------------
add_vertex(vc, v1.x + dx1, v1.y - dy1);
add_vertex(vc, v1.x + dx2, v1.y - dy2);
break;
case miter_join_revert:
// For the compatibility with SVG, PDF, etc,
// we use a simple bevel join instead of
// "smart" bevel
//-------------------
add_vertex(vc, v1.x + dx1, v1.y - dy1);
add_vertex(vc, v1.x + dx2, v1.y - dy2);
break;
case miter_join_round:
calc_arc(vc, v1.x, v1.y, dx1, -dy1, dx2, -dy2);
break;
case miter_join_round:
calc_arc(vc, v1.x, v1.y, dx1, -dy1, dx2, -dy2);
break;
default:
// If no miter-revert, calculate new dx1, dy1, dx2, dy2
//----------------
if(intersection_failed)
{
mlimit *= m_width_sign;
add_vertex(vc, v1.x + dx1 + dy1 * mlimit,
v1.y - dy1 + dx1 * mlimit);
add_vertex(vc, v1.x + dx2 - dy2 * mlimit,
v1.y - dy2 - dx2 * mlimit);
}
else
{
double x1 = v1.x + dx1;
double y1 = v1.y - dy1;
double x2 = v1.x + dx2;
double y2 = v1.y - dy2;
di = (lim - dbevel) / (di - dbevel);
add_vertex(vc, x1 + (xi - x1) * di,
y1 + (yi - y1) * di);
add_vertex(vc, x2 + (xi - x2) * di,
y2 + (yi - y2) * di);
}
break;
default:
// If no miter-revert, calculate new dx1, dy1, dx2, dy2
//----------------
if (intersection_failed)
{
mlimit *= m_width_sign;
add_vertex(vc,
v1.x + dx1 + dy1 * mlimit,
v1.y - dy1 + dx1 * mlimit);
add_vertex(vc,
v1.x + dx2 - dy2 * mlimit,
v1.y - dy2 - dx2 * mlimit);
}
else
{
double x1 = v1.x + dx1;
double y1 = v1.y - dy1;
double x2 = v1.x + dx2;
double y2 = v1.y - dy2;
di = (lim - dbevel) / (di - dbevel);
add_vertex(
vc, x1 + (xi - x1) * di, y1 + (yi - y1) * di);
add_vertex(
vc, x2 + (xi - x2) * di, y2 + (yi - y2) * di);
}
break;
}
}
}
//--------------------------------------------------------stroke_calc_cap
template<class VC>
void math_stroke<VC>::calc_cap(VC& vc,
const vertex_dist& v0,
const vertex_dist& v1,
double len)
template <class VC>
void math_stroke<VC>::calc_cap(
VC& vc, const vertex_dist& v0, const vertex_dist& v1, double len)
{
vc.remove_all();
@@ -329,9 +391,9 @@ namespace agg
dx1 *= m_width;
dy1 *= m_width;
if(m_line_cap != round_cap)
if (m_line_cap != round_cap)
{
if(m_line_cap == square_cap)
if (m_line_cap == square_cap)
{
dx2 = dy1 * m_width_sign;
dy2 = dx1 * m_width_sign;
@@ -341,21 +403,24 @@ namespace agg
}
else
{
double da = std::acos(m_width_abs / (m_width_abs + 0.125 / m_approx_scale)) * 2;
double da = std::acos(m_width_abs /
(m_width_abs + 0.125 / m_approx_scale)) *
2;
double a1;
int i;
int n = int(pi / da);
da = pi / (n + 1);
add_vertex(vc, v0.x - dx1, v0.y + dy1);
if(m_width_sign > 0)
if (m_width_sign > 0)
{
a1 = std::atan2(dy1, -dx1);
a1 += da;
for(i = 0; i < n; i++)
for (i = 0; i < n; i++)
{
add_vertex(vc, v0.x + std::cos(a1) * m_width,
v0.y + std::sin(a1) * m_width);
add_vertex(vc,
v0.x + std::cos(a1) * m_width,
v0.y + std::sin(a1) * m_width);
a1 += da;
}
}
@@ -363,10 +428,11 @@ namespace agg
{
a1 = std::atan2(-dy1, dx1);
a1 -= da;
for(i = 0; i < n; i++)
for (i = 0; i < n; i++)
{
add_vertex(vc, v0.x + std::cos(a1) * m_width,
v0.y + std::sin(a1) * m_width);
add_vertex(vc,
v0.x + std::cos(a1) * m_width,
v0.y + std::sin(a1) * m_width);
a1 -= da;
}
}
@@ -375,13 +441,13 @@ namespace agg
}
//-----------------------------------------------------------------------
template<class VC>
template <class VC>
void math_stroke<VC>::calc_join(VC& vc,
const vertex_dist& v0,
const vertex_dist& v1,
const vertex_dist& v2,
double len1,
double len2)
const vertex_dist& v0,
const vertex_dist& v1,
const vertex_dist& v2,
double len1,
double len2)
{
double dx1 = m_width * (v1.y - v0.y) / len1;
double dy1 = m_width * (v1.x - v0.x) / len1;
@@ -391,58 +457,72 @@ namespace agg
vc.remove_all();
double cp = cross_product(v0.x, v0.y, v1.x, v1.y, v2.x, v2.y);
if(cp != 0 && (cp > 0) == (m_width > 0))
if (cp != 0 && (cp > 0) == (m_width > 0))
{
// Inner join
//---------------
double limit = ((len1 < len2) ? len1 : len2) / m_width_abs;
if(limit < m_inner_miter_limit)
if (limit < m_inner_miter_limit)
{
limit = m_inner_miter_limit;
}
switch(m_inner_join)
switch (m_inner_join)
{
default: // inner_bevel
add_vertex(vc, v1.x + dx1, v1.y - dy1);
add_vertex(vc, v1.x + dx2, v1.y - dy2);
break;
default: // inner_bevel
add_vertex(vc, v1.x + dx1, v1.y - dy1);
add_vertex(vc, v1.x + dx2, v1.y - dy2);
break;
case inner_miter:
calc_miter(vc,
v0, v1, v2, dx1, dy1, dx2, dy2,
miter_join_revert,
limit, 0);
break;
case inner_jag:
case inner_round:
cp = (dx1-dx2) * (dx1-dx2) + (dy1-dy2) * (dy1-dy2);
if(cp < len1 * len1 && cp < len2 * len2)
{
case inner_miter:
calc_miter(vc,
v0, v1, v2, dx1, dy1, dx2, dy2,
miter_join_revert,
limit, 0);
}
else
{
if(m_inner_join == inner_jag)
v0,
v1,
v2,
dx1,
dy1,
dx2,
dy2,
miter_join_revert,
limit,
0);
break;
case inner_jag:
case inner_round:
cp = (dx1 - dx2) * (dx1 - dx2) + (dy1 - dy2) * (dy1 - dy2);
if (cp < len1 * len1 && cp < len2 * len2)
{
add_vertex(vc, v1.x + dx1, v1.y - dy1);
add_vertex(vc, v1.x, v1.y );
add_vertex(vc, v1.x + dx2, v1.y - dy2);
calc_miter(vc,
v0,
v1,
v2,
dx1,
dy1,
dx2,
dy2,
miter_join_revert,
limit,
0);
}
else
{
add_vertex(vc, v1.x + dx1, v1.y - dy1);
add_vertex(vc, v1.x, v1.y );
calc_arc(vc, v1.x, v1.y, dx2, -dy2, dx1, -dy1);
add_vertex(vc, v1.x, v1.y );
add_vertex(vc, v1.x + dx2, v1.y - dy2);
if (m_inner_join == inner_jag)
{
add_vertex(vc, v1.x + dx1, v1.y - dy1);
add_vertex(vc, v1.x, v1.y);
add_vertex(vc, v1.x + dx2, v1.y - dy2);
}
else
{
add_vertex(vc, v1.x + dx1, v1.y - dy1);
add_vertex(vc, v1.x, v1.y);
calc_arc(vc, v1.x, v1.y, dx2, -dy2, dx1, -dy1);
add_vertex(vc, v1.x, v1.y);
add_vertex(vc, v1.x + dx2, v1.y - dy2);
}
}
}
break;
break;
}
}
else
@@ -450,39 +530,44 @@ namespace agg
// Outer join
//---------------
// Calculate the distance between v1 and
// Calculate the distance between v1 and
// the central point of the bevel line segment
//---------------
double dx = (dx1 + dx2) / 2;
double dy = (dy1 + dy2) / 2;
double dbevel = std::sqrt(dx * dx + dy * dy);
if(m_line_join == round_join || m_line_join == bevel_join)
if (m_line_join == round_join || m_line_join == bevel_join)
{
// This is an optimization that reduces the number of points
// This is an optimization that reduces the number of points
// in cases of almost collinear segments. If there's no
// visible difference between bevel and miter joins we'd rather
// use miter join because it adds only one point instead of two.
// use miter join because it adds only one point instead of two.
//
// Here we calculate the middle point between the bevel points
// and then, the distance between v1 and this middle point.
// At outer joins this distance always less than stroke width,
// Here we calculate the middle point between the bevel points
// and then, the distance between v1 and this middle point.
// At outer joins this distance always less than stroke width,
// because it's actually the height of an isosceles triangle of
// v1 and its two bevel points. If the difference between this
// width and this value is small (no visible bevel) we can
// add just one point.
// width and this value is small (no visible bevel) we can
// add just one point.
//
// The constant in the expression makes the result approximately
// the same as in round joins and caps. You can safely comment
// The constant in the expression makes the result approximately
// the same as in round joins and caps. You can safely comment
// out this entire "if".
//-------------------
if(m_approx_scale * (m_width_abs - dbevel) < m_width_eps)
if (m_approx_scale * (m_width_abs - dbevel) < m_width_eps)
{
if(calc_intersection(v0.x + dx1, v0.y - dy1,
v1.x + dx1, v1.y - dy1,
v1.x + dx2, v1.y - dy2,
v2.x + dx2, v2.y - dy2,
&dx, &dy))
if (calc_intersection(v0.x + dx1,
v0.y - dy1,
v1.x + dx1,
v1.y - dy1,
v1.x + dx2,
v1.y - dy2,
v2.x + dx2,
v2.y - dy2,
&dx,
&dy))
{
add_vertex(vc, dx, dy);
}
@@ -494,33 +579,36 @@ namespace agg
}
}
switch(m_line_join)
switch (m_line_join)
{
case miter_join:
case miter_join_revert:
case miter_join_round:
calc_miter(vc,
v0, v1, v2, dx1, dy1, dx2, dy2,
m_line_join,
m_miter_limit,
dbevel);
break;
case miter_join:
case miter_join_revert:
case miter_join_round:
calc_miter(vc,
v0,
v1,
v2,
dx1,
dy1,
dx2,
dy2,
m_line_join,
m_miter_limit,
dbevel);
break;
case round_join:
calc_arc(vc, v1.x, v1.y, dx1, -dy1, dx2, -dy2);
break;
case round_join:
calc_arc(vc, v1.x, v1.y, dx1, -dy1, dx2, -dy2);
break;
default: // Bevel join
add_vertex(vc, v1.x + dx1, v1.y - dy1);
add_vertex(vc, v1.x + dx2, v1.y - dy2);
break;
default: // Bevel join
add_vertex(vc, v1.x + dx1, v1.y - dy1);
add_vertex(vc, v1.x + dx2, v1.y - dy2);
break;
}
}
}
}
#endif

View File

@@ -2,8 +2,8 @@
// 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.
// 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.
//
@@ -19,7 +19,7 @@
namespace agg
{
template<class VertexSource>
template <class VertexSource>
double path_length(VertexSource& vs, unsigned path_id = 0)
{
double len = 0.0;
@@ -33,11 +33,11 @@ namespace agg
unsigned cmd;
vs.rewind(path_id);
while(!is_stop(cmd = vs.vertex(&x2, &y2)))
while (!is_stop(cmd = vs.vertex(&x2, &y2)))
{
if(is_vertex(cmd))
if (is_vertex(cmd))
{
if(first || is_move_to(cmd))
if (first || is_move_to(cmd))
{
start_x = x2;
start_y = y2;
@@ -52,7 +52,7 @@ namespace agg
}
else
{
if(is_close(cmd) && !first)
if (is_close(cmd) && !first)
{
len += calc_distance(x1, y1, start_x, start_y);
}

View File

File diff suppressed because it is too large Load Diff

View File

@@ -2,8 +2,8 @@
// 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.
// 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.
//
@@ -22,105 +22,127 @@
namespace agg
{
//---------------------------------------------------------vertex_integer
template<class T, unsigned CoordShift=6> struct vertex_integer
template <class T, unsigned CoordShift = 6>
struct vertex_integer
{
enum path_cmd
{
cmd_move_to = 0,
cmd_line_to = 1,
cmd_curve3 = 2,
cmd_curve4 = 3
cmd_curve3 = 2,
cmd_curve4 = 3
};
enum coord_scale_e
{
coord_shift = CoordShift,
coord_scale = 1 << coord_shift
coord_scale = 1 << coord_shift
};
T x,y;
T x, y;
vertex_integer() {}
vertex_integer(T x_, T y_, unsigned flag) :
x(((x_ << 1) & ~1) | (flag & 1)),
y(((y_ << 1) & ~1) | (flag >> 1)) {}
vertex_integer(T x_, T y_, unsigned flag):
x(((x_ << 1) & ~1) | (flag & 1)),
y(((y_ << 1) & ~1) | (flag >> 1))
{
}
unsigned vertex(double* x_, double* y_,
double dx=0, double dy=0,
double scale=1.0) const
unsigned vertex(double* x_,
double* y_,
double dx = 0,
double dy = 0,
double scale = 1.0) const
{
*x_ = dx + (double(x >> 1) / coord_scale) * scale;
*y_ = dy + (double(y >> 1) / coord_scale) * scale;
switch(((y & 1) << 1) | (x & 1))
switch (((y & 1) << 1) | (x & 1))
{
case cmd_move_to: return path_cmd_move_to;
case cmd_line_to: return path_cmd_line_to;
case cmd_curve3: return path_cmd_curve3;
case cmd_curve4: return path_cmd_curve4;
case cmd_move_to:
return path_cmd_move_to;
case cmd_line_to:
return path_cmd_line_to;
case cmd_curve3:
return path_cmd_curve3;
case cmd_curve4:
return path_cmd_curve4;
}
return path_cmd_stop;
}
};
//---------------------------------------------------path_storage_integer
template<class T, unsigned CoordShift=6> class path_storage_integer
template <class T, unsigned CoordShift = 6>
class path_storage_integer
{
public:
typedef T value_type;
typedef vertex_integer<T, CoordShift> vertex_integer_type;
//--------------------------------------------------------------------
path_storage_integer() : m_storage(), m_vertex_idx(0), m_closed(true) {}
path_storage_integer(): m_storage(), m_vertex_idx(0), m_closed(true) {}
//--------------------------------------------------------------------
void remove_all() { m_storage.remove_all(); }
void remove_all()
{
m_storage.remove_all();
}
//--------------------------------------------------------------------
void move_to(T x, T y)
{
m_storage.add(vertex_integer_type(x, y, vertex_integer_type::cmd_move_to));
m_storage.add(
vertex_integer_type(x, y, vertex_integer_type::cmd_move_to));
}
//--------------------------------------------------------------------
void line_to(T x, T y)
{
m_storage.add(vertex_integer_type(x, y, vertex_integer_type::cmd_line_to));
m_storage.add(
vertex_integer_type(x, y, vertex_integer_type::cmd_line_to));
}
//--------------------------------------------------------------------
void curve3(T x_ctrl, T y_ctrl,
T x_to, T y_to)
void curve3(T x_ctrl, T y_ctrl, T x_to, T y_to)
{
m_storage.add(vertex_integer_type(x_ctrl, y_ctrl, vertex_integer_type::cmd_curve3));
m_storage.add(vertex_integer_type(x_to, y_to, vertex_integer_type::cmd_curve3));
m_storage.add(vertex_integer_type(
x_ctrl, y_ctrl, vertex_integer_type::cmd_curve3));
m_storage.add(vertex_integer_type(
x_to, y_to, vertex_integer_type::cmd_curve3));
}
//--------------------------------------------------------------------
void curve4(T x_ctrl1, T y_ctrl1,
T x_ctrl2, T y_ctrl2,
T x_to, T y_to)
void curve4(T x_ctrl1, T y_ctrl1, T x_ctrl2, T y_ctrl2, T x_to, T y_to)
{
m_storage.add(vertex_integer_type(x_ctrl1, y_ctrl1, vertex_integer_type::cmd_curve4));
m_storage.add(vertex_integer_type(x_ctrl2, y_ctrl2, vertex_integer_type::cmd_curve4));
m_storage.add(vertex_integer_type(x_to, y_to, vertex_integer_type::cmd_curve4));
m_storage.add(vertex_integer_type(
x_ctrl1, y_ctrl1, vertex_integer_type::cmd_curve4));
m_storage.add(vertex_integer_type(
x_ctrl2, y_ctrl2, vertex_integer_type::cmd_curve4));
m_storage.add(vertex_integer_type(
x_to, y_to, vertex_integer_type::cmd_curve4));
}
//--------------------------------------------------------------------
void close_polygon() {}
//--------------------------------------------------------------------
unsigned size() const { return m_storage.size(); }
unsigned size() const
{
return m_storage.size();
}
unsigned vertex(unsigned idx, double* x, double* y) const
{
return m_storage[idx].vertex(x, y);
}
//--------------------------------------------------------------------
unsigned byte_size() const { return m_storage.size() * sizeof(vertex_integer_type); }
unsigned byte_size() const
{
return m_storage.size() * sizeof(vertex_integer_type);
}
void serialize(int8u* ptr) const
{
unsigned i;
for(i = 0; i < m_storage.size(); i++)
for (i = 0; i < m_storage.size(); i++)
{
std::memcpy(ptr, &m_storage[i], sizeof(vertex_integer_type));
ptr += sizeof(vertex_integer_type);
@@ -128,22 +150,22 @@ namespace agg
}
//--------------------------------------------------------------------
void rewind(unsigned)
{
m_vertex_idx = 0;
void rewind(unsigned)
{
m_vertex_idx = 0;
m_closed = true;
}
//--------------------------------------------------------------------
unsigned vertex(double* x, double* y)
{
if(m_storage.size() < 2 || m_vertex_idx > m_storage.size())
if (m_storage.size() < 2 || m_vertex_idx > m_storage.size())
{
*x = 0;
*y = 0;
return path_cmd_stop;
}
if(m_vertex_idx == m_storage.size())
if (m_vertex_idx == m_storage.size())
{
*x = 0;
*y = 0;
@@ -151,7 +173,7 @@ namespace agg
return path_cmd_end_poly | path_flags_close;
}
unsigned cmd = m_storage[m_vertex_idx].vertex(x, y);
if(is_move_to(cmd) && !m_closed)
if (is_move_to(cmd) && !m_closed)
{
*x = 0;
*y = 0;
@@ -167,21 +189,25 @@ namespace agg
rect_d bounding_rect() const
{
rect_d bounds(1e100, 1e100, -1e100, -1e100);
if(m_storage.size() == 0)
if (m_storage.size() == 0)
{
bounds.x1 = bounds.y1 = bounds.x2 = bounds.y2 = 0.0;
}
else
{
unsigned i;
for(i = 0; i < m_storage.size(); i++)
for (i = 0; i < m_storage.size(); i++)
{
double x, y;
m_storage[i].vertex(&x, &y);
if(x < bounds.x1) bounds.x1 = x;
if(y < bounds.y1) bounds.y1 = y;
if(x > bounds.x2) bounds.x2 = x;
if(y > bounds.y2) bounds.y2 = y;
if (x < bounds.x1)
bounds.x1 = x;
if (y < bounds.y1)
bounds.y1 = y;
if (x > bounds.x2)
bounds.x2 = x;
if (y > bounds.y2)
bounds.y2 = y;
}
}
return bounds;
@@ -189,21 +215,19 @@ namespace agg
private:
pod_bvector<vertex_integer_type, 6> m_storage;
unsigned m_vertex_idx;
bool m_closed;
unsigned m_vertex_idx;
bool m_closed;
};
//-----------------------------------------serialized_integer_path_adaptor
template<class T, unsigned CoordShift=6> class serialized_integer_path_adaptor
template <class T, unsigned CoordShift = 6>
class serialized_integer_path_adaptor
{
public:
typedef vertex_integer<T, CoordShift> vertex_integer_type;
//--------------------------------------------------------------------
serialized_integer_path_adaptor() :
serialized_integer_path_adaptor():
m_data(0),
m_end(0),
m_ptr(0),
@@ -211,51 +235,55 @@ namespace agg
m_dy(0.0),
m_scale(1.0),
m_vertices(0)
{}
{
}
//--------------------------------------------------------------------
serialized_integer_path_adaptor(const int8u* data, unsigned size,
double dx, double dy) :
serialized_integer_path_adaptor(
const int8u* data, unsigned size, double dx, double dy):
m_data(data),
m_end(data + size),
m_ptr(data),
m_dx(dx),
m_dy(dy),
m_vertices(0)
{}
{
}
//--------------------------------------------------------------------
void init(const int8u* data, unsigned size,
double dx, double dy, double scale=1.0)
void init(const int8u* data,
unsigned size,
double dx,
double dy,
double scale = 1.0)
{
m_data = data;
m_end = data + size;
m_ptr = data;
m_dx = dx;
m_dy = dy;
m_scale = scale;
m_data = data;
m_end = data + size;
m_ptr = data;
m_dx = dx;
m_dy = dy;
m_scale = scale;
m_vertices = 0;
}
//--------------------------------------------------------------------
void rewind(unsigned)
{
m_ptr = m_data;
void rewind(unsigned)
{
m_ptr = m_data;
m_vertices = 0;
}
//--------------------------------------------------------------------
unsigned vertex(double* x, double* y)
{
if(m_data == 0 || m_ptr > m_end)
if (m_data == 0 || m_ptr > m_end)
{
*x = 0;
*y = 0;
return path_cmd_stop;
}
if(m_ptr == m_end)
if (m_ptr == m_end)
{
*x = 0;
*y = 0;
@@ -266,7 +294,7 @@ namespace agg
vertex_integer_type v;
std::memcpy(&v, m_ptr, sizeof(vertex_integer_type));
unsigned cmd = v.vertex(x, y, m_dx, m_dy, m_scale);
if(is_move_to(cmd) && m_vertices > 2)
if (is_move_to(cmd) && m_vertices > 2)
{
*x = 0;
*y = 0;
@@ -282,14 +310,12 @@ namespace agg
const int8u* m_data;
const int8u* m_end;
const int8u* m_ptr;
double m_dx;
double m_dy;
double m_scale;
unsigned m_vertices;
double m_dx;
double m_dy;
double m_scale;
unsigned m_vertices;
};
}
#endif

View File

@@ -2,8 +2,8 @@
// 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.
// 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.
//
@@ -19,52 +19,56 @@
#include "agg_line_aa_basics.h"
#include "agg_color_rgba.h"
namespace agg
{
//=======================================================pattern_filter_nn
template<class ColorT> struct pattern_filter_nn
template <class ColorT>
struct pattern_filter_nn
{
typedef ColorT color_type;
static unsigned dilation() { return 0; }
static unsigned dilation()
{
return 0;
}
static void AGG_INLINE pixel_low_res(color_type const* const* buf,
color_type* p, int x, int y)
static void AGG_INLINE pixel_low_res(
color_type const* const* buf, color_type* p, int x, int y)
{
*p = buf[y][x];
}
static void AGG_INLINE pixel_high_res(color_type const* const* buf,
color_type* p, int x, int y)
static void AGG_INLINE pixel_high_res(
color_type const* const* buf, color_type* p, int x, int y)
{
*p = buf[y >> line_subpixel_shift]
[x >> line_subpixel_shift];
*p = buf[y >> line_subpixel_shift][x >> line_subpixel_shift];
}
};
typedef pattern_filter_nn<rgba8> pattern_filter_nn_rgba8;
typedef pattern_filter_nn<rgba8> pattern_filter_nn_rgba8;
typedef pattern_filter_nn<rgba16> pattern_filter_nn_rgba16;
//===========================================pattern_filter_bilinear_rgba
template<class ColorT> struct pattern_filter_bilinear_rgba
template <class ColorT>
struct pattern_filter_bilinear_rgba
{
typedef ColorT color_type;
typedef typename color_type::value_type value_type;
typedef typename color_type::calc_type calc_type;
static unsigned dilation()
{
return 1;
}
static unsigned dilation() { return 1; }
static AGG_INLINE void pixel_low_res(color_type const* const* buf,
color_type* p, int x, int y)
static AGG_INLINE void pixel_low_res(
color_type const* const* buf, color_type* p, int x, int y)
{
*p = buf[y][x];
}
static AGG_INLINE void pixel_high_res(color_type const* const* buf,
color_type* p, int x, int y)
static AGG_INLINE void pixel_high_res(
color_type const* const* buf, color_type* p, int x, int y)
{
calc_type r, g, b, a;
r = g = b = a = 0;
@@ -77,8 +81,7 @@ namespace agg
y &= line_subpixel_mask;
const color_type* ptr = buf[y_lr] + x_lr;
weight = (line_subpixel_scale - x) *
(line_subpixel_scale - y);
weight = (line_subpixel_scale - x) * (line_subpixel_scale - y);
r += weight * ptr->r;
g += weight * ptr->g;
b += weight * ptr->b;
@@ -108,14 +111,18 @@ namespace agg
b += weight * ptr->b;
a += weight * ptr->a;
p->r = (value_type)color_type::downshift(r, line_subpixel_shift * 2);
p->g = (value_type)color_type::downshift(g, line_subpixel_shift * 2);
p->b = (value_type)color_type::downshift(b, line_subpixel_shift * 2);
p->a = (value_type)color_type::downshift(a, line_subpixel_shift * 2);
p->r =
(value_type)color_type::downshift(r, line_subpixel_shift * 2);
p->g =
(value_type)color_type::downshift(g, line_subpixel_shift * 2);
p->b =
(value_type)color_type::downshift(b, line_subpixel_shift * 2);
p->a =
(value_type)color_type::downshift(a, line_subpixel_shift * 2);
}
};
typedef pattern_filter_bilinear_rgba<rgba8> pattern_filter_bilinear_rgba8;
typedef pattern_filter_bilinear_rgba<rgba8> pattern_filter_bilinear_rgba8;
typedef pattern_filter_bilinear_rgba<rgba16> pattern_filter_bilinear_rgba16;
typedef pattern_filter_bilinear_rgba<rgba32> pattern_filter_bilinear_rgba32;
}

View File

@@ -2,8 +2,8 @@
// 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.
// 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.
//
@@ -16,16 +16,15 @@
#ifndef AGG_PIXFMT_AMASK_ADAPTOR_INCLUDED
#define AGG_PIXFMT_AMASK_ADAPTOR_INCLUDED
#include <cstring>
#include "agg_array.h"
#include "agg_rendering_buffer.h"
namespace agg
{
//==================================================pixfmt_amask_adaptor
template<class PixFmt, class AlphaMask> class pixfmt_amask_adaptor
template <class PixFmt, class AlphaMask>
class pixfmt_amask_adaptor
{
public:
typedef PixFmt pixfmt_type;
@@ -35,11 +34,14 @@ namespace agg
typedef typename amask_type::cover_type cover_type;
private:
enum span_extra_tail_e { span_extra_tail = 256 };
enum span_extra_tail_e
{
span_extra_tail = 256
};
void realloc_span(unsigned len)
{
if(len > m_span.size())
if (len > m_span.size())
{
m_span.resize(len + span_extra_tail);
}
@@ -48,7 +50,8 @@ namespace agg
void init_span(unsigned len)
{
realloc_span(len);
std::memset(&m_span[0], amask_type::cover_full, len * sizeof(cover_type));
std::memset(
&m_span[0], amask_type::cover_full, len * sizeof(cover_type));
}
void init_span(unsigned len, const cover_type* covers)
@@ -57,25 +60,39 @@ namespace agg
std::memcpy(&m_span[0], covers, len * sizeof(cover_type));
}
public:
pixfmt_amask_adaptor(pixfmt_type& pixf, amask_type& mask) :
m_pixf(&pixf), m_mask(&mask), m_span()
{}
pixfmt_amask_adaptor(pixfmt_type& pixf, amask_type& mask):
m_pixf(&pixf),
m_mask(&mask),
m_span()
{
}
void attach_pixfmt(pixfmt_type& pixf) { m_pixf = &pixf; }
void attach_alpha_mask(amask_type& mask) { m_mask = &mask; }
void attach_pixfmt(pixfmt_type& pixf)
{
m_pixf = &pixf;
}
void attach_alpha_mask(amask_type& mask)
{
m_mask = &mask;
}
//--------------------------------------------------------------------
template<class PixFmt2>
template <class PixFmt2>
bool attach_pixfmt(PixFmt2& pixf, int x1, int y1, int x2, int y2)
{
return m_pixf->attach(pixf, x1, y1, x2, y2);
}
//--------------------------------------------------------------------
unsigned width() const { return m_pixf->width(); }
unsigned height() const { return m_pixf->height(); }
unsigned width() const
{
return m_pixf->width();
}
unsigned height() const
{
return m_pixf->height();
}
//--------------------------------------------------------------------
color_type pixel(int x, int y)
@@ -96,9 +113,7 @@ namespace agg
}
//--------------------------------------------------------------------
void copy_hline(int x, int y,
unsigned len,
const color_type& c)
void copy_hline(int x, int y, unsigned len, const color_type& c)
{
realloc_span(len);
m_mask->fill_hspan(x, y, &m_span[0], len);
@@ -106,10 +121,8 @@ namespace agg
}
//--------------------------------------------------------------------
void blend_hline(int x, int y,
unsigned len,
const color_type& c,
cover_type)
void blend_hline(
int x, int y, unsigned len, const color_type& c, cover_type)
{
init_span(len);
m_mask->combine_hspan(x, y, &m_span[0], len);
@@ -117,9 +130,7 @@ namespace agg
}
//--------------------------------------------------------------------
void copy_vline(int x, int y,
unsigned len,
const color_type& c)
void copy_vline(int x, int y, unsigned len, const color_type& c)
{
realloc_span(len);
m_mask->fill_vspan(x, y, &m_span[0], len);
@@ -127,10 +138,8 @@ namespace agg
}
//--------------------------------------------------------------------
void blend_vline(int x, int y,
unsigned len,
const color_type& c,
cover_type)
void blend_vline(
int x, int y, unsigned len, const color_type& c, cover_type)
{
init_span(len);
m_mask->combine_vspan(x, y, &m_span[0], len);
@@ -138,63 +147,69 @@ namespace agg
}
//--------------------------------------------------------------------
void copy_from(const rendering_buffer& from,
int xdst, int ydst,
int xsrc, int ysrc,
unsigned len)
void copy_from(const rendering_buffer& from,
int xdst,
int ydst,
int xsrc,
int ysrc,
unsigned len)
{
m_pixf->copy_from(from, xdst, ydst, xsrc, ysrc, len);
}
//--------------------------------------------------------------------
void blend_solid_hspan(int x, int y,
unsigned len,
const color_type& c,
const cover_type* covers)
void blend_solid_hspan(int x,
int y,
unsigned len,
const color_type& c,
const cover_type* covers)
{
init_span(len, covers);
m_mask->combine_hspan(x, y, &m_span[0], len);
m_pixf->blend_solid_hspan(x, y, len, c, &m_span[0]);
}
//--------------------------------------------------------------------
void blend_solid_vspan(int x, int y,
unsigned len,
const color_type& c,
const cover_type* covers)
void blend_solid_vspan(int x,
int y,
unsigned len,
const color_type& c,
const cover_type* covers)
{
init_span(len, covers);
m_mask->combine_vspan(x, y, &m_span[0], len);
m_pixf->blend_solid_vspan(x, y, len, c, &m_span[0]);
}
//--------------------------------------------------------------------
void copy_color_hspan(int x, int y, unsigned len, const color_type* colors)
void copy_color_hspan(
int x, int y, unsigned len, const color_type* colors)
{
realloc_span(len);
m_mask->fill_hspan(x, y, &m_span[0], len);
m_pixf->blend_color_hspan(x, y, len, colors, &m_span[0], cover_full);
m_pixf->blend_color_hspan(
x, y, len, colors, &m_span[0], cover_full);
}
//--------------------------------------------------------------------
void copy_color_vspan(int x, int y, unsigned len, const color_type* colors)
void copy_color_vspan(
int x, int y, unsigned len, const color_type* colors)
{
realloc_span(len);
m_mask->fill_vspan(x, y, &m_span[0], len);
m_pixf->blend_color_vspan(x, y, len, colors, &m_span[0], cover_full);
m_pixf->blend_color_vspan(
x, y, len, colors, &m_span[0], cover_full);
}
//--------------------------------------------------------------------
void blend_color_hspan(int x, int y,
unsigned len,
const color_type* colors,
const cover_type* covers,
cover_type cover = cover_full)
void blend_color_hspan(int x,
int y,
unsigned len,
const color_type* colors,
const cover_type* covers,
cover_type cover = cover_full)
{
if(covers)
if (covers)
{
init_span(len, covers);
m_mask->combine_hspan(x, y, &m_span[0], len);
@@ -207,15 +222,15 @@ namespace agg
m_pixf->blend_color_hspan(x, y, len, colors, &m_span[0], cover);
}
//--------------------------------------------------------------------
void blend_color_vspan(int x, int y,
unsigned len,
const color_type* colors,
const cover_type* covers,
cover_type cover = cover_full)
void blend_color_vspan(int x,
int y,
unsigned len,
const color_type* colors,
const cover_type* covers,
cover_type cover = cover_full)
{
if(covers)
if (covers)
{
init_span(len, covers);
m_mask->combine_vspan(x, y, &m_span[0], len);
@@ -229,12 +244,11 @@ namespace agg
}
private:
pixfmt_type* m_pixf;
const amask_type* m_mask;
pixfmt_type* m_pixf;
const amask_type* m_mask;
pod_array<cover_type> m_span;
};
}
#endif

View File

@@ -2,8 +2,8 @@
// 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.
// 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.
//
@@ -35,21 +35,24 @@ namespace agg
};
//--------------------------------------------------------------blender_base
template<class ColorT, class Order = void>
template <class ColorT, class Order = void>
struct blender_base
{
typedef ColorT color_type;
typedef Order order_type;
typedef typename color_type::value_type value_type;
static rgba get(value_type r, value_type g, value_type b, value_type a, cover_type cover = cover_full)
static rgba get(value_type r,
value_type g,
value_type b,
value_type a,
cover_type cover = cover_full)
{
if (cover > cover_none)
{
rgba c(
color_type::to_double(r),
color_type::to_double(g),
color_type::to_double(b),
rgba c(color_type::to_double(r),
color_type::to_double(g),
color_type::to_double(b),
color_type::to_double(a));
if (cover < cover_full)
@@ -63,20 +66,24 @@ namespace agg
return c;
}
else return rgba::no_color();
else
return rgba::no_color();
}
static rgba get(const value_type* p, cover_type cover = cover_full)
{
return get(
p[order_type::R],
p[order_type::G],
p[order_type::B],
p[order_type::A],
return get(p[order_type::R],
p[order_type::G],
p[order_type::B],
p[order_type::A],
cover);
}
static void set(value_type* p, value_type r, value_type g, value_type b, value_type a)
static void set(value_type* p,
value_type r,
value_type g,
value_type b,
value_type a)
{
p[order_type::R] = r;
p[order_type::G] = g;

View File

@@ -2,8 +2,8 @@
// 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.
// 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.
//
@@ -13,12 +13,12 @@
// http://www.antigrain.com
//----------------------------------------------------------------------------
//
// Adaptation for high precision colors has been sponsored by
// 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.
//
//
//----------------------------------------------------------------------------
#ifndef AGG_PIXFMT_GRAY_INCLUDED
@@ -30,9 +30,10 @@
namespace agg
{
//============================================================blender_gray
template<class ColorT> struct blender_gray
template <class ColorT>
struct blender_gray
{
typedef ColorT color_type;
typedef typename color_type::value_type value_type;
@@ -43,22 +44,22 @@ namespace agg
// compositing function. Since the render buffer is opaque we skip the
// initial premultiply and final demultiply.
static AGG_INLINE void blend_pix(value_type* p,
value_type cv, value_type alpha, cover_type cover)
static AGG_INLINE void blend_pix(
value_type* p, value_type cv, value_type alpha, cover_type cover)
{
blend_pix(p, cv, color_type::mult_cover(alpha, cover));
}
static AGG_INLINE void blend_pix(value_type* p,
value_type cv, value_type alpha)
static AGG_INLINE void blend_pix(
value_type* p, value_type cv, value_type alpha)
{
*p = color_type::lerp(*p, cv, alpha);
}
};
//======================================================blender_gray_pre
template<class ColorT> struct blender_gray_pre
template <class ColorT>
struct blender_gray_pre
{
typedef ColorT color_type;
typedef typename color_type::value_type value_type;
@@ -66,32 +67,33 @@ namespace agg
typedef typename color_type::long_type long_type;
// Blend pixels using the premultiplied form of Alvy-Ray Smith's
// compositing function.
// compositing function.
static AGG_INLINE void blend_pix(value_type* p,
value_type cv, value_type alpha, cover_type cover)
static AGG_INLINE void blend_pix(
value_type* p, value_type cv, value_type alpha, cover_type cover)
{
blend_pix(p, color_type::mult_cover(cv, cover), color_type::mult_cover(alpha, cover));
blend_pix(p,
color_type::mult_cover(cv, cover),
color_type::mult_cover(alpha, cover));
}
static AGG_INLINE void blend_pix(value_type* p,
value_type cv, value_type alpha)
static AGG_INLINE void blend_pix(
value_type* p, value_type cv, value_type alpha)
{
*p = color_type::prelerp(*p, cv, alpha);
}
};
//=====================================================apply_gamma_dir_gray
template<class ColorT, class GammaLut> class apply_gamma_dir_gray
template <class ColorT, class GammaLut>
class apply_gamma_dir_gray
{
public:
typedef typename ColorT::value_type value_type;
apply_gamma_dir_gray(const GammaLut& gamma) : m_gamma(gamma) {}
apply_gamma_dir_gray(const GammaLut& gamma): m_gamma(gamma) {}
AGG_INLINE void operator () (value_type* p)
AGG_INLINE void operator()(value_type* p)
{
*p = m_gamma.dir(*p);
}
@@ -100,17 +102,16 @@ namespace agg
const GammaLut& m_gamma;
};
//=====================================================apply_gamma_inv_gray
template<class ColorT, class GammaLut> class apply_gamma_inv_gray
template <class ColorT, class GammaLut>
class apply_gamma_inv_gray
{
public:
typedef typename ColorT::value_type value_type;
apply_gamma_inv_gray(const GammaLut& gamma) : m_gamma(gamma) {}
apply_gamma_inv_gray(const GammaLut& gamma): m_gamma(gamma) {}
AGG_INLINE void operator () (value_type* p)
AGG_INLINE void operator()(value_type* p)
{
*p = m_gamma.inv(*p);
}
@@ -119,22 +120,23 @@ namespace agg
const GammaLut& m_gamma;
};
//=================================================pixfmt_alpha_blend_gray
template<class Blender, class RenBuf, unsigned Step = 1, unsigned Offset = 0>
template <class Blender,
class RenBuf,
unsigned Step = 1,
unsigned Offset = 0>
class pixfmt_alpha_blend_gray
{
public:
typedef pixfmt_gray_tag pixfmt_category;
typedef RenBuf rbuf_type;
typedef RenBuf rbuf_type;
typedef typename rbuf_type::row_data row_data;
typedef Blender blender_type;
typedef Blender blender_type;
typedef typename blender_type::color_type color_type;
typedef int order_type; // A fake one
typedef typename color_type::value_type value_type;
typedef typename color_type::calc_type calc_type;
enum
typedef int order_type; // A fake one
typedef typename color_type::value_type value_type;
typedef typename color_type::calc_type calc_type;
enum
{
num_components = 1,
pix_width = sizeof(value_type) * Step,
@@ -188,9 +190,8 @@ namespace agg
private:
//--------------------------------------------------------------------
AGG_INLINE void blend_pix(pixel_type* p,
value_type v, value_type a,
unsigned cover)
AGG_INLINE void blend_pix(
pixel_type* p, value_type v, value_type a, unsigned cover)
{
blender_type::blend_pix(p->c, v, a, cover);
}
@@ -202,7 +203,8 @@ namespace agg
}
//--------------------------------------------------------------------
AGG_INLINE void blend_pix(pixel_type* p, const color_type& c, unsigned cover)
AGG_INLINE void blend_pix(
pixel_type* p, const color_type& c, unsigned cover)
{
blender_type::blend_pix(p->c, c.v, c.a, cover);
}
@@ -214,7 +216,8 @@ namespace agg
}
//--------------------------------------------------------------------
AGG_INLINE void copy_or_blend_pix(pixel_type* p, const color_type& c, unsigned cover)
AGG_INLINE void copy_or_blend_pix(
pixel_type* p, const color_type& c, unsigned cover)
{
if (!c.is_transparent())
{
@@ -247,70 +250,95 @@ namespace agg
public:
//--------------------------------------------------------------------
explicit pixfmt_alpha_blend_gray(rbuf_type& rb) :
m_rbuf(&rb)
{}
void attach(rbuf_type& rb) { m_rbuf = &rb; }
explicit pixfmt_alpha_blend_gray(rbuf_type& rb): m_rbuf(&rb) {}
void attach(rbuf_type& rb)
{
m_rbuf = &rb;
}
//--------------------------------------------------------------------
template<class PixFmt>
template <class PixFmt>
bool attach(PixFmt& pixf, int x1, int y1, int x2, int y2)
{
rect_i r(x1, y1, x2, y2);
if (r.clip(rect_i(0, 0, pixf.width()-1, pixf.height()-1)))
if (r.clip(rect_i(0, 0, pixf.width() - 1, pixf.height() - 1)))
{
int stride = pixf.stride();
m_rbuf->attach(pixf.pix_ptr(r.x1, stride < 0 ? r.y2 : r.y1),
(r.x2 - r.x1) + 1,
(r.y2 - r.y1) + 1,
stride);
m_rbuf->attach(pixf.pix_ptr(r.x1, stride < 0 ? r.y2 : r.y1),
(r.x2 - r.x1) + 1,
(r.y2 - r.y1) + 1,
stride);
return true;
}
return false;
}
//--------------------------------------------------------------------
AGG_INLINE unsigned width() const { return m_rbuf->width(); }
AGG_INLINE unsigned height() const { return m_rbuf->height(); }
AGG_INLINE int stride() const { return m_rbuf->stride(); }
//--------------------------------------------------------------------
int8u* row_ptr(int y) { return m_rbuf->row_ptr(y); }
const int8u* row_ptr(int y) const { return m_rbuf->row_ptr(y); }
row_data row(int y) const { return m_rbuf->row(y); }
//--------------------------------------------------------------------
AGG_INLINE int8u* pix_ptr(int x, int y)
{
return m_rbuf->row_ptr(y) + sizeof(value_type) * (x * pix_step + pix_offset);
AGG_INLINE unsigned width() const
{
return m_rbuf->width();
}
AGG_INLINE unsigned height() const
{
return m_rbuf->height();
}
AGG_INLINE int stride() const
{
return m_rbuf->stride();
}
AGG_INLINE const int8u* pix_ptr(int x, int y) const
{
return m_rbuf->row_ptr(y) + sizeof(value_type) * (x * pix_step + pix_offset);
//--------------------------------------------------------------------
int8u* row_ptr(int y)
{
return m_rbuf->row_ptr(y);
}
const int8u* row_ptr(int y) const
{
return m_rbuf->row_ptr(y);
}
row_data row(int y) const
{
return m_rbuf->row(y);
}
//--------------------------------------------------------------------
AGG_INLINE int8u* pix_ptr(int x, int y)
{
return m_rbuf->row_ptr(y) +
sizeof(value_type) * (x * pix_step + pix_offset);
}
AGG_INLINE const int8u* pix_ptr(int x, int y) const
{
return m_rbuf->row_ptr(y) +
sizeof(value_type) * (x * pix_step + pix_offset);
}
// Return pointer to pixel value, forcing row to be allocated.
AGG_INLINE pixel_type* pix_value_ptr(int x, int y, unsigned len)
AGG_INLINE pixel_type* pix_value_ptr(int x, int y, unsigned len)
{
return (pixel_type*)(m_rbuf->row_ptr(x, y, len) + sizeof(value_type) * (x * pix_step + pix_offset));
return (
pixel_type*)(m_rbuf->row_ptr(x, y, len) +
sizeof(value_type) * (x * pix_step + pix_offset));
}
// Return pointer to pixel value, or null if row not allocated.
AGG_INLINE const pixel_type* pix_value_ptr(int x, int y) const
AGG_INLINE const pixel_type* pix_value_ptr(int x, int y) const
{
int8u* p = m_rbuf->row_ptr(y);
return p ? (pixel_type*)(p + sizeof(value_type) * (x * pix_step + pix_offset)) : 0;
return p ? (pixel_type*)(p + sizeof(value_type) *
(x * pix_step + pix_offset))
: 0;
}
// Get pixel pointer from raw buffer pointer.
AGG_INLINE static pixel_type* pix_value_ptr(void* p)
AGG_INLINE static pixel_type* pix_value_ptr(void* p)
{
return (pixel_type*)((value_type*)p + pix_offset);
}
// Get pixel pointer from raw buffer pointer.
AGG_INLINE static const pixel_type* pix_value_ptr(const void* p)
AGG_INLINE static const pixel_type* pix_value_ptr(const void* p)
{
return (const pixel_type*)((const value_type*)p + pix_offset);
}
@@ -352,44 +380,37 @@ namespace agg
}
//--------------------------------------------------------------------
AGG_INLINE void blend_pixel(int x, int y, const color_type& c, int8u cover)
AGG_INLINE void blend_pixel(
int x, int y, const color_type& c, int8u cover)
{
copy_or_blend_pix(pix_value_ptr(x, y, 1), c, cover);
}
//--------------------------------------------------------------------
AGG_INLINE void copy_hline(int x, int y,
unsigned len,
const color_type& c)
AGG_INLINE void copy_hline(
int x, int y, unsigned len, const color_type& c)
{
pixel_type* p = pix_value_ptr(x, y, len);
do
{
p->set(c);
p = p->next();
}
while(--len);
} while (--len);
}
//--------------------------------------------------------------------
AGG_INLINE void copy_vline(int x, int y,
unsigned len,
const color_type& c)
AGG_INLINE void copy_vline(
int x, int y, unsigned len, const color_type& c)
{
do
{
pix_value_ptr(x, y++, 1)->set(c);
}
while (--len);
} while (--len);
}
//--------------------------------------------------------------------
void blend_hline(int x, int y,
unsigned len,
const color_type& c,
int8u cover)
void blend_hline(
int x, int y, unsigned len, const color_type& c, int8u cover)
{
if (!c.is_transparent())
{
@@ -401,8 +422,7 @@ namespace agg
{
p->set(c);
p = p->next();
}
while (--len);
} while (--len);
}
else
{
@@ -410,18 +430,14 @@ namespace agg
{
blend_pix(p, c, cover);
p = p->next();
}
while (--len);
} while (--len);
}
}
}
//--------------------------------------------------------------------
void blend_vline(int x, int y,
unsigned len,
const color_type& c,
int8u cover)
void blend_vline(
int x, int y, unsigned len, const color_type& c, int8u cover)
{
if (!c.is_transparent())
{
@@ -430,32 +446,30 @@ namespace agg
do
{
pix_value_ptr(x, y++, 1)->set(c);
}
while (--len);
} while (--len);
}
else
{
do
{
blend_pix(pix_value_ptr(x, y++, 1), c, cover);
}
while (--len);
} while (--len);
}
}
}
//--------------------------------------------------------------------
void blend_solid_hspan(int x, int y,
unsigned len,
const color_type& c,
const int8u* covers)
void blend_solid_hspan(int x,
int y,
unsigned len,
const color_type& c,
const int8u* covers)
{
if (!c.is_transparent())
{
pixel_type* p = pix_value_ptr(x, y, len);
do
do
{
if (c.is_opaque() && *covers == cover_mask)
{
@@ -467,21 +481,20 @@ namespace agg
}
p = p->next();
++covers;
}
while (--len);
} while (--len);
}
}
//--------------------------------------------------------------------
void blend_solid_vspan(int x, int y,
unsigned len,
const color_type& c,
const int8u* covers)
void blend_solid_vspan(int x,
int y,
unsigned len,
const color_type& c,
const int8u* covers)
{
if (!c.is_transparent())
{
do
do
{
pixel_type* p = pix_value_ptr(x, y++, 1);
@@ -494,121 +507,111 @@ namespace agg
blend_pix(p, c, *covers);
}
++covers;
}
while (--len);
} while (--len);
}
}
//--------------------------------------------------------------------
void copy_color_hspan(int x, int y,
unsigned len,
const color_type* colors)
void copy_color_hspan(
int x, int y, unsigned len, const color_type* colors)
{
pixel_type* p = pix_value_ptr(x, y, len);
do
do
{
p->set(*colors++);
p = p->next();
}
while (--len);
} while (--len);
}
//--------------------------------------------------------------------
void copy_color_vspan(int x, int y,
unsigned len,
const color_type* colors)
void copy_color_vspan(
int x, int y, unsigned len, const color_type* colors)
{
do
do
{
pix_value_ptr(x, y++, 1)->set(*colors++);
}
while (--len);
} while (--len);
}
//--------------------------------------------------------------------
void blend_color_hspan(int x, int y,
unsigned len,
const color_type* colors,
const int8u* covers,
int8u cover)
void blend_color_hspan(int x,
int y,
unsigned len,
const color_type* colors,
const int8u* covers,
int8u cover)
{
pixel_type* p = pix_value_ptr(x, y, len);
if (covers)
{
do
do
{
copy_or_blend_pix(p, *colors++, *covers++);
p = p->next();
}
while (--len);
} while (--len);
}
else
{
if (cover == cover_mask)
{
do
do
{
copy_or_blend_pix(p, *colors++);
p = p->next();
}
while (--len);
} while (--len);
}
else
{
do
do
{
copy_or_blend_pix(p, *colors++, cover);
p = p->next();
}
while (--len);
} while (--len);
}
}
}
//--------------------------------------------------------------------
void blend_color_vspan(int x, int y,
unsigned len,
const color_type* colors,
const int8u* covers,
int8u cover)
void blend_color_vspan(int x,
int y,
unsigned len,
const color_type* colors,
const int8u* covers,
int8u cover)
{
if (covers)
{
do
do
{
copy_or_blend_pix(pix_value_ptr(x, y++, 1), *colors++, *covers++);
}
while (--len);
copy_or_blend_pix(
pix_value_ptr(x, y++, 1), *colors++, *covers++);
} while (--len);
}
else
{
if (cover == cover_mask)
{
do
do
{
copy_or_blend_pix(pix_value_ptr(x, y++, 1), *colors++);
}
while (--len);
} while (--len);
}
else
{
do
do
{
copy_or_blend_pix(pix_value_ptr(x, y++, 1), *colors++, cover);
}
while (--len);
copy_or_blend_pix(
pix_value_ptr(x, y++, 1), *colors++, cover);
} while (--len);
}
}
}
//--------------------------------------------------------------------
template<class Function> void for_each_pixel(Function f)
template <class Function>
void for_each_pixel(Function f)
{
unsigned y;
for (y = 0; y < height(); ++y)
@@ -622,48 +625,54 @@ namespace agg
{
f(p->c);
p = p->next();
}
while (--len);
} while (--len);
}
}
}
//--------------------------------------------------------------------
template<class GammaLut> void apply_gamma_dir(const GammaLut& g)
template <class GammaLut>
void apply_gamma_dir(const GammaLut& g)
{
for_each_pixel(apply_gamma_dir_gray<color_type, GammaLut>(g));
}
//--------------------------------------------------------------------
template<class GammaLut> void apply_gamma_inv(const GammaLut& g)
template <class GammaLut>
void apply_gamma_inv(const GammaLut& g)
{
for_each_pixel(apply_gamma_inv_gray<color_type, GammaLut>(g));
}
//--------------------------------------------------------------------
template<class RenBuf2>
void copy_from(const RenBuf2& from,
int xdst, int ydst,
int xsrc, int ysrc,
unsigned len)
template <class RenBuf2>
void copy_from(const RenBuf2& from,
int xdst,
int ydst,
int xsrc,
int ysrc,
unsigned len)
{
if (const int8u* p = from.row_ptr(ysrc))
{
std::memmove(m_rbuf->row_ptr(xdst, ydst, len) + xdst * pix_width,
p + xsrc * pix_width,
len * pix_width);
std::memmove(
m_rbuf->row_ptr(xdst, ydst, len) + xdst * pix_width,
p + xsrc * pix_width,
len * pix_width);
}
}
//--------------------------------------------------------------------
// Blend from single color, using grayscale surface as alpha channel.
template<class SrcPixelFormatRenderer>
void blend_from_color(const SrcPixelFormatRenderer& from,
const color_type& color,
int xdst, int ydst,
int xsrc, int ysrc,
unsigned len,
int8u cover)
template <class SrcPixelFormatRenderer>
void blend_from_color(const SrcPixelFormatRenderer& from,
const color_type& color,
int xdst,
int ydst,
int xsrc,
int ysrc,
unsigned len,
int8u cover)
{
typedef typename SrcPixelFormatRenderer::pixel_type src_pixel_type;
typedef typename SrcPixelFormatRenderer::color_type src_color_type;
@@ -672,26 +681,29 @@ namespace agg
{
pixel_type* pdst = pix_value_ptr(xdst, ydst, len);
do
do
{
copy_or_blend_pix(pdst, color, src_color_type::scale_cover(cover, psrc->c[0]));
copy_or_blend_pix(pdst,
color,
src_color_type::scale_cover(cover, psrc->c[0]));
psrc = psrc->next();
pdst = pdst->next();
}
while (--len);
} while (--len);
}
}
//--------------------------------------------------------------------
// Blend from color table, using grayscale surface as indexes into table.
// Obviously, this only works for integer value types.
template<class SrcPixelFormatRenderer>
void blend_from_lut(const SrcPixelFormatRenderer& from,
const color_type* color_lut,
int xdst, int ydst,
int xsrc, int ysrc,
unsigned len,
int8u cover)
// Blend from color table, using grayscale surface as indexes into
// table. Obviously, this only works for integer value types.
template <class SrcPixelFormatRenderer>
void blend_from_lut(const SrcPixelFormatRenderer& from,
const color_type* color_lut,
int xdst,
int ydst,
int xsrc,
int ysrc,
unsigned len,
int8u cover)
{
typedef typename SrcPixelFormatRenderer::pixel_type src_pixel_type;
@@ -699,13 +711,12 @@ namespace agg
{
pixel_type* pdst = pix_value_ptr(xdst, ydst, len);
do
do
{
copy_or_blend_pix(pdst, color_lut[psrc->c[0]], cover);
psrc = psrc->next();
pdst = pdst->next();
}
while (--len);
} while (--len);
}
}
@@ -723,16 +734,23 @@ namespace agg
typedef blender_gray_pre<gray16> blender_gray16_pre;
typedef blender_gray_pre<gray32> blender_gray32_pre;
typedef pixfmt_alpha_blend_gray<blender_gray8, rendering_buffer> pixfmt_gray8;
typedef pixfmt_alpha_blend_gray<blender_sgray8, rendering_buffer> pixfmt_sgray8;
typedef pixfmt_alpha_blend_gray<blender_gray16, rendering_buffer> pixfmt_gray16;
typedef pixfmt_alpha_blend_gray<blender_gray32, rendering_buffer> pixfmt_gray32;
typedef pixfmt_alpha_blend_gray<blender_gray8, rendering_buffer>
pixfmt_gray8;
typedef pixfmt_alpha_blend_gray<blender_sgray8, rendering_buffer>
pixfmt_sgray8;
typedef pixfmt_alpha_blend_gray<blender_gray16, rendering_buffer>
pixfmt_gray16;
typedef pixfmt_alpha_blend_gray<blender_gray32, rendering_buffer>
pixfmt_gray32;
typedef pixfmt_alpha_blend_gray<blender_gray8_pre, rendering_buffer> pixfmt_gray8_pre;
typedef pixfmt_alpha_blend_gray<blender_sgray8_pre, rendering_buffer> pixfmt_sgray8_pre;
typedef pixfmt_alpha_blend_gray<blender_gray16_pre, rendering_buffer> pixfmt_gray16_pre;
typedef pixfmt_alpha_blend_gray<blender_gray32_pre, rendering_buffer> pixfmt_gray32_pre;
typedef pixfmt_alpha_blend_gray<blender_gray8_pre, rendering_buffer>
pixfmt_gray8_pre;
typedef pixfmt_alpha_blend_gray<blender_sgray8_pre, rendering_buffer>
pixfmt_sgray8_pre;
typedef pixfmt_alpha_blend_gray<blender_gray16_pre, rendering_buffer>
pixfmt_gray16_pre;
typedef pixfmt_alpha_blend_gray<blender_gray32_pre, rendering_buffer>
pixfmt_gray32_pre;
}
#endif

View File

File diff suppressed because it is too large Load Diff

View File

File diff suppressed because it is too large Load Diff

View File

File diff suppressed because it is too large Load Diff

View File

@@ -2,8 +2,8 @@
// 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.
// 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.
//
@@ -21,7 +21,8 @@
namespace agg
{
//=======================================================pixfmt_transposer
template<class PixFmt> class pixfmt_transposer
template <class PixFmt>
class pixfmt_transposer
{
public:
typedef PixFmt pixfmt_type;
@@ -31,13 +32,22 @@ namespace agg
typedef typename color_type::calc_type calc_type;
//--------------------------------------------------------------------
pixfmt_transposer() : m_pixf(0) {}
explicit pixfmt_transposer(pixfmt_type& pixf) : m_pixf(&pixf) {}
void attach(pixfmt_type& pixf) { m_pixf = &pixf; }
pixfmt_transposer(): m_pixf(0) {}
explicit pixfmt_transposer(pixfmt_type& pixf): m_pixf(&pixf) {}
void attach(pixfmt_type& pixf)
{
m_pixf = &pixf;
}
//--------------------------------------------------------------------
AGG_INLINE unsigned width() const { return m_pixf->height(); }
AGG_INLINE unsigned height() const { return m_pixf->width(); }
AGG_INLINE unsigned width() const
{
return m_pixf->height();
}
AGG_INLINE unsigned height() const
{
return m_pixf->width();
}
//--------------------------------------------------------------------
AGG_INLINE color_type pixel(int x, int y) const
@@ -52,97 +62,92 @@ namespace agg
}
//--------------------------------------------------------------------
AGG_INLINE void blend_pixel(int x, int y,
const color_type& c,
int8u cover)
AGG_INLINE void blend_pixel(
int x, int y, const color_type& c, int8u cover)
{
m_pixf->blend_pixel(y, x, c, cover);
}
//--------------------------------------------------------------------
AGG_INLINE void copy_hline(int x, int y,
unsigned len,
const color_type& c)
AGG_INLINE void copy_hline(
int x, int y, unsigned len, const color_type& c)
{
m_pixf->copy_vline(y, x, len, c);
}
//--------------------------------------------------------------------
AGG_INLINE void copy_vline(int x, int y,
unsigned len,
const color_type& c)
AGG_INLINE void copy_vline(
int x, int y, unsigned len, const color_type& c)
{
m_pixf->copy_hline(y, x, len, c);
}
//--------------------------------------------------------------------
AGG_INLINE void blend_hline(int x, int y,
unsigned len,
const color_type& c,
int8u cover)
AGG_INLINE void blend_hline(
int x, int y, unsigned len, const color_type& c, int8u cover)
{
m_pixf->blend_vline(y, x, len, c, cover);
}
//--------------------------------------------------------------------
AGG_INLINE void blend_vline(int x, int y,
unsigned len,
const color_type& c,
int8u cover)
AGG_INLINE void blend_vline(
int x, int y, unsigned len, const color_type& c, int8u cover)
{
m_pixf->blend_hline(y, x, len, c, cover);
}
//--------------------------------------------------------------------
AGG_INLINE void blend_solid_hspan(int x, int y,
unsigned len,
const color_type& c,
const int8u* covers)
AGG_INLINE void blend_solid_hspan(int x,
int y,
unsigned len,
const color_type& c,
const int8u* covers)
{
m_pixf->blend_solid_vspan(y, x, len, c, covers);
}
//--------------------------------------------------------------------
AGG_INLINE void blend_solid_vspan(int x, int y,
unsigned len,
const color_type& c,
const int8u* covers)
AGG_INLINE void blend_solid_vspan(int x,
int y,
unsigned len,
const color_type& c,
const int8u* covers)
{
m_pixf->blend_solid_hspan(y, x, len, c, covers);
}
//--------------------------------------------------------------------
AGG_INLINE void copy_color_hspan(int x, int y,
unsigned len,
const color_type* colors)
AGG_INLINE void copy_color_hspan(
int x, int y, unsigned len, const color_type* colors)
{
m_pixf->copy_color_vspan(y, x, len, colors);
}
//--------------------------------------------------------------------
AGG_INLINE void copy_color_vspan(int x, int y,
unsigned len,
const color_type* colors)
AGG_INLINE void copy_color_vspan(
int x, int y, unsigned len, const color_type* colors)
{
m_pixf->copy_color_hspan(y, x, len, colors);
}
//--------------------------------------------------------------------
AGG_INLINE void blend_color_hspan(int x, int y,
unsigned len,
const color_type* colors,
const int8u* covers,
int8u cover)
AGG_INLINE void blend_color_hspan(int x,
int y,
unsigned len,
const color_type* colors,
const int8u* covers,
int8u cover)
{
m_pixf->blend_color_vspan(y, x, len, colors, covers, cover);
}
//--------------------------------------------------------------------
AGG_INLINE void blend_color_vspan(int x, int y,
unsigned len,
const color_type* colors,
const int8u* covers,
int8u cover)
AGG_INLINE void blend_color_vspan(int x,
int y,
unsigned len,
const color_type* colors,
const int8u* covers,
int8u cover)
{
m_pixf->blend_color_hspan(y, x, len, colors, covers, cover);
}
@@ -153,5 +158,3 @@ namespace agg
}
#endif

View File

@@ -2,15 +2,15 @@
// 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.
// 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.
//
//----------------------------------------------------------------------------
//
// The author gratefully acknowleges the support of David Turner,
// Robert Wilhelm, and Werner Lemberg - the authors of the FreeType
// The author gratefully acknowleges the support of David Turner,
// Robert Wilhelm, and Werner Lemberg - the authors of the FreeType
// libray - in producing this work. See http://www.freetype.org for details.
//
//----------------------------------------------------------------------------
@@ -19,12 +19,12 @@
// http://www.antigrain.com
//----------------------------------------------------------------------------
//
// Adaptation for 32-bit screen coordinates has been sponsored by
// Adaptation for 32-bit screen coordinates 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.
//
//
//----------------------------------------------------------------------------
#ifndef AGG_RASTERIZER_CELLS_AA_INCLUDED
#define AGG_RASTERIZER_CELLS_AA_INCLUDED
@@ -35,21 +35,21 @@
#include "agg_math.h"
#include "agg_array.h"
namespace agg
{
//-----------------------------------------------------rasterizer_cells_aa
// An internal class that implements the main rasterization algorithm.
// Used in the rasterizer. Should not be used direcly.
template<class Cell> class rasterizer_cells_aa
template <class Cell>
class rasterizer_cells_aa
{
enum cell_block_scale_e
{
cell_block_shift = 12,
cell_block_size = 1 << cell_block_shift,
cell_block_mask = cell_block_size - 1,
cell_block_pool = 256
cell_block_size = 1 << cell_block_shift,
cell_block_mask = cell_block_size - 1,
cell_block_pool = 256
};
struct sorted_y
@@ -63,75 +63,87 @@ namespace agg
typedef rasterizer_cells_aa<Cell> self_type;
~rasterizer_cells_aa();
rasterizer_cells_aa(unsigned cell_block_limit=1024);
rasterizer_cells_aa(unsigned cell_block_limit = 1024);
void reset();
void style(const cell_type& style_cell);
void line(int x1, int y1, int x2, int y2);
int min_x() const { return m_min_x; }
int min_y() const { return m_min_y; }
int max_x() const { return m_max_x; }
int max_y() const { return m_max_y; }
int min_x() const
{
return m_min_x;
}
int min_y() const
{
return m_min_y;
}
int max_x() const
{
return m_max_x;
}
int max_y() const
{
return m_max_y;
}
void sort_cells();
unsigned total_cells() const
unsigned total_cells() const
{
return m_num_cells;
}
unsigned scanline_num_cells(unsigned y) const
{
return m_sorted_y[y - m_min_y].num;
unsigned scanline_num_cells(unsigned y) const
{
return m_sorted_y[y - m_min_y].num;
}
const cell_type* const* scanline_cells(unsigned y) const
{
return m_sorted_cells.data() + m_sorted_y[y - m_min_y].start;
{
return m_sorted_cells.data() + m_sorted_y[y - m_min_y].start;
}
bool sorted() const { return m_sorted; }
bool sorted() const
{
return m_sorted;
}
private:
rasterizer_cells_aa(const self_type&);
const self_type& operator = (const self_type&);
const self_type& operator=(const self_type&);
void set_curr_cell(int x, int y);
void add_curr_cell();
void render_hline(int ey, int x1, int y1, int x2, int y2);
void allocate_block();
private:
unsigned m_num_blocks;
unsigned m_max_blocks;
unsigned m_curr_block;
unsigned m_num_cells;
unsigned m_cell_block_limit;
cell_type** m_cells;
cell_type* m_curr_cell_ptr;
pod_vector<cell_type*> m_sorted_cells;
pod_vector<sorted_y> m_sorted_y;
cell_type m_curr_cell;
cell_type m_style_cell;
int m_min_x;
int m_min_y;
int m_max_x;
int m_max_y;
bool m_sorted;
unsigned m_num_blocks;
unsigned m_max_blocks;
unsigned m_curr_block;
unsigned m_num_cells;
unsigned m_cell_block_limit;
cell_type** m_cells;
cell_type* m_curr_cell_ptr;
pod_vector<cell_type*> m_sorted_cells;
pod_vector<sorted_y> m_sorted_y;
cell_type m_curr_cell;
cell_type m_style_cell;
int m_min_x;
int m_min_y;
int m_max_x;
int m_max_y;
bool m_sorted;
};
//------------------------------------------------------------------------
template<class Cell>
template <class Cell>
rasterizer_cells_aa<Cell>::~rasterizer_cells_aa()
{
if(m_num_blocks)
if (m_num_blocks)
{
cell_type** ptr = m_cells + m_num_blocks - 1;
while(m_num_blocks--)
while (m_num_blocks--)
{
pod_allocator<cell_type>::deallocate(*ptr, cell_block_size);
ptr--;
@@ -141,13 +153,13 @@ namespace agg
}
//------------------------------------------------------------------------
template<class Cell>
rasterizer_cells_aa<Cell>::rasterizer_cells_aa(unsigned cell_block_limit) :
template <class Cell>
rasterizer_cells_aa<Cell>::rasterizer_cells_aa(unsigned cell_block_limit):
m_num_blocks(0),
m_max_blocks(0),
m_curr_block(0),
m_num_cells(0),
m_cell_block_limit(cell_block_limit),
m_cell_block_limit(cell_block_limit),
m_cells(0),
m_curr_cell_ptr(0),
m_sorted_cells(),
@@ -163,10 +175,10 @@ namespace agg
}
//------------------------------------------------------------------------
template<class Cell>
template <class Cell>
void rasterizer_cells_aa<Cell>::reset()
{
m_num_cells = 0;
m_num_cells = 0;
m_curr_block = 0;
m_curr_cell.initial();
m_style_cell.initial();
@@ -178,14 +190,15 @@ namespace agg
}
//------------------------------------------------------------------------
template<class Cell>
template <class Cell>
AGG_INLINE void rasterizer_cells_aa<Cell>::add_curr_cell()
{
if(m_curr_cell.area | m_curr_cell.cover)
if (m_curr_cell.area | m_curr_cell.cover)
{
if((m_num_cells & cell_block_mask) == 0)
if ((m_num_cells & cell_block_mask) == 0)
{
if(m_num_blocks >= m_cell_block_limit) return;
if (m_num_blocks >= m_cell_block_limit)
return;
allocate_block();
}
*m_curr_cell_ptr++ = m_curr_cell;
@@ -194,25 +207,24 @@ namespace agg
}
//------------------------------------------------------------------------
template<class Cell>
template <class Cell>
AGG_INLINE void rasterizer_cells_aa<Cell>::set_curr_cell(int x, int y)
{
if(m_curr_cell.not_equal(x, y, m_style_cell))
if (m_curr_cell.not_equal(x, y, m_style_cell))
{
add_curr_cell();
m_curr_cell.style(m_style_cell);
m_curr_cell.x = x;
m_curr_cell.y = y;
m_curr_cell.x = x;
m_curr_cell.y = y;
m_curr_cell.cover = 0;
m_curr_cell.area = 0;
m_curr_cell.area = 0;
}
}
//------------------------------------------------------------------------
template<class Cell>
AGG_INLINE void rasterizer_cells_aa<Cell>::render_hline(int ey,
int x1, int y1,
int x2, int y2)
template <class Cell>
AGG_INLINE void rasterizer_cells_aa<Cell>::render_hline(
int ey, int x1, int y1, int x2, int y2)
{
int ex1 = x1 >> poly_subpixel_shift;
int ex2 = x2 >> poly_subpixel_shift;
@@ -223,59 +235,59 @@ namespace agg
long long dx;
int incr, lift, mod, rem;
//trivial case. Happens often
if(y1 == y2)
// trivial case. Happens often
if (y1 == y2)
{
set_curr_cell(ex2, ey);
return;
}
//everything is located in a single cell. That is easy!
if(ex1 == ex2)
// everything is located in a single cell. That is easy!
if (ex1 == ex2)
{
delta = y2 - y1;
m_curr_cell.cover += delta;
m_curr_cell.area += (fx1 + fx2) * delta;
m_curr_cell.area += (fx1 + fx2) * delta;
return;
}
//ok, we'll have to render a run of adjacent cells on the same
//hline...
p = (poly_subpixel_scale - fx1) * (y2 - y1);
// ok, we'll have to render a run of adjacent cells on the same
// hline...
p = (poly_subpixel_scale - fx1) * (y2 - y1);
first = poly_subpixel_scale;
incr = 1;
incr = 1;
dx = (long long)x2 - (long long)x1;
if(dx < 0)
if (dx < 0)
{
p = fx1 * (y2 - y1);
p = fx1 * (y2 - y1);
first = 0;
incr = -1;
dx = -dx;
incr = -1;
dx = -dx;
}
delta = (int)(p / dx);
mod = (int)(p % dx);
mod = (int)(p % dx);
if(mod < 0)
if (mod < 0)
{
delta--;
mod += dx;
}
m_curr_cell.cover += delta;
m_curr_cell.area += (fx1 + first) * delta;
m_curr_cell.area += (fx1 + first) * delta;
ex1 += incr;
set_curr_cell(ex1, ey);
y1 += delta;
y1 += delta;
if(ex1 != ex2)
if (ex1 != ex2)
{
p = poly_subpixel_scale * (y2 - y1 + delta);
lift = (int)(p / dx);
rem = (int)(p % dx);
p = poly_subpixel_scale * (y2 - y1 + delta);
lift = (int)(p / dx);
rem = (int)(p % dx);
if (rem < 0)
{
@@ -288,41 +300,45 @@ namespace agg
while (ex1 != ex2)
{
delta = lift;
mod += rem;
if(mod >= 0)
mod += rem;
if (mod >= 0)
{
mod -= dx;
delta++;
}
m_curr_cell.cover += delta;
m_curr_cell.area += poly_subpixel_scale * delta;
y1 += delta;
m_curr_cell.area += poly_subpixel_scale * delta;
y1 += delta;
ex1 += incr;
set_curr_cell(ex1, ey);
}
}
delta = y2 - y1;
m_curr_cell.cover += delta;
m_curr_cell.area += (fx2 + poly_subpixel_scale - first) * delta;
m_curr_cell.area += (fx2 + poly_subpixel_scale - first) * delta;
}
//------------------------------------------------------------------------
template<class Cell>
AGG_INLINE void rasterizer_cells_aa<Cell>::style(const cell_type& style_cell)
{
m_style_cell.style(style_cell);
template <class Cell>
AGG_INLINE void rasterizer_cells_aa<Cell>::style(
const cell_type& style_cell)
{
m_style_cell.style(style_cell);
}
//------------------------------------------------------------------------
template<class Cell>
template <class Cell>
void rasterizer_cells_aa<Cell>::line(int x1, int y1, int x2, int y2)
{
enum dx_limit_e { dx_limit = 16384 << poly_subpixel_shift };
enum dx_limit_e
{
dx_limit = 16384 << poly_subpixel_shift
};
long long dx = (long long)x2 - (long long)x1;
if(dx >= dx_limit || dx <= -dx_limit)
if (dx >= dx_limit || dx <= -dx_limit)
{
int cx = (int)(((long long)x1 + (long long)x2) >> 1);
int cy = (int)(((long long)y1 + (long long)y2) >> 1);
@@ -342,85 +358,95 @@ namespace agg
int rem, mod, lift, delta, first, incr;
long long p;
if(ex1 < m_min_x) m_min_x = ex1;
if(ex1 > m_max_x) m_max_x = ex1;
if(ey1 < m_min_y) m_min_y = ey1;
if(ey1 > m_max_y) m_max_y = ey1;
if(ex2 < m_min_x) m_min_x = ex2;
if(ex2 > m_max_x) m_max_x = ex2;
if(ey2 < m_min_y) m_min_y = ey2;
if(ey2 > m_max_y) m_max_y = ey2;
if (ex1 < m_min_x)
m_min_x = ex1;
if (ex1 > m_max_x)
m_max_x = ex1;
if (ey1 < m_min_y)
m_min_y = ey1;
if (ey1 > m_max_y)
m_max_y = ey1;
if (ex2 < m_min_x)
m_min_x = ex2;
if (ex2 > m_max_x)
m_max_x = ex2;
if (ey2 < m_min_y)
m_min_y = ey2;
if (ey2 > m_max_y)
m_max_y = ey2;
set_curr_cell(ex1, ey1);
//everything is on a single hline
if(ey1 == ey2)
// everything is on a single hline
if (ey1 == ey2)
{
render_hline(ey1, x1, fy1, x2, fy2);
return;
}
//Vertical line - we have to calculate start and end cells,
//and then - the common values of the area and coverage for
//all cells of the line. We know exactly there's only one
//cell, so, we don't have to call render_hline().
incr = 1;
if(dx == 0)
// Vertical line - we have to calculate start and end cells,
// and then - the common values of the area and coverage for
// all cells of the line. We know exactly there's only one
// cell, so, we don't have to call render_hline().
incr = 1;
if (dx == 0)
{
int ex = x1 >> poly_subpixel_shift;
int two_fx = (x1 - (ex << poly_subpixel_shift)) << 1;
int area;
first = poly_subpixel_scale;
if(dy < 0)
if (dy < 0)
{
first = 0;
incr = -1;
incr = -1;
}
x_from = x1;
//render_hline(ey1, x_from, fy1, x_from, first);
// render_hline(ey1, x_from, fy1, x_from, first);
delta = first - fy1;
m_curr_cell.cover += delta;
m_curr_cell.area += two_fx * delta;
m_curr_cell.area += two_fx * delta;
ey1 += incr;
set_curr_cell(ex, ey1);
delta = first + first - poly_subpixel_scale;
area = two_fx * delta;
while(ey1 != ey2)
while (ey1 != ey2)
{
//render_hline(ey1, x_from, poly_subpixel_scale - first, x_from, first);
// render_hline(ey1, x_from, poly_subpixel_scale - first,
// x_from, first);
m_curr_cell.cover = delta;
m_curr_cell.area = area;
m_curr_cell.area = area;
ey1 += incr;
set_curr_cell(ex, ey1);
}
//render_hline(ey1, x_from, poly_subpixel_scale - first, x_from, fy2);
// render_hline(ey1, x_from, poly_subpixel_scale - first, x_from,
// fy2);
delta = fy2 - poly_subpixel_scale + first;
m_curr_cell.cover += delta;
m_curr_cell.area += two_fx * delta;
m_curr_cell.area += two_fx * delta;
return;
}
//ok, we have to render several hlines
p = (poly_subpixel_scale - fy1) * dx;
// ok, we have to render several hlines
p = (poly_subpixel_scale - fy1) * dx;
first = poly_subpixel_scale;
if(dy < 0)
if (dy < 0)
{
p = fy1 * dx;
p = fy1 * dx;
first = 0;
incr = -1;
dy = -dy;
incr = -1;
dy = -dy;
}
delta = (int)(p / dy);
mod = (int)(p % dy);
mod = (int)(p % dy);
if(mod < 0)
if (mod < 0)
{
delta--;
mod += dy;
@@ -432,23 +458,23 @@ namespace agg
ey1 += incr;
set_curr_cell(x_from >> poly_subpixel_shift, ey1);
if(ey1 != ey2)
if (ey1 != ey2)
{
p = poly_subpixel_scale * dx;
lift = (int)(p / dy);
rem = (int)(p % dy);
p = poly_subpixel_scale * dx;
lift = (int)(p / dy);
rem = (int)(p % dy);
if(rem < 0)
if (rem < 0)
{
lift--;
rem += dy;
}
mod -= dy;
while(ey1 != ey2)
while (ey1 != ey2)
{
delta = lift;
mod += rem;
mod += rem;
if (mod >= 0)
{
mod -= dy;
@@ -456,7 +482,8 @@ namespace agg
}
x_to = x_from + delta;
render_hline(ey1, x_from, poly_subpixel_scale - first, x_to, first);
render_hline(
ey1, x_from, poly_subpixel_scale - first, x_to, first);
x_from = x_to;
ey1 += incr;
@@ -467,63 +494,60 @@ namespace agg
}
//------------------------------------------------------------------------
template<class Cell>
template <class Cell>
void rasterizer_cells_aa<Cell>::allocate_block()
{
if(m_curr_block >= m_num_blocks)
if (m_curr_block >= m_num_blocks)
{
if(m_num_blocks >= m_max_blocks)
if (m_num_blocks >= m_max_blocks)
{
cell_type** new_cells =
pod_allocator<cell_type*>::allocate(m_max_blocks +
cell_block_pool);
cell_type** new_cells = pod_allocator<cell_type*>::allocate(
m_max_blocks + cell_block_pool);
if(m_cells)
if (m_cells)
{
std::memcpy(new_cells, m_cells, m_max_blocks * sizeof(cell_type*));
pod_allocator<cell_type*>::deallocate(m_cells, m_max_blocks);
std::memcpy(
new_cells, m_cells, m_max_blocks * sizeof(cell_type*));
pod_allocator<cell_type*>::deallocate(
m_cells, m_max_blocks);
}
m_cells = new_cells;
m_max_blocks += cell_block_pool;
}
m_cells[m_num_blocks++] =
m_cells[m_num_blocks++] =
pod_allocator<cell_type>::allocate(cell_block_size);
}
m_curr_cell_ptr = m_cells[m_curr_block++];
}
//------------------------------------------------------------------------
template <class T> static AGG_INLINE void swap_cells(T* a, T* b)
template <class T>
static AGG_INLINE void swap_cells(T* a, T* b)
{
T temp = *a;
*a = *b;
*b = temp;
}
//------------------------------------------------------------------------
enum
{
qsort_threshold = 9
};
//------------------------------------------------------------------------
template<class Cell>
template <class Cell>
void qsort_cells(Cell** start, unsigned num)
{
Cell** stack[80];
Cell*** top;
Cell** limit;
Cell** base;
Cell** stack[80];
Cell*** top;
Cell** limit;
Cell** base;
limit = start + num;
base = start;
top = stack;
base = start;
top = stack;
for (;;)
{
@@ -533,7 +557,7 @@ namespace agg
Cell** j;
Cell** pivot;
if(len > qsort_threshold)
if (len > qsort_threshold)
{
// we use base + len/2 as the pivot
pivot = base + len / 2;
@@ -542,29 +566,33 @@ namespace agg
i = base + 1;
j = limit - 1;
// now ensure that *i <= *base <= *j
if((*j)->x < (*i)->x)
// now ensure that *i <= *base <= *j
if ((*j)->x < (*i)->x)
{
swap_cells(i, j);
}
if((*base)->x < (*i)->x)
if ((*base)->x < (*i)->x)
{
swap_cells(base, i);
}
if((*j)->x < (*base)->x)
if ((*j)->x < (*base)->x)
{
swap_cells(base, j);
}
for(;;)
for (;;)
{
int x = (*base)->x;
do i++; while( (*i)->x < x );
do j--; while( x < (*j)->x );
do
i++;
while ((*i)->x < x);
do
j--;
while (x < (*j)->x);
if(i > j)
if (i > j)
{
break;
}
@@ -575,17 +603,17 @@ namespace agg
swap_cells(base, j);
// now, push the largest sub-array
if(j - base > limit - i)
if (j - base > limit - i)
{
top[0] = base;
top[1] = j;
base = i;
base = i;
}
else
{
top[0] = i;
top[1] = limit;
limit = j;
limit = j;
}
top += 2;
}
@@ -595,9 +623,9 @@ namespace agg
j = base;
i = j + 1;
for(; i < limit; j = i, i++)
for (; i < limit; j = i, i++)
{
for(; j[1]->x < (*j)->x; j--)
for (; j[1]->x < (*j)->x; j--)
{
swap_cells(j + 1, j);
if (j == base)
@@ -607,10 +635,10 @@ namespace agg
}
}
if(top > stack)
if (top > stack)
{
top -= 2;
base = top[0];
top -= 2;
base = top[0];
limit = top[1];
}
else
@@ -621,33 +649,34 @@ namespace agg
}
}
//------------------------------------------------------------------------
template<class Cell>
template <class Cell>
void rasterizer_cells_aa<Cell>::sort_cells()
{
if(m_sorted) return; //Perform sort only the first time.
if (m_sorted)
return; // Perform sort only the first time.
add_curr_cell();
m_curr_cell.x = std::numeric_limits<int>::max();
m_curr_cell.y = std::numeric_limits<int>::max();
m_curr_cell.x = std::numeric_limits<int>::max();
m_curr_cell.y = std::numeric_limits<int>::max();
m_curr_cell.cover = 0;
m_curr_cell.area = 0;
m_curr_cell.area = 0;
if(m_num_cells == 0) return;
if (m_num_cells == 0)
return;
// DBG: Check to see if min/max works well.
//for(unsigned nc = 0; nc < m_num_cells; nc++)
//{
// cell_type* cell = m_cells[nc >> cell_block_shift] + (nc & cell_block_mask);
// if(cell->x < m_min_x ||
// cell->y < m_min_y ||
// cell->x > m_max_x ||
// cell->y > m_max_y)
// {
// cell = cell; // Breakpoint here
// }
//}
// DBG: Check to see if min/max works well.
// for(unsigned nc = 0; nc < m_num_cells; nc++)
//{
// cell_type* cell = m_cells[nc >> cell_block_shift] + (nc &
// cell_block_mask); if(cell->x < m_min_x ||
// cell->y < m_min_y ||
// cell->x > m_max_x ||
// cell->y > m_max_y)
// {
// cell = cell; // Breakpoint here
// }
//}
// Allocate the array of cell pointers
m_sorted_cells.allocate(m_num_cells, 16);
@@ -657,15 +686,15 @@ namespace agg
// Create the Y-histogram (count the numbers of cells for each Y)
cell_type** block_ptr = m_cells;
cell_type* cell_ptr;
cell_type* cell_ptr;
unsigned nb = m_num_cells;
unsigned i;
while(nb)
while (nb)
{
cell_ptr = *block_ptr++;
i = (nb > cell_block_size) ? unsigned(cell_block_size) : nb;
nb -= i;
while(i--)
while (i--)
{
m_sorted_y[cell_ptr->y - m_min_y].start++;
++cell_ptr;
@@ -674,7 +703,7 @@ namespace agg
// Convert the Y-histogram into the array of starting indexes
unsigned start = 0;
for(i = 0; i < m_sorted_y.size(); i++)
for (i = 0; i < m_sorted_y.size(); i++)
{
unsigned v = m_sorted_y[i].start;
m_sorted_y[i].start = start;
@@ -684,12 +713,12 @@ namespace agg
// Fill the cell pointer array sorted by Y
block_ptr = m_cells;
nb = m_num_cells;
while(nb)
while (nb)
{
cell_ptr = *block_ptr++;
i = (nb > cell_block_size) ? unsigned(cell_block_size) : nb;
nb -= i;
while(i--)
while (i--)
{
sorted_y& curr_y = m_sorted_y[cell_ptr->y - m_min_y];
m_sorted_cells[curr_y.start + curr_y.num] = cell_ptr;
@@ -697,12 +726,12 @@ namespace agg
++cell_ptr;
}
}
// Finally arrange the X-arrays
for(i = 0; i < m_sorted_y.size(); i++)
for (i = 0; i < m_sorted_y.size(); i++)
{
const sorted_y& curr_y = m_sorted_y[i];
if(curr_y.num)
if (curr_y.num)
{
qsort_cells(m_sorted_cells.data() + curr_y.start, curr_y.num);
}
@@ -710,33 +739,38 @@ namespace agg
m_sorted = true;
}
//------------------------------------------------------scanline_hit_test
class scanline_hit_test
{
public:
scanline_hit_test(int x) : m_x(x), m_hit(false) {}
scanline_hit_test(int x): m_x(x), m_hit(false) {}
void reset_spans() {}
void finalize(int) {}
void add_cell(int x, int)
{
if(m_x == x) m_hit = true;
if (m_x == x)
m_hit = true;
}
void add_span(int x, int len, int)
{
if(m_x >= x && m_x < x+len) m_hit = true;
if (m_x >= x && m_x < x + len)
m_hit = true;
}
unsigned num_spans() const
{
return 1;
}
bool hit() const
{
return m_hit;
}
unsigned num_spans() const { return 1; }
bool hit() const { return m_hit; }
private:
int m_x;
int m_x;
bool m_hit;
};
}
#endif

View File

@@ -2,15 +2,15 @@
// Anti-Grain Geometry - Version 2.3
// 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.
// 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.
//
//----------------------------------------------------------------------------
//
// The author gratefully acknowleges the support of David Turner,
// Robert Wilhelm, and Werner Lemberg - the authors of the FreeType
// The author gratefully acknowleges the support of David Turner,
// Robert Wilhelm, and Werner Lemberg - the authors of the FreeType
// libray - in producing this work. See http://www.freetype.org for details.
//
//----------------------------------------------------------------------------
@@ -19,12 +19,12 @@
// http://www.antigrain.com
//----------------------------------------------------------------------------
//
// Adaptation for 32-bit screen coordinates has been sponsored by
// Adaptation for 32-bit screen coordinates 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.
//
//
//----------------------------------------------------------------------------
#ifndef AGG_RASTERIZER_COMPOUND_AA_INCLUDED
#define AGG_RASTERIZER_COMPOUND_AA_INCLUDED
@@ -37,41 +37,41 @@ namespace agg
{
//-----------------------------------------------------------cell_style_aa
// A pixel cell. There're no constructors defined and it was done
// intentionally in order to avoid extra overhead when allocating an
// A pixel cell. There're no constructors defined and it was done
// intentionally in order to avoid extra overhead when allocating an
// array of cells.
struct cell_style_aa
{
int x;
int y;
int cover;
int area;
int x;
int y;
int cover;
int area;
int16 left, right;
void initial()
{
x = std::numeric_limits<int>::max();
y = std::numeric_limits<int>::max();
x = std::numeric_limits<int>::max();
y = std::numeric_limits<int>::max();
cover = 0;
area = 0;
left = -1;
area = 0;
left = -1;
right = -1;
}
void style(const cell_style_aa& c)
{
left = c.left;
left = c.left;
right = c.right;
}
int not_equal(int ex, int ey, const cell_style_aa& c) const
{
return ((unsigned)ex - (unsigned)x) | ((unsigned)ey - (unsigned)y) |
((unsigned)left - (unsigned)c.left) | ((unsigned)right - (unsigned)c.right);
return ((unsigned)ex - (unsigned)x) | ((unsigned)ey - (unsigned)y) |
((unsigned)left - (unsigned)c.left) |
((unsigned)right - (unsigned)c.right);
}
};
//===========================================================layer_order_e
enum layer_order_e
{
@@ -80,45 +80,45 @@ namespace agg
layer_inverse //------layer_inverse
};
//==================================================rasterizer_compound_aa
template<class Clip=rasterizer_sl_clip_int> class rasterizer_compound_aa
template <class Clip = rasterizer_sl_clip_int>
class rasterizer_compound_aa
{
struct style_info
{
struct style_info
{
unsigned start_cell;
unsigned num_cells;
int last_x;
int last_x;
};
struct cell_info
{
int x, area, cover;
int x, area, cover;
};
public:
typedef Clip clip_type;
typedef typename Clip::conv_type conv_type;
typedef Clip clip_type;
typedef typename Clip::conv_type conv_type;
typedef typename Clip::coord_type coord_type;
enum aa_scale_e
{
aa_shift = 8,
aa_scale = 1 << aa_shift,
aa_mask = aa_scale - 1,
aa_shift = 8,
aa_scale = 1 << aa_shift,
aa_mask = aa_scale - 1,
aa_scale2 = aa_scale * 2,
aa_mask2 = aa_scale2 - 1
aa_mask2 = aa_scale2 - 1
};
//--------------------------------------------------------------------
rasterizer_compound_aa() :
rasterizer_compound_aa():
m_outline(),
m_clipper(),
m_filling_rule(fill_non_zero),
m_layer_order(layer_direct),
m_styles(), // Active Styles
m_ast(), // Active Style Table (unique values)
m_asm(), // Active Style Mask
m_styles(), // Active Styles
m_ast(), // Active Style Table (unique values)
m_asm(), // Active Style Mask
m_cells(),
m_cover_buf(),
m_min_style(std::numeric_limits<int>::max()),
@@ -128,10 +128,11 @@ namespace agg
m_scan_y(std::numeric_limits<int>::max()),
m_sl_start(0),
m_sl_len(0)
{}
{
}
//--------------------------------------------------------------------
void reset();
void reset();
void reset_clipping();
void clip_box(double x1, double y1, double x2, double y2);
void filling_rule(filling_rule_e filling_rule);
@@ -149,76 +150,104 @@ namespace agg
void edge_d(double x1, double y1, double x2, double y2);
//-------------------------------------------------------------------
template<class VertexSource>
void add_path(VertexSource& vs, unsigned path_id=0)
template <class VertexSource>
void add_path(VertexSource& vs, unsigned path_id = 0)
{
double x;
double y;
unsigned cmd;
vs.rewind(path_id);
if(m_outline.sorted()) reset();
while(!is_stop(cmd = vs.vertex(&x, &y)))
if (m_outline.sorted())
reset();
while (!is_stop(cmd = vs.vertex(&x, &y)))
{
add_vertex(x, y, cmd);
}
}
//--------------------------------------------------------------------
int min_x() const { return m_outline.min_x(); }
int min_y() const { return m_outline.min_y(); }
int max_x() const { return m_outline.max_x(); }
int max_y() const { return m_outline.max_y(); }
int min_style() const { return m_min_style; }
int max_style() const { return m_max_style; }
int min_x() const
{
return m_outline.min_x();
}
int min_y() const
{
return m_outline.min_y();
}
int max_x() const
{
return m_outline.max_x();
}
int max_y() const
{
return m_outline.max_y();
}
int min_style() const
{
return m_min_style;
}
int max_style() const
{
return m_max_style;
}
//--------------------------------------------------------------------
void sort();
bool rewind_scanlines();
unsigned sweep_styles();
int scanline_start() const { return m_sl_start; }
unsigned scanline_length() const { return m_sl_len; }
int scanline_start() const
{
return m_sl_start;
}
unsigned scanline_length() const
{
return m_sl_len;
}
unsigned style(unsigned style_idx) const;
cover_type* allocate_cover_buffer(unsigned len);
//--------------------------------------------------------------------
bool navigate_scanline(int y);
bool navigate_scanline(int y);
bool hit_test(int tx, int ty);
//--------------------------------------------------------------------
AGG_INLINE unsigned calculate_alpha(int area) const
{
int cover = area >> (poly_subpixel_shift*2 + 1 - aa_shift);
if(cover < 0) cover = -cover;
if(m_filling_rule == fill_even_odd)
int cover = area >> (poly_subpixel_shift * 2 + 1 - aa_shift);
if (cover < 0)
cover = -cover;
if (m_filling_rule == fill_even_odd)
{
cover &= aa_mask2;
if(cover > aa_scale)
if (cover > aa_scale)
{
cover = aa_scale2 - cover;
}
}
if(cover > aa_mask) cover = aa_mask;
if (cover > aa_mask)
cover = aa_mask;
return cover;
}
//--------------------------------------------------------------------
// Sweeps one scanline with one style index. The style ID can be
// determined by calling style().
template<class Scanline> bool sweep_scanline(Scanline& sl, int style_idx)
// Sweeps one scanline with one style index. The style ID can be
// determined by calling style().
template <class Scanline>
bool sweep_scanline(Scanline& sl, int style_idx)
{
int scan_y = m_scan_y - 1;
if(scan_y > m_outline.max_y()) return false;
if (scan_y > m_outline.max_y())
return false;
sl.reset_spans();
if(style_idx < 0)
if (style_idx < 0)
{
style_idx = 0;
}
else
else
{
style_idx++;
}
@@ -229,7 +258,7 @@ namespace agg
cell_info* cell = &m_cells[st.start_cell];
int cover = 0;
while(num_cells--)
while (num_cells--)
{
unsigned alpha;
int x = cell->x;
@@ -239,24 +268,26 @@ namespace agg
++cell;
if(area)
if (area)
{
alpha = calculate_alpha((cover << (poly_subpixel_shift + 1)) - area);
alpha = calculate_alpha(
(cover << (poly_subpixel_shift + 1)) - area);
sl.add_cell(x, alpha);
x++;
}
if(num_cells && cell->x > x)
if (num_cells && cell->x > x)
{
alpha = calculate_alpha(cover << (poly_subpixel_shift + 1));
if(alpha)
if (alpha)
{
sl.add_span(x, cell->x - x, alpha);
}
}
}
if(sl.num_spans() == 0) return false;
if (sl.num_spans() == 0)
return false;
sl.finalize(scan_y);
return true;
}
@@ -267,76 +298,69 @@ namespace agg
//--------------------------------------------------------------------
// Disable copying
rasterizer_compound_aa(const rasterizer_compound_aa<Clip>&);
const rasterizer_compound_aa<Clip>&
operator = (const rasterizer_compound_aa<Clip>&);
const rasterizer_compound_aa<Clip>& operator=(
const rasterizer_compound_aa<Clip>&);
private:
rasterizer_cells_aa<cell_style_aa> m_outline;
clip_type m_clipper;
filling_rule_e m_filling_rule;
layer_order_e m_layer_order;
pod_vector<style_info> m_styles; // Active Styles
pod_vector<unsigned> m_ast; // Active Style Table (unique values)
pod_vector<int8u> m_asm; // Active Style Mask
pod_vector<cell_info> m_cells;
clip_type m_clipper;
filling_rule_e m_filling_rule;
layer_order_e m_layer_order;
pod_vector<style_info> m_styles; // Active Styles
pod_vector<unsigned> m_ast; // Active Style Table (unique values)
pod_vector<int8u> m_asm; // Active Style Mask
pod_vector<cell_info> m_cells;
pod_vector<cover_type> m_cover_buf;
int m_min_style;
int m_max_style;
int m_min_style;
int m_max_style;
coord_type m_start_x;
coord_type m_start_y;
int m_scan_y;
int m_sl_start;
unsigned m_sl_len;
int m_scan_y;
int m_sl_start;
unsigned m_sl_len;
};
//------------------------------------------------------------------------
template<class Clip>
void rasterizer_compound_aa<Clip>::reset()
{
m_outline.reset();
template <class Clip>
void rasterizer_compound_aa<Clip>::reset()
{
m_outline.reset();
m_min_style = std::numeric_limits<int>::max();
m_max_style = std::numeric_limits<int>::min();
m_scan_y = std::numeric_limits<int>::max();
m_sl_start = 0;
m_sl_len = 0;
m_scan_y = std::numeric_limits<int>::max();
m_sl_start = 0;
m_sl_len = 0;
}
//------------------------------------------------------------------------
template<class Clip>
void rasterizer_compound_aa<Clip>::filling_rule(filling_rule_e filling_rule)
{
m_filling_rule = filling_rule;
template <class Clip>
void rasterizer_compound_aa<Clip>::filling_rule(filling_rule_e filling_rule)
{
m_filling_rule = filling_rule;
}
//------------------------------------------------------------------------
template<class Clip>
template <class Clip>
void rasterizer_compound_aa<Clip>::layer_order(layer_order_e order)
{
m_layer_order = order;
}
//------------------------------------------------------------------------
template<class Clip>
void rasterizer_compound_aa<Clip>::clip_box(double x1, double y1,
double x2, double y2)
template <class Clip>
void rasterizer_compound_aa<Clip>::clip_box(
double x1, double y1, double x2, double y2)
{
reset();
m_clipper.clip_box(conv_type::upscale(x1), conv_type::upscale(y1),
conv_type::upscale(x2), conv_type::upscale(y2));
m_clipper.clip_box(conv_type::upscale(x1),
conv_type::upscale(y1),
conv_type::upscale(x2),
conv_type::upscale(y2));
}
//------------------------------------------------------------------------
template<class Clip>
template <class Clip>
void rasterizer_compound_aa<Clip>::reset_clipping()
{
reset();
@@ -344,7 +368,7 @@ namespace agg
}
//------------------------------------------------------------------------
template<class Clip>
template <class Clip>
void rasterizer_compound_aa<Clip>::styles(int left, int right)
{
cell_style_aa cell;
@@ -352,108 +376,111 @@ namespace agg
cell.left = (int16)left;
cell.right = (int16)right;
m_outline.style(cell);
if(left >= 0 && left < m_min_style) m_min_style = left;
if(left >= 0 && left > m_max_style) m_max_style = left;
if(right >= 0 && right < m_min_style) m_min_style = right;
if(right >= 0 && right > m_max_style) m_max_style = right;
if (left >= 0 && left < m_min_style)
m_min_style = left;
if (left >= 0 && left > m_max_style)
m_max_style = left;
if (right >= 0 && right < m_min_style)
m_min_style = right;
if (right >= 0 && right > m_max_style)
m_max_style = right;
}
//------------------------------------------------------------------------
template<class Clip>
template <class Clip>
void rasterizer_compound_aa<Clip>::move_to(int x, int y)
{
if(m_outline.sorted()) reset();
m_clipper.move_to(m_start_x = conv_type::downscale(x),
m_start_y = conv_type::downscale(y));
if (m_outline.sorted())
reset();
m_clipper.move_to(m_start_x = conv_type::downscale(x),
m_start_y = conv_type::downscale(y));
}
//------------------------------------------------------------------------
template<class Clip>
template <class Clip>
void rasterizer_compound_aa<Clip>::line_to(int x, int y)
{
m_clipper.line_to(m_outline,
conv_type::downscale(x),
conv_type::downscale(y));
m_clipper.line_to(
m_outline, conv_type::downscale(x), conv_type::downscale(y));
}
//------------------------------------------------------------------------
template<class Clip>
void rasterizer_compound_aa<Clip>::move_to_d(double x, double y)
{
if(m_outline.sorted()) reset();
m_clipper.move_to(m_start_x = conv_type::upscale(x),
m_start_y = conv_type::upscale(y));
}
//------------------------------------------------------------------------
template<class Clip>
void rasterizer_compound_aa<Clip>::line_to_d(double x, double y)
{
m_clipper.line_to(m_outline,
conv_type::upscale(x),
conv_type::upscale(y));
}
//------------------------------------------------------------------------
template<class Clip>
void rasterizer_compound_aa<Clip>::add_vertex(double x, double y, unsigned cmd)
template <class Clip>
void rasterizer_compound_aa<Clip>::move_to_d(double x, double y)
{
if(is_move_to(cmd))
if (m_outline.sorted())
reset();
m_clipper.move_to(m_start_x = conv_type::upscale(x),
m_start_y = conv_type::upscale(y));
}
//------------------------------------------------------------------------
template <class Clip>
void rasterizer_compound_aa<Clip>::line_to_d(double x, double y)
{
m_clipper.line_to(
m_outline, conv_type::upscale(x), conv_type::upscale(y));
}
//------------------------------------------------------------------------
template <class Clip>
void rasterizer_compound_aa<Clip>::add_vertex(
double x, double y, unsigned cmd)
{
if (is_move_to(cmd))
{
move_to_d(x, y);
}
else
if(is_vertex(cmd))
else if (is_vertex(cmd))
{
line_to_d(x, y);
}
else
if(is_close(cmd))
else if (is_close(cmd))
{
m_clipper.line_to(m_outline, m_start_x, m_start_y);
}
}
//------------------------------------------------------------------------
template<class Clip>
template <class Clip>
void rasterizer_compound_aa<Clip>::edge(int x1, int y1, int x2, int y2)
{
if(m_outline.sorted()) reset();
if (m_outline.sorted())
reset();
m_clipper.move_to(conv_type::downscale(x1), conv_type::downscale(y1));
m_clipper.line_to(m_outline,
conv_type::downscale(x2),
conv_type::downscale(y2));
}
//------------------------------------------------------------------------
template<class Clip>
void rasterizer_compound_aa<Clip>::edge_d(double x1, double y1,
double x2, double y2)
{
if(m_outline.sorted()) reset();
m_clipper.move_to(conv_type::upscale(x1), conv_type::upscale(y1));
m_clipper.line_to(m_outline,
conv_type::upscale(x2),
conv_type::upscale(y2));
m_clipper.line_to(
m_outline, conv_type::downscale(x2), conv_type::downscale(y2));
}
//------------------------------------------------------------------------
template<class Clip>
template <class Clip>
void rasterizer_compound_aa<Clip>::edge_d(
double x1, double y1, double x2, double y2)
{
if (m_outline.sorted())
reset();
m_clipper.move_to(conv_type::upscale(x1), conv_type::upscale(y1));
m_clipper.line_to(
m_outline, conv_type::upscale(x2), conv_type::upscale(y2));
}
//------------------------------------------------------------------------
template <class Clip>
AGG_INLINE void rasterizer_compound_aa<Clip>::sort()
{
m_outline.sort_cells();
}
//------------------------------------------------------------------------
template<class Clip>
template <class Clip>
AGG_INLINE bool rasterizer_compound_aa<Clip>::rewind_scanlines()
{
m_outline.sort_cells();
if(m_outline.total_cells() == 0)
if (m_outline.total_cells() == 0)
{
return false;
}
if(m_max_style < m_min_style)
if (m_max_style < m_min_style)
{
return false;
}
@@ -463,17 +490,19 @@ namespace agg
}
//------------------------------------------------------------------------
template<class Clip>
template <class Clip>
AGG_INLINE void rasterizer_compound_aa<Clip>::add_style(int style_id)
{
if(style_id < 0) style_id = 0;
else style_id -= m_min_style - 1;
if (style_id < 0)
style_id = 0;
else
style_id -= m_min_style - 1;
unsigned nbyte = style_id >> 3;
unsigned mask = 1 << (style_id & 7);
style_info* style = &m_styles[style_id];
if((m_asm[nbyte] & mask) == 0)
if ((m_asm[nbyte] & mask) == 0)
{
m_ast.add(style_id);
m_asm[nbyte] |= mask;
@@ -486,30 +515,33 @@ namespace agg
//------------------------------------------------------------------------
// Returns the number of styles
template<class Clip>
template <class Clip>
unsigned rasterizer_compound_aa<Clip>::sweep_styles()
{
for(;;)
for (;;)
{
if(m_scan_y > m_outline.max_y()) return 0;
if (m_scan_y > m_outline.max_y())
return 0;
unsigned num_cells = m_outline.scanline_num_cells(m_scan_y);
const cell_style_aa* const* cells = m_outline.scanline_cells(m_scan_y);
const cell_style_aa* const* cells =
m_outline.scanline_cells(m_scan_y);
unsigned num_styles = m_max_style - m_min_style + 2;
const cell_style_aa* curr_cell;
unsigned style_id;
style_info* style;
cell_info* cell;
m_cells.allocate(num_cells * 2, 256); // Each cell can have two styles
m_cells.allocate(
num_cells * 2, 256); // Each cell can have two styles
m_ast.capacity(num_styles, 64);
m_asm.allocate((num_styles + 7) >> 3, 8);
m_asm.zero();
if(num_cells)
if (num_cells)
{
// Pre-add zero (for no-fill style, that is, -1).
// We need that to ensure that the "-1 style" would go first.
m_asm[0] |= 1;
m_asm[0] |= 1;
m_ast.add(0);
style = &m_styles[0];
style->start_cell = 0;
@@ -517,8 +549,8 @@ namespace agg
style->last_x = std::numeric_limits<int>::min();
m_sl_start = cells[0]->x;
m_sl_len = cells[num_cells-1]->x - m_sl_start + 1;
while(num_cells--)
m_sl_len = cells[num_cells - 1]->x - m_sl_start + 1;
while (num_cells--)
{
curr_cell = *cells++;
add_style(curr_cell->left);
@@ -528,7 +560,7 @@ namespace agg
// Convert the Y-histogram into the array of starting indexes
unsigned i;
unsigned start_cell = 0;
for(i = 0; i < m_ast.size(); i++)
for (i = 0; i < m_ast.size(); i++)
{
style_info& st = m_styles[m_ast[i]];
unsigned v = st.start_cell;
@@ -539,60 +571,67 @@ namespace agg
cells = m_outline.scanline_cells(m_scan_y);
num_cells = m_outline.scanline_num_cells(m_scan_y);
while(num_cells--)
while (num_cells--)
{
curr_cell = *cells++;
style_id = (curr_cell->left < 0) ? 0 :
curr_cell->left - m_min_style + 1;
style_id = (curr_cell->left < 0)
? 0
: curr_cell->left - m_min_style + 1;
style = &m_styles[style_id];
if(curr_cell->x == style->last_x)
if (curr_cell->x == style->last_x)
{
cell = &m_cells[style->start_cell + style->num_cells - 1];
cell->area += curr_cell->area;
cell =
&m_cells[style->start_cell + style->num_cells - 1];
cell->area += curr_cell->area;
cell->cover += curr_cell->cover;
}
else
{
cell = &m_cells[style->start_cell + style->num_cells];
cell->x = curr_cell->x;
cell->area = curr_cell->area;
cell->cover = curr_cell->cover;
cell->x = curr_cell->x;
cell->area = curr_cell->area;
cell->cover = curr_cell->cover;
style->last_x = curr_cell->x;
style->num_cells++;
}
style_id = (curr_cell->right < 0) ? 0 :
curr_cell->right - m_min_style + 1;
style_id = (curr_cell->right < 0)
? 0
: curr_cell->right - m_min_style + 1;
style = &m_styles[style_id];
if(curr_cell->x == style->last_x)
if (curr_cell->x == style->last_x)
{
cell = &m_cells[style->start_cell + style->num_cells - 1];
cell->area -= curr_cell->area;
cell =
&m_cells[style->start_cell + style->num_cells - 1];
cell->area -= curr_cell->area;
cell->cover -= curr_cell->cover;
}
else
{
cell = &m_cells[style->start_cell + style->num_cells];
cell->x = curr_cell->x;
cell->area = -curr_cell->area;
cell->cover = -curr_cell->cover;
style->last_x = curr_cell->x;
cell->x = curr_cell->x;
cell->area = -curr_cell->area;
cell->cover = -curr_cell->cover;
style->last_x = curr_cell->x;
style->num_cells++;
}
}
}
if(m_ast.size() > 1) break;
if (m_ast.size() > 1)
break;
++m_scan_y;
}
++m_scan_y;
if(m_layer_order != layer_unsorted)
if (m_layer_order != layer_unsorted)
{
range_adaptor<pod_vector<unsigned> > ra(m_ast, 1, m_ast.size() - 1);
if(m_layer_order == layer_direct) quick_sort(ra, unsigned_greater);
else quick_sort(ra, unsigned_less);
range_adaptor<pod_vector<unsigned>> ra(m_ast, 1, m_ast.size() - 1);
if (m_layer_order == layer_direct)
quick_sort(ra, unsigned_greater);
else
quick_sort(ra, unsigned_less);
}
return m_ast.size() - 1;
@@ -600,27 +639,27 @@ namespace agg
//------------------------------------------------------------------------
// Returns style ID depending of the existing style index
template<class Clip>
AGG_INLINE
unsigned rasterizer_compound_aa<Clip>::style(unsigned style_idx) const
template <class Clip>
AGG_INLINE unsigned rasterizer_compound_aa<Clip>::style(
unsigned style_idx) const
{
return m_ast[style_idx + 1] + m_min_style - 1;
}
//------------------------------------------------------------------------
template<class Clip>
//------------------------------------------------------------------------
template <class Clip>
AGG_INLINE bool rasterizer_compound_aa<Clip>::navigate_scanline(int y)
{
m_outline.sort_cells();
if(m_outline.total_cells() == 0)
if (m_outline.total_cells() == 0)
{
return false;
}
if(m_max_style < m_min_style)
if (m_max_style < m_min_style)
{
return false;
}
if(y < m_outline.min_y() || y > m_outline.max_y())
if (y < m_outline.min_y() || y > m_outline.max_y())
{
return false;
}
@@ -628,18 +667,18 @@ namespace agg
m_styles.allocate(m_max_style - m_min_style + 2, 128);
return true;
}
//------------------------------------------------------------------------
template<class Clip>
//------------------------------------------------------------------------
template <class Clip>
bool rasterizer_compound_aa<Clip>::hit_test(int tx, int ty)
{
if(!navigate_scanline(ty))
if (!navigate_scanline(ty))
{
return false;
}
unsigned num_styles = sweep_styles();
if(num_styles <= 0)
unsigned num_styles = sweep_styles();
if (num_styles <= 0)
{
return false;
}
@@ -649,9 +688,10 @@ namespace agg
return sl.hit();
}
//------------------------------------------------------------------------
template<class Clip>
cover_type* rasterizer_compound_aa<Clip>::allocate_cover_buffer(unsigned len)
//------------------------------------------------------------------------
template <class Clip>
cover_type* rasterizer_compound_aa<Clip>::allocate_cover_buffer(
unsigned len)
{
m_cover_buf.allocate(len, 256);
return &m_cover_buf[0];
@@ -659,7 +699,4 @@ namespace agg
}
#endif

View File

@@ -2,8 +2,8 @@
// 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.
// 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.
//
@@ -20,17 +20,21 @@
namespace agg
{
//======================================================rasterizer_outline
template<class Renderer> class rasterizer_outline
template <class Renderer>
class rasterizer_outline
{
public:
explicit rasterizer_outline(Renderer& ren) :
m_ren(&ren),
m_start_x(0),
m_start_y(0),
explicit rasterizer_outline(Renderer& ren):
m_ren(&ren),
m_start_x(0),
m_start_y(0),
m_vertices(0)
{}
void attach(Renderer& ren) { m_ren = &ren; }
{
}
void attach(Renderer& ren)
{
m_ren = &ren;
}
//--------------------------------------------------------------------
void move_to(int x, int y)
@@ -61,7 +65,7 @@ namespace agg
//--------------------------------------------------------------------
void close()
{
if(m_vertices > 2)
if (m_vertices > 2)
{
line_to(m_start_x, m_start_y);
}
@@ -71,15 +75,16 @@ namespace agg
//--------------------------------------------------------------------
void add_vertex(double x, double y, unsigned cmd)
{
if(is_move_to(cmd))
if (is_move_to(cmd))
{
move_to_d(x, y);
}
else
else
{
if(is_end_poly(cmd))
if (is_end_poly(cmd))
{
if(is_closed(cmd)) close();
if (is_closed(cmd))
close();
}
else
{
@@ -88,60 +93,54 @@ namespace agg
}
}
//--------------------------------------------------------------------
template<class VertexSource>
void add_path(VertexSource& vs, unsigned path_id=0)
template <class VertexSource>
void add_path(VertexSource& vs, unsigned path_id = 0)
{
double x;
double y;
unsigned cmd;
vs.rewind(path_id);
while(!is_stop(cmd = vs.vertex(&x, &y)))
while (!is_stop(cmd = vs.vertex(&x, &y)))
{
add_vertex(x, y, cmd);
}
}
//--------------------------------------------------------------------
template<class VertexSource, class ColorStorage, class PathId>
void render_all_paths(VertexSource& vs,
const ColorStorage& colors,
const PathId& path_id,
unsigned num_paths)
template <class VertexSource, class ColorStorage, class PathId>
void render_all_paths(VertexSource& vs,
const ColorStorage& colors,
const PathId& path_id,
unsigned num_paths)
{
for(unsigned i = 0; i < num_paths; i++)
for (unsigned i = 0; i < num_paths; i++)
{
m_ren->line_color(colors[i]);
add_path(vs, path_id[i]);
}
}
//--------------------------------------------------------------------
template<class Ctrl> void render_ctrl(Ctrl& c)
template <class Ctrl>
void render_ctrl(Ctrl& c)
{
unsigned i;
for(i = 0; i < c.num_paths(); i++)
for (i = 0; i < c.num_paths(); i++)
{
m_ren->line_color(c.color(i));
add_path(c, i);
}
}
private:
Renderer* m_ren;
int m_start_x;
int m_start_y;
unsigned m_vertices;
int m_start_x;
int m_start_y;
unsigned m_vertices;
};
}
#endif

View File

@@ -2,8 +2,8 @@
// 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.
// 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.
//
@@ -24,13 +24,17 @@ namespace agg
{
//-------------------------------------------------------------------------
inline bool cmp_dist_start(int d) { return d > 0; }
inline bool cmp_dist_end(int d) { return d <= 0; }
inline bool cmp_dist_start(int d)
{
return d > 0;
}
inline bool cmp_dist_end(int d)
{
return d <= 0;
}
//-----------------------------------------------------------line_aa_vertex
// Vertex (x, y) with the distance to the next one. The last vertex has
// Vertex (x, y) with the distance to the next one. The last vertex has
// the distance between the last and the first points
struct line_aa_vertex
{
@@ -39,34 +43,29 @@ namespace agg
int len;
line_aa_vertex() {}
line_aa_vertex(int x_, int y_) :
x(x_),
y(y_),
len(0)
{
}
line_aa_vertex(int x_, int y_): x(x_), y(y_), len(0) {}
bool operator () (const line_aa_vertex& val)
bool operator()(const line_aa_vertex& val)
{
double dx = val.x - x;
double dy = val.y - y;
return (len = uround(std::sqrt(dx * dx + dy * dy))) >
return (len = uround(std::sqrt(dx * dx + dy * dy))) >
(line_subpixel_scale + line_subpixel_scale / 2);
}
};
//----------------------------------------------------------outline_aa_join_e
enum outline_aa_join_e
{
outline_no_join, //-----outline_no_join
outline_miter_join, //-----outline_miter_join
outline_round_join, //-----outline_round_join
outline_miter_accurate_join //-----outline_accurate_join
outline_no_join, //-----outline_no_join
outline_miter_join, //-----outline_miter_join
outline_round_join, //-----outline_round_join
outline_miter_accurate_join //-----outline_accurate_join
};
//=======================================================rasterizer_outline_aa
template<class Renderer, class Coord=line_coord> class rasterizer_outline_aa
template <class Renderer, class Coord = line_coord>
class rasterizer_outline_aa
{
private:
//------------------------------------------------------------------------
@@ -83,37 +82,50 @@ namespace agg
void draw(draw_vars& dv, unsigned start, unsigned end);
public:
typedef line_aa_vertex vertex_type;
typedef line_aa_vertex vertex_type;
typedef vertex_sequence<vertex_type, 6> vertex_storage_type;
explicit rasterizer_outline_aa(Renderer& ren) :
m_ren(&ren),
m_line_join(ren.accurate_join_only() ?
outline_miter_accurate_join :
outline_round_join),
explicit rasterizer_outline_aa(Renderer& ren):
m_ren(&ren),
m_line_join(ren.accurate_join_only() ? outline_miter_accurate_join
: outline_round_join),
m_round_cap(false),
m_start_x(0),
m_start_y(0)
{}
void attach(Renderer& ren) { m_ren = &ren; }
//------------------------------------------------------------------------
void line_join(outline_aa_join_e join)
{
m_line_join = m_ren->accurate_join_only() ?
outline_miter_accurate_join :
join;
{
}
void attach(Renderer& ren)
{
m_ren = &ren;
}
bool line_join() const { return m_line_join; }
//------------------------------------------------------------------------
void round_cap(bool v) { m_round_cap = v; }
bool round_cap() const { return m_round_cap; }
void line_join(outline_aa_join_e join)
{
m_line_join = m_ren->accurate_join_only()
? outline_miter_accurate_join
: join;
}
bool line_join() const
{
return m_line_join;
}
//------------------------------------------------------------------------
void round_cap(bool v)
{
m_round_cap = v;
}
bool round_cap() const
{
return m_round_cap;
}
//------------------------------------------------------------------------
void move_to(int x, int y)
{
m_src_vertices.modify_last(vertex_type(m_start_x = x, m_start_y = y));
m_src_vertices.modify_last(
vertex_type(m_start_x = x, m_start_y = y));
}
//------------------------------------------------------------------------
@@ -140,17 +152,17 @@ namespace agg
//------------------------------------------------------------------------
void add_vertex(double x, double y, unsigned cmd)
{
if(is_move_to(cmd))
if (is_move_to(cmd))
{
render(false);
move_to_d(x, y);
}
else
else
{
if(is_end_poly(cmd))
if (is_end_poly(cmd))
{
render(is_closed(cmd));
if(is_closed(cmd))
if (is_closed(cmd))
{
move_to(m_start_x, m_start_y);
}
@@ -163,42 +175,41 @@ namespace agg
}
//------------------------------------------------------------------------
template<class VertexSource>
void add_path(VertexSource& vs, unsigned path_id=0)
template <class VertexSource>
void add_path(VertexSource& vs, unsigned path_id = 0)
{
double x;
double y;
unsigned cmd;
vs.rewind(path_id);
while(!is_stop(cmd = vs.vertex(&x, &y)))
while (!is_stop(cmd = vs.vertex(&x, &y)))
{
add_vertex(x, y, cmd);
}
render(false);
}
//------------------------------------------------------------------------
template<class VertexSource, class ColorStorage, class PathId>
void render_all_paths(VertexSource& vs,
const ColorStorage& colors,
const PathId& path_id,
unsigned num_paths)
template <class VertexSource, class ColorStorage, class PathId>
void render_all_paths(VertexSource& vs,
const ColorStorage& colors,
const PathId& path_id,
unsigned num_paths)
{
for(unsigned i = 0; i < num_paths; i++)
for (unsigned i = 0; i < num_paths; i++)
{
m_ren->color(colors[i]);
add_path(vs, path_id[i]);
}
}
//------------------------------------------------------------------------
template<class Ctrl> void render_ctrl(Ctrl& c)
template <class Ctrl>
void render_ctrl(Ctrl& c)
{
unsigned i;
for(i = 0; i < c.num_paths(); i++)
for (i = 0; i < c.num_paths(); i++)
{
m_ren->color(c.color(i));
add_path(c, i);
@@ -207,58 +218,59 @@ namespace agg
private:
rasterizer_outline_aa(const rasterizer_outline_aa<Renderer, Coord>&);
const rasterizer_outline_aa<Renderer, Coord>& operator =
(const rasterizer_outline_aa<Renderer, Coord>&);
const rasterizer_outline_aa<Renderer, Coord>& operator=(
const rasterizer_outline_aa<Renderer, Coord>&);
Renderer* m_ren;
Renderer* m_ren;
vertex_storage_type m_src_vertices;
outline_aa_join_e m_line_join;
bool m_round_cap;
int m_start_x;
int m_start_y;
outline_aa_join_e m_line_join;
bool m_round_cap;
int m_start_x;
int m_start_y;
};
//----------------------------------------------------------------------------
template<class Renderer, class Coord>
void rasterizer_outline_aa<Renderer, Coord>::draw(draw_vars& dv,
unsigned start,
unsigned end)
template <class Renderer, class Coord>
void rasterizer_outline_aa<Renderer, Coord>::draw(
draw_vars& dv, unsigned start, unsigned end)
{
unsigned i;
const vertex_storage_type::value_type* v;
for(i = start; i < end; i++)
for (i = start; i < end; i++)
{
if(m_line_join == outline_round_join)
if (m_line_join == outline_round_join)
{
dv.xb1 = dv.curr.x1 + (dv.curr.y2 - dv.curr.y1);
dv.yb1 = dv.curr.y1 - (dv.curr.x2 - dv.curr.x1);
dv.xb2 = dv.curr.x2 + (dv.curr.y2 - dv.curr.y1);
dv.xb1 = dv.curr.x1 + (dv.curr.y2 - dv.curr.y1);
dv.yb1 = dv.curr.y1 - (dv.curr.x2 - dv.curr.x1);
dv.xb2 = dv.curr.x2 + (dv.curr.y2 - dv.curr.y1);
dv.yb2 = dv.curr.y2 - (dv.curr.x2 - dv.curr.x1);
}
switch(dv.flags)
switch (dv.flags)
{
case 0: m_ren->line3(dv.curr, dv.xb1, dv.yb1, dv.xb2, dv.yb2); break;
case 1: m_ren->line2(dv.curr, dv.xb2, dv.yb2); break;
case 2: m_ren->line1(dv.curr, dv.xb1, dv.yb1); break;
case 3: m_ren->line0(dv.curr); break;
case 0:
m_ren->line3(dv.curr, dv.xb1, dv.yb1, dv.xb2, dv.yb2);
break;
case 1:
m_ren->line2(dv.curr, dv.xb2, dv.yb2);
break;
case 2:
m_ren->line1(dv.curr, dv.xb1, dv.yb1);
break;
case 3:
m_ren->line0(dv.curr);
break;
}
if(m_line_join == outline_round_join && (dv.flags & 2) == 0)
if (m_line_join == outline_round_join && (dv.flags & 2) == 0)
{
m_ren->pie(dv.curr.x2, dv.curr.y2,
dv.curr.x2 + (dv.curr.y2 - dv.curr.y1),
dv.curr.y2 - (dv.curr.x2 - dv.curr.x1),
dv.curr.x2 + (dv.next.y2 - dv.next.y1),
dv.curr.y2 - (dv.next.x2 - dv.next.x1));
m_ren->pie(dv.curr.x2,
dv.curr.y2,
dv.curr.x2 + (dv.curr.y2 - dv.curr.y1),
dv.curr.y2 - (dv.curr.x2 - dv.curr.x1),
dv.curr.x2 + (dv.next.y2 - dv.next.y1),
dv.curr.y2 - (dv.next.x2 - dv.next.x1));
}
dv.x1 = dv.x2;
@@ -267,7 +279,8 @@ namespace agg
dv.lnext = m_src_vertices[dv.idx].len;
++dv.idx;
if(dv.idx >= m_src_vertices.size()) dv.idx = 0;
if (dv.idx >= m_src_vertices.size())
dv.idx = 0;
v = &m_src_vertices[dv.idx];
dv.x2 = v->x;
@@ -278,41 +291,40 @@ namespace agg
dv.xb1 = dv.xb2;
dv.yb1 = dv.yb2;
switch(m_line_join)
switch (m_line_join)
{
case outline_no_join:
dv.flags = 3;
break;
case outline_no_join:
dv.flags = 3;
break;
case outline_miter_join:
dv.flags >>= 1;
dv.flags |= ((dv.curr.diagonal_quadrant() ==
dv.next.diagonal_quadrant()) << 1);
if((dv.flags & 2) == 0)
{
case outline_miter_join:
dv.flags >>= 1;
dv.flags |= ((dv.curr.diagonal_quadrant() ==
dv.next.diagonal_quadrant())
<< 1);
if ((dv.flags & 2) == 0)
{
bisectrix(dv.curr, dv.next, &dv.xb2, &dv.yb2);
}
break;
case outline_round_join:
dv.flags >>= 1;
dv.flags |= ((dv.curr.diagonal_quadrant() ==
dv.next.diagonal_quadrant())
<< 1);
break;
case outline_miter_accurate_join:
dv.flags = 0;
bisectrix(dv.curr, dv.next, &dv.xb2, &dv.yb2);
}
break;
case outline_round_join:
dv.flags >>= 1;
dv.flags |= ((dv.curr.diagonal_quadrant() ==
dv.next.diagonal_quadrant()) << 1);
break;
case outline_miter_accurate_join:
dv.flags = 0;
bisectrix(dv.curr, dv.next, &dv.xb2, &dv.yb2);
break;
break;
}
}
}
//----------------------------------------------------------------------------
template<class Renderer, class Coord>
template <class Renderer, class Coord>
void rasterizer_outline_aa<Renderer, Coord>::render(bool close_polygon)
{
m_src_vertices.close(close_polygon);
@@ -324,26 +336,26 @@ namespace agg
int y2;
int lprev;
if(close_polygon)
if (close_polygon)
{
if(m_src_vertices.size() >= 3)
if (m_src_vertices.size() >= 3)
{
dv.idx = 2;
v = &m_src_vertices[m_src_vertices.size() - 1];
x1 = v->x;
y1 = v->y;
v = &m_src_vertices[m_src_vertices.size() - 1];
x1 = v->x;
y1 = v->y;
lprev = v->len;
v = &m_src_vertices[0];
v = &m_src_vertices[0];
x2 = v->x;
y2 = v->y;
dv.lcurr = v->len;
line_parameters prev(x1, y1, x2, y2, lprev);
v = &m_src_vertices[1];
dv.x1 = v->x;
dv.y1 = v->y;
dv.x1 = v->x;
dv.y1 = v->y;
dv.lnext = v->len;
dv.curr = line_parameters(x2, y2, dv.x1, dv.y1, dv.lcurr);
@@ -357,30 +369,32 @@ namespace agg
dv.xb2 = 0;
dv.yb2 = 0;
switch(m_line_join)
switch (m_line_join)
{
case outline_no_join:
dv.flags = 3;
break;
case outline_no_join:
dv.flags = 3;
break;
case outline_miter_join:
case outline_round_join:
dv.flags =
(prev.diagonal_quadrant() == dv.curr.diagonal_quadrant()) |
((dv.curr.diagonal_quadrant() == dv.next.diagonal_quadrant()) << 1);
break;
case outline_miter_join:
case outline_round_join:
dv.flags = (prev.diagonal_quadrant() ==
dv.curr.diagonal_quadrant()) |
((dv.curr.diagonal_quadrant() ==
dv.next.diagonal_quadrant())
<< 1);
break;
case outline_miter_accurate_join:
dv.flags = 0;
break;
case outline_miter_accurate_join:
dv.flags = 0;
break;
}
if((dv.flags & 1) == 0 && m_line_join != outline_round_join)
if ((dv.flags & 1) == 0 && m_line_join != outline_round_join)
{
bisectrix(prev, dv.curr, &dv.xb1, &dv.yb1);
}
if((dv.flags & 2) == 0 && m_line_join != outline_round_join)
if ((dv.flags & 2) == 0 && m_line_join != outline_round_join)
{
bisectrix(dv.curr, dv.next, &dv.xb2, &dv.yb2);
}
@@ -389,7 +403,7 @@ namespace agg
}
else
{
switch(m_src_vertices.size())
switch (m_src_vertices.size())
{
case 0:
case 1:
@@ -397,26 +411,34 @@ namespace agg
case 2:
{
v = &m_src_vertices[0];
x1 = v->x;
y1 = v->y;
v = &m_src_vertices[0];
x1 = v->x;
y1 = v->y;
lprev = v->len;
v = &m_src_vertices[1];
x2 = v->x;
y2 = v->y;
v = &m_src_vertices[1];
x2 = v->x;
y2 = v->y;
line_parameters lp(x1, y1, x2, y2, lprev);
if(m_round_cap)
if (m_round_cap)
{
m_ren->semidot(cmp_dist_start, x1, y1, x1 + (y2 - y1), y1 - (x2 - x1));
m_ren->semidot(cmp_dist_start,
x1,
y1,
x1 + (y2 - y1),
y1 - (x2 - x1));
}
m_ren->line3(lp,
x1 + (y2 - y1),
y1 - (x2 - x1),
x2 + (y2 - y1),
y2 - (x2 - x1));
if(m_round_cap)
m_ren->line3(lp,
x1 + (y2 - y1),
y1 - (x2 - x1),
x2 + (y2 - y1),
y2 - (x2 - x1));
if (m_round_cap)
{
m_ren->semidot(cmp_dist_end, x2, y2, x2 + (y2 - y1), y2 - (x2 - x1));
m_ren->semidot(cmp_dist_end,
x2,
y2,
x2 + (y2 - y1),
y2 - (x2 - x1));
}
}
break;
@@ -425,48 +447,72 @@ namespace agg
{
int x3, y3;
int lnext;
v = &m_src_vertices[0];
x1 = v->x;
y1 = v->y;
v = &m_src_vertices[0];
x1 = v->x;
y1 = v->y;
lprev = v->len;
v = &m_src_vertices[1];
x2 = v->x;
y2 = v->y;
v = &m_src_vertices[1];
x2 = v->x;
y2 = v->y;
lnext = v->len;
v = &m_src_vertices[2];
x3 = v->x;
y3 = v->y;
v = &m_src_vertices[2];
x3 = v->x;
y3 = v->y;
line_parameters lp1(x1, y1, x2, y2, lprev);
line_parameters lp2(x2, y2, x3, y3, lnext);
if(m_round_cap)
if (m_round_cap)
{
m_ren->semidot(cmp_dist_start, x1, y1, x1 + (y2 - y1), y1 - (x2 - x1));
m_ren->semidot(cmp_dist_start,
x1,
y1,
x1 + (y2 - y1),
y1 - (x2 - x1));
}
if(m_line_join == outline_round_join)
if (m_line_join == outline_round_join)
{
m_ren->line3(lp1, x1 + (y2 - y1), y1 - (x2 - x1),
x2 + (y2 - y1), y2 - (x2 - x1));
m_ren->line3(lp1,
x1 + (y2 - y1),
y1 - (x2 - x1),
x2 + (y2 - y1),
y2 - (x2 - x1));
m_ren->pie(x2, y2, x2 + (y2 - y1), y2 - (x2 - x1),
x2 + (y3 - y2), y2 - (x3 - x2));
m_ren->pie(x2,
y2,
x2 + (y2 - y1),
y2 - (x2 - x1),
x2 + (y3 - y2),
y2 - (x3 - x2));
m_ren->line3(lp2, x2 + (y3 - y2), y2 - (x3 - x2),
x3 + (y3 - y2), y3 - (x3 - x2));
m_ren->line3(lp2,
x2 + (y3 - y2),
y2 - (x3 - x2),
x3 + (y3 - y2),
y3 - (x3 - x2));
}
else
{
bisectrix(lp1, lp2, &dv.xb1, &dv.yb1);
m_ren->line3(lp1, x1 + (y2 - y1), y1 - (x2 - x1),
dv.xb1, dv.yb1);
m_ren->line3(lp1,
x1 + (y2 - y1),
y1 - (x2 - x1),
dv.xb1,
dv.yb1);
m_ren->line3(lp2, dv.xb1, dv.yb1,
x3 + (y3 - y2), y3 - (x3 - x2));
m_ren->line3(lp2,
dv.xb1,
dv.yb1,
x3 + (y3 - y2),
y3 - (x3 - x2));
}
if(m_round_cap)
if (m_round_cap)
{
m_ren->semidot(cmp_dist_end, x3, y3, x3 + (y3 - y2), y3 - (x3 - x2));
m_ren->semidot(cmp_dist_end,
x3,
y3,
x3 + (y3 - y2),
y3 - (x3 - x2));
}
}
break;
@@ -475,116 +521,133 @@ namespace agg
{
dv.idx = 3;
v = &m_src_vertices[0];
x1 = v->x;
y1 = v->y;
v = &m_src_vertices[0];
x1 = v->x;
y1 = v->y;
lprev = v->len;
v = &m_src_vertices[1];
v = &m_src_vertices[1];
x2 = v->x;
y2 = v->y;
dv.lcurr = v->len;
line_parameters prev(x1, y1, x2, y2, lprev);
v = &m_src_vertices[2];
dv.x1 = v->x;
dv.y1 = v->y;
dv.x1 = v->x;
dv.y1 = v->y;
dv.lnext = v->len;
dv.curr = line_parameters(x2, y2, dv.x1, dv.y1, dv.lcurr);
v = &m_src_vertices[dv.idx];
dv.x2 = v->x;
dv.y2 = v->y;
dv.next = line_parameters(dv.x1, dv.y1, dv.x2, dv.y2, dv.lnext);
dv.next =
line_parameters(dv.x1, dv.y1, dv.x2, dv.y2, dv.lnext);
dv.xb1 = 0;
dv.yb1 = 0;
dv.xb2 = 0;
dv.yb2 = 0;
switch(m_line_join)
switch (m_line_join)
{
case outline_no_join:
dv.flags = 3;
break;
case outline_no_join:
dv.flags = 3;
break;
case outline_miter_join:
case outline_round_join:
dv.flags =
(prev.diagonal_quadrant() == dv.curr.diagonal_quadrant()) |
((dv.curr.diagonal_quadrant() == dv.next.diagonal_quadrant()) << 1);
break;
case outline_miter_join:
case outline_round_join:
dv.flags = (prev.diagonal_quadrant() ==
dv.curr.diagonal_quadrant()) |
((dv.curr.diagonal_quadrant() ==
dv.next.diagonal_quadrant())
<< 1);
break;
case outline_miter_accurate_join:
dv.flags = 0;
break;
case outline_miter_accurate_join:
dv.flags = 0;
break;
}
if(m_round_cap)
if (m_round_cap)
{
m_ren->semidot(cmp_dist_start, x1, y1, x1 + (y2 - y1), y1 - (x2 - x1));
m_ren->semidot(cmp_dist_start,
x1,
y1,
x1 + (y2 - y1),
y1 - (x2 - x1));
}
if((dv.flags & 1) == 0)
if ((dv.flags & 1) == 0)
{
if(m_line_join == outline_round_join)
if (m_line_join == outline_round_join)
{
m_ren->line3(prev, x1 + (y2 - y1), y1 - (x2 - x1),
x2 + (y2 - y1), y2 - (x2 - x1));
m_ren->pie(prev.x2, prev.y2,
x2 + (y2 - y1), y2 - (x2 - x1),
dv.curr.x1 + (dv.curr.y2 - dv.curr.y1),
dv.curr.y1 - (dv.curr.x2 - dv.curr.x1));
m_ren->line3(prev,
x1 + (y2 - y1),
y1 - (x2 - x1),
x2 + (y2 - y1),
y2 - (x2 - x1));
m_ren->pie(prev.x2,
prev.y2,
x2 + (y2 - y1),
y2 - (x2 - x1),
dv.curr.x1 + (dv.curr.y2 - dv.curr.y1),
dv.curr.y1 - (dv.curr.x2 - dv.curr.x1));
}
else
{
bisectrix(prev, dv.curr, &dv.xb1, &dv.yb1);
m_ren->line3(prev, x1 + (y2 - y1), y1 - (x2 - x1),
dv.xb1, dv.yb1);
m_ren->line3(prev,
x1 + (y2 - y1),
y1 - (x2 - x1),
dv.xb1,
dv.yb1);
}
}
else
{
m_ren->line1(prev,
x1 + (y2 - y1),
y1 - (x2 - x1));
m_ren->line1(prev, x1 + (y2 - y1), y1 - (x2 - x1));
}
if((dv.flags & 2) == 0 && m_line_join != outline_round_join)
if ((dv.flags & 2) == 0 &&
m_line_join != outline_round_join)
{
bisectrix(dv.curr, dv.next, &dv.xb2, &dv.yb2);
}
draw(dv, 1, m_src_vertices.size() - 2);
if((dv.flags & 1) == 0)
if ((dv.flags & 1) == 0)
{
if(m_line_join == outline_round_join)
if (m_line_join == outline_round_join)
{
m_ren->line3(dv.curr,
dv.curr.x1 + (dv.curr.y2 - dv.curr.y1),
dv.curr.y1 - (dv.curr.x2 - dv.curr.x1),
dv.curr.x2 + (dv.curr.y2 - dv.curr.y1),
dv.curr.y2 - (dv.curr.x2 - dv.curr.x1));
m_ren->line3(dv.curr,
dv.curr.x1 + (dv.curr.y2 - dv.curr.y1),
dv.curr.y1 - (dv.curr.x2 - dv.curr.x1),
dv.curr.x2 + (dv.curr.y2 - dv.curr.y1),
dv.curr.y2 - (dv.curr.x2 - dv.curr.x1));
}
else
{
m_ren->line3(dv.curr, dv.xb1, dv.yb1,
dv.curr.x2 + (dv.curr.y2 - dv.curr.y1),
dv.curr.y2 - (dv.curr.x2 - dv.curr.x1));
m_ren->line3(dv.curr,
dv.xb1,
dv.yb1,
dv.curr.x2 + (dv.curr.y2 - dv.curr.y1),
dv.curr.y2 - (dv.curr.x2 - dv.curr.x1));
}
}
else
{
m_ren->line2(dv.curr,
dv.curr.x2 + (dv.curr.y2 - dv.curr.y1),
dv.curr.y2 - (dv.curr.x2 - dv.curr.x1));
m_ren->line2(dv.curr,
dv.curr.x2 + (dv.curr.y2 - dv.curr.y1),
dv.curr.y2 - (dv.curr.x2 - dv.curr.x1));
}
if(m_round_cap)
if (m_round_cap)
{
m_ren->semidot(cmp_dist_end, dv.curr.x2, dv.curr.y2,
dv.curr.x2 + (dv.curr.y2 - dv.curr.y1),
dv.curr.y2 - (dv.curr.x2 - dv.curr.x1));
m_ren->semidot(cmp_dist_end,
dv.curr.x2,
dv.curr.y2,
dv.curr.x2 + (dv.curr.y2 - dv.curr.y1),
dv.curr.y2 - (dv.curr.x2 - dv.curr.x1));
}
}
break;
}
@@ -592,9 +655,6 @@ namespace agg
m_src_vertices.remove_all();
}
}
#endif

View File

@@ -2,15 +2,15 @@
// 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.
// 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.
//
//----------------------------------------------------------------------------
//
// The author gratefully acknowleges the support of David Turner,
// Robert Wilhelm, and Werner Lemberg - the authors of the FreeType
// The author gratefully acknowleges the support of David Turner,
// Robert Wilhelm, and Werner Lemberg - the authors of the FreeType
// libray - in producing this work. See http://www.freetype.org for details.
//
//----------------------------------------------------------------------------
@@ -19,12 +19,12 @@
// http://www.antigrain.com
//----------------------------------------------------------------------------
//
// Adaptation for 32-bit screen coordinates has been sponsored by
// Adaptation for 32-bit screen coordinates 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.
//
//
//----------------------------------------------------------------------------
#ifndef AGG_RASTERIZER_SCANLINE_AA_INCLUDED
#define AGG_RASTERIZER_SCANLINE_AA_INCLUDED
@@ -34,14 +34,13 @@
#include "agg_rasterizer_scanline_aa_nogamma.h"
#include "agg_gamma_functions.h"
namespace agg
{
//==================================================rasterizer_scanline_aa
// Polygon rasterizer that is used to render filled polygons with
// high-quality Anti-Aliasing. Internally, by default, the class uses
// integer coordinates in format 24.8, i.e. 24 bits for integer part
// and 8 bits for fractional - see poly_subpixel_shift. This class can be
// Polygon rasterizer that is used to render filled polygons with
// high-quality Anti-Aliasing. Internally, by default, the class uses
// integer coordinates in format 24.8, i.e. 24 bits for integer part
// and 8 bits for fractional - see poly_subpixel_shift. This class can be
// used in the following way:
//
// 1. filling_rule(filling_rule_e ft) - optional.
@@ -50,25 +49,27 @@ namespace agg
//
// 3. reset()
//
// 4. move_to(x, y) / line_to(x, y) - make the polygon. One can create
// 4. move_to(x, y) / line_to(x, y) - make the polygon. One can create
// more than one contour, but each contour must consist of at least 3
// vertices, i.e. move_to(x1, y1); line_to(x2, y2); line_to(x3, y3);
// is the absolute minimum of vertices that define a triangle.
// The algorithm does not check either the number of vertices nor
// coincidence of their coordinates, but in the worst case it just
// coincidence of their coordinates, but in the worst case it just
// won't draw anything.
// The orger of the vertices (clockwise or counterclockwise)
// The orger of the vertices (clockwise or counterclockwise)
// is important when using the non-zero filling rule (fill_non_zero).
// In this case the vertex order of all the contours must be the same
// if you want your intersecting polygons to be without "holes".
// You actually can use different vertices order. If the contours do not
// intersect each other the order is not important anyway. If they do,
// contours with the same vertex order will be rendered without "holes"
// while the intersecting contours with different orders will have "holes".
// You actually can use different vertices order. If the contours do not
// intersect each other the order is not important anyway. If they do,
// contours with the same vertex order will be rendered without "holes"
// while the intersecting contours with different orders will have
// "holes".
//
// filling_rule() and gamma() can be called anytime before "sweeping".
//------------------------------------------------------------------------
template<class Clip=rasterizer_sl_clip_int> class rasterizer_scanline_aa
template <class Clip = rasterizer_sl_clip_int>
class rasterizer_scanline_aa
{
enum status
{
@@ -79,21 +80,21 @@ namespace agg
};
public:
typedef Clip clip_type;
typedef typename Clip::conv_type conv_type;
typedef Clip clip_type;
typedef typename Clip::conv_type conv_type;
typedef typename Clip::coord_type coord_type;
enum aa_scale_e
{
aa_shift = 8,
aa_scale = 1 << aa_shift,
aa_mask = aa_scale - 1,
aa_shift = 8,
aa_scale = 1 << aa_shift,
aa_mask = aa_scale - 1,
aa_scale2 = aa_scale * 2,
aa_mask2 = aa_scale2 - 1
aa_mask2 = aa_scale2 - 1
};
//--------------------------------------------------------------------
rasterizer_scanline_aa(unsigned cell_block_limit=1024) :
rasterizer_scanline_aa(unsigned cell_block_limit = 1024):
m_outline(cell_block_limit),
m_clipper(),
m_filling_rule(fill_non_zero),
@@ -103,12 +104,14 @@ namespace agg
m_status(status_initial)
{
int i;
for(i = 0; i < aa_scale; i++) m_gamma[i] = i;
for (i = 0; i < aa_scale; i++)
m_gamma[i] = i;
}
//--------------------------------------------------------------------
template<class GammaF>
rasterizer_scanline_aa(const GammaF& gamma_function, unsigned cell_block_limit) :
template <class GammaF>
rasterizer_scanline_aa(
const GammaF& gamma_function, unsigned cell_block_limit):
m_outline(cell_block_limit),
m_clipper(m_outline),
m_filling_rule(fill_non_zero),
@@ -121,26 +124,31 @@ namespace agg
}
//--------------------------------------------------------------------
void reset();
void reset();
void reset_clipping();
void clip_box(double x1, double y1, double x2, double y2);
void filling_rule(filling_rule_e filling_rule);
void auto_close(bool flag) { m_auto_close = flag; }
void auto_close(bool flag)
{
m_auto_close = flag;
}
//--------------------------------------------------------------------
template<class GammaF> void gamma(const GammaF& gamma_function)
{
template <class GammaF>
void gamma(const GammaF& gamma_function)
{
int i;
for(i = 0; i < aa_scale; i++)
for (i = 0; i < aa_scale; i++)
{
m_gamma[i] = uround(gamma_function(double(i) / aa_mask) * aa_mask);
m_gamma[i] =
uround(gamma_function(double(i) / aa_mask) * aa_mask);
}
}
//--------------------------------------------------------------------
unsigned apply_gamma(unsigned cover) const
{
return m_gamma[cover];
unsigned apply_gamma(unsigned cover) const
{
return m_gamma[cover];
}
//--------------------------------------------------------------------
@@ -155,26 +163,39 @@ namespace agg
void edge_d(double x1, double y1, double x2, double y2);
//-------------------------------------------------------------------
template<class VertexSource>
void add_path(VertexSource& vs, unsigned path_id=0)
template <class VertexSource>
void add_path(VertexSource& vs, unsigned path_id = 0)
{
double x;
double y;
unsigned cmd;
vs.rewind(path_id);
if(m_outline.sorted()) reset();
while(!is_stop(cmd = vs.vertex(&x, &y)))
if (m_outline.sorted())
reset();
while (!is_stop(cmd = vs.vertex(&x, &y)))
{
add_vertex(x, y, cmd);
}
}
//--------------------------------------------------------------------
int min_x() const { return m_outline.min_x(); }
int min_y() const { return m_outline.min_y(); }
int max_x() const { return m_outline.max_x(); }
int max_y() const { return m_outline.max_y(); }
int min_x() const
{
return m_outline.min_x();
}
int min_y() const
{
return m_outline.min_y();
}
int max_x() const
{
return m_outline.max_x();
}
int max_y() const
{
return m_outline.max_y();
}
//--------------------------------------------------------------------
void sort();
@@ -184,71 +205,80 @@ namespace agg
//--------------------------------------------------------------------
AGG_INLINE unsigned calculate_alpha(int area) const
{
int cover = area >> (poly_subpixel_shift*2 + 1 - aa_shift);
int cover = area >> (poly_subpixel_shift * 2 + 1 - aa_shift);
if(cover < 0) cover = -cover;
if(m_filling_rule == fill_even_odd)
if (cover < 0)
cover = -cover;
if (m_filling_rule == fill_even_odd)
{
cover &= aa_mask2;
if(cover > aa_scale)
if (cover > aa_scale)
{
cover = aa_scale2 - cover;
}
}
if(cover > aa_mask) cover = aa_mask;
if (cover > aa_mask)
cover = aa_mask;
return m_gamma[cover];
}
//--------------------------------------------------------------------
template<class Scanline> bool sweep_scanline(Scanline& sl)
template <class Scanline>
bool sweep_scanline(Scanline& sl)
{
for(;;)
for (;;)
{
if(m_scan_y > m_outline.max_y()) return false;
if (m_scan_y > m_outline.max_y())
return false;
sl.reset_spans();
unsigned num_cells = m_outline.scanline_num_cells(m_scan_y);
const cell_aa* const* cells = m_outline.scanline_cells(m_scan_y);
const cell_aa* const* cells =
m_outline.scanline_cells(m_scan_y);
int cover = 0;
while(num_cells)
while (num_cells)
{
const cell_aa* cur_cell = *cells;
int x = cur_cell->x;
int x = cur_cell->x;
int area = cur_cell->area;
unsigned alpha;
cover += cur_cell->cover;
//accumulate all cells with the same X
while(--num_cells)
// accumulate all cells with the same X
while (--num_cells)
{
cur_cell = *++cells;
if(cur_cell->x != x) break;
area += cur_cell->area;
if (cur_cell->x != x)
break;
area += cur_cell->area;
cover += cur_cell->cover;
}
if(area)
if (area)
{
alpha = calculate_alpha((cover << (poly_subpixel_shift + 1)) - area);
if(alpha)
alpha = calculate_alpha(
(cover << (poly_subpixel_shift + 1)) - area);
if (alpha)
{
sl.add_cell(x, alpha);
}
x++;
}
if(num_cells && cur_cell->x > x)
if (num_cells && cur_cell->x > x)
{
alpha = calculate_alpha(cover << (poly_subpixel_shift + 1));
if(alpha)
alpha =
calculate_alpha(cover << (poly_subpixel_shift + 1));
if (alpha)
{
sl.add_span(x, cur_cell->x - x, alpha);
}
}
}
if(sl.num_spans()) break;
if (sl.num_spans())
break;
++m_scan_y;
}
@@ -260,64 +290,54 @@ namespace agg
//--------------------------------------------------------------------
bool hit_test(int tx, int ty);
private:
//--------------------------------------------------------------------
// Disable copying
rasterizer_scanline_aa(const rasterizer_scanline_aa<Clip>&);
const rasterizer_scanline_aa<Clip>&
operator = (const rasterizer_scanline_aa<Clip>&);
const rasterizer_scanline_aa<Clip>& operator=(
const rasterizer_scanline_aa<Clip>&);
private:
rasterizer_cells_aa<cell_aa> m_outline;
clip_type m_clipper;
int m_gamma[aa_scale];
clip_type m_clipper;
int m_gamma[aa_scale];
filling_rule_e m_filling_rule;
bool m_auto_close;
coord_type m_start_x;
coord_type m_start_y;
unsigned m_status;
int m_scan_y;
bool m_auto_close;
coord_type m_start_x;
coord_type m_start_y;
unsigned m_status;
int m_scan_y;
};
//------------------------------------------------------------------------
template<class Clip>
void rasterizer_scanline_aa<Clip>::reset()
{
m_outline.reset();
template <class Clip>
void rasterizer_scanline_aa<Clip>::reset()
{
m_outline.reset();
m_status = status_initial;
}
//------------------------------------------------------------------------
template<class Clip>
void rasterizer_scanline_aa<Clip>::filling_rule(filling_rule_e filling_rule)
{
m_filling_rule = filling_rule;
template <class Clip>
void rasterizer_scanline_aa<Clip>::filling_rule(filling_rule_e filling_rule)
{
m_filling_rule = filling_rule;
}
//------------------------------------------------------------------------
template<class Clip>
void rasterizer_scanline_aa<Clip>::clip_box(double x1, double y1,
double x2, double y2)
template <class Clip>
void rasterizer_scanline_aa<Clip>::clip_box(
double x1, double y1, double x2, double y2)
{
reset();
m_clipper.clip_box(conv_type::upscale(x1), conv_type::upscale(y1),
conv_type::upscale(x2), conv_type::upscale(y2));
m_clipper.clip_box(conv_type::upscale(x1),
conv_type::upscale(y1),
conv_type::upscale(x2),
conv_type::upscale(y2));
}
//------------------------------------------------------------------------
template<class Clip>
template <class Clip>
void rasterizer_scanline_aa<Clip>::reset_clipping()
{
reset();
@@ -325,10 +345,10 @@ namespace agg
}
//------------------------------------------------------------------------
template<class Clip>
template <class Clip>
void rasterizer_scanline_aa<Clip>::close_polygon()
{
if(m_status == status_line_to)
if (m_status == status_line_to)
{
m_clipper.line_to(m_outline, m_start_x, m_start_y);
m_status = status_closed;
@@ -336,107 +356,110 @@ namespace agg
}
//------------------------------------------------------------------------
template<class Clip>
template <class Clip>
void rasterizer_scanline_aa<Clip>::move_to(int x, int y)
{
if(m_outline.sorted()) reset();
if(m_auto_close) close_polygon();
m_clipper.move_to(m_start_x = conv_type::downscale(x),
m_start_y = conv_type::downscale(y));
if (m_outline.sorted())
reset();
if (m_auto_close)
close_polygon();
m_clipper.move_to(m_start_x = conv_type::downscale(x),
m_start_y = conv_type::downscale(y));
m_status = status_move_to;
}
//------------------------------------------------------------------------
template<class Clip>
template <class Clip>
void rasterizer_scanline_aa<Clip>::line_to(int x, int y)
{
m_clipper.line_to(m_outline,
conv_type::downscale(x),
conv_type::downscale(y));
m_clipper.line_to(
m_outline, conv_type::downscale(x), conv_type::downscale(y));
m_status = status_line_to;
}
//------------------------------------------------------------------------
template<class Clip>
void rasterizer_scanline_aa<Clip>::move_to_d(double x, double y)
{
if(m_outline.sorted()) reset();
if(m_auto_close) close_polygon();
m_clipper.move_to(m_start_x = conv_type::upscale(x),
m_start_y = conv_type::upscale(y));
template <class Clip>
void rasterizer_scanline_aa<Clip>::move_to_d(double x, double y)
{
if (m_outline.sorted())
reset();
if (m_auto_close)
close_polygon();
m_clipper.move_to(m_start_x = conv_type::upscale(x),
m_start_y = conv_type::upscale(y));
m_status = status_move_to;
}
//------------------------------------------------------------------------
template<class Clip>
void rasterizer_scanline_aa<Clip>::line_to_d(double x, double y)
{
m_clipper.line_to(m_outline,
conv_type::upscale(x),
conv_type::upscale(y));
template <class Clip>
void rasterizer_scanline_aa<Clip>::line_to_d(double x, double y)
{
m_clipper.line_to(
m_outline, conv_type::upscale(x), conv_type::upscale(y));
m_status = status_line_to;
}
//------------------------------------------------------------------------
template<class Clip>
void rasterizer_scanline_aa<Clip>::add_vertex(double x, double y, unsigned cmd)
template <class Clip>
void rasterizer_scanline_aa<Clip>::add_vertex(
double x, double y, unsigned cmd)
{
if(is_move_to(cmd))
if (is_move_to(cmd))
{
move_to_d(x, y);
}
else
if(is_vertex(cmd))
else if (is_vertex(cmd))
{
line_to_d(x, y);
}
else
if(is_close(cmd))
else if (is_close(cmd))
{
close_polygon();
}
}
//------------------------------------------------------------------------
template<class Clip>
template <class Clip>
void rasterizer_scanline_aa<Clip>::edge(int x1, int y1, int x2, int y2)
{
if(m_outline.sorted()) reset();
if (m_outline.sorted())
reset();
m_clipper.move_to(conv_type::downscale(x1), conv_type::downscale(y1));
m_clipper.line_to(m_outline,
conv_type::downscale(x2),
conv_type::downscale(y2));
m_status = status_move_to;
}
//------------------------------------------------------------------------
template<class Clip>
void rasterizer_scanline_aa<Clip>::edge_d(double x1, double y1,
double x2, double y2)
{
if(m_outline.sorted()) reset();
m_clipper.move_to(conv_type::upscale(x1), conv_type::upscale(y1));
m_clipper.line_to(m_outline,
conv_type::upscale(x2),
conv_type::upscale(y2));
m_clipper.line_to(
m_outline, conv_type::downscale(x2), conv_type::downscale(y2));
m_status = status_move_to;
}
//------------------------------------------------------------------------
template<class Clip>
template <class Clip>
void rasterizer_scanline_aa<Clip>::edge_d(
double x1, double y1, double x2, double y2)
{
if (m_outline.sorted())
reset();
m_clipper.move_to(conv_type::upscale(x1), conv_type::upscale(y1));
m_clipper.line_to(
m_outline, conv_type::upscale(x2), conv_type::upscale(y2));
m_status = status_move_to;
}
//------------------------------------------------------------------------
template <class Clip>
void rasterizer_scanline_aa<Clip>::sort()
{
if(m_auto_close) close_polygon();
if (m_auto_close)
close_polygon();
m_outline.sort_cells();
}
//------------------------------------------------------------------------
template<class Clip>
template <class Clip>
AGG_INLINE bool rasterizer_scanline_aa<Clip>::rewind_scanlines()
{
if(m_auto_close) close_polygon();
if (m_auto_close)
close_polygon();
m_outline.sort_cells();
if(m_outline.total_cells() == 0)
if (m_outline.total_cells() == 0)
{
return false;
}
@@ -444,16 +467,15 @@ namespace agg
return true;
}
//------------------------------------------------------------------------
template<class Clip>
template <class Clip>
AGG_INLINE bool rasterizer_scanline_aa<Clip>::navigate_scanline(int y)
{
if(m_auto_close) close_polygon();
if (m_auto_close)
close_polygon();
m_outline.sort_cells();
if(m_outline.total_cells() == 0 ||
y < m_outline.min_y() ||
y > m_outline.max_y())
if (m_outline.total_cells() == 0 || y < m_outline.min_y() ||
y > m_outline.max_y())
{
return false;
}
@@ -462,20 +484,16 @@ namespace agg
}
//------------------------------------------------------------------------
template<class Clip>
template <class Clip>
bool rasterizer_scanline_aa<Clip>::hit_test(int tx, int ty)
{
if(!navigate_scanline(ty)) return false;
if (!navigate_scanline(ty))
return false;
scanline_hit_test sl(tx);
sweep_scanline(sl);
return sl.hit();
}
}
#endif

View File

@@ -2,15 +2,15 @@
// 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.
// 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.
//
//----------------------------------------------------------------------------
//
// The author gratefully acknowleges the support of David Turner,
// Robert Wilhelm, and Werner Lemberg - the authors of the FreeType
// The author gratefully acknowleges the support of David Turner,
// Robert Wilhelm, and Werner Lemberg - the authors of the FreeType
// libray - in producing this work. See http://www.freetype.org for details.
//
//----------------------------------------------------------------------------
@@ -19,12 +19,12 @@
// http://www.antigrain.com
//----------------------------------------------------------------------------
//
// Adaptation for 32-bit screen coordinates has been sponsored by
// Adaptation for 32-bit screen coordinates 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.
//
//
//----------------------------------------------------------------------------
#ifndef AGG_RASTERIZER_SCANLINE_AA_NOGAMMA_INCLUDED
#define AGG_RASTERIZER_SCANLINE_AA_NOGAMMA_INCLUDED
@@ -33,14 +33,12 @@
#include "agg_rasterizer_cells_aa.h"
#include "agg_rasterizer_sl_clip.h"
namespace agg
{
//-----------------------------------------------------------------cell_aa
// A pixel cell. There're no constructors defined and it was done
// intentionally in order to avoid extra overhead when allocating an
// A pixel cell. There're no constructors defined and it was done
// intentionally in order to avoid extra overhead when allocating an
// array of cells.
struct cell_aa
{
@@ -54,7 +52,7 @@ namespace agg
x = std::numeric_limits<int>::max();
y = std::numeric_limits<int>::max();
cover = 0;
area = 0;
area = 0;
}
void style(const cell_aa&) {}
@@ -65,12 +63,11 @@ namespace agg
}
};
//==================================================rasterizer_scanline_aa_nogamma
// Polygon rasterizer that is used to render filled polygons with
// high-quality Anti-Aliasing. Internally, by default, the class uses
// integer coordinates in format 24.8, i.e. 24 bits for integer part
// and 8 bits for fractional - see poly_subpixel_shift. This class can be
// Polygon rasterizer that is used to render filled polygons with
// high-quality Anti-Aliasing. Internally, by default, the class uses
// integer coordinates in format 24.8, i.e. 24 bits for integer part
// and 8 bits for fractional - see poly_subpixel_shift. This class can be
// used in the following way:
//
// 1. filling_rule(filling_rule_e ft) - optional.
@@ -79,25 +76,27 @@ namespace agg
//
// 3. reset()
//
// 4. move_to(x, y) / line_to(x, y) - make the polygon. One can create
// 4. move_to(x, y) / line_to(x, y) - make the polygon. One can create
// more than one contour, but each contour must consist of at least 3
// vertices, i.e. move_to(x1, y1); line_to(x2, y2); line_to(x3, y3);
// is the absolute minimum of vertices that define a triangle.
// The algorithm does not check either the number of vertices nor
// coincidence of their coordinates, but in the worst case it just
// coincidence of their coordinates, but in the worst case it just
// won't draw anything.
// The orger of the vertices (clockwise or counterclockwise)
// The orger of the vertices (clockwise or counterclockwise)
// is important when using the non-zero filling rule (fill_non_zero).
// In this case the vertex order of all the contours must be the same
// if you want your intersecting polygons to be without "holes".
// You actually can use different vertices order. If the contours do not
// intersect each other the order is not important anyway. If they do,
// contours with the same vertex order will be rendered without "holes"
// while the intersecting contours with different orders will have "holes".
// You actually can use different vertices order. If the contours do not
// intersect each other the order is not important anyway. If they do,
// contours with the same vertex order will be rendered without "holes"
// while the intersecting contours with different orders will have
// "holes".
//
// filling_rule() and gamma() can be called anytime before "sweeping".
//------------------------------------------------------------------------
template<class Clip=rasterizer_sl_clip_int> class rasterizer_scanline_aa_nogamma
template <class Clip = rasterizer_sl_clip_int>
class rasterizer_scanline_aa_nogamma
{
enum status
{
@@ -108,21 +107,21 @@ namespace agg
};
public:
typedef Clip clip_type;
typedef typename Clip::conv_type conv_type;
typedef Clip clip_type;
typedef typename Clip::conv_type conv_type;
typedef typename Clip::coord_type coord_type;
enum aa_scale_e
{
aa_shift = 8,
aa_scale = 1 << aa_shift,
aa_mask = aa_scale - 1,
aa_shift = 8,
aa_scale = 1 << aa_shift,
aa_mask = aa_scale - 1,
aa_scale2 = aa_scale * 2,
aa_mask2 = aa_scale2 - 1
aa_mask2 = aa_scale2 - 1
};
//--------------------------------------------------------------------
rasterizer_scanline_aa_nogamma(unsigned cell_block_limit=1024) :
rasterizer_scanline_aa_nogamma(unsigned cell_block_limit = 1024):
m_outline(cell_block_limit),
m_clipper(),
m_filling_rule(fill_non_zero),
@@ -134,15 +133,18 @@ namespace agg
}
//--------------------------------------------------------------------
void reset();
void reset();
void reset_clipping();
void clip_box(double x1, double y1, double x2, double y2);
void filling_rule(filling_rule_e filling_rule);
void auto_close(bool flag) { m_auto_close = flag; }
void auto_close(bool flag)
{
m_auto_close = flag;
}
//--------------------------------------------------------------------
unsigned apply_gamma(unsigned cover) const
{
unsigned apply_gamma(unsigned cover) const
{
return cover;
}
@@ -158,26 +160,39 @@ namespace agg
void edge_d(double x1, double y1, double x2, double y2);
//-------------------------------------------------------------------
template<class VertexSource>
void add_path(VertexSource& vs, unsigned path_id=0)
template <class VertexSource>
void add_path(VertexSource& vs, unsigned path_id = 0)
{
double x;
double y;
unsigned cmd;
vs.rewind(path_id);
if(m_outline.sorted()) reset();
while(!is_stop(cmd = vs.vertex(&x, &y)))
if (m_outline.sorted())
reset();
while (!is_stop(cmd = vs.vertex(&x, &y)))
{
add_vertex(x, y, cmd);
}
}
//--------------------------------------------------------------------
int min_x() const { return m_outline.min_x(); }
int min_y() const { return m_outline.min_y(); }
int max_x() const { return m_outline.max_x(); }
int max_y() const { return m_outline.max_y(); }
int min_x() const
{
return m_outline.min_x();
}
int min_y() const
{
return m_outline.min_y();
}
int max_x() const
{
return m_outline.max_x();
}
int max_y() const
{
return m_outline.max_y();
}
//--------------------------------------------------------------------
void sort();
@@ -187,71 +202,80 @@ namespace agg
//--------------------------------------------------------------------
AGG_INLINE unsigned calculate_alpha(int area) const
{
int cover = area >> (poly_subpixel_shift*2 + 1 - aa_shift);
int cover = area >> (poly_subpixel_shift * 2 + 1 - aa_shift);
if(cover < 0) cover = -cover;
if(m_filling_rule == fill_even_odd)
if (cover < 0)
cover = -cover;
if (m_filling_rule == fill_even_odd)
{
cover &= aa_mask2;
if(cover > aa_scale)
if (cover > aa_scale)
{
cover = aa_scale2 - cover;
}
}
if(cover > aa_mask) cover = aa_mask;
if (cover > aa_mask)
cover = aa_mask;
return cover;
}
//--------------------------------------------------------------------
template<class Scanline> bool sweep_scanline(Scanline& sl)
template <class Scanline>
bool sweep_scanline(Scanline& sl)
{
for(;;)
for (;;)
{
if(m_scan_y > m_outline.max_y()) return false;
if (m_scan_y > m_outline.max_y())
return false;
sl.reset_spans();
unsigned num_cells = m_outline.scanline_num_cells(m_scan_y);
const cell_aa* const* cells = m_outline.scanline_cells(m_scan_y);
const cell_aa* const* cells =
m_outline.scanline_cells(m_scan_y);
int cover = 0;
while(num_cells)
while (num_cells)
{
const cell_aa* cur_cell = *cells;
int x = cur_cell->x;
int x = cur_cell->x;
int area = cur_cell->area;
unsigned alpha;
cover += cur_cell->cover;
//accumulate all cells with the same X
while(--num_cells)
// accumulate all cells with the same X
while (--num_cells)
{
cur_cell = *++cells;
if(cur_cell->x != x) break;
area += cur_cell->area;
if (cur_cell->x != x)
break;
area += cur_cell->area;
cover += cur_cell->cover;
}
if(area)
if (area)
{
alpha = calculate_alpha((cover << (poly_subpixel_shift + 1)) - area);
if(alpha)
alpha = calculate_alpha(
(cover << (poly_subpixel_shift + 1)) - area);
if (alpha)
{
sl.add_cell(x, alpha);
}
x++;
}
if(num_cells && cur_cell->x > x)
if (num_cells && cur_cell->x > x)
{
alpha = calculate_alpha(cover << (poly_subpixel_shift + 1));
if(alpha)
alpha =
calculate_alpha(cover << (poly_subpixel_shift + 1));
if (alpha)
{
sl.add_span(x, cur_cell->x - x, alpha);
}
}
}
if(sl.num_spans()) break;
if (sl.num_spans())
break;
++m_scan_y;
}
@@ -263,63 +287,55 @@ namespace agg
//--------------------------------------------------------------------
bool hit_test(int tx, int ty);
private:
//--------------------------------------------------------------------
// Disable copying
rasterizer_scanline_aa_nogamma(const rasterizer_scanline_aa_nogamma<Clip>&);
const rasterizer_scanline_aa_nogamma<Clip>&
operator = (const rasterizer_scanline_aa_nogamma<Clip>&);
rasterizer_scanline_aa_nogamma(
const rasterizer_scanline_aa_nogamma<Clip>&);
const rasterizer_scanline_aa_nogamma<Clip>& operator=(
const rasterizer_scanline_aa_nogamma<Clip>&);
private:
rasterizer_cells_aa<cell_aa> m_outline;
clip_type m_clipper;
clip_type m_clipper;
filling_rule_e m_filling_rule;
bool m_auto_close;
coord_type m_start_x;
coord_type m_start_y;
unsigned m_status;
int m_scan_y;
bool m_auto_close;
coord_type m_start_x;
coord_type m_start_y;
unsigned m_status;
int m_scan_y;
};
//------------------------------------------------------------------------
template<class Clip>
void rasterizer_scanline_aa_nogamma<Clip>::reset()
{
m_outline.reset();
template <class Clip>
void rasterizer_scanline_aa_nogamma<Clip>::reset()
{
m_outline.reset();
m_status = status_initial;
}
//------------------------------------------------------------------------
template<class Clip>
void rasterizer_scanline_aa_nogamma<Clip>::filling_rule(filling_rule_e filling_rule)
{
m_filling_rule = filling_rule;
template <class Clip>
void rasterizer_scanline_aa_nogamma<Clip>::filling_rule(
filling_rule_e filling_rule)
{
m_filling_rule = filling_rule;
}
//------------------------------------------------------------------------
template<class Clip>
void rasterizer_scanline_aa_nogamma<Clip>::clip_box(double x1, double y1,
double x2, double y2)
template <class Clip>
void rasterizer_scanline_aa_nogamma<Clip>::clip_box(
double x1, double y1, double x2, double y2)
{
reset();
m_clipper.clip_box(conv_type::upscale(x1), conv_type::upscale(y1),
conv_type::upscale(x2), conv_type::upscale(y2));
m_clipper.clip_box(conv_type::upscale(x1),
conv_type::upscale(y1),
conv_type::upscale(x2),
conv_type::upscale(y2));
}
//------------------------------------------------------------------------
template<class Clip>
template <class Clip>
void rasterizer_scanline_aa_nogamma<Clip>::reset_clipping()
{
reset();
@@ -327,10 +343,10 @@ namespace agg
}
//------------------------------------------------------------------------
template<class Clip>
template <class Clip>
void rasterizer_scanline_aa_nogamma<Clip>::close_polygon()
{
if(m_status == status_line_to)
if (m_status == status_line_to)
{
m_clipper.line_to(m_outline, m_start_x, m_start_y);
m_status = status_closed;
@@ -338,107 +354,111 @@ namespace agg
}
//------------------------------------------------------------------------
template<class Clip>
template <class Clip>
void rasterizer_scanline_aa_nogamma<Clip>::move_to(int x, int y)
{
if(m_outline.sorted()) reset();
if(m_auto_close) close_polygon();
m_clipper.move_to(m_start_x = conv_type::downscale(x),
m_start_y = conv_type::downscale(y));
if (m_outline.sorted())
reset();
if (m_auto_close)
close_polygon();
m_clipper.move_to(m_start_x = conv_type::downscale(x),
m_start_y = conv_type::downscale(y));
m_status = status_move_to;
}
//------------------------------------------------------------------------
template<class Clip>
template <class Clip>
void rasterizer_scanline_aa_nogamma<Clip>::line_to(int x, int y)
{
m_clipper.line_to(m_outline,
conv_type::downscale(x),
conv_type::downscale(y));
m_clipper.line_to(
m_outline, conv_type::downscale(x), conv_type::downscale(y));
m_status = status_line_to;
}
//------------------------------------------------------------------------
template<class Clip>
void rasterizer_scanline_aa_nogamma<Clip>::move_to_d(double x, double y)
{
if(m_outline.sorted()) reset();
if(m_auto_close) close_polygon();
m_clipper.move_to(m_start_x = conv_type::upscale(x),
m_start_y = conv_type::upscale(y));
template <class Clip>
void rasterizer_scanline_aa_nogamma<Clip>::move_to_d(double x, double y)
{
if (m_outline.sorted())
reset();
if (m_auto_close)
close_polygon();
m_clipper.move_to(m_start_x = conv_type::upscale(x),
m_start_y = conv_type::upscale(y));
m_status = status_move_to;
}
//------------------------------------------------------------------------
template<class Clip>
void rasterizer_scanline_aa_nogamma<Clip>::line_to_d(double x, double y)
{
m_clipper.line_to(m_outline,
conv_type::upscale(x),
conv_type::upscale(y));
template <class Clip>
void rasterizer_scanline_aa_nogamma<Clip>::line_to_d(double x, double y)
{
m_clipper.line_to(
m_outline, conv_type::upscale(x), conv_type::upscale(y));
m_status = status_line_to;
}
//------------------------------------------------------------------------
template<class Clip>
void rasterizer_scanline_aa_nogamma<Clip>::add_vertex(double x, double y, unsigned cmd)
template <class Clip>
void rasterizer_scanline_aa_nogamma<Clip>::add_vertex(
double x, double y, unsigned cmd)
{
if(is_move_to(cmd))
if (is_move_to(cmd))
{
move_to_d(x, y);
}
else
if(is_vertex(cmd))
else if (is_vertex(cmd))
{
line_to_d(x, y);
}
else
if(is_close(cmd))
else if (is_close(cmd))
{
close_polygon();
}
}
//------------------------------------------------------------------------
template<class Clip>
void rasterizer_scanline_aa_nogamma<Clip>::edge(int x1, int y1, int x2, int y2)
template <class Clip>
void rasterizer_scanline_aa_nogamma<Clip>::edge(
int x1, int y1, int x2, int y2)
{
if(m_outline.sorted()) reset();
if (m_outline.sorted())
reset();
m_clipper.move_to(conv_type::downscale(x1), conv_type::downscale(y1));
m_clipper.line_to(m_outline,
conv_type::downscale(x2),
conv_type::downscale(y2));
m_status = status_move_to;
}
//------------------------------------------------------------------------
template<class Clip>
void rasterizer_scanline_aa_nogamma<Clip>::edge_d(double x1, double y1,
double x2, double y2)
{
if(m_outline.sorted()) reset();
m_clipper.move_to(conv_type::upscale(x1), conv_type::upscale(y1));
m_clipper.line_to(m_outline,
conv_type::upscale(x2),
conv_type::upscale(y2));
m_clipper.line_to(
m_outline, conv_type::downscale(x2), conv_type::downscale(y2));
m_status = status_move_to;
}
//------------------------------------------------------------------------
template<class Clip>
template <class Clip>
void rasterizer_scanline_aa_nogamma<Clip>::edge_d(
double x1, double y1, double x2, double y2)
{
if (m_outline.sorted())
reset();
m_clipper.move_to(conv_type::upscale(x1), conv_type::upscale(y1));
m_clipper.line_to(
m_outline, conv_type::upscale(x2), conv_type::upscale(y2));
m_status = status_move_to;
}
//------------------------------------------------------------------------
template <class Clip>
void rasterizer_scanline_aa_nogamma<Clip>::sort()
{
if(m_auto_close) close_polygon();
if (m_auto_close)
close_polygon();
m_outline.sort_cells();
}
//------------------------------------------------------------------------
template<class Clip>
template <class Clip>
AGG_INLINE bool rasterizer_scanline_aa_nogamma<Clip>::rewind_scanlines()
{
if(m_auto_close) close_polygon();
if (m_auto_close)
close_polygon();
m_outline.sort_cells();
if(m_outline.total_cells() == 0)
if (m_outline.total_cells() == 0)
{
return false;
}
@@ -446,16 +466,16 @@ namespace agg
return true;
}
//------------------------------------------------------------------------
template<class Clip>
AGG_INLINE bool rasterizer_scanline_aa_nogamma<Clip>::navigate_scanline(int y)
template <class Clip>
AGG_INLINE bool rasterizer_scanline_aa_nogamma<Clip>::navigate_scanline(
int y)
{
if(m_auto_close) close_polygon();
if (m_auto_close)
close_polygon();
m_outline.sort_cells();
if(m_outline.total_cells() == 0 ||
y < m_outline.min_y() ||
y > m_outline.max_y())
if (m_outline.total_cells() == 0 || y < m_outline.min_y() ||
y > m_outline.max_y())
{
return false;
}
@@ -464,20 +484,16 @@ namespace agg
}
//------------------------------------------------------------------------
template<class Clip>
template <class Clip>
bool rasterizer_scanline_aa_nogamma<Clip>::hit_test(int tx, int ty)
{
if(!navigate_scanline(ty)) return false;
if (!navigate_scanline(ty))
return false;
scanline_hit_test sl(tx);
sweep_scanline(sl);
return sl.hit();
}
}
#endif

View File

@@ -2,8 +2,8 @@
// 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.
// 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.
//
@@ -24,7 +24,7 @@ namespace agg
{
poly_max_coord = (1 << 30) - 1 //----poly_max_coord
};
//------------------------------------------------------------ras_conv_int
struct ras_conv_int
{
@@ -33,10 +33,22 @@ namespace agg
{
return iround(a * b / c);
}
static int xi(int v) { return v; }
static int yi(int v) { return v; }
static int upscale(double v) { return iround(v * poly_subpixel_scale); }
static int downscale(int v) { return v; }
static int xi(int v)
{
return v;
}
static int yi(int v)
{
return v;
}
static int upscale(double v)
{
return iround(v * poly_subpixel_scale);
}
static int downscale(int v)
{
return v;
}
};
//--------------------------------------------------------ras_conv_int_sat
@@ -47,13 +59,22 @@ namespace agg
{
return saturation<poly_max_coord>::iround(a * b / c);
}
static int xi(int v) { return v; }
static int yi(int v) { return v; }
static int upscale(double v)
{
return saturation<poly_max_coord>::iround(v * poly_subpixel_scale);
static int xi(int v)
{
return v;
}
static int yi(int v)
{
return v;
}
static int upscale(double v)
{
return saturation<poly_max_coord>::iround(v * poly_subpixel_scale);
}
static int downscale(int v)
{
return v;
}
static int downscale(int v) { return v; }
};
//---------------------------------------------------------ras_conv_int_3x
@@ -64,10 +85,22 @@ namespace agg
{
return iround(a * b / c);
}
static int xi(int v) { return v * 3; }
static int yi(int v) { return v; }
static int upscale(double v) { return iround(v * poly_subpixel_scale); }
static int downscale(int v) { return v; }
static int xi(int v)
{
return v * 3;
}
static int yi(int v)
{
return v;
}
static int upscale(double v)
{
return iround(v * poly_subpixel_scale);
}
static int downscale(int v)
{
return v;
}
};
//-----------------------------------------------------------ras_conv_dbl
@@ -78,10 +111,22 @@ namespace agg
{
return a * b / c;
}
static int xi(double v) { return iround(v * poly_subpixel_scale); }
static int yi(double v) { return iround(v * poly_subpixel_scale); }
static double upscale(double v) { return v; }
static double downscale(int v) { return v / double(poly_subpixel_scale); }
static int xi(double v)
{
return iround(v * poly_subpixel_scale);
}
static int yi(double v)
{
return iround(v * poly_subpixel_scale);
}
static double upscale(double v)
{
return v;
}
static double downscale(int v)
{
return v / double(poly_subpixel_scale);
}
};
//--------------------------------------------------------ras_conv_dbl_3x
@@ -92,32 +137,42 @@ namespace agg
{
return a * b / c;
}
static int xi(double v) { return iround(v * poly_subpixel_scale * 3); }
static int yi(double v) { return iround(v * poly_subpixel_scale); }
static double upscale(double v) { return v; }
static double downscale(int v) { return v / double(poly_subpixel_scale); }
static int xi(double v)
{
return iround(v * poly_subpixel_scale * 3);
}
static int yi(double v)
{
return iround(v * poly_subpixel_scale);
}
static double upscale(double v)
{
return v;
}
static double downscale(int v)
{
return v / double(poly_subpixel_scale);
}
};
//------------------------------------------------------rasterizer_sl_clip
template<class Conv> class rasterizer_sl_clip
template <class Conv>
class rasterizer_sl_clip
{
public:
typedef Conv conv_type;
typedef Conv conv_type;
typedef typename Conv::coord_type coord_type;
typedef rect_base<coord_type> rect_type;
typedef rect_base<coord_type> rect_type;
//--------------------------------------------------------------------
rasterizer_sl_clip() :
m_clip_box(0,0,0,0),
rasterizer_sl_clip():
m_clip_box(0, 0, 0, 0),
m_x1(0),
m_y1(0),
m_f1(0),
m_clipping(false)
{}
m_clipping(false)
{
}
//--------------------------------------------------------------------
void reset_clipping()
@@ -126,7 +181,8 @@ namespace agg
}
//--------------------------------------------------------------------
void clip_box(coord_type x1, coord_type y1, coord_type x2, coord_type y2)
void clip_box(
coord_type x1, coord_type y1, coord_type x2, coord_type y2)
{
m_clip_box = rect_type(x1, y1, x2, y2);
m_clip_box.normalize();
@@ -138,27 +194,32 @@ namespace agg
{
m_x1 = x1;
m_y1 = y1;
if(m_clipping) m_f1 = clipping_flags(x1, y1, m_clip_box);
if (m_clipping)
m_f1 = clipping_flags(x1, y1, m_clip_box);
}
private:
//------------------------------------------------------------------------
template<class Rasterizer>
template <class Rasterizer>
AGG_INLINE void line_clip_y(Rasterizer& ras,
coord_type x1, coord_type y1,
coord_type x2, coord_type y2,
unsigned f1, unsigned f2) const
coord_type x1,
coord_type y1,
coord_type x2,
coord_type y2,
unsigned f1,
unsigned f2) const
{
f1 &= 10;
f2 &= 10;
if((f1 | f2) == 0)
if ((f1 | f2) == 0)
{
// Fully visible
ras.line(Conv::xi(x1), Conv::yi(y1), Conv::xi(x2), Conv::yi(y2));
ras.line(
Conv::xi(x1), Conv::yi(y1), Conv::xi(x2), Conv::yi(y2));
}
else
{
if(f1 == f2)
if (f1 == f2)
{
// Invisible by Y
return;
@@ -169,45 +230,48 @@ namespace agg
coord_type tx2 = x2;
coord_type ty2 = y2;
if(f1 & 8) // y1 < clip.y1
if (f1 & 8) // y1 < clip.y1
{
tx1 = x1 + Conv::mul_div(m_clip_box.y1-y1, x2-x1, y2-y1);
tx1 = x1 +
Conv::mul_div(m_clip_box.y1 - y1, x2 - x1, y2 - y1);
ty1 = m_clip_box.y1;
}
if(f1 & 2) // y1 > clip.y2
if (f1 & 2) // y1 > clip.y2
{
tx1 = x1 + Conv::mul_div(m_clip_box.y2-y1, x2-x1, y2-y1);
tx1 = x1 +
Conv::mul_div(m_clip_box.y2 - y1, x2 - x1, y2 - y1);
ty1 = m_clip_box.y2;
}
if(f2 & 8) // y2 < clip.y1
if (f2 & 8) // y2 < clip.y1
{
tx2 = x1 + Conv::mul_div(m_clip_box.y1-y1, x2-x1, y2-y1);
tx2 = x1 +
Conv::mul_div(m_clip_box.y1 - y1, x2 - x1, y2 - y1);
ty2 = m_clip_box.y1;
}
if(f2 & 2) // y2 > clip.y2
if (f2 & 2) // y2 > clip.y2
{
tx2 = x1 + Conv::mul_div(m_clip_box.y2-y1, x2-x1, y2-y1);
tx2 = x1 +
Conv::mul_div(m_clip_box.y2 - y1, x2 - x1, y2 - y1);
ty2 = m_clip_box.y2;
}
ras.line(Conv::xi(tx1), Conv::yi(ty1),
Conv::xi(tx2), Conv::yi(ty2));
ras.line(
Conv::xi(tx1), Conv::yi(ty1), Conv::xi(tx2), Conv::yi(ty2));
}
}
public:
//--------------------------------------------------------------------
template<class Rasterizer>
template <class Rasterizer>
void line_to(Rasterizer& ras, coord_type x2, coord_type y2)
{
if(m_clipping)
if (m_clipping)
{
unsigned f2 = clipping_flags(x2, y2, m_clip_box);
if((m_f1 & 10) == (f2 & 10) && (m_f1 & 10) != 0)
if ((m_f1 & 10) == (f2 & 10) && (m_f1 & 10) != 0)
{
// Invisible by Y
m_x1 = x2;
@@ -218,113 +282,133 @@ namespace agg
coord_type x1 = m_x1;
coord_type y1 = m_y1;
unsigned f1 = m_f1;
unsigned f1 = m_f1;
coord_type y3, y4;
unsigned f3, f4;
unsigned f3, f4;
switch(((f1 & 5) << 1) | (f2 & 5))
switch (((f1 & 5) << 1) | (f2 & 5))
{
case 0: // Visible by X
line_clip_y(ras, x1, y1, x2, y2, f1, f2);
break;
case 0: // Visible by X
line_clip_y(ras, x1, y1, x2, y2, f1, f2);
break;
case 1: // x2 > clip.x2
y3 = y1 + Conv::mul_div(m_clip_box.x2-x1, y2-y1, x2-x1);
f3 = clipping_flags_y(y3, m_clip_box);
line_clip_y(ras, x1, y1, m_clip_box.x2, y3, f1, f3);
line_clip_y(ras, m_clip_box.x2, y3, m_clip_box.x2, y2, f3, f2);
break;
case 1: // x2 > clip.x2
y3 = y1 + Conv::mul_div(
m_clip_box.x2 - x1, y2 - y1, x2 - x1);
f3 = clipping_flags_y(y3, m_clip_box);
line_clip_y(ras, x1, y1, m_clip_box.x2, y3, f1, f3);
line_clip_y(
ras, m_clip_box.x2, y3, m_clip_box.x2, y2, f3, f2);
break;
case 2: // x1 > clip.x2
y3 = y1 + Conv::mul_div(m_clip_box.x2-x1, y2-y1, x2-x1);
f3 = clipping_flags_y(y3, m_clip_box);
line_clip_y(ras, m_clip_box.x2, y1, m_clip_box.x2, y3, f1, f3);
line_clip_y(ras, m_clip_box.x2, y3, x2, y2, f3, f2);
break;
case 2: // x1 > clip.x2
y3 = y1 + Conv::mul_div(
m_clip_box.x2 - x1, y2 - y1, x2 - x1);
f3 = clipping_flags_y(y3, m_clip_box);
line_clip_y(
ras, m_clip_box.x2, y1, m_clip_box.x2, y3, f1, f3);
line_clip_y(ras, m_clip_box.x2, y3, x2, y2, f3, f2);
break;
case 3: // x1 > clip.x2 && x2 > clip.x2
line_clip_y(ras, m_clip_box.x2, y1, m_clip_box.x2, y2, f1, f2);
break;
case 3: // x1 > clip.x2 && x2 > clip.x2
line_clip_y(
ras, m_clip_box.x2, y1, m_clip_box.x2, y2, f1, f2);
break;
case 4: // x2 < clip.x1
y3 = y1 + Conv::mul_div(m_clip_box.x1-x1, y2-y1, x2-x1);
f3 = clipping_flags_y(y3, m_clip_box);
line_clip_y(ras, x1, y1, m_clip_box.x1, y3, f1, f3);
line_clip_y(ras, m_clip_box.x1, y3, m_clip_box.x1, y2, f3, f2);
break;
case 4: // x2 < clip.x1
y3 = y1 + Conv::mul_div(
m_clip_box.x1 - x1, y2 - y1, x2 - x1);
f3 = clipping_flags_y(y3, m_clip_box);
line_clip_y(ras, x1, y1, m_clip_box.x1, y3, f1, f3);
line_clip_y(
ras, m_clip_box.x1, y3, m_clip_box.x1, y2, f3, f2);
break;
case 6: // x1 > clip.x2 && x2 < clip.x1
y3 = y1 + Conv::mul_div(m_clip_box.x2-x1, y2-y1, x2-x1);
y4 = y1 + Conv::mul_div(m_clip_box.x1-x1, y2-y1, x2-x1);
f3 = clipping_flags_y(y3, m_clip_box);
f4 = clipping_flags_y(y4, m_clip_box);
line_clip_y(ras, m_clip_box.x2, y1, m_clip_box.x2, y3, f1, f3);
line_clip_y(ras, m_clip_box.x2, y3, m_clip_box.x1, y4, f3, f4);
line_clip_y(ras, m_clip_box.x1, y4, m_clip_box.x1, y2, f4, f2);
break;
case 6: // x1 > clip.x2 && x2 < clip.x1
y3 = y1 + Conv::mul_div(
m_clip_box.x2 - x1, y2 - y1, x2 - x1);
y4 = y1 + Conv::mul_div(
m_clip_box.x1 - x1, y2 - y1, x2 - x1);
f3 = clipping_flags_y(y3, m_clip_box);
f4 = clipping_flags_y(y4, m_clip_box);
line_clip_y(
ras, m_clip_box.x2, y1, m_clip_box.x2, y3, f1, f3);
line_clip_y(
ras, m_clip_box.x2, y3, m_clip_box.x1, y4, f3, f4);
line_clip_y(
ras, m_clip_box.x1, y4, m_clip_box.x1, y2, f4, f2);
break;
case 8: // x1 < clip.x1
y3 = y1 + Conv::mul_div(m_clip_box.x1-x1, y2-y1, x2-x1);
f3 = clipping_flags_y(y3, m_clip_box);
line_clip_y(ras, m_clip_box.x1, y1, m_clip_box.x1, y3, f1, f3);
line_clip_y(ras, m_clip_box.x1, y3, x2, y2, f3, f2);
break;
case 8: // x1 < clip.x1
y3 = y1 + Conv::mul_div(
m_clip_box.x1 - x1, y2 - y1, x2 - x1);
f3 = clipping_flags_y(y3, m_clip_box);
line_clip_y(
ras, m_clip_box.x1, y1, m_clip_box.x1, y3, f1, f3);
line_clip_y(ras, m_clip_box.x1, y3, x2, y2, f3, f2);
break;
case 9: // x1 < clip.x1 && x2 > clip.x2
y3 = y1 + Conv::mul_div(m_clip_box.x1-x1, y2-y1, x2-x1);
y4 = y1 + Conv::mul_div(m_clip_box.x2-x1, y2-y1, x2-x1);
f3 = clipping_flags_y(y3, m_clip_box);
f4 = clipping_flags_y(y4, m_clip_box);
line_clip_y(ras, m_clip_box.x1, y1, m_clip_box.x1, y3, f1, f3);
line_clip_y(ras, m_clip_box.x1, y3, m_clip_box.x2, y4, f3, f4);
line_clip_y(ras, m_clip_box.x2, y4, m_clip_box.x2, y2, f4, f2);
break;
case 9: // x1 < clip.x1 && x2 > clip.x2
y3 = y1 + Conv::mul_div(
m_clip_box.x1 - x1, y2 - y1, x2 - x1);
y4 = y1 + Conv::mul_div(
m_clip_box.x2 - x1, y2 - y1, x2 - x1);
f3 = clipping_flags_y(y3, m_clip_box);
f4 = clipping_flags_y(y4, m_clip_box);
line_clip_y(
ras, m_clip_box.x1, y1, m_clip_box.x1, y3, f1, f3);
line_clip_y(
ras, m_clip_box.x1, y3, m_clip_box.x2, y4, f3, f4);
line_clip_y(
ras, m_clip_box.x2, y4, m_clip_box.x2, y2, f4, f2);
break;
case 12: // x1 < clip.x1 && x2 < clip.x1
line_clip_y(ras, m_clip_box.x1, y1, m_clip_box.x1, y2, f1, f2);
break;
case 12: // x1 < clip.x1 && x2 < clip.x1
line_clip_y(
ras, m_clip_box.x1, y1, m_clip_box.x1, y2, f1, f2);
break;
}
m_f1 = f2;
}
else
{
ras.line(Conv::xi(m_x1), Conv::yi(m_y1),
Conv::xi(x2), Conv::yi(y2));
ras.line(
Conv::xi(m_x1), Conv::yi(m_y1), Conv::xi(x2), Conv::yi(y2));
}
m_x1 = x2;
m_y1 = y2;
}
private:
rect_type m_clip_box;
coord_type m_x1;
coord_type m_y1;
unsigned m_f1;
bool m_clipping;
rect_type m_clip_box;
coord_type m_x1;
coord_type m_y1;
unsigned m_f1;
bool m_clipping;
};
//---------------------------------------------------rasterizer_sl_no_clip
class rasterizer_sl_no_clip
{
public:
typedef ras_conv_int conv_type;
typedef int coord_type;
typedef int coord_type;
rasterizer_sl_no_clip() : m_x1(0), m_y1(0) {}
rasterizer_sl_no_clip(): m_x1(0), m_y1(0) {}
void reset_clipping() {}
void clip_box(coord_type, coord_type, coord_type, coord_type) {}
void move_to(coord_type x1, coord_type y1) { m_x1 = x1; m_y1 = y1; }
void move_to(coord_type x1, coord_type y1)
{
m_x1 = x1;
m_y1 = y1;
}
template<class Rasterizer>
void line_to(Rasterizer& ras, coord_type x2, coord_type y2)
{
ras.line(m_x1, m_y1, x2, y2);
m_x1 = x2;
template <class Rasterizer>
void line_to(Rasterizer& ras, coord_type x2, coord_type y2)
{
ras.line(m_x1, m_y1, x2, y2);
m_x1 = x2;
m_y1 = y2;
}
@@ -332,19 +416,17 @@ namespace agg
int m_x1, m_y1;
};
// -----rasterizer_sl_clip_int
// -----rasterizer_sl_clip_int_sat
// -----rasterizer_sl_clip_int_3x
// -----rasterizer_sl_clip_dbl
// -----rasterizer_sl_clip_dbl_3x
//------------------------------------------------------------------------
typedef rasterizer_sl_clip<ras_conv_int> rasterizer_sl_clip_int;
typedef rasterizer_sl_clip<ras_conv_int> rasterizer_sl_clip_int;
typedef rasterizer_sl_clip<ras_conv_int_sat> rasterizer_sl_clip_int_sat;
typedef rasterizer_sl_clip<ras_conv_int_3x> rasterizer_sl_clip_int_3x;
typedef rasterizer_sl_clip<ras_conv_dbl> rasterizer_sl_clip_dbl;
typedef rasterizer_sl_clip<ras_conv_dbl_3x> rasterizer_sl_clip_dbl_3x;
typedef rasterizer_sl_clip<ras_conv_int_3x> rasterizer_sl_clip_int_3x;
typedef rasterizer_sl_clip<ras_conv_dbl> rasterizer_sl_clip_dbl;
typedef rasterizer_sl_clip<ras_conv_dbl_3x> rasterizer_sl_clip_dbl_3x;
}

View File

File diff suppressed because it is too large Load Diff

View File

File diff suppressed because it is too large Load Diff

View File

@@ -2,8 +2,8 @@
// 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.
// 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.
//
@@ -28,7 +28,8 @@ namespace agg
{
//----------------------------------------------------------renderer_mclip
template<class PixelFormat> class renderer_mclip
template <class PixelFormat>
class renderer_mclip
{
public:
typedef PixelFormat pixfmt_type;
@@ -37,44 +38,87 @@ namespace agg
typedef renderer_base<pixfmt_type> base_ren_type;
//--------------------------------------------------------------------
explicit renderer_mclip(pixfmt_type& pixf) :
explicit renderer_mclip(pixfmt_type& pixf):
m_ren(pixf),
m_curr_cb(0),
m_bounds(m_ren.xmin(), m_ren.ymin(), m_ren.xmax(), m_ren.ymax())
{}
{
}
void attach(pixfmt_type& pixf)
{
m_ren.attach(pixf);
reset_clipping(true);
}
//--------------------------------------------------------------------
const pixfmt_type& ren() const { return m_ren.ren(); }
pixfmt_type& ren() { return m_ren.ren(); }
//--------------------------------------------------------------------
unsigned width() const { return m_ren.width(); }
unsigned height() const { return m_ren.height(); }
const pixfmt_type& ren() const
{
return m_ren.ren();
}
pixfmt_type& ren()
{
return m_ren.ren();
}
//--------------------------------------------------------------------
const rect_i& clip_box() const { return m_ren.clip_box(); }
int xmin() const { return m_ren.xmin(); }
int ymin() const { return m_ren.ymin(); }
int xmax() const { return m_ren.xmax(); }
int ymax() const { return m_ren.ymax(); }
unsigned width() const
{
return m_ren.width();
}
unsigned height() const
{
return m_ren.height();
}
//--------------------------------------------------------------------
const rect_i& bounding_clip_box() const { return m_bounds; }
int bounding_xmin() const { return m_bounds.x1; }
int bounding_ymin() const { return m_bounds.y1; }
int bounding_xmax() const { return m_bounds.x2; }
int bounding_ymax() const { return m_bounds.y2; }
const rect_i& clip_box() const
{
return m_ren.clip_box();
}
int xmin() const
{
return m_ren.xmin();
}
int ymin() const
{
return m_ren.ymin();
}
int xmax() const
{
return m_ren.xmax();
}
int ymax() const
{
return m_ren.ymax();
}
//--------------------------------------------------------------------
void first_clip_box()
const rect_i& bounding_clip_box() const
{
return m_bounds;
}
int bounding_xmin() const
{
return m_bounds.x1;
}
int bounding_ymin() const
{
return m_bounds.y1;
}
int bounding_xmax() const
{
return m_bounds.x2;
}
int bounding_ymax() const
{
return m_bounds.y2;
}
//--------------------------------------------------------------------
void first_clip_box()
{
m_curr_cb = 0;
if(m_clip.size())
if (m_clip.size())
{
const rect_i& cb = m_clip[0];
m_ren.clip_box_naked(cb.x1, cb.y1, cb.x2, cb.y2);
@@ -82,15 +126,15 @@ namespace agg
}
//--------------------------------------------------------------------
bool next_clip_box()
{
if(++m_curr_cb < m_clip.size())
bool next_clip_box()
{
if (++m_curr_cb < m_clip.size())
{
const rect_i& cb = m_clip[m_curr_cb];
m_ren.clip_box_naked(cb.x1, cb.y1, cb.x2, cb.y2);
return true;
}
return false;
return false;
}
//--------------------------------------------------------------------
@@ -101,19 +145,23 @@ namespace agg
m_curr_cb = 0;
m_bounds = m_ren.clip_box();
}
//--------------------------------------------------------------------
void add_clip_box(int x1, int y1, int x2, int y2)
{
rect_i cb(x1, y1, x2, y2);
rect_i cb(x1, y1, x2, y2);
cb.normalize();
if(cb.clip(rect_i(0, 0, width() - 1, height() - 1)))
if (cb.clip(rect_i(0, 0, width() - 1, height() - 1)))
{
m_clip.add(cb);
if(cb.x1 < m_bounds.x1) m_bounds.x1 = cb.x1;
if(cb.y1 < m_bounds.y1) m_bounds.y1 = cb.y1;
if(cb.x2 > m_bounds.x2) m_bounds.x2 = cb.x2;
if(cb.y2 > m_bounds.y2) m_bounds.y2 = cb.y2;
if (cb.x1 < m_bounds.x1)
m_bounds.x1 = cb.x1;
if (cb.y1 < m_bounds.y1)
m_bounds.y1 = cb.y1;
if (cb.x2 > m_bounds.x2)
m_bounds.x2 = cb.x2;
if (cb.y2 > m_bounds.y2)
m_bounds.y2 = cb.y2;
}
}
@@ -122,20 +170,19 @@ namespace agg
{
m_ren.clear(c);
}
//--------------------------------------------------------------------
void copy_pixel(int x, int y, const color_type& c)
{
first_clip_box();
do
{
if(m_ren.inbox(x, y))
if (m_ren.inbox(x, y))
{
m_ren.ren().copy_pixel(x, y, c);
break;
}
}
while(next_clip_box());
} while (next_clip_box());
}
//--------------------------------------------------------------------
@@ -144,13 +191,12 @@ namespace agg
first_clip_box();
do
{
if(m_ren.inbox(x, y))
if (m_ren.inbox(x, y))
{
m_ren.ren().blend_pixel(x, y, c, cover);
break;
}
}
while(next_clip_box());
} while (next_clip_box());
}
//--------------------------------------------------------------------
@@ -159,12 +205,11 @@ namespace agg
first_clip_box();
do
{
if(m_ren.inbox(x, y))
if (m_ren.inbox(x, y))
{
return m_ren.ren().pixel(x, y);
}
}
while(next_clip_box());
} while (next_clip_box());
return color_type::no_color();
}
@@ -175,8 +220,7 @@ namespace agg
do
{
m_ren.copy_hline(x1, y, x2, c);
}
while(next_clip_box());
} while (next_clip_box());
}
//--------------------------------------------------------------------
@@ -186,32 +230,29 @@ namespace agg
do
{
m_ren.copy_vline(x, y1, y2, c);
}
while(next_clip_box());
} while (next_clip_box());
}
//--------------------------------------------------------------------
void blend_hline(int x1, int y, int x2,
const color_type& c, cover_type cover)
void blend_hline(
int x1, int y, int x2, const color_type& c, cover_type cover)
{
first_clip_box();
do
{
m_ren.blend_hline(x1, y, x2, c, cover);
}
while(next_clip_box());
} while (next_clip_box());
}
//--------------------------------------------------------------------
void blend_vline(int x, int y1, int y2,
const color_type& c, cover_type cover)
void blend_vline(
int x, int y1, int y2, const color_type& c, cover_type cover)
{
first_clip_box();
do
{
m_ren.blend_vline(x, y1, y2, c, cover);
}
while(next_clip_box());
} while (next_clip_box());
}
//--------------------------------------------------------------------
@@ -221,47 +262,52 @@ namespace agg
do
{
m_ren.copy_bar(x1, y1, x2, y2, c);
}
while(next_clip_box());
} while (next_clip_box());
}
//--------------------------------------------------------------------
void blend_bar(int x1, int y1, int x2, int y2,
const color_type& c, cover_type cover)
void blend_bar(int x1,
int y1,
int x2,
int y2,
const color_type& c,
cover_type cover)
{
first_clip_box();
do
{
m_ren.blend_bar(x1, y1, x2, y2, c, cover);
}
while(next_clip_box());
} while (next_clip_box());
}
//--------------------------------------------------------------------
void blend_solid_hspan(int x, int y, int len,
const color_type& c, const cover_type* covers)
void blend_solid_hspan(int x,
int y,
int len,
const color_type& c,
const cover_type* covers)
{
first_clip_box();
do
{
m_ren.blend_solid_hspan(x, y, len, c, covers);
}
while(next_clip_box());
} while (next_clip_box());
}
//--------------------------------------------------------------------
void blend_solid_vspan(int x, int y, int len,
const color_type& c, const cover_type* covers)
void blend_solid_vspan(int x,
int y,
int len,
const color_type& c,
const cover_type* covers)
{
first_clip_box();
do
{
m_ren.blend_solid_vspan(x, y, len, c, covers);
}
while(next_clip_box());
} while (next_clip_box());
}
//--------------------------------------------------------------------
void copy_color_hspan(int x, int y, int len, const color_type* colors)
{
@@ -269,81 +315,78 @@ namespace agg
do
{
m_ren.copy_color_hspan(x, y, len, colors);
}
while(next_clip_box());
} while (next_clip_box());
}
//--------------------------------------------------------------------
void blend_color_hspan(int x, int y, int len,
const color_type* colors,
const cover_type* covers,
cover_type cover = cover_full)
void blend_color_hspan(int x,
int y,
int len,
const color_type* colors,
const cover_type* covers,
cover_type cover = cover_full)
{
first_clip_box();
do
{
m_ren.blend_color_hspan(x, y, len, colors, covers, cover);
}
while(next_clip_box());
} while (next_clip_box());
}
//--------------------------------------------------------------------
void blend_color_vspan(int x, int y, int len,
const color_type* colors,
const cover_type* covers,
cover_type cover = cover_full)
void blend_color_vspan(int x,
int y,
int len,
const color_type* colors,
const cover_type* covers,
cover_type cover = cover_full)
{
first_clip_box();
do
{
m_ren.blend_color_vspan(x, y, len, colors, covers, cover);
}
while(next_clip_box());
} while (next_clip_box());
}
//--------------------------------------------------------------------
void copy_from(const rendering_buffer& from,
const rect_i* rc=0,
int x_to=0,
int y_to=0)
void copy_from(const rendering_buffer& from,
const rect_i* rc = 0,
int x_to = 0,
int y_to = 0)
{
first_clip_box();
do
{
m_ren.copy_from(from, rc, x_to, y_to);
}
while(next_clip_box());
} while (next_clip_box());
}
//--------------------------------------------------------------------
template<class SrcPixelFormatRenderer>
void blend_from(const SrcPixelFormatRenderer& src,
const rect_i* rect_src_ptr = 0,
int dx = 0,
int dy = 0,
cover_type cover = cover_full)
template <class SrcPixelFormatRenderer>
void blend_from(const SrcPixelFormatRenderer& src,
const rect_i* rect_src_ptr = 0,
int dx = 0,
int dy = 0,
cover_type cover = cover_full)
{
first_clip_box();
do
{
m_ren.blend_from(src, rect_src_ptr, dx, dy, cover);
}
while(next_clip_box());
} while (next_clip_box());
}
private:
renderer_mclip(const renderer_mclip<PixelFormat>&);
const renderer_mclip<PixelFormat>&
operator = (const renderer_mclip<PixelFormat>&);
const renderer_mclip<PixelFormat>& operator=(
const renderer_mclip<PixelFormat>&);
base_ren_type m_ren;
base_ren_type m_ren;
pod_bvector<rect_i, 4> m_clip;
unsigned m_curr_cb;
rect_i m_bounds;
unsigned m_curr_cb;
rect_i m_bounds;
};
}
#endif

View File

File diff suppressed because it is too large Load Diff

View File

File diff suppressed because it is too large Load Diff

View File

@@ -2,8 +2,8 @@
// 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.
// 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.
//
@@ -28,41 +28,58 @@
namespace agg
{
//-----------------------------------------------------renderer_primitives
template<class BaseRenderer> class renderer_primitives
template <class BaseRenderer>
class renderer_primitives
{
public:
typedef BaseRenderer base_ren_type;
typedef typename base_ren_type::color_type color_type;
//--------------------------------------------------------------------
explicit renderer_primitives(base_ren_type& ren) :
explicit renderer_primitives(base_ren_type& ren):
m_ren(&ren),
m_fill_color(),
m_line_color(),
m_curr_x(0),
m_curr_y(0)
{}
void attach(base_ren_type& ren) { m_ren = &ren; }
//--------------------------------------------------------------------
static int coord(double c)
{
return iround(c * line_bresenham_interpolator::subpixel_scale);
{
}
void attach(base_ren_type& ren)
{
m_ren = &ren;
}
//--------------------------------------------------------------------
void fill_color(const color_type& c) { m_fill_color = c; }
void line_color(const color_type& c) { m_line_color = c; }
const color_type& fill_color() const { return m_fill_color; }
const color_type& line_color() const { return m_line_color; }
static int coord(double c)
{
return iround(c * line_bresenham_interpolator::subpixel_scale);
}
//--------------------------------------------------------------------
void fill_color(const color_type& c)
{
m_fill_color = c;
}
void line_color(const color_type& c)
{
m_line_color = c;
}
const color_type& fill_color() const
{
return m_fill_color;
}
const color_type& line_color() const
{
return m_line_color;
}
//--------------------------------------------------------------------
void rectangle(int x1, int y1, int x2, int y2)
{
m_ren->blend_hline(x1, y1, x2-1, m_line_color, cover_full);
m_ren->blend_vline(x2, y1, y2-1, m_line_color, cover_full);
m_ren->blend_hline(x1+1, y2, x2, m_line_color, cover_full);
m_ren->blend_vline(x1, y1+1, y2, m_line_color, cover_full);
m_ren->blend_hline(x1, y1, x2 - 1, m_line_color, cover_full);
m_ren->blend_vline(x2, y1, y2 - 1, m_line_color, cover_full);
m_ren->blend_hline(x1 + 1, y2, x2, m_line_color, cover_full);
m_ren->blend_vline(x1, y1 + 1, y2, m_line_color, cover_full);
}
//--------------------------------------------------------------------
@@ -72,10 +89,11 @@ namespace agg
}
//--------------------------------------------------------------------
void outlined_rectangle(int x1, int y1, int x2, int y2)
void outlined_rectangle(int x1, int y1, int x2, int y2)
{
rectangle(x1, y1, x2, y2);
m_ren->blend_bar(x1+1, y1+1, x2-1, y2-1, m_fill_color, cover_full);
m_ren->blend_bar(
x1 + 1, y1 + 1, x2 - 1, y2 - 1, m_fill_color, cover_full);
}
//--------------------------------------------------------------------
@@ -93,8 +111,7 @@ namespace agg
m_ren->blend_pixel(x - dx, y - dy, m_line_color, cover_full);
m_ren->blend_pixel(x - dx, y + dy, m_line_color, cover_full);
++ei;
}
while(dy < 0);
} while (dy < 0);
}
//--------------------------------------------------------------------
@@ -111,17 +128,19 @@ namespace agg
dx += ei.dx();
dy += ei.dy();
if(dy != dy0)
if (dy != dy0)
{
m_ren->blend_hline(x-dx0, y+dy0, x+dx0, m_fill_color, cover_full);
m_ren->blend_hline(x-dx0, y-dy0, x+dx0, m_fill_color, cover_full);
m_ren->blend_hline(
x - dx0, y + dy0, x + dx0, m_fill_color, cover_full);
m_ren->blend_hline(
x - dx0, y - dy0, x + dx0, m_fill_color, cover_full);
}
dx0 = dx;
dy0 = dy;
++ei;
}
while(dy < 0);
m_ren->blend_hline(x-dx0, y+dy0, x+dx0, m_fill_color, cover_full);
} while (dy < 0);
m_ren->blend_hline(
x - dx0, y + dy0, x + dx0, m_fill_color, cover_full);
}
//--------------------------------------------------------------------
@@ -141,50 +160,61 @@ namespace agg
m_ren->blend_pixel(x - dx, y - dy, m_line_color, cover_full);
m_ren->blend_pixel(x - dx, y + dy, m_line_color, cover_full);
if(ei.dy() && dx)
if (ei.dy() && dx)
{
m_ren->blend_hline(x-dx+1, y+dy, x+dx-1, m_fill_color, cover_full);
m_ren->blend_hline(x-dx+1, y-dy, x+dx-1, m_fill_color, cover_full);
m_ren->blend_hline(x - dx + 1,
y + dy,
x + dx - 1,
m_fill_color,
cover_full);
m_ren->blend_hline(x - dx + 1,
y - dy,
x + dx - 1,
m_fill_color,
cover_full);
}
++ei;
}
while(dy < 0);
} while (dy < 0);
}
//--------------------------------------------------------------------
void line(int x1, int y1, int x2, int y2, bool last=false)
void line(int x1, int y1, int x2, int y2, bool last = false)
{
line_bresenham_interpolator li(x1, y1, x2, y2);
unsigned len = li.len();
if(len == 0)
if (len == 0)
{
if(last)
if (last)
{
m_ren->blend_pixel(li.line_lr(x1), li.line_lr(y1), m_line_color, cover_full);
m_ren->blend_pixel(li.line_lr(x1),
li.line_lr(y1),
m_line_color,
cover_full);
}
return;
}
if(last) ++len;
if (last)
++len;
if(li.is_ver())
if (li.is_ver())
{
do
{
m_ren->blend_pixel(li.x2(), li.y1(), m_line_color, cover_full);
m_ren->blend_pixel(
li.x2(), li.y1(), m_line_color, cover_full);
li.vstep();
}
while(--len);
} while (--len);
}
else
{
do
{
m_ren->blend_pixel(li.x1(), li.y2(), m_line_color, cover_full);
m_ren->blend_pixel(
li.x1(), li.y2(), m_line_color, cover_full);
li.hstep();
}
while(--len);
} while (--len);
}
}
@@ -196,7 +226,7 @@ namespace agg
}
//--------------------------------------------------------------------
void line_to(int x, int y, bool last=false)
void line_to(int x, int y, bool last = false)
{
line(m_curr_x, m_curr_y, x, y, last);
m_curr_x = x;
@@ -204,12 +234,24 @@ namespace agg
}
//--------------------------------------------------------------------
const base_ren_type& ren() const { return *m_ren; }
base_ren_type& ren() { return *m_ren; }
const base_ren_type& ren() const
{
return *m_ren;
}
base_ren_type& ren()
{
return *m_ren;
}
//--------------------------------------------------------------------
const rendering_buffer& rbuf() const { return m_ren->rbuf(); }
rendering_buffer& rbuf() { return m_ren->rbuf(); }
const rendering_buffer& rbuf() const
{
return m_ren->rbuf();
}
rendering_buffer& rbuf()
{
return m_ren->rbuf();
}
private:
base_ren_type* m_ren;

View File

@@ -2,8 +2,8 @@
// 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.
// 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.
//
@@ -22,7 +22,7 @@ namespace agg
{
//==============================================renderer_raster_htext_solid
template<class BaseRenderer, class GlyphGenerator>
template <class BaseRenderer, class GlyphGenerator>
class renderer_raster_htext_solid
{
public:
@@ -31,43 +31,58 @@ namespace agg
typedef typename glyph_gen_type::glyph_rect glyph_rect;
typedef typename ren_type::color_type color_type;
renderer_raster_htext_solid(ren_type& ren, glyph_gen_type& glyph) :
renderer_raster_htext_solid(ren_type& ren, glyph_gen_type& glyph):
m_ren(&ren),
m_glyph(&glyph)
{}
void attach(ren_type& ren) { m_ren = &ren; }
{
}
void attach(ren_type& ren)
{
m_ren = &ren;
}
//--------------------------------------------------------------------
void color(const color_type& c) { m_color = c; }
const color_type& color() const { return m_color; }
void color(const color_type& c)
{
m_color = c;
}
const color_type& color() const
{
return m_color;
}
//--------------------------------------------------------------------
template<class CharT>
void render_text(double x, double y, const CharT* str, bool flip=false)
template <class CharT>
void render_text(
double x, double y, const CharT* str, bool flip = false)
{
glyph_rect r;
while(*str)
while (*str)
{
m_glyph->prepare(&r, x, y, *str, flip);
if(r.x2 >= r.x1)
if (r.x2 >= r.x1)
{
int i;
if(flip)
if (flip)
{
for(i = r.y1; i <= r.y2; i++)
for (i = r.y1; i <= r.y2; i++)
{
m_ren->blend_solid_hspan(r.x1, i, (r.x2 - r.x1 + 1),
m_color,
m_glyph->span(r.y2 - i));
m_ren->blend_solid_hspan(r.x1,
i,
(r.x2 - r.x1 + 1),
m_color,
m_glyph->span(r.y2 - i));
}
}
else
{
for(i = r.y1; i <= r.y2; i++)
for (i = r.y1; i <= r.y2; i++)
{
m_ren->blend_solid_hspan(r.x1, i, (r.x2 - r.x1 + 1),
m_color,
m_glyph->span(i - r.y1));
m_ren->blend_solid_hspan(r.x1,
i,
(r.x2 - r.x1 + 1),
m_color,
m_glyph->span(i - r.y1));
}
}
}
@@ -83,10 +98,8 @@ namespace agg
color_type m_color;
};
//=============================================renderer_raster_vtext_solid
template<class BaseRenderer, class GlyphGenerator>
template <class BaseRenderer, class GlyphGenerator>
class renderer_raster_vtext_solid
{
public:
@@ -95,43 +108,54 @@ namespace agg
typedef typename glyph_gen_type::glyph_rect glyph_rect;
typedef typename ren_type::color_type color_type;
renderer_raster_vtext_solid(ren_type& ren, glyph_gen_type& glyph) :
renderer_raster_vtext_solid(ren_type& ren, glyph_gen_type& glyph):
m_ren(&ren),
m_glyph(&glyph)
{
}
//--------------------------------------------------------------------
void color(const color_type& c) { m_color = c; }
const color_type& color() const { return m_color; }
void color(const color_type& c)
{
m_color = c;
}
const color_type& color() const
{
return m_color;
}
//--------------------------------------------------------------------
template<class CharT>
void render_text(double x, double y, const CharT* str, bool flip=false)
template <class CharT>
void render_text(
double x, double y, const CharT* str, bool flip = false)
{
glyph_rect r;
while(*str)
while (*str)
{
m_glyph->prepare(&r, x, y, *str, !flip);
if(r.x2 >= r.x1)
if (r.x2 >= r.x1)
{
int i;
if(flip)
if (flip)
{
for(i = r.y1; i <= r.y2; i++)
for (i = r.y1; i <= r.y2; i++)
{
m_ren->blend_solid_vspan(i, r.x1, (r.x2 - r.x1 + 1),
m_color,
m_glyph->span(i - r.y1));
m_ren->blend_solid_vspan(i,
r.x1,
(r.x2 - r.x1 + 1),
m_color,
m_glyph->span(i - r.y1));
}
}
else
{
for(i = r.y1; i <= r.y2; i++)
for (i = r.y1; i <= r.y2; i++)
{
m_ren->blend_solid_vspan(i, r.x1, (r.x2 - r.x1 + 1),
m_color,
m_glyph->span(r.y2 - i));
m_ren->blend_solid_vspan(i,
r.x1,
(r.x2 - r.x1 + 1),
m_color,
m_glyph->span(r.y2 - i));
}
}
}
@@ -147,13 +171,8 @@ namespace agg
color_type m_color;
};
//===================================================renderer_raster_htext
template<class ScanlineRenderer, class GlyphGenerator>
template <class ScanlineRenderer, class GlyphGenerator>
class renderer_raster_htext
{
public:
@@ -174,24 +193,37 @@ namespace agg
const cover_type* covers;
const_span() {}
const_span(int x_, unsigned len_, const cover_type* covers_) :
x(x_), len(len_), covers(covers_)
{}
const_span(int x_, unsigned len_, const cover_type* covers_):
x(x_),
len(len_),
covers(covers_)
{
}
};
typedef const const_span* const_iterator;
//----------------------------------------------------------------
scanline_single_span(int x, int y, unsigned len,
const cover_type* covers) :
scanline_single_span(
int x, int y, unsigned len, const cover_type* covers):
m_y(y),
m_span(x, len, covers)
{}
{
}
//----------------------------------------------------------------
int y() const { return m_y; }
unsigned num_spans() const { return 1; }
const_iterator begin() const { return &m_span; }
int y() const
{
return m_y;
}
unsigned num_spans() const
{
return 1;
}
const_iterator begin() const
{
return &m_span;
}
private:
//----------------------------------------------------------------
@@ -199,48 +231,44 @@ namespace agg
const_span m_span;
};
//--------------------------------------------------------------------
renderer_raster_htext(ren_type& ren, glyph_gen_type& glyph) :
renderer_raster_htext(ren_type& ren, glyph_gen_type& glyph):
m_ren(&ren),
m_glyph(&glyph)
{
}
//--------------------------------------------------------------------
template<class CharT>
void render_text(double x, double y, const CharT* str, bool flip=false)
template <class CharT>
void render_text(
double x, double y, const CharT* str, bool flip = false)
{
glyph_rect r;
while(*str)
while (*str)
{
m_glyph->prepare(&r, x, y, *str, flip);
if(r.x2 >= r.x1)
if (r.x2 >= r.x1)
{
m_ren->prepare();
int i;
if(flip)
if (flip)
{
for(i = r.y1; i <= r.y2; i++)
for (i = r.y1; i <= r.y2; i++)
{
m_ren->render(
scanline_single_span(r.x1,
i,
(r.x2 - r.x1 + 1),
m_glyph->span(r.y2 - i)));
m_ren->render(scanline_single_span(r.x1,
i,
(r.x2 - r.x1 + 1),
m_glyph->span(r.y2 - i)));
}
}
else
{
for(i = r.y1; i <= r.y2; i++)
for (i = r.y1; i <= r.y2; i++)
{
m_ren->render(
scanline_single_span(r.x1,
i,
(r.x2 - r.x1 + 1),
m_glyph->span(i - r.y1)));
m_ren->render(scanline_single_span(r.x1,
i,
(r.x2 - r.x1 + 1),
m_glyph->span(i - r.y1)));
}
}
}
@@ -255,10 +283,6 @@ namespace agg
glyph_gen_type* m_glyph;
};
}
#endif

View File

File diff suppressed because it is too large Load Diff

View File

@@ -2,8 +2,8 @@
// 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.
// 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.
//
@@ -27,13 +27,14 @@ namespace agg
{
//===========================================================row_accessor
template<class T> class row_accessor
template <class T>
class row_accessor
{
public:
typedef const_row_info<T> row_data;
//-------------------------------------------------------------------
row_accessor() :
row_accessor():
m_buf(0),
m_start(0),
m_width(0),
@@ -43,7 +44,7 @@ namespace agg
}
//--------------------------------------------------------------------
row_accessor(T* buf, unsigned width, unsigned height, int stride) :
row_accessor(T* buf, unsigned width, unsigned height, int stride):
m_buf(0),
m_start(0),
m_width(0),
@@ -53,7 +54,6 @@ namespace agg
attach(buf, width, height, stride);
}
//--------------------------------------------------------------------
void attach(T* buf, unsigned width, unsigned height, int stride)
{
@@ -61,45 +61,68 @@ namespace agg
m_width = width;
m_height = height;
m_stride = stride;
if(stride < 0)
{
if (stride < 0)
{
m_start = m_buf - (AGG_INT64)(height - 1) * stride;
}
}
//--------------------------------------------------------------------
AGG_INLINE T* buf() { return m_buf; }
AGG_INLINE const T* buf() const { return m_buf; }
AGG_INLINE unsigned width() const { return m_width; }
AGG_INLINE unsigned height() const { return m_height; }
AGG_INLINE int stride() const { return m_stride; }
AGG_INLINE unsigned stride_abs() const
AGG_INLINE T* buf()
{
return (m_stride < 0) ? unsigned(-m_stride) : unsigned(m_stride);
return m_buf;
}
AGG_INLINE const T* buf() const
{
return m_buf;
}
AGG_INLINE unsigned width() const
{
return m_width;
}
AGG_INLINE unsigned height() const
{
return m_height;
}
AGG_INLINE int stride() const
{
return m_stride;
}
AGG_INLINE unsigned stride_abs() const
{
return (m_stride < 0) ? unsigned(-m_stride) : unsigned(m_stride);
}
//--------------------------------------------------------------------
AGG_INLINE T* row_ptr(int, int y, unsigned)
{
return m_start + y * (AGG_INT64)m_stride;
AGG_INLINE T* row_ptr(int, int y, unsigned)
{
return m_start + y * (AGG_INT64)m_stride;
}
AGG_INLINE T* row_ptr(int y) { return m_start + y * (AGG_INT64)m_stride; }
AGG_INLINE const T* row_ptr(int y) const { return m_start + y * (AGG_INT64)m_stride; }
AGG_INLINE row_data row (int y) const
{
return row_data(0, m_width-1, row_ptr(y));
AGG_INLINE T* row_ptr(int y)
{
return m_start + y * (AGG_INT64)m_stride;
}
AGG_INLINE const T* row_ptr(int y) const
{
return m_start + y * (AGG_INT64)m_stride;
}
AGG_INLINE row_data row(int y) const
{
return row_data(0, m_width - 1, row_ptr(y));
}
//--------------------------------------------------------------------
template<class RenBuf>
template <class RenBuf>
void copy_from(const RenBuf& src)
{
unsigned h = height();
if(src.height() < h) h = src.height();
if (src.height() < h)
h = src.height();
unsigned l = stride_abs();
if(src.stride_abs() < l) l = src.stride_abs();
if (src.stride_abs() < l)
l = src.stride_abs();
l *= sizeof(T);
unsigned y;
@@ -116,11 +139,11 @@ namespace agg
unsigned y;
unsigned w = width();
unsigned stride = stride_abs();
for(y = 0; y < height(); y++)
for (y = 0; y < height(); y++)
{
T* p = row_ptr(0, y, w);
unsigned x;
for(x = 0; x < stride; x++)
for (x = 0; x < stride; x++)
{
*p++ = value;
}
@@ -129,24 +152,22 @@ namespace agg
private:
//--------------------------------------------------------------------
T* m_buf; // Pointer to renrdering buffer
T* m_start; // Pointer to first pixel depending on stride
unsigned m_width; // Width in pixels
unsigned m_height; // Height in pixels
int m_stride; // Number of bytes per row. Can be < 0
T* m_buf; // Pointer to renrdering buffer
T* m_start; // Pointer to first pixel depending on stride
unsigned m_width; // Width in pixels
unsigned m_height; // Height in pixels
int m_stride; // Number of bytes per row. Can be < 0
};
//==========================================================row_ptr_cache
template<class T> class row_ptr_cache
template <class T>
class row_ptr_cache
{
public:
typedef const_row_info<T> row_data;
//-------------------------------------------------------------------
row_ptr_cache() :
row_ptr_cache():
m_buf(0),
m_rows(),
m_width(0),
@@ -156,7 +177,7 @@ namespace agg
}
//--------------------------------------------------------------------
row_ptr_cache(T* buf, unsigned width, unsigned height, int stride) :
row_ptr_cache(T* buf, unsigned width, unsigned height, int stride):
m_buf(0),
m_rows(),
m_width(0),
@@ -173,21 +194,21 @@ namespace agg
m_width = width;
m_height = height;
m_stride = stride;
if(height > m_rows.size())
if (height > m_rows.size())
{
m_rows.resize(height);
}
T* row_ptr = m_buf;
if(stride < 0)
if (stride < 0)
{
row_ptr = m_buf - (AGG_INT64)(height - 1) * stride;
}
T** rows = &m_rows[0];
while(height--)
while (height--)
{
*rows++ = row_ptr;
row_ptr += stride;
@@ -195,41 +216,67 @@ namespace agg
}
//--------------------------------------------------------------------
AGG_INLINE T* buf() { return m_buf; }
AGG_INLINE const T* buf() const { return m_buf; }
AGG_INLINE unsigned width() const { return m_width; }
AGG_INLINE unsigned height() const { return m_height; }
AGG_INLINE int stride() const { return m_stride; }
AGG_INLINE unsigned stride_abs() const
AGG_INLINE T* buf()
{
return (m_stride < 0) ? unsigned(-m_stride) : unsigned(m_stride);
return m_buf;
}
AGG_INLINE const T* buf() const
{
return m_buf;
}
AGG_INLINE unsigned width() const
{
return m_width;
}
AGG_INLINE unsigned height() const
{
return m_height;
}
AGG_INLINE int stride() const
{
return m_stride;
}
AGG_INLINE unsigned stride_abs() const
{
return (m_stride < 0) ? unsigned(-m_stride) : unsigned(m_stride);
}
//--------------------------------------------------------------------
AGG_INLINE T* row_ptr(int, int y, unsigned)
{
return m_rows[y];
AGG_INLINE T* row_ptr(int, int y, unsigned)
{
return m_rows[y];
}
AGG_INLINE T* row_ptr(int y) { return m_rows[y]; }
AGG_INLINE const T* row_ptr(int y) const { return m_rows[y]; }
AGG_INLINE row_data row (int y) const
{
return row_data(0, m_width-1, m_rows[y]);
AGG_INLINE T* row_ptr(int y)
{
return m_rows[y];
}
AGG_INLINE const T* row_ptr(int y) const
{
return m_rows[y];
}
AGG_INLINE row_data row(int y) const
{
return row_data(0, m_width - 1, m_rows[y]);
}
//--------------------------------------------------------------------
T const* const* rows() const { return &m_rows[0]; }
T const* const* rows() const
{
return &m_rows[0];
}
//--------------------------------------------------------------------
template<class RenBuf>
template <class RenBuf>
void copy_from(const RenBuf& src)
{
unsigned h = height();
if(src.height() < h) h = src.height();
if (src.height() < h)
h = src.height();
unsigned l = stride_abs();
if(src.stride_abs() < l) l = src.stride_abs();
if (src.stride_abs() < l)
l = src.stride_abs();
l *= sizeof(T);
unsigned y;
@@ -246,11 +293,11 @@ namespace agg
unsigned y;
unsigned w = width();
unsigned stride = stride_abs();
for(y = 0; y < height(); y++)
for (y = 0; y < height(); y++)
{
T* p = row_ptr(0, y, w);
unsigned x;
for(x = 0; x < stride; x++)
for (x = 0; x < stride; x++)
{
*p++ = value;
}
@@ -259,43 +306,39 @@ namespace agg
private:
//--------------------------------------------------------------------
T* m_buf; // Pointer to renrdering buffer
pod_array<T*> m_rows; // Pointers to each row of the buffer
unsigned m_width; // Width in pixels
unsigned m_height; // Height in pixels
int m_stride; // Number of bytes per row. Can be < 0
T* m_buf; // Pointer to renrdering buffer
pod_array<T*> m_rows; // Pointers to each row of the buffer
unsigned m_width; // Width in pixels
unsigned m_height; // Height in pixels
int m_stride; // Number of bytes per row. Can be < 0
};
//========================================================rendering_buffer
//
// The definition of the main type for accessing the rows in the frame
// buffer. It provides functionality to navigate to the rows in a
// rectangular matrix, from top to bottom or from bottom to top depending
//
// The definition of the main type for accessing the rows in the frame
// buffer. It provides functionality to navigate to the rows in a
// rectangular matrix, from top to bottom or from bottom to top depending
// on stride.
//
// row_accessor is cheap to create/destroy, but performs one multiplication
// when calling row_ptr().
//
// row_ptr_cache creates an array of pointers to rows, so, the access
// via row_ptr() may be faster. But it requires memory allocation
// when creating. For example, on typical Intel Pentium hardware
//
// row_ptr_cache creates an array of pointers to rows, so, the access
// via row_ptr() may be faster. But it requires memory allocation
// when creating. For example, on typical Intel Pentium hardware
// row_ptr_cache speeds span_image_filter_rgb_nn up to 10%
//
// It's used only in short hand typedefs like pixfmt_rgba32 and can be
// It's used only in short hand typedefs like pixfmt_rgba32 and can be
// redefined in agg_config.h
// In real applications you can use both, depending on your needs
//------------------------------------------------------------------------
#ifdef AGG_RENDERING_BUFFER
typedef AGG_RENDERING_BUFFER rendering_buffer;
#else
// typedef row_ptr_cache<int8u> rendering_buffer;
// typedef row_ptr_cache<int8u> rendering_buffer;
typedef row_accessor<int8u> rendering_buffer;
#endif
}
#endif

Some files were not shown because too many files have changed in this diff Show More