Пример #1
0
// Parse triples: i, i/j/k, i//k, i/j
static vertex_index parseTriple(const char* &token, int vsize, int vnsize, int vtsize)
{
    vertex_index vi(-1);
    
    vi.v_idx = fixIndex(atoi(token), vsize);
    token += strcspn(token, "/ \t\r");
    if (token[0] != '/') {
        return vi;
    }
    token++;
    
    // i//k
    if (token[0] == '/') {
        token++;
        vi.vn_idx = fixIndex(atoi(token), vnsize);
        token += strcspn(token, "/ \t\r");
        return vi;
    }
    
    // i/j/k or i/j
    vi.vt_idx = fixIndex(atoi(token), vtsize);
    token += strcspn(token, "/ \t\r");
    if (token[0] != '/') {
        return vi;
    }
    
    // i/j/k
    token++;  // skip '/'
    vi.vn_idx = fixIndex(atoi(token), vnsize);
    token += strcspn(token, "/ \t\r");
    return vi;
}
Пример #2
0
// Sets 'blockpos' to point to the next block segment for the inode (and moves onto the
// next block descriptor inode if necessary)
int blockSeekNextSegment(pfs_cache_t *clink, pfs_blockpos_t *blockpos)
{
	pfs_cache_t *nextSegment;
	int result=0;

	if (blockpos->byte_offset)   
	{
		printf("ps2fs: Panic: This is a bug!\n");
		return -1;
	}

	// If we're at the end of the block descriptor array for the current
	// inode, then move onto the next inode
	if (fixIndex(blockpos->block_segment+1)==0)
	{
		if ((nextSegment=blockGetNextSegment(cacheUsedAdd(blockpos->inode), &result)) == NULL)
			return result;
		cacheAdd(blockpos->inode);
		blockpos->inode=nextSegment;
		if (clink->u.inode->number_data-1 == ++blockpos->block_segment)
			return -EINVAL;
	}

	blockpos->block_offset=0;
	blockpos->block_segment++;
	return result;
}
Пример #3
0
PyObjectHandle LuaToPythonConverter::convertToBytes(lua_State* L, int index) {
  fixIndex(L, index);

  if (auto ref = getOpaqueRef(L, index)) {
    // Must convert to a Python bytes object.
    if (PyBytes_Check(ref->obj.get())) {
      return ref->obj;
    } else if (PyUnicode_Check(ref->obj.get())) {
      PyObjectHandle obj(PyUnicode_AsUTF8String(ref->obj.get()));
      checkPythonError(obj, L, "convertToBytes(unicode)");
      return obj;
    } else {
      luaL_error(L, "neither bytes nor unicode");
    }
  }

  int type = lua_type(L, index);
  if (type != LUA_TSTRING) {
    luaL_error(L, "Invalid type for convertToBytes: %d", type);
  }

  size_t len;
  const char* str = lua_tolstring(L, index, &len);
  PyObjectHandle obj(PyBytes_FromStringAndSize(str, len));
  checkPythonError(obj, L, "convertToBytes");
  return obj;
}
Пример #4
0
PyObjectHandle LuaToPythonConverter::convertToUnicode(lua_State* L, int index) {
  fixIndex(L, index);

  if (auto ref = getOpaqueRef(L, index)) {
    // Must convert to a Python unicode object.
    if (PyBytes_Check(ref->obj.get())) {
      char* data = PyBytes_AS_STRING(ref->obj.get());
      Py_ssize_t len = PyBytes_GET_SIZE(ref->obj.get());
      PyObjectHandle obj(PyUnicode_DecodeUTF8(data, len, "strict"));
      checkPythonError(obj, L, "convertToUnicode(bytes)");
      return obj;
    } else if (PyUnicode_Check(ref->obj.get())) {
      return ref->obj;
    } else {
      luaL_error(L, "neither bytes nor unicode");
    }
  }

  int type = lua_type(L, index);
  if (type != LUA_TSTRING) {
    luaL_error(L, "Invalid type for convertToUnicode: %d", type);
  }

  size_t len;
  const char* str = lua_tolstring(L, index, &len);
  PyObjectHandle obj(PyUnicode_DecodeUTF8(str, len, "strict"));
  checkPythonError(obj, L, "convertToUnicdoe");
  return obj;
}
void VisualizationDrawer::paintFixations(){

    fixationsPixmap.fill(Qt::white);
    QPainter painter(&fixationsPixmap);

    double increment = _samplesPerFragment / fixationsPixmap.height();

    int counter = 0;
    QFont font=painter.font() ;
    font.setPointSize ( 8 );
    painter.setFont(font);

    std::stringstream number;
    number.str("");

    double posStart = 0;
    double posEnd = 0;

    int auxIndex = 0;
    if (fixAllM->n_rows > 0){
        uvec fixIndex =  arma::find(fixAllM->col(FIXCOL_END) >= _currentFragmentStartIndex);

        if (!fixIndex.is_empty()){
            auxIndex = fixIndex(0);
        }else{
            auxIndex = fixAllM->n_rows ;
        }

    }

    for (uword i = auxIndex; i < fixAllM->n_rows  ; i++){
        if ((fixAllM->at(i,FIXCOL_START) >= _currentFragmentStartIndex && fixAllM->at(i,FIXCOL_START) <=  _currentFragmentEndIndex ) ||(fixAllM->at(i,FIXCOL_START) <= _currentFragmentStartIndex && fixAllM->at(i,FIXCOL_END) >= _currentFragmentStartIndex )){

            if (fixAllM->at(i,FIXCOL_START) <= _currentFragmentStartIndex && fixAllM->at(i,FIXCOL_END) >= _currentFragmentStartIndex ) // If it's a fixation that didn't end in the previous segment
                posStart = -1;
            else
                posStart = (fixAllM->at(i,FIXCOL_START) - _currentFragmentStartIndex ) * (1/increment);

            posEnd = ((fixAllM->at(i,FIXCOL_END) - _currentFragmentStartIndex ) * (1/increment)) - posStart;

            if (fixAllM->at(i,FIXCOL_SMOOTH_PURSUIT) == Consts::SMOOTHP_YES){
                painter.setBrush(QBrush("#ffbc00"));
            }else{
                painter.setBrush(QBrush("#1ac500"));
            }

            painter.drawRect(QRect( posStart ,25, posEnd,16));
            number.str("");
            number << counter;
            painter.drawText( QPoint(posStart,23), number.str().c_str() );

            counter ++; // Next fixation

        }else if (fixAllM->at(i,FIXCOL_END) >= _currentFragmentEndIndex){
            break;
        }
    }

    painter.end();
}
Пример #6
0
pfs_cache_t *getDentriesChunk(pfs_blockpos_t *position, int *result)
{
	pfs_blockinfo *bi;
	pfs_mount_t *pfsMount=position->inode->pfsMount;

	bi = &position->inode->u.inode->data[fixIndex(position->block_segment)];

	return cacheGetData(pfsMount, bi->subpart,
		 ((bi->number + position->block_offset) << pfsMount->inode_scale) +
		 position->byte_offset / metaSize, CACHE_FLAG_NOTHING, result);
}
Пример #7
0
// Attempt to expand the block segment 'blockpos' by 'count' blocks
int blockExpandSegment(pfs_cache_t *clink, pfs_blockpos_t *blockpos, u32 count)
{
	int ret;
	pfs_blockinfo *bi;

	if(fixIndex(blockpos->block_segment)==0)
		return 0;

	bi = &blockpos->inode->u.inode->data[fixIndex(blockpos->block_segment)];

	if ((ret = bitmapAllocateAdditionalZones(clink->pfsMount, bi, count)))
	{
		bi->count+=ret;
		clink->u.inode->number_blocks+=ret;
		blockpos->inode->flags |= CACHE_FLAG_DIRTY;
		clink->flags |= CACHE_FLAG_DIRTY;
	}

	return ret;
}
Пример #8
0
PyObjectHandle LuaToPythonConverter::convertToDict(lua_State* L, int index) {
  fixIndex(L, index);

  if (auto ref = getOpaqueRef(L, index)) {
    // There's no simple way to convert arbitrary mappings to dict.
    // Let's just bail out if it isn't a dict.
    checkPythonError(PyDict_Check(ref->obj.get()), L, "not a dict");
    return ref->obj;
  }

  return convertDictFromTable(L, index, false);
}
Пример #9
0
PyObjectHandle LuaToPythonConverter::convertToList(lua_State* L, int index) {
  fixIndex(L, index);

  if (auto ref = getOpaqueRef(L, index)) {
    // Must convert to a Python list
    PyObjectHandle list(PySequence_List(ref->obj.get()));
    checkPythonError(list, L, "cannot convert to list");
    return list;
  }

  return convertListFromTable(L, index, false);
}
Пример #10
0
PyObjectHandle LuaToPythonConverter::convertToTuple(lua_State* L, int index) {
  fixIndex(L, index);

  if (auto ref = getOpaqueRef(L, index)) {
    // Must convert to a Python tuple.
    PyObjectHandle tup(PySequence_Tuple(ref->obj.get()));
    checkPythonError(tup, L, "cannot convert to tuple");
    return tup;
  }

  return convertTupleFromTable(L, index, false);
}
Пример #11
0
PyObjectHandle LuaToPythonConverter::convertToFastSequence(lua_State* L,
                                                           int index) {
  fixIndex(L, index);

  if (auto ref = getOpaqueRef(L, index)) {
    // Must convert to a Python list or tuple
    PyObjectHandle seq(PySequence_Fast(ref->obj.get(), ""));
    checkPythonError(seq, L, "cannot convert to fast sequence");
    return seq;
  }

  return convertTupleFromTable(L, index, false);
}
Пример #12
0
/* fixa diverse opmoden
** postinc och predec
** minne,minne
*/
static void doOpModes(void)
{
	INPUT *in;
	OPERAND op1,op2,rop1,rop2;
	/* 1. l�s instruktion */
	in=READER();
	if(!in)
		return;

	switch(in->type) {
	case IS_INSTR:
		/* Eleminera PC relativt om m�jligt */
		in->data.instr.op1=fixPC(in->data.instr.op1);
		in->data.instr.op2=fixPC(in->data.instr.op2);
		op1=in->data.instr.op1;
		op2=in->data.instr.op2;
		/* 2. pre op 1 */
		fixPre(in,op1);
		/* 3. get op 1 */
		op1=fixIndex(in,op1);
		rop1=getOp(in,op1);
		/* 4. post op 1 */
		fixPost(in,op1);
		/* 5. pre op 2 */
		fixPre(in,op2);
		/* 6. instruktion */
		rop2=cleanOp(op2);
		rop2=fixIndex(in,rop2);
		genInstr(in,rop1,rop2);
		/* 7. post op 2 */
		fixPost(in,op2);
		break;
	default:
		output(in);
		break;
	}
}
Пример #13
0
PyObjectHandle LuaToPythonConverter::convertToInt(lua_State* L, int index) {
  fixIndex(L, index);

  if (auto ref = getOpaqueRef(L, index)) {
    PyObjectHandle obj(PyNumber_Int(ref->obj.get()));
    checkPythonError(obj, L, "convertToInt(ref)");
    return obj;
  }
  int type = lua_type(L, index);
  if (type != LUA_TNUMBER) {
    luaL_error(L, "Invalid type for convertToInt: %d", type);
  }
  double val = lua_tonumber(L, index);
  long lval = folly::to<long>(val);
  PyObjectHandle obj(PyInt_FromLong(lval));
  checkPythonError(obj, L, "convertToInt");
  return obj;
}
Пример #14
0
void test_fix_index(void)
{
    // Return value for 0 should be 0.
    TEST_CHECK(fixIndex(0, 12) == 0);

    // Return value for non 0-indexed value should become 0-indexed.
    TEST_CHECK(fixIndex(1, 12) == 0);
    TEST_CHECK(fixIndex(2, 12) == 1);

    // Return value for relative-indexed value should be offset from the total size.
    TEST_CHECK(fixIndex(-1, 12) == 11);
    TEST_CHECK(fixIndex(-12, 12) == 0);
    TEST_CHECK(fixIndex(-13, 12) == -1); // TODO: should the result be clamped to 0?
}
void DialogVideoPlayer::paintCurrentVisualizationFrame() {


    bool show_fixation_numbers = true;

    QPixmap pixmap(display_width, display_height);
    pixmap.fill(Qt::transparent);
    QPainter painter(&pixmap);


    QPen myPen(QColor(0,0,0,127), 1, Qt::SolidLine);
    myPen.setCapStyle(Qt::RoundCap);
    painter.setPen(myPen);

    if (show_fixation_numbers && p_fixAllM->n_rows > 0) {
        QFont serifFont("Times", 64, QFont::Bold);
        painter.setFont(serifFont);
        uvec fixIndex =  arma::find((*p_fixAllM).col(FIXCOL_START) <= currentIndex);
        mat aux = (*p_fixAllM).rows(fixIndex);
        fixIndex =  arma::find(aux.col(FIXCOL_END) >= currentIndex);
        if (fixIndex.n_rows != 0) {
            painter.drawText( QRect(0, 0, display_width, display_height), Qt::AlignCenter, QString::number(fixIndex(0)) );
        }
    }


    mat *matrixToUse = settingPlaySmooth ? p_smoothM : p_roughM;

    if (matrixToUse->is_empty()) return;

    QPen *pensToUse = settingPlaySmooth ? smoothPens : roughPens;
    int nPensToUse = settingPlaySmooth ? 1 : 2;
    double width_multi = settingPlaySmooth ? (double)display_width / (double)expWidth : display_width;
    double height_multi = settingPlaySmooth ? (double)display_height / (double)expHeight : display_height;

    for(int i = 0; i < nPensToUse; ++i) {
        myPen.setColor(pensToUse[i * 2].color());

        // Pupil width
        if (p_roughM->n_cols >= 8 && p_roughM->at(currentIndex, 6) > 0 && p_roughM->at(currentIndex, 7) > 0) {
            double width = (p_roughM->at(currentIndex, 6) + p_roughM->at(currentIndex, 7)) / 6;
            int penWidth = (int)floor(width * actualDotSize);
            myPen.setWidth(penWidth);
        } else {
            myPen.setWidth(actualDotSize);
        }



        uword index = 2 * (i + 1);
        int x = matrixToUse->at(currentIndex, index) * width_multi;
        int y = matrixToUse->at(currentIndex, index + 1) * height_multi;

        painter.setPen(myPen);
        painter.drawPoint(x,y);
        painter.setPen(whitePen);
        painter.drawPoint(x,y);
    }


    painter.end();
    visualizationPixmapItem->setPixmap(pixmap);

}
Пример #16
0
// Attempts to allocate 'blocks' new blocks for an inode
int blockAllocNewSegment(pfs_cache_t *clink, pfs_blockpos_t *blockpos, u32 blocks)
{
	pfs_blockinfo bi, *bi2;
	int result=0;
	pfs_mount_t *pfsMount=clink->pfsMount;
	u32 i, old_blocks = blocks;

	dprintf2("ps2fs CALL: allocNewBlockSegment(, , %ld)\n", blocks);

	if (cacheIsFull())
		return -ENOMEM;

	// create "indirect segment descriptor" if necessary
	if (fixIndex(clink->u.inode->number_data) == 0)
	{
		pfs_cache_t *clink2;

		bi2 = &blockpos->inode->u.inode->data[fixIndex(blockpos->block_segment)];
		bi.subpart=bi2->subpart;
		bi.count=1;
		bi.number=bi2->number+bi2->count;
		result=searchFreeZone(pfsMount, &bi, clink->u.inode->number_blocks);
		if (result<0)
		{
			dprintf("ps2fs: Error: Couldnt allocate zone! (1)\n");
			return result;
		}

		clink2=cacheGetData(pfsMount, bi.subpart, bi.number << pfsMount->inode_scale,
								CACHE_FLAG_SEGI | CACHE_FLAG_NOLOAD, &result);
		memset(clink2->u.inode, 0, sizeof(pfs_inode));
		clink2->u.inode->magic=PFS_SEGI_MAGIC;

		memcpy(&clink2->u.inode->inode_block, &clink->u.inode->inode_block, sizeof(pfs_blockinfo)); 
		memcpy(&clink2->u.inode->last_segment, &blockpos->inode->u.inode->data[0], sizeof(pfs_blockinfo));
		memcpy(&clink2->u.inode->data[0], &bi, sizeof(pfs_blockinfo));

		clink2->flags |= CACHE_FLAG_DIRTY;

		clink->u.inode->number_blocks+=bi.count;
		clink->u.inode->number_data++;

		memcpy(&clink->u.inode->last_segment, &bi, sizeof(pfs_blockinfo));

		clink->u.inode->number_segdesg++;

		clink->flags |= CACHE_FLAG_DIRTY;
		blockpos->block_segment++;
		blockpos->block_offset=0;

		memcpy(&blockpos->inode->u.inode->next_segment, &bi, sizeof(pfs_blockinfo));

		blockpos->inode->flags |= CACHE_FLAG_DIRTY;
		cacheAdd(blockpos->inode);
		blockpos->inode=clink2;
	}

	bi2 = &blockpos->inode->u.inode->data[fixIndex(blockpos->block_segment)];
	bi.subpart = bi2->subpart;
	bi.count = blocks;
	bi.number = bi2->number + bi2->count;

	result = searchFreeZone(pfsMount, &bi, clink->u.inode->number_blocks);
	if(result < 0)
	{
		dprintf("ps2fs: Error: Couldnt allocate zone! (2)\n");
		return result;
	}

	clink->u.inode->number_blocks += bi.count;
	clink->u.inode->number_data++;
	clink->flags |= CACHE_FLAG_DIRTY;
	blockpos->block_offset=0;
	blockpos->block_segment++;

	i = fixIndex(clink->u.inode->number_data-1);
	memcpy(&blockpos->inode->u.inode->data[i], &bi, sizeof(pfs_blockinfo));

	blockpos->inode->flags |= CACHE_FLAG_DIRTY;
	blocks -= bi.count;
	if (blocks)
		blocks -= blockExpandSegment(clink, blockpos, blocks);

	return old_blocks - blocks;
}
void DialogVideoPlayer::paintFixations() {

    QPixmap fixationsPixmap = QPixmap(ui->fixationsView->width(), ui->fixationsView->height());
    fixationsPixmap.fill(Qt::white);
    QPainter painter(&fixationsPixmap);

    double positionMultiplier = (double)ui->fixationsView->width() / (double)samplesPerFragment;

    int counter = 0;
    QFont font = painter.font() ;
    font.setPointSize ( 8 );
    painter.setFont(font);

    std::stringstream number;
    number.str("");

    double posStart = 0;
    double posEnd = 0;

    uword start_index = currentFragment * samplesPerFragment;
    uword end_index = start_index + samplesPerFragment;

    int auxIndex = 0;
    if (p_fixAllM->n_rows > 0) {
        uvec fixIndex =  arma::find(p_fixAllM->col(FIXCOL_END) >= start_index);

        if (!fixIndex.is_empty()) {
            auxIndex = fixIndex(0);
        } else {
            auxIndex = p_fixAllM->n_rows ;
        }

    }

    for (uword i = auxIndex; i < p_fixAllM->n_rows  ; i++) {

        bool fixation_starts_after_fragment_start = p_fixAllM->at(i, FIXCOL_START) >= start_index;
        bool fixation_starts_before_fragment_end = p_fixAllM->at(i, FIXCOL_START) <=  end_index;
        bool fixation_starts_before_fragment_start = p_fixAllM->at(i, FIXCOL_START) <= start_index;
        bool fixation_ends_after_fragment_start = p_fixAllM->at(i, FIXCOL_END) >= start_index;

        if ((fixation_starts_after_fragment_start && fixation_starts_before_fragment_end) ||
                (fixation_starts_before_fragment_start && fixation_ends_after_fragment_start)) {

            // If it's a fixation that didn't end in the previous segment
            if (fixation_starts_before_fragment_start && fixation_ends_after_fragment_start )
                posStart = -1;
            else
                posStart = (p_fixAllM->at(i, FIXCOL_START) - start_index ) * positionMultiplier;


            posEnd = ((p_fixAllM->at(i, FIXCOL_END) - start_index ) * positionMultiplier) - posStart;

            if (p_fixAllM->at(i, FIXCOL_SMOOTH_PURSUIT) == Consts::SMOOTHP_YES) {
                painter.setBrush(QBrush("#ffbc00"));
            } else {
                painter.setBrush(QBrush("#1ac500"));
            }

            painter.drawRect(QRect(posStart, 12, posEnd, 16));
            number.str("");
            number << counter;
            painter.drawText( QPoint(posStart, 9), number.str().c_str() );

            counter ++; // Next fixation

        } else if (p_fixAllM->at(i, FIXCOL_END) >= end_index) {
            break;
        }
    }

    painter.end();
    fixationsPixmapItem->setPixmap(fixationsPixmap);
}
Пример #18
0
// Returns the block info for the block segment corresponding to the
// files current position.
pfs_blockinfo* blockGetCurrent(pfs_blockpos_t *blockpos)
{
	return &blockpos->inode->u.inode->data[fixIndex(blockpos->block_segment)];
}
Пример #19
0
void ioctl2Free(pfs_cache_t *pfree)
{
	pfs_blockinfo b;
	int result;
	pfs_mount_t *pfsMount = pfree->pfsMount;
	pfs_inode *inode = pfree->u.inode;
	u32 nextsegdesc = 1, limit = inode->number_data, i, j = 0, zones;
	pfs_blockinfo *bi;
	pfs_cache_t *clink;

	zones = inode->size / pfsMount->zsize;
	if(inode->size % pfsMount->zsize)
		zones++;
	if(inode->number_segdesg + zones == inode->number_blocks)
		return;

	j = zones;
	b.number = 0;
	clink = cacheUsedAdd(pfree);

	// iterate through each of the block segments used by the inode
	for (i = 1; i < limit && j; i++)
	{
		if(fixIndex(i) == 0)
		{
			if ((clink = blockGetNextSegment(clink, &result)) == 0)
				return;

			nextsegdesc++;
		}
		else
			if(j < clink->u.inode->data[fixIndex(i)].count)
			{
				clink->u.inode->data[fixIndex(i)].count -= j;
				b.subpart = clink->u.inode->data[fixIndex(i)].subpart;
				b.count = j;
				b.number = clink->u.inode->data[fixIndex(i)].number +
					clink->u.inode->data[fixIndex(i)].count;
				j = 0;
				clink->flags |= CACHE_FLAG_DIRTY;
			}
			else
				j -= clink->u.inode->data[fixIndex(i)].count;
	}

	pfree->u.inode->number_data = i;
	pfree->u.inode->number_blocks = zones + nextsegdesc;
	pfree->u.inode->number_segdesg = nextsegdesc;
	pfree->u.inode->last_segment.number = clink->u.inode->data[0].number;
	pfree->u.inode->last_segment.subpart= clink->u.inode->data[0].subpart;
	pfree->u.inode->last_segment.count  = clink->u.inode->data[0].count;
	pfree->flags |= CACHE_FLAG_DIRTY;

	if (b.number)
		bitmapFreeBlockSegment(pfsMount, &b);

	while(i < limit)
	{
		if (fixIndex(i) == 0)
		{
			if((clink = blockGetNextSegment(clink, &result)) == 0)
				return;
		}
		bi = &clink->u.inode->data[fixIndex(i++)];
		bitmapFreeBlockSegment(pfsMount, bi);
		cacheMarkClean(pfsMount, bi->subpart, bi->number<<pfsMount->inode_scale,
			(bi->number+bi->count)<<pfsMount->inode_scale);
	}

	cacheAdd(clink);
}