/* Code based on example taken from: * http://www.devmaster.net/forums/showthread.php?t=1094 */ static void add_flat_triangle(struct image *image, int x0, int y0, int x1, int y1, int x2, int y2, unsigned char mult, const uint16_t add[]) { unsigned char *buf; unsigned int i, j; // compute slopes for the two triangle legs float dx0 = (float)(x2 - x0) / (y2 - y0); float dx1 = (float)(x2 - x1) / (y2 - y1); int yRange = 0; float lx = (float) x0, rx = (float) x1; if (y0 < y2) { yRange = y2 - y0; buf = image_at(image, 0, y0); } else { yRange = y0 - y2; buf = image_at(image, 0, y2); lx = rx = (float)x2; } for (i=0; i < yRange; ++i) { for (j=(int)(lx); j<(int)((rx) + 1.0f); ++j) add_dot(buf + 3 * j, mult, add); lx += dx0; rx += dx1; buf += image->stride; } }
/** * @brief Gets current cell * @param void * @return char - Cell pattern with 2 MSB as controls for ENTER, LEFT, RIGHT * terminated cell entry, WITH_CANCEL for CANCEL and NO_DOTS when nothing to * return (wait) */ char get_cell(void) { char last_dot = get_dot(); char ret_val = NO_DOTS; switch(last_dot) { case NO_DOTS: return NO_DOTS; break; // If one of the dots, then add to cell state case '1': case '2': case '3': case '4': case '5': case '6': io_cell_state = add_dot(io_cell_state, last_dot); return NO_DOTS; break; // If a control is pressed, return cell state with control preserved in // 2 MSB of char case ENTER: case LEFT: case RIGHT: case CANCEL: ret_val = io_cell_state; io_cell_state = NO_DOTS; switch (last_dot) { case ENTER: io_user_cancel = false; io_user_abort = false; log_msg("[IO] Cell pattern: %x\n\r", ret_val | WITH_ENTER); return ret_val | WITH_ENTER; break; case LEFT: io_user_cancel = false; io_user_abort = false; return ret_val | WITH_LEFT; break; case RIGHT: io_user_cancel = false; io_user_abort = false; return ret_val | WITH_RIGHT; break; case CANCEL: if (ret_val == 0x00) { if (io_user_cancel == true) { io_user_abort = true; io_user_cancel = false; } else { io_user_cancel = true; io_user_abort = false; } } return ret_val | WITH_CANCEL; break; // Should not execute this code default: log_msg("[IO] Invalid dot: %x\n\r", last_dot); quit_mode(); return NO_DOTS; break; } break; // Should not execute this code default: log_msg("[IO] Invalid dot: %x\n\r", last_dot); quit_mode(); return NO_DOTS; break; } }