BOOL AbortHandler_CheckMemoryRange( UINT8* start, UINT8* end ) { #define INRANGE(start,end,mem) ((UINT32)(start) >= HalSystemConfig.mem.Base && (UINT32)(end) <= (HalSystemConfig.mem.Base+HalSystemConfig.mem.Size)) if(INRANGE(start,end,RAM1 )) return TRUE; if(INRANGE(start,end,FLASH)) return TRUE; #undef INRANGE return FALSE; }
void bs_flush_byte(struct bitstream_st *bs) { u_int8_t *endp; assert(INRANGE(bs->byte_end, bs->byte_window, AFTER_OF(bs->byte_window))); assert(INRANGE(bs->byte_p, bs->byte_window, bs->byte_end)); endp = bs->byte_p; bs->byte_p = bs->byte_window; if (bs->blocked) return; bs_write(bs, bs->byte_window, endp - bs->byte_window); } /* bs_flush_byte */
unsigned lc_atou(char const *str, unsigned base) { unsigned result; #ifdef CONFIG_FANCY_UI assert(INRANGE(base, 2, 10)); for (result = 0; *str; result *= base, result += *str++ - '0') if (!INRANGE(*str, '0', '9')) die(EXIT_ERR_USER, "%s: unsigned integer " "expected", str); #endif return result; } /* lc_atou */
void bs_flush_bit(struct bitstream_st *bs) { #ifdef CONFIG_COMPRESS u_int8_t *endp, *wp; assert(INRANGE(bs->bit_end, bs->bit_window, AFTER_OF(bs->bit_window))); assert(INRANGE(bs->bit_p, bs->bit_window, bs->bit_end)); assert((bs->bit_p - bs->bit_window) % 8 == 0); endp = bs->bit_p; bs->bit_p = bs->bit_window; if (bs->blocked) return; if ((bs->byte_end - bs->byte_p) * BITS_OF(u_int8_t) < endp - bs->bit_window) bs_flush_byte(bs); wp = bs->bit_window; while (wp < endp) { u_int8_t c; assert((*wp & ~1) == 0); c = 0; c |= *wp++; c <<= 1; c |= *wp++; c <<= 1; c |= *wp++; c <<= 1; c |= *wp++; c <<= 1; c |= *wp++; c <<= 1; c |= *wp++; c <<= 1; c |= *wp++; c <<= 1; c |= *wp++; *bs->byte_p++ = c; } /* while */ assert(bs->byte_p <= bs->byte_end); #endif /* CONFIG_COMPRESS */ } /* bs_flus_bit */
handler* tuple::get_component(int index) { //MESSAGE(cerr, "in tuple():: get_component()"); //debug(cerr, index); //debug(cerr, my_oid()); //debug(cerr, int(storage_ptr)); if (!INRANGE(index, 1, (int) v_sz)) { MESSAGE(cerr, "out of range in tuple::get_component()"); throw( boundaryException(1, v_sz, index) ); } oid_t x = oid_list::operator()(index); //debug(cerr, x); //debug(cerr, x.ccode()); //debug(cerr, x.icode()); handler* y = 0; if ( x.icode() != 0 ) y = new handler(x, storage_ptr); return y; }
cset_handlerPtr info_base::get_set(int i) { if ( !INRANGE(i, 0, num_cset_ptrs-1) ) throw (boundaryException(0, num_cset_ptrs-1, i)); return info_base_set_ptrs[i]; }
voidPtr heap::operator()(int ind) { if ( INRANGE(ind, 1, count()) ) { voidPtr *heap_space = (voidPtr*)buffer::get_base(); return heap_space[ind]; } else return 0; }
uint8_t identMovieType(uint32_t fps1000) { #define INRANGE(value,type) \ {\ if((fps1000 > value-300) &&( fps1000 < value+300))\ {\ r=type;\ printf("Looks like "#type" \n");\ }\ } uint8_t r=0; INRANGE(25000,FRAME_PAL); INRANGE(23976,FRAME_FILM); INRANGE(29970,FRAME_NTSC); return r; }
dl_list_handlerPtr info_base::get_list(int i) { if ( !INRANGE(i, 0, num_list_ptrs-1) ) { throw(boundaryException(0, num_list_ptrs-1, i)); } return info_base_list_ptrs[i]; }
unsigned bs_fill_byte(struct bitstream_st *bs, int eofok) { unsigned n; assert(INRANGE(bs->byte_end, bs->byte_window, AFTER_OF(bs->byte_window))); assert(INRANGE(bs->byte_p, bs->byte_window, bs->byte_end)); n = bs_read(bs, bs->byte_window, sizeof(bs->byte_window)); bs->eof = n != sizeof(bs->byte_window); bs->byte_p = bs->byte_window; bs->byte_end = &bs->byte_window[n]; if (!n && !eofok) unexpected_eof(bs); return n; } /* bs_fill_byte */
/* * Check monitor spec. */ static int timing_within_monitor_spec(MonitorModeTiming * mmtp) { float hsf; /* Horz. sync freq in Hz */ float vsf; /* Vert. sync freq in Hz */ hsf = mmtp->pixelClock * 1000.0f / mmtp->HTotal; vsf = hsf / mmtp->VTotal; if ((mmtp->flags & INTERLACED)) vsf *= 2.0f; if ((mmtp->flags & DOUBLESCAN)) vsf /= 2.0f; DPRINTF("hsf = %f (in:%d), vsf = %f (in:%d)\n", hsf / 1000, (int) INRANGE(hsf, horizsync), vsf, (int) INRANGE(vsf, vertrefresh)); return INRANGE(hsf, horizsync) && INRANGE(vsf, vertrefresh); }
/* * Ensure the divisor is an even number. If it isn't, make it in even number. * @param divisor: Divisor to check * @return : An even-number divisor */ static inline uint8_t zynq7000_even_divisor(uint8_t divisor) { if ((divisor % 2) != 0) { return INRANGE(CLK_DIVISOR_MIN + 1, divisor - 1, CLK_DIVISOR_MAX - 1); } else { return divisor; } }
void bs_put_byte(u_int8_t c) { assert(INRANGE(output_bs.byte_p, output_bs.byte_window, output_bs.byte_end)); if (output_bs.byte_p == output_bs.byte_end) bs_flush_byte(&output_bs); updateCRC(output_bs.crc, c); *output_bs.byte_p++ = c; } /* bs_put_byte */
oid_list_handler* dl_list::get_locs(handler& query, int index) { if ( !INRANGE(index, 0, (int) v_num_indices-1) ) throw(boundaryException(0, v_num_indices-1, index)); if ( v_indices[index] == 0 ) throw(stringException("NULL index handler ptr")); return (*v_indices[index]) -> get_loc_list(query); }
static int str_in_block(StrPool *p, char *s) { int i; for(i = 0; i < ap_size(&p->strblocks); ++i) { StrBlock *sb = p->strblocks[i]; if(INRANGE(s,sb->block,sb->block+sb->n)) return 1; } return 0; }
/*------------------------------------------------------*/ unsigned bs_get_bit(void) { assert(INRANGE(input_bs.bit_p, input_bs.bit_window, input_bs.bit_end)); if (input_bs.bit_p == input_bs.bit_end) bs_fill_bit(&input_bs, 0); assert((*input_bs.bit_p & ~1) == 0); return *input_bs.bit_p++; } /* bs_get_bit */
dtype fn(type x) { if (INRANGE(x)) { x = roundit(x); return ((dtype)x); } else { feraiseexcept(FE_INVALID); return (DTYPE_MAX); } }
unsigned bs_fill_bit(struct bitstream_st *bs, int eofok) { #ifdef CONFIG_DECOMPRESS unsigned n; u_int8_t *wp; assert(INRANGE(bs->bit_end, bs->bit_window, AFTER_OF(bs->bit_window))); assert(INRANGE(bs->bit_p, bs->bit_window, bs->bit_end)); n = bs->byte_end > bs->byte_p ? bs->byte_end - bs->byte_p : bs_fill_byte(bs, eofok); n *= BITS_OF(u_int8_t); bs->bit_p = bs->bit_window; bs->bit_end = n > MEMBS_OF(bs->bit_window) ? AFTER_OF(bs->bit_window) : &bs->bit_window[n]; wp = bs->bit_window; while (wp < bs->bit_end) { u_int8_t c; c = *bs->byte_p++; *wp++ = (c & (1 << 7)) != 0; *wp++ = (c & (1 << 6)) != 0; *wp++ = (c & (1 << 5)) != 0; *wp++ = (c & (1 << 4)) != 0; *wp++ = (c & (1 << 3)) != 0; *wp++ = (c & (1 << 2)) != 0; *wp++ = (c & (1 << 1)) != 0; *wp++ = (c & (1 << 0)) != 0; } /* while */ assert(bs->byte_p <= bs->byte_end); return n; #endif /* CONFIG_DECOMPRESS */ } /* bs_fill_bit */
/*------------------------------------------------------*/ int getAndMoveToFrontDecode(unsigned limit) { char yy[256]; int32_t i, tmpOrigPtr; tmpOrigPtr = getUInt32(); origPtr = (tmpOrigPtr < 0 ? -tmpOrigPtr : tmpOrigPtr) - 1; initModels(); for (i = 0; i < 256; i++) yy[i] = i; for (block_end = 0; ; block_end++) { unsigned nextSym; nextSym = getSymbol(&models[MODEL_BASIS]); if (nextSym == VAL_RUNA || nextSym == VAL_RUNB) { /* Acquire run-length bits, most significant first */ unsigned n; n = 0; do { n <<= 1; n++; if (nextSym == VAL_RUNA) n++; nextSym = getSymbol(&models[MODEL_BASIS]); } while (nextSym == VAL_RUNA || nextSym == VAL_RUNB); if (block_end + n > limit) invalid_input("file corrupt"); memset(&ll[block_end], yy[0], n); block_end += n; } /* if */ if (nextSym == VAL_EOB) break; nextSym = getMTFVal(nextSym); assert(INRANGE(nextSym, 1, 255)); if (block_end >= limit) invalid_input("file corrupt"); ll[block_end] = yy[nextSym]; memmove(&yy[1], &yy[0], nextSym); yy[0] = ll[block_end]; } /* for */ return tmpOrigPtr < 0; } /* getAndMoveToFrontDecode */
oid_t dl_list::get_first_oid(const handler& query, int index) { if ( !INRANGE(index, 0, (int) v_num_indices-1) ) { MESSAGE(cerr, "cset::get_first_oid(): invalid index"); throw(boundaryException(0, v_num_indices-1, index)); } if ( v_indices[index] == 0 ) { throw(stringException("cset::get_first_oid(): NULL index ptr")); } return (*v_indices[index]) -> first_of_invlist(query); }
void oledPrintFmt (oledConfig *oledConfig, const char *fmt, ...) { char buffer[80]; char *token, *curBuf; bool_t lastLoop=FALSE; va_list ap; RET_UNLESS_INIT(oledConfig); va_start(ap, fmt); chvsnprintf(buffer, sizeof(buffer), fmt, ap); va_end(ap); if (buffer[0] == 0) return; const char* endPtr = &(buffer[strnlen(buffer, sizeof (buffer)) -1]); // replace escape color sequence by color command for respective backend // ESC c 0 à 9 : couleur index of background and foreground // replace escape n by carriage return, line feed for (curBuf=buffer;curBuf<endPtr && lastLoop == FALSE;) { token = index (curBuf, 27); if (token == NULL) { // on peut imprimer les derniers caractères et terminer lastLoop = TRUE; } else { // token pointe sur le char d'echappement ESC // on met un caractère de fin de chaine à la place *token++ =0; } oledPrintBuffer (oledConfig, curBuf); oledConfig->curXpos += strnlen (curBuf, sizeof(buffer)); if (lastLoop == FALSE) { // next two char a color coding scheme if (tolower((uint32_t) (*token)) == 'c') { const int32_t colorIndex = INRANGE(0, COLOR_TABLE_SIZE-1, *++token - '0'); oledUseColorIndex (oledConfig, colorIndex); // DebugTrace ("useColorIndex %d", colorIndex); curBuf=token+1; } else if (tolower((uint32_t) (*token)) == 'n') { // DebugTrace ("carriage return"); oledGotoXY (oledConfig, 0, oledConfig->curYpos+1); curBuf=token+1; } } } }
handler* short_list::get_component(int index) { if ( !INRANGE(index, 1, v_sz) ) { MESSAGE(cerr, "out of range in short_list::get_component()"); throw(boundaryException(1, v_sz, index)); } oid_t x = oid_list::operator()(index); handler *y = 0; if ( x.icode() != 0 ) y = new handler(x, storage_ptr); return y; }
/*------------------------------------------------------*/ unsigned getSymbol(struct Model *m) { unsigned symbol; unsigned const *f; u_int32_t smallL, smallH, smallT, smallR, smallR_x_smallL, target; smallT = m->totFreq; /* Get target value */ smallR = bigR / smallT; target = bigD / smallR; if (target >= smallT) target = smallT - 1; smallH = 0; for (f = m->freq; ; f++) { assert(f < &m->freq[m->numSymbols]); smallH += *f; if (smallH > target) break; } smallL = smallH - *f; smallR_x_smallL = smallR * smallL; bigD -= smallR_x_smallL; if (smallH < smallT) bigR = smallR * *f; else bigR -= smallR_x_smallL; while (bigR <= TWO_TO_THE(smallB - 2)) { bigR <<= 1; bigD <<= 1; bigD |= bs_get_bit(); } symbol = f - m->freq; assert(INRANGE(symbol, 0, m->numSymbols - 1)); updateModel(m, symbol); return symbol; } /* getSymbol */
Boolean void_ptr_array::insert(void* elmt, int i) { /* MESSAGE(cerr, "INSERT to void_ptr_array"); debug(cerr, int(i)); debug(cerr, int(elmt)); */ if ( !INRANGE(i, 0, count()-1) ) { expandWith( 2*i - count() ); } memcpy( v_base + i * sizeof(voidPtr), (char*)&elmt, sizeof(elmt) ); return true; }
static freq_t _pll_set_freq(clk_t* clk, freq_t hz) { volatile uint32_t* ctrl_reg; volatile uint32_t* cfg_reg; uint32_t status_mask; uint32_t fin; uint8_t fdiv; fin = clk_get_freq(clk->parent); fdiv = fin / hz; fdiv = INRANGE(PLL_CTRL_FDIV_MIN, fdiv, PLL_CTRL_FDIV_MAX); status_mask = _decode_pll(clk, &ctrl_reg, &cfg_reg); if (status_mask == 0) { return 0; } /* Program the feedback divider value and the configuration register */ *ctrl_reg &= ~(PLL_CTRL_FDIV_MASK); *ctrl_reg |= PLL_CTRL_FDIV(fdiv); *cfg_reg = pll_cfg_tbl[fdiv - PLL_CTRL_FDIV_MIN].pll_cfg; /* Force the PLL into bypass mode */ *ctrl_reg |= PLL_CTRL_BYPASS_FORCE; /* Assert and de-assert the PLL reset */ *ctrl_reg |= PLL_CTRL_RESET; *ctrl_reg &= ~(PLL_CTRL_RESET); /* Verify that the PLL is locked */ while (!(clk_regs->pll_status & status_mask)); /* Disable the PLL bypass mode */ *ctrl_reg &= ~(PLL_CTRL_BYPASS_FORCE); return clk_get_freq(clk); }
struct resource * isa_alloc_resource(device_t bus, device_t child, int type, int *rid, u_long start, u_long end, u_long count, u_int flags) { /* * Consider adding a resource definition. */ int passthrough = (device_get_parent(child) != bus); int isdefault = (start == 0UL && end == ~0UL); struct resource_list *rl; struct resource_list_entry *rle; u_long base, limit; rl = BUS_GET_RESOURCE_LIST(bus, child); if (!passthrough && !isdefault) { rle = resource_list_find(rl, type, *rid); if (!rle) { if (*rid < 0) return (NULL); switch (type) { case SYS_RES_IRQ: if (*rid >= ISA_NIRQ) return (NULL); break; case SYS_RES_DRQ: if (*rid >= ISA_NDRQ) return (NULL); break; case SYS_RES_MEMORY: if (*rid >= ISA_NMEM) return (NULL); break; case SYS_RES_IOPORT: if (*rid >= ISA_NPORT) return (NULL); break; default: return (NULL); } resource_list_add(rl, type, *rid, start, end, count); } } /* * Sanity check if the resource in the respective entry is fully * mapped and specified and its type allocable. A driver could * have added an out of range resource on its own. */ if (!passthrough) { if ((rle = resource_list_find(rl, type, *rid)) == NULL) return (NULL); base = limit = 0; switch (type) { case SYS_RES_MEMORY: base = isa_mem_base; limit = base + isa_mem_limit; break; case SYS_RES_IOPORT: base = isa_io_base; limit = base + isa_io_limit; break; case SYS_RES_IRQ: if (rle->start != rle->end || rle->start <= 7) return (NULL); break; case SYS_RES_DRQ: break; default: return (NULL); } if (type == SYS_RES_MEMORY || type == SYS_RES_IOPORT) { if (!INRANGE(rle->start, base, limit) || !INRANGE(rle->end, base, limit)) return (NULL); } } return (resource_list_alloc(rl, bus, child, type, rid, start, end, count, flags)); }
static int put_image(struct vf_instance* vf, mp_image_t* mpi, double pts){ int buf_x=0, buf_y=0, buf_pos=0; int have, got, want; int xpos=0, ypos=0, pos=0; unsigned char red=0, green=0, blue=0; int alpha; mp_image_t* dmpi; dmpi = vf_get_image(vf->next, mpi->imgfmt, MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_PREFER_ALIGNED_STRIDE, mpi->w, mpi->h); memcpy_pic( dmpi->planes[0], mpi->planes[0], mpi->width, mpi->height, dmpi->stride[0], mpi->stride[0] ); memcpy_pic( dmpi->planes[1], mpi->planes[1], mpi->chroma_width, mpi->chroma_height, dmpi->stride[1], mpi->stride[1] ); memcpy_pic( dmpi->planes[2], mpi->planes[2], mpi->chroma_width, mpi->chroma_height, dmpi->stride[2], mpi->stride[2] ); if(vf->priv->stream_fd >= 0) { struct timeval tv; int ready; FD_SET( vf->priv->stream_fd, &vf->priv->stream_fdset ); tv.tv_sec=0; tv.tv_usec=0; ready = select( vf->priv->stream_fd+1, &vf->priv->stream_fdset, NULL, NULL, &tv ); if(ready > 0) { // We've got new data from the FIFO char cmd[20], args[100]; int imgw,imgh,imgx,imgy,clear,imgalpha,pxsz=1,command; unsigned char *buffer = NULL; if(! _read_cmd( vf->priv->stream_fd, cmd, args) ) { mp_msg(MSGT_VFILTER, MSGL_ERR, "\nvf_bmovl: Error reading commands: %s\n\n", strerror(errno)); return FALSE; } mp_msg(MSGT_VFILTER, MSGL_DBG2, "\nDEBUG: Got: %s+%s\n", cmd, args); command=NONE; if ( strncmp(cmd,"RGBA32",6)==0 ) { pxsz=4; command = IMG_RGBA32; } else if( strncmp(cmd,"ABGR32",6)==0 ) { pxsz=4; command = IMG_ABGR32; } else if( strncmp(cmd,"RGB24" ,5)==0 ) { pxsz=3; command = IMG_RGB24; } else if( strncmp(cmd,"BGR24" ,5)==0 ) { pxsz=3; command = IMG_BGR24; } else if( strncmp(cmd,"CLEAR" ,5)==0 ) { pxsz=1; command = CMD_CLEAR; } else if( strncmp(cmd,"ALPHA" ,5)==0 ) { pxsz=1; command = CMD_ALPHA; } else if( strncmp(cmd,"OPAQUE",6)==0 ) vf->priv->opaque=TRUE; else if( strncmp(cmd,"SHOW", 4)==0 ) vf->priv->hidden=FALSE; else if( strncmp(cmd,"HIDE", 4)==0 ) vf->priv->hidden=TRUE; else if( strncmp(cmd,"FLUSH" ,5)==0 ) return vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE); else { mp_msg(MSGT_VFILTER, MSGL_WARN, "\nvf_bmovl: Unknown command: '%s'. Ignoring.\n", cmd); return vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE); } if(command == CMD_ALPHA) { sscanf( args, "%d %d %d %d %d", &imgw, &imgh, &imgx, &imgy, &imgalpha); mp_msg(MSGT_VFILTER, MSGL_DBG2, "\nDEBUG: ALPHA: %d %d %d %d %d\n\n", imgw, imgh, imgx, imgy, imgalpha); if(imgw==0 && imgh==0) vf->priv->opaque=FALSE; } if(command & IS_RAWIMG) { sscanf( args, "%d %d %d %d %d %d", &imgw, &imgh, &imgx, &imgy, &imgalpha, &clear); mp_msg(MSGT_VFILTER, MSGL_DBG2, "\nDEBUG: RAWIMG: %d %d %d %d %d %d\n\n", imgw, imgh, imgx, imgy, imgalpha, clear); buffer = malloc(imgw*imgh*pxsz); if(!buffer) { mp_msg(MSGT_VFILTER, MSGL_WARN, "\nvf_bmovl: Couldn't allocate temporary buffer! Skipping...\n\n"); return vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE); } /* pipes/sockets might need multiple calls to read(): */ want = (imgw*imgh*pxsz); have = 0; while (have < want) { got = read( vf->priv->stream_fd, buffer+have, want-have ); if (got == 0) { mp_msg(MSGT_VFILTER, MSGL_WARN, "\nvf_bmovl: premature EOF...\n\n"); break; } if (got < 0) { mp_msg(MSGT_VFILTER, MSGL_WARN, "\nvf_bmovl: read error: %s\n\n", strerror(errno)); break; } have += got; } mp_msg(MSGT_VFILTER, MSGL_DBG2, "Got %d bytes... (wanted %d)\n", have, want ); if(clear) { memset( vf->priv->bitmap.y, 0, vf->priv->w*vf->priv->h ); memset( vf->priv->bitmap.u, 128, vf->priv->w*vf->priv->h/4 ); memset( vf->priv->bitmap.v, 128, vf->priv->w*vf->priv->h/4 ); memset( vf->priv->bitmap.a, 0, vf->priv->w*vf->priv->h ); memset( vf->priv->bitmap.oa, 0, vf->priv->w*vf->priv->h ); vf->priv->x1 = dmpi->width; vf->priv->y1 = dmpi->height; vf->priv->x2 = vf->priv->y2 = 0; } // Define how much of our bitmap that contains graphics! vf->priv->x1 = av_clip(imgx, 0, vf->priv->x1); vf->priv->y1 = av_clip(imgy, 0, vf->priv->y1); vf->priv->x2 = av_clip(imgx + imgw, vf->priv->x2, vf->priv->w); vf->priv->y2 = av_clip(imgy + imgh, vf->priv->y2, vf->priv->h); } if( command == CMD_CLEAR ) { sscanf( args, "%d %d %d %d", &imgw, &imgh, &imgx, &imgy); mp_msg(MSGT_VFILTER, MSGL_DBG2, "\nDEBUG: CLEAR: %d %d %d %d\n\n", imgw, imgh, imgx, imgy); for( ypos=imgy ; (ypos < (imgy+imgh)) && (ypos < vf->priv->y2) ; ypos++ ) { memset( vf->priv->bitmap.y + (ypos*vf->priv->w) + imgx, 0, imgw ); memset( vf->priv->bitmap.a + (ypos*vf->priv->w) + imgx, 0, imgw ); memset( vf->priv->bitmap.oa + (ypos*vf->priv->w) + imgx, 0, imgw ); if(ypos%2) { memset( vf->priv->bitmap.u + ((ypos/2)*dmpi->stride[1]) + (imgx/2), 128, imgw/2 ); memset( vf->priv->bitmap.v + ((ypos/2)*dmpi->stride[2]) + (imgx/2), 128, imgw/2 ); } } // Recalculate area that contains graphics if( (imgx <= vf->priv->x1) && ( (imgw+imgx) >= vf->priv->x2) ) { if( (imgy <= vf->priv->y1) && ( (imgy+imgh) >= vf->priv->y1) ) vf->priv->y1 = imgy+imgh; if( (imgy <= vf->priv->y2) && ( (imgy+imgh) >= vf->priv->y2) ) vf->priv->y2 = imgy; } if( (imgy <= vf->priv->y1) && ( (imgy+imgh) >= vf->priv->y2) ) { if( (imgx <= vf->priv->x1) && ( (imgx+imgw) >= vf->priv->x1) ) vf->priv->x1 = imgx+imgw; if( (imgx <= vf->priv->x2) && ( (imgx+imgw) >= vf->priv->x2) ) vf->priv->x2 = imgx; } return vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE); } for( buf_y=0 ; (buf_y < imgh) && (buf_y < (vf->priv->h-imgy)) ; buf_y++ ) { for( buf_x=0 ; (buf_x < (imgw*pxsz)) && (buf_x < ((vf->priv->w+imgx)*pxsz)) ; buf_x += pxsz ) { if(command & IS_RAWIMG) buf_pos = (buf_y * imgw * pxsz) + buf_x; pos = ((buf_y+imgy) * vf->priv->w) + ((buf_x/pxsz)+imgx); switch(command) { case IMG_RGBA32: red = buffer[buf_pos+0]; green = buffer[buf_pos+1]; blue = buffer[buf_pos+2]; alpha = buffer[buf_pos+3]; break; case IMG_ABGR32: alpha = buffer[buf_pos+0]; blue = buffer[buf_pos+1]; green = buffer[buf_pos+2]; red = buffer[buf_pos+3]; break; case IMG_RGB24: red = buffer[buf_pos+0]; green = buffer[buf_pos+1]; blue = buffer[buf_pos+2]; alpha = 0xFF; break; case IMG_BGR24: blue = buffer[buf_pos+0]; green = buffer[buf_pos+1]; red = buffer[buf_pos+2]; alpha = 0xFF; break; case CMD_ALPHA: vf->priv->bitmap.a[pos] = INRANGE((vf->priv->bitmap.oa[pos]+imgalpha),0,255); break; default: mp_msg(MSGT_VFILTER, MSGL_ERR, "vf_bmovl: Internal error!\n"); return FALSE; } if( command & IS_RAWIMG ) { vf->priv->bitmap.y[pos] = rgb2y(red,green,blue); vf->priv->bitmap.oa[pos] = alpha; vf->priv->bitmap.a[pos] = INRANGE((alpha+imgalpha),0,255); if((buf_y%2) && ((buf_x/pxsz)%2)) { pos = ( ((buf_y+imgy)/2) * dmpi->stride[1] ) + (((buf_x/pxsz)+imgx)/2); vf->priv->bitmap.u[pos] = rgb2u(red,green,blue); vf->priv->bitmap.v[pos] = rgb2v(red,green,blue); } } } // for buf_x } // for buf_y free (buffer); } else if(ready < 0) { mp_msg(MSGT_VFILTER, MSGL_WARN, "\nvf_bmovl: Error %d in fifo: %s\n\n", errno, strerror(errno)); } } if(vf->priv->hidden) return vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE); if(vf->priv->opaque) { // Just copy buffer memory to screen for( ypos=vf->priv->y1 ; ypos < vf->priv->y2 ; ypos++ ) { fast_memcpy( dmpi->planes[0] + (ypos*dmpi->stride[0]) + vf->priv->x1, vf->priv->bitmap.y + (ypos*vf->priv->w) + vf->priv->x1, vf->priv->x2 - vf->priv->x1 ); if(ypos%2) { fast_memcpy( dmpi->planes[1] + ((ypos/2)*dmpi->stride[1]) + (vf->priv->x1/2), vf->priv->bitmap.u + (((ypos/2)*(vf->priv->w)/2)) + (vf->priv->x1/2), (vf->priv->x2 - vf->priv->x1)/2 ); fast_memcpy( dmpi->planes[2] + ((ypos/2)*dmpi->stride[2]) + (vf->priv->x1/2), vf->priv->bitmap.v + (((ypos/2)*(vf->priv->w)/2)) + (vf->priv->x1/2), (vf->priv->x2 - vf->priv->x1)/2 ); } } } else { // Blit the bitmap to the videoscreen, pixel for pixel for( ypos=vf->priv->y1 ; ypos < vf->priv->y2 ; ypos++ ) { for ( xpos=vf->priv->x1 ; xpos < vf->priv->x2 ; xpos++ ) { pos = (ypos * dmpi->stride[0]) + xpos; alpha = vf->priv->bitmap.a[pos]; if (alpha == 0) continue; // Completly transparent pixel if (alpha == 255) { // Opaque pixel dmpi->planes[0][pos] = vf->priv->bitmap.y[pos]; if ((ypos%2) && (xpos%2)) { pos = ( (ypos/2) * dmpi->stride[1] ) + (xpos/2); dmpi->planes[1][pos] = vf->priv->bitmap.u[pos]; dmpi->planes[2][pos] = vf->priv->bitmap.v[pos]; } } else { // Alphablended pixel dmpi->planes[0][pos] = ((255 - alpha) * (int)dmpi->planes[0][pos] + alpha * (int)vf->priv->bitmap.y[pos]) >> 8; if ((ypos%2) && (xpos%2)) { pos = ( (ypos/2) * dmpi->stride[1] ) + (xpos/2); dmpi->planes[1][pos] = ((255 - alpha) * (int)dmpi->planes[1][pos] + alpha * (int)vf->priv->bitmap.u[pos]) >> 8; dmpi->planes[2][pos] = ((255 - alpha) * (int)dmpi->planes[2][pos] + alpha * (int)vf->priv->bitmap.v[pos]) >> 8; } } } // for xpos } // for ypos } // if !opaque
static void svgalib_key_handler (int scancode, int press) { int i; /* Trim high bytes off (for safety) */ scancode &= 0x7F; press &= 0x7F; if (key_state[scancode] == press) return; /* Key held down */ key_state[scancode] = press; if (press == KEY_EVENTRELEASE) { /* Key released */ if (scancode == SCANCODE_LEFTCONTROL) key_control &= ~1; if (scancode == SCANCODE_RIGHTCONTROL) key_control &= ~2; if (scancode == SCANCODE_LEFTALT) key_alt &= ~1; if (scancode == SCANCODE_RIGHTALT) key_alt &= ~2; return; } switch (scancode) { case SCANCODE_LEFTSHIFT: case SCANCODE_RIGHTSHIFT: key_value= 0; break; case SCANCODE_LEFTCONTROL: key_control |= 1; key_value= 0; break; case SCANCODE_RIGHTCONTROL: key_control |= 2; key_value= 0; break; case SCANCODE_LEFTALT: key_alt |= 1; key_value= 0; break; case SCANCODE_RIGHTALT: key_alt |= 2; key_value= 0; break; case SCANCODE_CURSORUP: case SCANCODE_CURSORBLOCKUP: key_value= KEY_UP; break; case SCANCODE_CURSORDOWN: case SCANCODE_CURSORBLOCKDOWN: key_value= KEY_DOWN; break; case SCANCODE_CURSORLEFT: case SCANCODE_CURSORBLOCKLEFT: key_value= KEY_LEFT; break; case SCANCODE_CURSORRIGHT: case SCANCODE_CURSORBLOCKRIGHT: key_value= KEY_RIGHT; break; case SCANCODE_CURSORUPLEFT: key_value= KEY_UP_LEFT; break; case SCANCODE_CURSORUPRIGHT: key_value= KEY_UP_RIGHT; break; case SCANCODE_CURSORDOWNLEFT: key_value= KEY_DOWN_LEFT; break; case SCANCODE_CURSORDOWNRIGHT: key_value= KEY_DOWN_RIGHT; break; case SCANCODE_ENTER: case SCANCODE_KEYPADENTER: key_value= KEY_ENTER; break; case SCANCODE_KEYPADPLUS: key_value= '+'; break; case SCANCODE_KEYPADMINUS: key_value= '-'; break; case SCANCODE_REMOVE: key_value= 0x53; break; case SCANCODE_INSERT: key_value= 0x52; break; case SCANCODE_TAB: key_value = 0x09; break; case SCANCODE_F1: case SCANCODE_F2: case SCANCODE_F3: case SCANCODE_F4: case SCANCODE_F5: case SCANCODE_F6: case SCANCODE_F7: case SCANCODE_F8: case SCANCODE_F9: case SCANCODE_F10: { int ftable[10] = { 0x3B00, 0x3C00, 0x3D00, 0x3E00, 0x3F00, 0x4000, 0x4100, 0x4200, 0x4300, 0x4400}; key_value= ftable[(scancode - SCANCODE_F1)]; break; } case SCANCODE_F11: key_value = KEY_STATUSLN; break; case SCANCODE_F12: key_value = KEY_PRIORITY; break; case SCANCODE_ESCAPE: key_value= KEY_ESCAPE; break; default: /* Map scancode to ASCII key_value*/ for (i=0; ; i++) { if (key_map[i].scancode == 0) break; if (key_map[i].scancode == scancode) { key_value = key_map[i].ascii; break; } } if (INRANGE (scancode, SCANCODE_Q, SCANCODE_P) || INRANGE (scancode, SCANCODE_A, SCANCODE_L) || INRANGE (scancode, SCANCODE_Z, SCANCODE_M)) { if (key_control || key_alt) { key_value &= ~0x20; key_value -= 0x40; } if (key_alt) { key_value = scancode_table[key_value - 1] << 8; } } } }
double strcmp95(char *ying, char *yang, long y_length, int *ind_c[]) { /* Arguments: ying and yang are pointers to the 2 strings to be compared. The strings need not be NUL-terminated strings because the length is passed. y_length is the length of the strings. ind_c is an array that is used to define whether certain options should be activated. A nonzero value indicates the option is deactivated. The options are: ind_c[0] Increase the probability of a match when the number of matched characters is large. This option allows for a little more tolerance when the strings are large. It is not an appropriate test when comparing fixed length fields such as phone and social security numbers. ind_c[1] All lower case characters are converted to upper case prior to the comparison. Disabling this feature means that the lower case string "code" will not be recognized as the same as the upper case string "CODE". Also, the adjustment for similar characters section only applies to uppercase characters. The suggested values are all zeros for character strings such as names. */ static int pass=0, adjwt[91][91]; static char sp[39][2] = {'A','E', 'A','I', 'A','O', 'A','U', 'B','V', 'E','I', 'E','O', 'E','U', 'I','O', 'I','U', 'O','U', 'I','Y', 'E','Y', 'C','G', 'E','F', 'W','U', 'W','V', 'X','K', 'S','Z', 'X','S', 'Q','C', 'U','V', 'M','N', 'L','I', 'Q','O', 'P','R', 'I','J', '2','Z', '5','S', '8','B', '1','I', '1','L', '0','O', '0','Q', 'C','K', 'G','J', 'E',' ', 'Y',' ', 'S',' '}; char ying_hold[MAX_VAR_SIZE], yang_hold[MAX_VAR_SIZE], ying_flag[MAX_VAR_SIZE], yang_flag[MAX_VAR_SIZE]; double weight, Num_sim; long minv, search_range, lowlim, ying_length, hilim, N_trans, Num_com, yang_length; int yl1, yi_st, N_simi; register int i, j, k; /* Initialize the adjwt array on the first call to the function only. The adjwt array is used to give partial credit for characters that may be errors due to known phonetic or character recognition errors. A typical example is to match the letter "O" with the number "0" */ if (!pass) { pass++; for (i=0; i<91; i++) for (j=0; j<91; j++) adjwt[i][j] = 0; for (i=0; i<36; i++) { char i0 = sp[i][0]; char i1 = sp[i][1]; // printf("indices sp[%d][0]=%c, sp[%d][1]=%c\n", i, i0, i, i1); // printf(" adjwt[%d][%d]=3, adjwt[%d][%d]=3\n", i0, i1, i1, i0); adjwt[sp[i][0]][sp[i][1]] = 3; adjwt[sp[i][1]][sp[i][0]] = 3; } } /* If either string is blank - return - added in Version 2 */ if (!strncmp(ying,NULL60,y_length)) return(0.0); if (!strncmp(yang,NULL60,y_length)) return(0.0); /* Identify the strings to be compared by stripping off all leading and trailing spaces. */ k = y_length - 1; for(j = 0;((ying[j]==' ') && (j < k));j++); for(i = k;((ying[i]==' ') && (i > 0));i--); ying_length = i + 1 - j; yi_st = j; printf("\n"); printf("ying start: %d\n", yi_st); printf("ying length: %ld\n", ying_length); for(j = 0;((yang[j]==' ') && (j < k));j++); for(i = k;((yang[i]==' ') && (i > 0));i--); yang_length = i + 1 - j; printf("yang start: %d\n", j); printf("yang length: %ld\n", yang_length); ying_hold[0]=yang_hold[0]=0; strncat(ying_hold,&ying[yi_st],ying_length); strncat(yang_hold,&yang[j],yang_length); if (ying_length > yang_length) { search_range = ying_length; minv = yang_length; } else { search_range = yang_length; minv = ying_length; } /* If either string is blank - return */ /* if (!minv) return(0.0); removed in version 2 */ /* Blank out the flags */ ying_flag[0] = yang_flag[0] = 0; strncat(ying_flag,NULL60,search_range); strncat(yang_flag,NULL60,search_range); search_range = (search_range/2) - 1; if (search_range < 0) search_range = 0; /* added in version 2 */ /* Convert all lower case characters to upper case. */ if (!ind_c[1]) { for (i = 0;i < ying_length;i++) if (islower(ying_hold[i])) ying_hold[i] -= 32; for (j = 0;j < yang_length;j++) if (islower(yang_hold[j])) yang_hold[j] -= 32; } printf("Search range: %ld\n", search_range); printf("Minv: %ld\n", minv); printf("ying hold: '%s'\n", ying_hold); printf("yang hold: '%s'\n", yang_hold); printf("\n"); /* Looking only within the search range, count and flag the matched pairs. */ Num_com = 0; yl1 = yang_length - 1; for (i = 0;i < ying_length;i++) { lowlim = (i >= search_range) ? i - search_range : 0; hilim = ((i + search_range) <= yl1) ? (i + search_range) : yl1; printf("%d. Looking for char %c in range [%ld, %ld (incl)]\n", i, ying_hold[i],lowlim, hilim); for (j = lowlim;j <= hilim;j++) { printf(" j:%2d char: %c\n", j, yang_hold[j]); if ((yang_flag[j] != '1') && (yang_hold[j] == ying_hold[i])) { yang_flag[j] = '1'; ying_flag[i] = '1'; Num_com++; break; } } } printf("Num com: %ld\n", Num_com); printf("ying flag: '%s'\n", ying_flag); printf("yang flag: '%s'\n", yang_flag); /* If no characters in common - return */ if (!Num_com) return(0.0); /* Count the number of transpositions */ k = N_trans = 0; for (i = 0;i < ying_length;i++) { if (ying_flag[i] == '1') { for (j = k;j < yang_length;j++) { if (yang_flag[j] == '1') { k = j + 1; break; } } if (ying_hold[i] != yang_hold[j]) N_trans++; } } printf("Transpositions: %ld\n", N_trans); N_trans = N_trans / 2; weight= Num_com / ((double) ying_length) + Num_com / ((double) yang_length) + ((double) (Num_com - N_trans)) / ((double) Num_com); weight = weight / 3.0; printf("First weight: %.6f\n", weight); /* adjust for similarities in nonmatched characters */ N_simi = 0; if (minv > Num_com) { for (i = 0;i < ying_length;i++) { if (ying_flag[i] == ' ' && INRANGE(ying_hold[i])) { for (j = 0;j < yang_length;j++) { if (yang_flag[j] == ' ' && INRANGE(yang_hold[j])) { if (adjwt[ying_hold[i]][yang_hold[j]] > 0) { N_simi += adjwt[ying_hold[i]][yang_hold[j]]; yang_flag[j] = '2'; break; } } } } } } Num_sim = ((double) N_simi)/10.0 + Num_com; printf("N_simi : %d\n", N_simi); printf("Num sim: %.6f\n", Num_sim); printf("ying flag: '%s'\n", ying_flag); printf("yang flag: '%s'\n", yang_flag); /* Main weight computation. */ weight= Num_sim / ((double) ying_length) + Num_sim / ((double) yang_length) + ((double) (Num_com - N_trans)) / ((double) Num_com); weight = weight / 3.0; printf("Weight: %.6f\n", weight); /* Continue to boost the weight if the strings are similar */ if (weight > 0.7) { /* Adjust for having up to the first 4 characters in common */ j = (minv >= 4) ? 4 : minv; for (i=0;((i<j)&&(ying_hold[i]==yang_hold[i])&&(NOTNUM(ying_hold[i])));i++) printf("pre-match: %d\n", i); if (i) { printf("final pre-match: %d\n", i); weight += i * 0.1 * (1.0 - weight); } printf("Adjusted weight: %.6f\n", weight); /* Optionally adjust for long strings. */ /* After agreeing beginning chars, at least two more must agree and the agreeing characters must be > .5 of remaining characters. */ if ((!ind_c[0]) && (minv>4) && (Num_com>i+1) && (2*Num_com>=minv+i)) if (NOTNUM(ying_hold[0])) { weight += (double) (1.0-weight) * ((double) (Num_com-i-1) / ((double) (ying_length+yang_length-i*2+2))); printf("Re-adjusted weight: %.6f\n", weight); } } return(weight); } /* strcmp95 */
void HsvJNode::judge(const Result *result) { Result& myResult = this->result; myResult.setImage(result->getImage()); cvCvtColor(result->getImage(), hsvImage, CV_BGR2HSV); BgrImage hsvImage = this->hsvImage; int max_points = -1, curMaskIdx = 1; for(std::list<HsvSample>::iterator t = samples.begin(); t != samples.end(); ++t) { HsvSample &sample = *t; int cur_points = 0, nextMaskIdx = (curMaskIdx+1)%2; BwImage nextMask = masks[nextMaskIdx]; for(int i = 0; i < height; ++i) for(int j = 0; j < width; ++j) { BgrPixel &p = hsvImage[i][j]; int h = p.b * 2; unsigned char s = p.g, v = p.r; if(INRANGE(h, sample.h_min, sample.h_max) && INRANGE(s, sample.s_min, sample.s_max) && INRANGE(v, sample.v_min, sample.v_max)) { ++cur_points; nextMask[i][j] = 255; } else nextMask[i][j] = 0; } //cvMorphologyEx(tempFireRegion, tempFireRegion, NULL, structuringElement, CV_MOP_OPEN); //cvMorphologyEx(tempFireRegion, tempFireRegion, NULL, structuringElement, CV_MOP_CLOSE); //for(size_t i = 0; i < height; ++i) for(size_t j = 0; j < width; ++j) if(fireWrapper[i][j] != 0) ++cur_points; if(cur_points > max_points) { max_points = cur_points; curMaskIdx = nextMaskIdx; //if(fireRegion != NULL)cvReleaseImage(&fireRegion); //fireRegion = cvCloneImage(tempFireRegion); } } /* int max_points = -1; for(std::list<HsvSample>::iterator t = samples.begin(); t != samples.end(); ++t) { HsvSample &sample = *t; int cur_points = 0; for(size_t i = 0; i < height; ++i) for(size_t j = 0; j < width; ++j) { BgrPixel &p = hsvWrapper[i][j]; int h = p.b * 2; unsigned char s = p.g, v = p.r; if(INRANGE(h, sample.h_min, sample.h_max) && INRANGE(s, sample.s_min, sample.s_max) && INRANGE(v, sample.v_min, sample.v_max)) fireWrapper[i][j] = 255; else fireWrapper[i][j] = 0; } cvMorphologyEx(tempFireRegion, tempFireRegion, NULL, structuringElement, CV_MOP_OPEN); cvMorphologyEx(tempFireRegion, tempFireRegion, NULL, structuringElement, CV_MOP_CLOSE); for(size_t i = 0; i < height; ++i) for(size_t j = 0; j < width; ++j) if(fireWrapper[i][j] != 0) ++cur_points; if(cur_points > max_points) { max_points = cur_points; if(fireRegion != NULL)cvReleaseImage(&fireRegion); fireRegion = cvCloneImage(tempFireRegion); } } */ myResult.setMask(masks[curMaskIdx]); if(show_info) { cvShowImage(name.c_str(), myResult.getMask()); } }