caryclark@google.com | 639df89 | 2012-01-10 21:46:10 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * SkAntiEdge.h |
| 3 | * core |
| 4 | * |
| 5 | * Created by Cary Clark on 5/6/11. |
| 6 | * Copyright 2011 __MyCompanyName__. All rights reserved. |
| 7 | * |
| 8 | */ |
| 9 | |
| 10 | #ifndef SkAntiEdge_DEFINED |
| 11 | #define SkAntiEdge_DEFINED |
| 12 | |
| 13 | #include "SkFixed.h" |
| 14 | #include "SkTDArray.h" |
| 15 | |
| 16 | struct SkBitmap; |
| 17 | struct SkPoint; |
| 18 | |
| 19 | struct SkAntiEdge { |
| 20 | SkAntiEdge* fNext; // list in walking order (y, then x, then diag) |
| 21 | SkAntiEdge* fPrev; // reverse in walking order |
| 22 | SkAntiEdge* fLink; // list in connected order, top to bottom |
| 23 | |
| 24 | SkFixed fFirstX; // starting X |
| 25 | SkFixed fFirstY; // starting Y |
| 26 | SkFixed fLastX; // ending X |
| 27 | SkFixed fLastY; // ending Y |
| 28 | SkFixed fX0; // computed edge current value (may be off end) |
| 29 | SkFixed fY0; |
| 30 | SkFixed fX; // edge current value (always on edge) |
| 31 | SkFixed fY; |
| 32 | SkFixed fDX; // change in X per unit step in Y |
| 33 | SkFixed fDY; // change in Y per unit step in X |
| 34 | SkFixed fWalkX; // unit step position (integer after initial step) |
| 35 | SkFixed fWalkY; |
| 36 | uint16_t fPartialY; // initial partial coverage in Y (0 .. SkFixed1] |
| 37 | int16_t fWindingSum; // winding including contributions to the left |
| 38 | int8_t fWinding; // 1 or -1 (could be 2 bits) |
| 39 | bool fFinished : 1; |
| 40 | unsigned fDXFlipped : 1; // used as bool and to adjust calculations (0/1) |
| 41 | bool fLinkSet : 1; // set if edge has been attached to another edge |
| 42 | |
| 43 | void calcLine(); |
| 44 | bool setLine(const SkPoint& p0, const SkPoint& p1); |
| 45 | uint16_t advanceX(SkFixed left); |
| 46 | uint16_t advanceFlippedX(SkFixed left); |
| 47 | void advanceY(SkFixed top); |
| 48 | // FIXME: mark DEBUG |
| 49 | void pointInLine(SkFixed x, SkFixed y); |
| 50 | void pointOnLine(SkFixed x, SkFixed y); |
| 51 | void validate(); |
| 52 | }; |
| 53 | |
| 54 | class SkAntiEdgeBuilder { |
| 55 | public: |
| 56 | void process(const SkPoint* points, int ptCount, |
| 57 | uint8_t* result, int pixelCol, int pixelRow); |
| 58 | private: |
| 59 | int build(const SkPoint pts[], int count); |
| 60 | void calc(); |
| 61 | void link(); |
| 62 | void sort(); |
| 63 | void sort(SkTDArray<SkAntiEdge*>&); |
| 64 | void split(); |
| 65 | void split(SkAntiEdge* edge, SkFixed y); |
| 66 | void walk(uint8_t* result, int rowBytes, int height); |
| 67 | SkAntiEdge fHeadEdge; |
| 68 | SkAntiEdge fTailEdge; |
| 69 | SkTDArray<SkAntiEdge> fEdges; |
| 70 | SkTDArray<SkAntiEdge*> fList; |
| 71 | }; |
| 72 | |
| 73 | void SkAntiEdge_Test(); |
| 74 | void CreateSweep(SkBitmap* , float width); |
| 75 | void CreateHorz(SkBitmap* ); |
| 76 | void CreateVert(SkBitmap* ); |
| 77 | void CreateAngle(SkBitmap* sweep, float angle); |
| 78 | |
| 79 | #endif |