/** Reset histogram. */ void Histogram::reset() { histogram_block->reset(); // memset(histogram, 0, histogram_size); number_of_values = 0; for (unsigned int i = 0; i < undo_num; ++i) { switch_undo(i); reset_undo(); } switch_undo(0); }
/** Undo. */ void Histogram::undo() { for (unsigned int z = 0; z < depth; ++z) { for (unsigned int y = 0; y < height; ++y) { for (unsigned int x = 0; x < width; ++x) { unsigned int index = z * width * height + y * width + x; histogram[index] -= undo_overlay[undo_current][index]; } } } number_of_values -= undo_num_vals[undo_current]; reset_undo(); }
void replace(editor_t *ed, int pos, int len, char *buf, int bufsize, int doundo) { char *p; undo_t *undo; // Store undo information if (doundo) { reset_undo(ed); undo = ed->undotail; if (undo && len == 0 && bufsize == 1 && undo->erased == 0 && pos == undo->pos + undo->inserted) { // Insert character at end of current redo buffer undo->redobuf = neutron_realloc(undo->redobuf, undo->inserted + 1); undo->redobuf[undo->inserted] = *buf; undo->inserted++; } else if (undo && len == 1 && bufsize == 0 && undo->inserted == 0 && pos == undo->pos) { // Erase character at end of current undo buffer undo->undobuf = neutron_realloc(undo->undobuf, undo->erased + 1); undo->undobuf[undo->erased] = get(ed, pos); undo->erased++; } else if (undo && len == 1 && bufsize == 0 && undo->inserted == 0 && pos == undo->pos - 1) { // Erase character at beginning of current undo buffer undo->pos--; undo->undobuf = neutron_realloc(undo->undobuf, undo->erased + 1); memmove(undo->undobuf + 1, undo->undobuf, undo->erased); undo->undobuf[0] = get(ed, pos); undo->erased++; } else { // Create new undo buffer undo = (undo_t *) neutron_malloc(sizeof (struct _undo_t)); if (ed->undotail) ed->undotail->next = undo; undo->prev = ed->undotail; undo->next = 0; ed->undotail = ed->undo = undo; if (!ed->undohead) ed->undohead = undo; undo->pos = pos; undo->erased = len; undo->inserted = bufsize; undo->undobuf = undo->redobuf = 0; if (len > 0) { undo->undobuf = neutron_malloc(len); copy(ed, undo->undobuf, pos, len); } if (bufsize > 0) { undo->redobuf = neutron_malloc(bufsize); memcpy(undo->redobuf, buf, bufsize); } } } p = ed->start + pos; if (bufsize == 0 && p <= ed->gap && p + len >= ed->gap) { // Handle deletions at the edges of the gap ed->rest += len - (ed->gap - p); ed->gap = p; } else { // Move the gap move_gap(ed, pos + len, bufsize - len); // Replace contents memcpy(ed->start + pos, buf, bufsize); ed->gap = ed->start + pos + bufsize; } // Mark buffer as dirty ed->dirty = 1; }