ofImage& ofxSlitScan::getOutputImage(){ if(outputIsDirty){ //calculate the new distorted image unsigned char* writebuffer = outputImage.getPixels(); unsigned char* outbuffer = writebuffer; int x, y, offset, lower_offset, upper_offset, pixelIndex; float precise, alpha, invalpha; int mapMin = capacity - timeDelay - timeWidth;// (time_delay + time_width); int mapMax = capacity - 1 - timeDelay;// - time_delay; int mapRange = mapMax - mapMin; int n = width * height; pixelIndex = 0; if(blend){ for(int i = 0; i < n; i++) { //find pixel point in local reference precise = delayMapPixels[i] * mapRange + mapMin; //cast it to an integer offset = int(precise); //calculate alpha alpha = precise - offset; invalpha = 1 - alpha; //convert to framepointer reference point lower_offset = frame_index(framepointer, offset, capacity); upper_offset = frame_index(framepointer, offset+1, capacity); //get buffers unsigned char *a = buffer[lower_offset] + pixelIndex; unsigned char *b = buffer[upper_offset] + pixelIndex; //interpolate and set values for(int c = 0; c < bytesPerPixel; c++) { *outbuffer++ = (a[c]*invalpha)+(b[c]*alpha); } pixelIndex += bytesPerPixel; } } else{ pixelIndex = 0; for(int i = 0; i < n; i++) { int index = delayMapPixels[i] * mapRange + mapMin; index = frame_index(framepointer, index, capacity); // faster than memcpy because the compiler can optimize it for(int c = 0; c < bytesPerPixel; c++) { *outbuffer++ = buffer[index][pixelIndex + c]; } pixelIndex += bytesPerPixel; } } outputImage.setFromPixels(writebuffer, width, height, type); outputIsDirty = false; } return outputImage; }
static inline void * __page_get(void) { void *hp = cos_get_vas_page(); struct frame *f = frame_alloc(); assert(hp && f); frame_ref(f); f->nmaps = -1; /* belongs to us... */ f->c.addr = (vaddr_t)hp; /* ...at this address */ if (cos_mmap_cntl(COS_MMAP_GRANT, MAPPING_RW, cos_spd_id(), (vaddr_t)hp, frame_index(f))) { printc("grant @ %p for frame %d\n", hp, frame_index(f)); BUG(); } return hp; }
bool IdentityRS::render(stk::StkFrames &frames, MuTick base_tick, MuTick start_tick, MuTick end_tick) { for (MuTick i=start_tick; i<end_tick; i++) { for (int j=frames.channels()-1; j>=0; j--) { frames(frame_index(base_tick, i), j) = i; } } return true; }
static inline void * __page_get(void) { void *hp = cos_get_vas_page(); struct frame *f = frame_alloc(); assert(hp && f); frame_ref(f); if (cos_mmap_cntl(COS_MMAP_GRANT, 0, cos_spd_id(), (vaddr_t)hp, frame_index(f))) { BUG(); } return hp; }
bool ResampleStream::render(MuTick buffer_start, MuBuffer *buffer) { if ((sample_source_ == NULL) || (timing_source_ == NULL)) { return false; } timing_buffer_.resize(buffer->frames(), buffer->channels()); MuUtils::zero_buffer(&timing_buffer_); if (!timing_source_->render(buffer_start, &timing_buffer_)) { return false; } MuFloat min = (double)LONG_MAX; MuFloat max = (double)LONG_MIN; // find min and max times in timing_buffer_ for (int i=timing_buffer_.frames()-1; i>=0; i--) { MuFloat v = timing_buffer_(i, 0); // channel 0 only min = (v < min) ? v : min; max = (v > max) ? v : max; } MuTick min_tick = (MuTick)floor(min); MuTick max_tick = (MuTick)ceil(max); // add 1 to for sample[i+1] interpolation. MuTick n_frames = (max_tick - min_tick) + 1; // Fetch source samples sample_buffer_.resize(n_frames, buffer->channels()); MuUtils::zero_buffer(&sample_buffer_); if (!sample_source_->render(min_tick, &sample_buffer_)) { return false; } MuTick buffer_end = buffer_start + buffer->frames(); for (MuTick tick=buffer_start; tick<buffer_end; tick++) { // use channel 0 (only) for timing information MuFloat ftau = timing_buffer_(frame_index(buffer_start, tick), 0); MuTick itau = ( MuTick )ftau; MuFloat alpha = ftau - itau; for (int channel = buffer->channels()-1; channel >= 0; channel--) { if (alpha == 0.0) { (*buffer)(frame_index(buffer_start, tick), channel) = sample_buffer_(frame_index(min_tick, itau), channel); } else { MuFloat y0 = sample_buffer_(frame_index(min_tick, itau), channel); MuFloat y1 = sample_buffer_(frame_index(min_tick, itau+1), channel); MuFloat dy = y1 - y0; (*buffer)(frame_index(buffer_start, tick), channel) = y0 + dy * alpha; } } } return true; }
/* Make a child mapping */ static struct mapping * mapping_crt(struct mapping *p, struct frame *f, spdid_t dest, vaddr_t to, int flags) { struct comp_vas *cv = cvas_lookup(dest); struct mapping *m = NULL; long idx = to >> PAGE_SHIFT; assert(!p || p->f == f); assert(dest && to); /* no vas structure for this spd yet... */ if (!cv) { cv = cvas_alloc(dest); if (!cv) goto done; assert(cv == cvas_lookup(dest)); } assert(cv->pages); if (cvect_lookup(cv->pages, idx)) goto collision; cvas_ref(cv); m = cslab_alloc_mapping(); if (!m) goto collision; if (cos_mmap_cntl(COS_MMAP_GRANT, flags, dest, to, frame_index(f))) { printc("mem_man: could not grant at %x:%d\n", dest, (int)to); goto no_mapping; } mapping_init(m, dest, to, p, f); assert(!p || frame_nrefs(f) > 0); frame_ref(f); assert(frame_nrefs(f) > 0); if (cvect_add(cv->pages, m, idx)) BUG(); done: return m; no_mapping: cslab_free_mapping(m); collision: cvas_deref(cv); m = NULL; goto done; }
static void __mapping_destroy(struct mapping *m) { struct comp_vas *cv; int idx; assert(m); assert(EMPTY_LIST(m, _s, s_)); assert(m->p == NULL && m->c == NULL); cv = cvas_lookup(m->spdid); assert(cv && cv->pages); assert(m == cvect_lookup(cv->pages, m->addr >> PAGE_SHIFT)); cvect_del(cv->pages, m->addr >> PAGE_SHIFT); cvas_deref(cv); idx = cos_mmap_cntl(COS_MMAP_REVOKE, 0, m->spdid, m->addr, 0); assert(idx == frame_index(m->f)); frame_deref(m->f); cslab_free_mapping(m); }
int main() { ct_print_header("text/html", NULL); const gchar *path = ct_get_path_info(); const gchar *query = ct_get_query_string(); GList *thumbs = gen_thumbs(read_dir("large")); if (!path || g_str_equal(path, "/")) frame_index(); else if (g_str_equal(path, "/head")) frame_head(); else if (g_str_equal(path, "/nav")) frame_nav(FALSE, thumbs); else if (g_str_equal(path, "/noframe")) frame_nav(TRUE, thumbs); else if (g_str_equal(path, "/show_small")) frame_show("small", "show_large", query); else if (g_str_equal(path, "/show_large")) frame_show("large", "show_small", query); }
void ofxSlitScan::pixelsForFrame(int num, unsigned char* outbuf){ memcpy(outbuf, buffer[frame_index(framepointer, num, capacity)], bytesPerFrame*sizeof(unsigned char)); }