static void variation_init (void) { int button_pressed = (GPIO_INR & (1<<GPIO_I_POWERBUTTON)) != 0; if (button_pressed) alias_set ("variation", CONFIG_VARIATION_SUFFIX); MASK_AND_SET (GPIO_OUTR, 1<<GPIO_I_LEDSTATUS, button_pressed ? (1<<GPIO_I_LEDSTATUS): 0); }
void determine_arch_number (void) { int arch_id = 0; char sz[10]; switch (((CSC_PWRSR >> CSC_PWRSR_CHIPID_SHIFT) & CSC_PWRSR_CHIPID_MASK) & 0xf0) { default: case 0x00: arch_id = 389; /* LPD7A400 */ case 0x20: arch_id = 390; /* LPD7A404 */ } snprintf (sz, 10, "%d", arch_id); alias_set ("arch-number", sz); }
bool next(GridT &from, GridT &to){ to.fill(0); for (size_t y=0; y<from.height(); ++y){ for (size_t x=0; x<from.width(); ++x){ auto source = from.get_point({x, y}); if (source){ auto& dest1 = to.get_point({x, y}); if (source > (UIMAX(U) - dest1)) return true; dest1 += source; Point<T> source_point(x, y); /*((T)x) / ((T)from.width()), ((T)y) / ((T)from.height()));*/ for (Point<double> corner : points){ auto dest_point = source_point.approach(corner); if (alias_set(to, source, dest_point)) return true; } } } } return false; }
static int DoAnalyzeFindRegionsBorder(int width, int height, imbyte* map, imushort* new_map, int connect) { int i, j; imbyte* pmap1 = map - width; // previous line (line -1 = invalid) imushort* new_pmap1 = new_map - width; imbyte* pmap = map; // current line (line 0) imushort* new_pmap = new_map; int region_count = 2; // still consider: 0- background, 1-border imushort* alias_table = new imushort [MAX_COUNT]; memset(alias_table, 0, MAX_COUNT); // aliases are all zero at start (not used) for (i = 0; i < height; i++) { for (j = 0; j < width; j++) { if (pmap[j]) { int b01 = j > 0? 1: 0; // valid for pmap[j-1] int b10 = i > 0? 1: 0; // valid for pmap1[j] int b11 = i > 0 && j > 0? 1: 0; // valid for pmap1[j-1] int b12 = i > 0 && j < width-1? 1: 0; // valid for pmap1[j+1] if ((b01&&pmap[j-1]) || (b10&&pmap1[j]) || (connect == 8 && ((b11&&pmap1[j-1]) || (b12&&pmap1[j+1])))) // 4 or 8 connected to the previous neighbors { imushort region = 0; if (b01&&pmap[j-1]) { if (!region) region = new_pmap[j-1]; // horizontal neighbor -00 else // X1 { // this is a right border pixel that connects to an horizontal neighbor // this pixel can connect two different regions alias_set(alias_table, region, new_pmap[j-1]); } } if (b10&&pmap1[j]) // vertical neighbor { if (!region) region = new_pmap1[j]; // isolated vertical neighbor -X- else // 01 { // an horizontal neighbor connects to a vertical neighbor -X- // X1 // this pixel can connect two different regions alias_set(alias_table, region, new_pmap1[j]); } } else if (region && connect == 8 && (b12&&pmap1[j+1])) { // an horizontal neighbor connects to a right corner neighbor 00X // X1 // this pixel can connect two different regions alias_set(alias_table, region, new_pmap1[j+1]); } if (connect == 8 && ((b11&&pmap1[j-1]) || (b12&&pmap1[j+1])) && !region) // isolated corner { // a left corner neighbor or a right corner neighbor X0X // 01 if (b11&&pmap1[j-1]) // left corner region = new_pmap1[j-1]; if (b12&&pmap1[j+1]) // right corner { if (!region) // isolated right corner region = new_pmap1[j+1]; else { // this pixel can connect two different regions alias_set(alias_table, new_pmap1[j-1], new_pmap1[j+1]); } } } new_pmap[j] = region; } else { // this pixel touches no pixels // create a new region 000 // 01 new_pmap[j] = (imushort)region_count; region_count++; if (region_count > MAX_COUNT) { delete [] alias_table; return -1; } } } } pmap1 = pmap; new_pmap1 = new_pmap; pmap += width; new_pmap += width; } // now all pixels are marked, // but some marks are aliases to others // ajust the alias table to be a remap table // and return the real region count alias_update(alias_table, region_count); int count = width*height; for (i = 0; i < count; i++) { new_map[i] = alias_table[new_map[i]]; } delete [] alias_table; return region_count; }
static int DoAnalyzeFindRegions(int width, int height, imbyte* map, imushort* new_map, int connect) { int i, j; // mark the pixels that touch the border // if a region touch the border, is the invalid region 1 imbyte* pmap = map; imushort* new_pmap = new_map; for (j = 0; j < width; j++) // first line { if (pmap[j]) new_pmap[j] = 1; } pmap += width; new_pmap += width; for (i = 1; i < height-1; i++) // first column { if (pmap[0]) new_pmap[0] = 1; pmap += width; new_pmap += width; } // find and connect the regions imbyte* pmap1 = map; // previous line (line 0) imushort* new_pmap1 = new_map; pmap = map + width; // current line (line 1) new_pmap = new_map + width; int region_count = 2; // 0- background, 1-border imushort* alias_table = new imushort [MAX_COUNT]; memset(alias_table, 0, MAX_COUNT); // aliases are all zero at start (not used) for (i = 1; i < height; i++) { for (j = 1; j < width; j++) { int has_j1 = j < width-1? 1: 0; if (pmap[j]) { if (pmap[j-1] || pmap1[j] || (connect == 8 && (pmap1[j-1] || (has_j1&&pmap1[j+1])))) // 4 or 8 connected to the previous neighbors { imushort region = 0; if (i == height-1 || j == width-1) { region = new_pmap[j] = 1; } if (pmap[j-1]) { if (!region) region = new_pmap[j-1]; // horizontal neighbor -00 else // X1 { // this is a right border pixel that connects to an horizontal neighbor // this pixel can connect two different regions alias_set(alias_table, region, new_pmap[j-1]); } } if (pmap1[j]) // vertical neighbor { if (!region) region = new_pmap1[j]; // isolated vertical neighbor -X- else // 01 { // an horizontal neighbor connects to a vertical neighbor -X- // X1 // this pixel can connect two different regions alias_set(alias_table, region, new_pmap1[j]); } } else if (region && connect==8 && (has_j1&&pmap1[j+1])) { // an horizontal neighbor connects to a right corner neighbor 00X // X1 // this pixel can connect two different regions alias_set(alias_table, region, new_pmap1[j+1]); } if (connect == 8 && (pmap1[j-1] || (has_j1&&pmap1[j+1])) && !region) // isolated corner { // a left corner neighbor or a right corner neighbor X0X // 01 if (pmap1[j-1]) // left corner region = new_pmap1[j-1]; if (pmap1[j+1]) // right corner { if (!region) // isolated right corner region = new_pmap1[j+1]; else { // this pixel can connect two different regions alias_set(alias_table, new_pmap1[j-1], new_pmap1[j+1]); } } } new_pmap[j] = region; } else { // this pixel touches no pixels if (i == height-1 || j == width-1) new_pmap[j] = 1; else { // create a new region 000 // 01 new_pmap[j] = (imushort)region_count; region_count++; if (region_count > MAX_COUNT) { delete [] alias_table; return -1; } } } } } pmap1 = pmap; new_pmap1 = new_pmap; pmap += width; new_pmap += width; } // now all pixels are marked, // but some marks are aliases to others // ajust the alias table to be a remap table // and return the real region count alias_update(alias_table, region_count); int count = width*height; for (i = 0; i < count; i++) { new_map[i] = alias_table[new_map[i]]; } delete [] alias_table; return region_count; }