static uint16_t to_region_code(const char *region) { #define REGION_CODE(r, c) if (!strcasecmp(region, r)) return c REGION_CODE("NA", 0x0001); REGION_CODE("WW", 0x0002); REGION_CODE("GR", 0x0003); REGION_CODE("PR", 0x0004); REGION_CODE("RU", 0x0005); REGION_CODE("BZ", 0x0006); REGION_CODE("IN", 0x0007); REGION_CODE("KO", 0x0008); REGION_CODE("JP", 0x0009); #undef REGION_CODE return 0; }
DFBBoolean dfb_clip_line( const DFBRegion *clip, DFBRegion *line ) { unsigned char region_code1 = REGION_CODE( line->x1, line->y1, clip->x1, clip->x2, clip->y1, clip->y2 ); unsigned char region_code2 = REGION_CODE( line->x2, line->y2, clip->x1, clip->x2, clip->y1, clip->y2 ); while (region_code1 | region_code2) { /* line completely outside the clipping rectangle */ if (region_code1 & region_code2) return DFB_FALSE; if (region_code1) { if (region_code1 & 8) { /* divide line at bottom*/ line->x1 = line->x1 +(line->x2-line->x1) * (clip->y2 - line->y1) / (line->y2-line->y1); line->y1 = clip->y2; } else if (region_code1 & 4) { /* divide line at top*/ line->x1 = line->x1 +(line->x2-line->x1) * (clip->y1 - line->y1) / (line->y2-line->y1); line->y1 = clip->y1; } else if (region_code1 & 2) { /* divide line at right*/ line->y1 = line->y1 +(line->y2-line->y1) * (clip->x2 - line->x1) / (line->x2-line->x1); line->x1 = clip->x2; } else if (region_code1 & 1) { /* divide line at right*/ line->y1 = line->y1 +(line->y2-line->y1) * (clip->x1 - line->x1) / (line->x2-line->x1); line->x1 = clip->x1; } region_code1 = REGION_CODE( line->x1, line->y1, clip->x1, clip->x2, clip->y1, clip->y2 ); } else { if (region_code2 & 8) { /* divide line at bottom*/ line->x2 = line->x1 +(line->x2-line->x1) * (clip->y2 - line->y1) / (line->y2-line->y1); line->y2 = clip->y2; } else if (region_code2 & 4) { /* divide line at top*/ line->x2 = line->x1 +(line->x2-line->x1) * (clip->y1 - line->y1) / (line->y2-line->y1); line->y2 = clip->y1; } else if (region_code2 & 2) { /* divide line at right*/ line->y2 = line->y1 +(line->y2-line->y1) * (clip->x2 - line->x1) / (line->x2-line->x1); line->x2 = clip->x2; } else if (region_code2 & 1) { /* divide line at right*/ line->y2 = line->y1 +(line->y2-line->y1) * (clip->x1 - line->x1) / (line->x2-line->x1); line->x2 = clip->x1; } region_code2 = REGION_CODE( line->x2, line->y2, clip->x1, clip->x2, clip->y1, clip->y2 ); } } /* successfully clipped or clipping not neccessary */ return DFB_TRUE; }