Пример #1
0
i32 RecME::BlockDiff(byte *pbInput0, i32 iStride0, byte *pbInput1, i32 iStride1, i32 iBlockSize, i32 iSkipPel)
{
	
        
//    for (int i = 0; i<OpTypeVec.size(); i++) {
//      int result = myOp[i]->calc(var1, var2); 
//        printf("this is the return value %d\n", result);
//    }
//
    byte *pbIn0, *pbIn1;
	i32 iSAD = 0;
	for(i32 y=0;y<iBlockSize;y+=(1+iSkipPel))
	{
		m_iNumSADs++;
//        pbIn0 = (myOp[0]->calc_ref(pbInput0, y*iStride0);
//        pbIn1 = myOp[1]->calc_ref(pbInput1, y*iStride0);
		pbIn0 = pbInput0 + y*iStride0;
		pbIn1 = pbInput1 + y*iStride0;
        for(i32 x=0;x<iBlockSize;x+=(1+iSkipPel)){
            i32 iSADtemp = ABS(myOp[2]->calc(i32(pbIn0[x]), -1*i32(pbIn1[x]))); //AdditionOp 
            iSAD = myOp[3]->calc(iSAD, iSADtemp);	//AdditionOp 
        }
     }	
    return iSAD;
}
Пример #2
0
Expr CodeGen_X86::mulhi_shr(Expr a, Expr b, int shr) {
    Type ty = a.type();
    if (ty.is_vector() && ty.bits() == 16) {
        // We can use pmulhu for this op.
        Expr p;
        if (ty.is_uint()) {
            p = u16(u32(a) * u32(b) / 65536);
        } else {
            p = i16(i32(a) * i32(b) / 65536);
        }
        if (shr) {
            p = p >> shr;
        }
        return p;
    }
Пример #3
0
/*==============================================================================
 * FUNCTION:        DfaTest::testMeetPointer
 * OVERVIEW:        Test meeting IntegerTypes with various other types
 *============================================================================*/
void DfaTest::testMeetPointer()
{
    IntegerType i32(32, 1);
    IntegerType u32(32, -1);
    PointerType pi32(&i32);
    PointerType pu32(&u32);
    VoidType v;

    std::ostringstream ost1;
    ost1 << pu32.getCtype();
    std::string actual(ost1.str());
    std::string expected("unsigned int *");
    CPPUNIT_ASSERT_EQUAL(expected, actual);

    bool ch = false;
    Type *res = pi32.meetWith(&pu32, ch, false);
    CPPUNIT_ASSERT(ch == true);
    std::ostringstream ost2;
    ost2 << res->getCtype();
    actual = ost2.str();
    expected = "/*signed?*/int *";
    CPPUNIT_ASSERT_EQUAL(expected, actual);

    ch = false;
    res = pi32.meetWith(&v, ch, false);
    CPPUNIT_ASSERT(ch == false);

    res = pi32.meetWith(&i32, ch, false);
    std::ostringstream ost3;
    ost3 << res;
    actual = ost3.str();
    expected = "union";
    CPPUNIT_ASSERT_EQUAL(expected, actual);
}
Пример #4
0
void fire(WeaponType const& self, State& state, TransientState& transient_state, Scalar angle, Vector2 vel, Vector2 pos, i16 owner) {

	//auto& mod = state.mod;

	if (owner >= 0) {
		auto& worm = state.worms.of_index(owner);
		worm.muzzle_fire = self.muzzle_fire();
	}


	
	/*
	if(w.leaveShells > 0) <--
	{
		if(game.rand(w.leaveShells) == 0)
		{
			leaveShellTimer = w.leaveShellDelay;
		}
	}
	
	if(w.launchSound >= 0)
	{
		if(w.loopSound)
		{
			if(!game.soundPlayer->isPlaying(&weapons[currentWeapon]))
			{
				game.soundPlayer->play(w.launchSound, &weapons[currentWeapon], -1);
			}
		}
		else
		{
			game.soundPlayer->play(w.launchSound);
		}
	}
	*/

	// TODO: Looping?
	transient_state.play_sound(state.mod, self.fire_sound(), transient_state);

	auto dir = sincos(angle);
	auto anglevel = vel * self.worm_vel_ratio() + dir * self.speed();

	pos += dir * i32(self.fire_offset());

	auto& ty = state.mod.get_nobject_type(self.nobject_type());

	u32 lparts = self.parts();
	for (u32 i = 0; i < lparts; ++i) {

		auto part_vel = anglevel;

		if (self.distribution() != Ratio()) {

			part_vel += rand_max_vector2(state.rand, self.distribution());
		}

		create(ty, state, angle, pos, part_vel, owner);
	}
}
Пример #5
0
static int get_integer(char** ptr, int* len, int* value)
{
    char* src = *ptr;

    if ((*src != INTL_INTEGER) || (*len < 5))
	return -1;
    *value = i32(src+1);
    *ptr = src+5;
    *len = *len-5;
    return 0;
}
Пример #6
0
static bool WriteCharacters(ZFile& File, ZCharacterManager& CharacterManager)
{
	auto CharacterCount = i32(CharacterManager.size());
	WRITE(CharacterCount);

	for (auto& Item : CharacterManager)
	{
		auto Char = Item.second;
		ReplayPlayerInfo Info;
		Char->Save(Info);
		WRITE(Info);
	}

	return true;
}
Пример #7
0
/*==============================================================================
 * FUNCTION:        DfaTest::testMeetSize
 * OVERVIEW:        Test meeting IntegerTypes with various other types
 *============================================================================*/
void DfaTest::testMeetSize()
{
    IntegerType i32(32, 1);
    SizeType s32(32);
    SizeType s16(16);
    FloatType flt(32);
    VoidType v;

    bool ch = false;
    Type *res = s32.meetWith(&i32, ch, false);
    CPPUNIT_ASSERT(ch == true);
    std::ostringstream ost1;
    ost1 << res;
    std::string actual(ost1.str());
    std::string expected("i32");
    CPPUNIT_ASSERT_EQUAL(expected, actual);

    ch = false;
    res = s32.meetWith(&s16, ch, false);
    CPPUNIT_ASSERT(ch == false);

#if 0
    // There is a known failure here; to show the warning, use ErrLogger
    Boomerang::get()->setLogger(new ErrLogger);

    res = s16.meetWith(&flt, ch, false);
    CPPUNIT_ASSERT(ch == true);
    std::ostringstream ost2;
    ost2 << res;
    actual = ost2.str();
    expected = "union";
    CPPUNIT_ASSERT_EQUAL(expected, actual);
#endif

    ch = false;
    res = s16.meetWith(&v, ch, false);
    CPPUNIT_ASSERT(ch == false);
    std::ostringstream ost3;
    ost3 << res;
    actual = ost3.str();
    expected = "16";
    CPPUNIT_ASSERT_EQUAL(expected, actual);
}
Пример #8
0
fa_pair_t fa_buffer_read_audio(fa_string_t path)
{
    int             channels;
    buffer_t        buffer;

    SNDFILE         *file;
    SF_INFO         info;
    info.format     = 0;

    {
        char *cpath     = fa_string_to_utf8(path);
        //file            = sf_open(cpath, SFM_READ, &info);

//        if (sf_error(file)) {
//            char err[100];
//            snprintf(err, 100, "Could not read audio file '%s'", cpath);
//            return (pair_t) fa_error_create_simple(error, string(err), string("Doremir.Buffer"));
//        }

        inform(string_append(string("Reading "), path));
    }
    {
        size_t bufSize  = info.frames * info.channels * sizeof(double);
        buffer          = fa_buffer_create(bufSize);
        double *raw     = fa_buffer_unsafe_address(buffer);

        //sf_count_t sz   = sf_read_double(file, raw, bufSize / sizeof(double));
        //buffer          = fa_buffer_dresize(sz * sizeof(double), buffer);

        if (info.channels == 1) {
            channels = 1;
        } else if (info.channels == 2) {
            channels = 2;
        } else {
            buffer_fatal("Unknown buffer type", info.channels);
        }

//        if (sf_close(file)) {
//            return (pair_t) fa_error_create_simple(error, string("Could not close"), string("Doremir.Buffer"));
//        }
    }
    return pair(i32(channels), buffer);
}
Пример #9
0
/*==============================================================================
 * FUNCTION:        DfaTest::testMeetUnion
 * OVERVIEW:        Test meeting IntegerTypes with various other types
 *============================================================================*/
void DfaTest::testMeetUnion()
{
    UnionType u1;
    IntegerType i32(32, 1);
    IntegerType j32(32, 0);
    IntegerType u32(32, -1);
    FloatType flt(32);
    u1.addType(&i32, "bow");
    u1.addType(&flt, "wow");

    std::ostringstream ost1;
    ost1 << u1.getCtype();
    std::string actual(ost1.str());
    std::string expected("union { int bow; float wow; }");
    CPPUNIT_ASSERT_EQUAL(expected, actual);

    bool ch = false;
    Type *res = u1.meetWith(&j32, ch, false);
    CPPUNIT_ASSERT(ch == false);
    std::ostringstream ost2;
    ost2 << res->getCtype();
    actual = ost2.str();
    expected = "union { int bow; float wow; }";
    CPPUNIT_ASSERT_EQUAL(expected, actual);

    res = u1.meetWith(&j32, ch, false);
    CPPUNIT_ASSERT(ch == false);
    std::ostringstream ost3;
    ost3 << u1.getCtype();
    actual = ost3.str();
    expected = "union { int bow; float wow; }";
    CPPUNIT_ASSERT_EQUAL(expected, actual);

    // Note: this test relies on the int in the union having signedness 1
    res = u1.meetWith(&u32, ch, false);
    CPPUNIT_ASSERT(ch == true);
    std::ostringstream ost4;
    ost4 << u1.getCtype();
    actual = ost4.str();
    expected = "union { /*signed?*/int bow; float wow; }";
    CPPUNIT_ASSERT_EQUAL(expected, actual);
}
Пример #10
0
void ImageLibrary::addImage(char const* name, Image* image, bool big)
{
  Locker lock_(lock);
  if (images.has(name))
    return;

  String name16 = String::format("images\\%s.bin", name);
  File* file16 = mpq->openFile(name16, File::REWRITE);
  if (file16)
  {
    Image i16(16, 16);
    BLTInfo blt16(image);
    blt16.setDstSize(16, 16);
    i16.blt(blt16);
    i16.modBrightness(1.16f);
    i16.sharpen(0.08f);
    i16.writeBIN(file16);
    delete file16;
    loadImage(name16);
  }

  if (big)
  {
    String name32 = String::format("images\\big%s.bin", name);
    File* file32 = mpq->openFile(name32, File::REWRITE);
    if (file32)
    {
      Image i32(32, 32);
      BLTInfo blt32(image);
      blt32.setDstSize(32, 32);
      i32.blt(blt32);
      i32.modBrightness(1.16f);
  //    i32.sharpen(0.08f);
      i32.writeBIN(file32);
      delete file32;
      loadImage(name32);
    }
  }
}
Пример #11
0
//--------------------------------------------------------------------------------------------------
void q3Heap::Free( void *memory )
{
	assert( memory );
	q3Header* node = (q3Header*)Q3_PTR_ADD( memory, -i32( sizeof( q3Header ) ) );

	q3Header* next = node->next;
	q3Header* prev = node->prev;
	q3FreeBlock* nextBlock = NULL;
	i32 prevBlockIndex = ~0;
	q3FreeBlock* prevBlock = NULL;
	i32 freeBlockCount = m_freeBlockCount;

	for ( i32 i = 0; i < freeBlockCount; ++i )
	{
		q3FreeBlock* block = m_freeBlocks + i;
		q3Header* header = block->header;

		if ( header == next )
			nextBlock = block;

		else if ( header == prev )
		{
			prevBlock = block;
			prevBlockIndex = i;
		}
	}

	bool merged = false;

	if ( prevBlock )
	{
		merged = true;

		prev->next = next;
		if ( next )
			next->prev = prev;

		prevBlock->size += node->size;
		prev->size = prevBlock->size;

		if ( nextBlock )
		{
			nextBlock->header = prev;
			nextBlock->size += prev->size;
			prev->size = nextBlock->size;

			q3Header* nextnext = next->next;
			prev->next = nextnext;

			if ( nextnext )
				nextnext->prev = prev;

			// Remove the nextBlock from the freeBlocks array
			assert( m_freeBlockCount );
			assert( prevBlockIndex != ~0 );
			--m_freeBlockCount;
			m_freeBlocks[ prevBlockIndex ] = m_freeBlocks[ m_freeBlockCount ];
		}
	}

	else if ( nextBlock )
	{
		merged = true;

		nextBlock->header = node;
		nextBlock->size += node->size;
		node->size = nextBlock->size;

		q3Header* nextnext = next->next;

		if ( nextnext )
			nextnext->prev = node;

		node->next = nextnext;
	}

	if ( !merged )
	{
		q3FreeBlock block;
		block.header = node;
		block.size = node->size;

		if ( m_freeBlockCount == m_freeBlockCapacity )
		{
			q3FreeBlock* oldBlocks = m_freeBlocks;
			i32 oldCapacity = m_freeBlockCapacity;

			m_freeBlockCapacity *= 2;
			m_freeBlocks = (q3FreeBlock*)q3Alloc( sizeof( q3FreeBlock ) * m_freeBlockCapacity );

			memcpy( m_freeBlocks, oldBlocks, sizeof( q3FreeBlock ) * oldCapacity );
			q3Free( oldBlocks );
		}

		m_freeBlocks[ m_freeBlockCount++ ] = block;
	}
}
Пример #12
0
void Colorization::setScaledValue(PointBuffer& data,
                                  double value,
                                  Dimension const& d,
                                  std::size_t pointIndex) const
{

    float flt(0.0);
    boost::int8_t i8(0);
    boost::uint8_t u8(0);
    boost::int16_t i16(0);
    boost::uint16_t u16(0);
    boost::int32_t i32(0);
    boost::uint32_t u32(0);
    boost::int64_t i64(0);
    boost::uint64_t u64(0);


    boost::uint32_t size = d.getByteSize();
    switch (d.getInterpretation())
    {
        case dimension::Float:
            if (size == 4)
            {
                flt = static_cast<float>(value);
                data.setField<float>(d, pointIndex, flt);
            }
            if (size == 8)
            {
                data.setField<double>(d, pointIndex, value);
            }
            break;

        case dimension::SignedInteger:
        case dimension::SignedByte:
            if (size == 1)
            {
                i8 = d.removeScaling<boost::int8_t>(value);
                data.setField<boost::int8_t>(d, pointIndex, i8);
            }
            if (size == 2)
            {
                i16 = d.removeScaling<boost::int16_t>(value);
                data.setField<boost::int16_t>(d, pointIndex, i16);
            }
            if (size == 4)
            {
                i32 = d.removeScaling<boost::int32_t>(value);
                data.setField<boost::int32_t>(d, pointIndex, i32);
            }
            if (size == 8)
            {
                i64 = d.removeScaling<boost::int64_t>(value);
                data.setField<boost::int64_t>(d, pointIndex, i64);
            }
            break;

        case dimension::UnsignedInteger:
        case dimension::UnsignedByte:
            if (size == 1)
            {
                u8 = d.removeScaling<boost::uint8_t>(value);
                data.setField<boost::uint8_t>(d, pointIndex, u8);
            }
            if (size == 2)
            {
                u16 = d.removeScaling<boost::uint16_t>(value);
                data.setField<boost::uint16_t>(d, pointIndex, u16);
            }
            if (size == 4)
            {
                u32 = d.removeScaling<boost::uint32_t>(value);
                data.setField<boost::uint32_t>(d, pointIndex, u32);
            }
            if (size == 8)
            {
                u64 = d.removeScaling<boost::uint64_t>(value);
                data.setField<boost::uint64_t>(d, pointIndex, u64);
            }
            break;

        case dimension::Pointer:    // stored as 64 bits, even on a 32-bit box
        case dimension::Undefined:
            throw pdal_error("Dimension data type unable to be reprojected");

    }
}
Пример #13
0
double Colorization::getScaledValue(PointBuffer& data,
                                    Dimension const& d,
                                    std::size_t pointIndex) const
{
    double output(0.0);

    float flt(0.0);
    boost::int8_t i8(0);
    boost::uint8_t u8(0);
    boost::int16_t i16(0);
    boost::uint16_t u16(0);
    boost::int32_t i32(0);
    boost::uint32_t u32(0);
    boost::int64_t i64(0);
    boost::uint64_t u64(0);

    boost::uint32_t size = d.getByteSize();
    switch (d.getInterpretation())
    {
        case dimension::Float:
            if (size == 4)
            {
                flt = data.getField<float>(d, pointIndex);
                output = static_cast<double>(flt);
            }
            if (size == 8)
            {
                output = data.getField<double>(d, pointIndex);
            }
            break;

        case dimension::SignedInteger:
        case dimension::SignedByte:
            if (size == 1)
            {
                i8 = data.getField<boost::int8_t>(d, pointIndex);
                output = d.applyScaling<boost::int8_t>(i8);
            }
            if (size == 2)
            {
                i16 = data.getField<boost::int16_t>(d, pointIndex);
                output = d.applyScaling<boost::int16_t>(i16);
            }
            if (size == 4)
            {
                i32 = data.getField<boost::int32_t>(d, pointIndex);
                output = d.applyScaling<boost::int32_t>(i32);
            }
            if (size == 8)
            {
                i64 = data.getField<boost::int64_t>(d, pointIndex);
                output = d.applyScaling<boost::int64_t>(i64);
            }
            break;

        case dimension::UnsignedInteger:
        case dimension::UnsignedByte:
            if (size == 1)
            {
                u8 = data.getField<boost::uint8_t>(d, pointIndex);
                output = d.applyScaling<boost::uint8_t>(u8);
            }
            if (size == 2)
            {
                u16 = data.getField<boost::uint16_t>(d, pointIndex);
                output = d.applyScaling<boost::uint16_t>(u16);
            }
            if (size == 4)
            {
                u32 = data.getField<boost::uint32_t>(d, pointIndex);
                output = d.applyScaling<boost::uint32_t>(u32);
            }
            if (size == 8)
            {
                u64 = data.getField<boost::uint64_t>(d, pointIndex);
                output = d.applyScaling<boost::uint64_t>(u64);
            }
            break;

        case dimension::Pointer:    // stored as 64 bits, even on a 32-bit box
        case dimension::Undefined:
            throw pdal_error("Dimension data type unable to be reprojected");
    }

    return output;
}
Пример #14
0
static ErlDrvSSizeT zlib_ctl(ErlDrvData drv_data, unsigned int command, char *buf,
			     ErlDrvSizeT len, char **rbuf, ErlDrvSizeT rlen)
{
    ZLibData* d = (ZLibData*)drv_data;
    int res;

    switch(command) {
    case DEFLATE_INIT:
	if (len != 4) goto badarg;
	if (d->state != ST_NONE) goto badarg;
	res = deflateInit(&d->s, i32(buf));
	if (res == Z_OK) {
	    d->state = ST_DEFLATE;
	    d->want_crc = 0;
	    d->crc = crc32(0L, Z_NULL, 0);
	}
	return zlib_return(res, rbuf, rlen);

    case DEFLATE_INIT2: {
	int wbits;

	if (len != 20) goto badarg;
	if (d->state != ST_NONE) goto badarg;
	wbits = i32(buf+8);
	res = deflateInit2(&d->s, i32(buf), i32(buf+4), wbits, 
			   i32(buf+12), i32(buf+16));
	if (res == Z_OK) {
	    d->state = ST_DEFLATE;
	    d->want_crc = (wbits < 0);
	    d->crc = crc32(0L, Z_NULL, 0);
	}
	return zlib_return(res, rbuf, rlen);
    }
	
    case DEFLATE_SETDICT:
	if (d->state != ST_DEFLATE) goto badarg;
	res = deflateSetDictionary(&d->s, (unsigned char*)buf, len);
	if (res == Z_OK) {
	    return zlib_value(d->s.adler, rbuf, rlen);
	} else {
	    return zlib_return(res, rbuf, rlen);
	}

    case DEFLATE_RESET:
	if (len != 0) goto badarg;
	if (d->state != ST_DEFLATE) goto badarg;
	driver_deq(d->port, driver_sizeq(d->port));
	res = deflateReset(&d->s);
	return zlib_return(res, rbuf, rlen);	
	
    case DEFLATE_END:
	if (len != 0) goto badarg;
	if (d->state != ST_DEFLATE) goto badarg;
	driver_deq(d->port, driver_sizeq(d->port));
	res = deflateEnd(&d->s);
	d->state = ST_NONE;
	return zlib_return(res, rbuf, rlen);

    case DEFLATE_PARAMS:
	if (len != 8) goto badarg;
	if (d->state != ST_DEFLATE) goto badarg;
	res = deflateParams(&d->s, i32(buf), i32(buf+4));
	return zlib_return(res, rbuf, rlen);

    case DEFLATE:
	if (d->state != ST_DEFLATE) goto badarg;
	if (len != 4) goto badarg;
	res = zlib_deflate(d, i32(buf));
	return zlib_return(res, rbuf, rlen);

    case INFLATE_INIT:
	if (len != 0) goto badarg;
	if (d->state != ST_NONE) goto badarg;
	res = inflateInit(&d->s);
	if (res == Z_OK) {
	    d->state = ST_INFLATE;
	    d->inflate_eos_seen = 0;
	    d->want_crc = 0;
	    d->crc = crc32(0L, Z_NULL, 0);
	}
	return zlib_return(res, rbuf, rlen);	
	
    case INFLATE_INIT2: {
	int wbits;

	if (len != 4) goto badarg;	
	if (d->state != ST_NONE) goto badarg;
	wbits = i32(buf);
	res = inflateInit2(&d->s, wbits);
	if (res == Z_OK) {
	    d->state = ST_INFLATE;
	    d->inflate_eos_seen = 0;
	    d->want_crc = (wbits < 0);
	    d->crc = crc32(0L, Z_NULL, 0);
	}
	return zlib_return(res, rbuf, rlen);
    }
	
    case INFLATE_SETDICT:
	if (d->state != ST_INFLATE) goto badarg;
	res = inflateSetDictionary(&d->s, (unsigned char*)buf, len);
	return zlib_return(res, rbuf, rlen);

    case INFLATE_SYNC:
	if (d->state != ST_INFLATE) goto badarg;
	if (len != 0) goto badarg;
	if (driver_sizeq(d->port) == 0) {
	    res = Z_BUF_ERROR;
	} else {
	    int vlen;
	    SysIOVec* iov = driver_peekq(d->port, &vlen);

	    d->s.next_in = iov[0].iov_base;
	    d->s.avail_in = iov[0].iov_len;
	    res = inflateSync(&d->s);
	}
	return zlib_return(res, rbuf, rlen);

    case INFLATE_RESET:
	if (d->state != ST_INFLATE) goto badarg;
	if (len != 0) goto badarg;
	driver_deq(d->port, driver_sizeq(d->port));
	res = inflateReset(&d->s);
	d->inflate_eos_seen = 0;
	return zlib_return(res, rbuf, rlen);

    case INFLATE_END:
	if (d->state != ST_INFLATE) goto badarg;
	if (len != 0) goto badarg;
	driver_deq(d->port, driver_sizeq(d->port));
	res = inflateEnd(&d->s);
	if (res == Z_OK && d->inflate_eos_seen == 0) {
	    res = Z_DATA_ERROR;
	}
	d->state = ST_NONE;
	return zlib_return(res, rbuf, rlen);

    case INFLATE:
	if (d->state != ST_INFLATE) goto badarg;
	if (len != 4) goto badarg;
	res = zlib_inflate(d, i32(buf));
	if (res == Z_NEED_DICT) {
	    return zlib_value2(3, d->s.adler, rbuf, rlen);
	} else {
	    return zlib_return(res, rbuf, rlen);
	}

    case GET_QSIZE:
	return zlib_value(driver_sizeq(d->port), rbuf, rlen);

    case GET_BUFSZ:
	return zlib_value(d->binsz_need, rbuf, rlen);

    case SET_BUFSZ: {
	int need;
	if (len != 4) goto badarg;
	need = i32(buf);
	if ((need < 16) || (need > 0x00ffffff))
	    goto badarg;
	if (d->binsz_need != need) {
	    d->binsz_need = need;
	    if (d->bin != NULL) {
		if (d->s.avail_out == d->binsz) {
		    driver_free_binary(d->bin);
		    d->bin = NULL;
		    d->binsz = 0;
		}
		else
		    zlib_output(d);
	    }
	}
	return zlib_return(Z_OK, rbuf, rlen);
    }

    case CRC32_0:
	return zlib_value(d->crc, rbuf, rlen);

    case CRC32_1: {
	uLong crc = crc32(0L, Z_NULL, 0);
	crc = crc32(crc, (unsigned char*) buf, len);
	return zlib_value(crc, rbuf, rlen);
    }
	
    case CRC32_2: {
	uLong crc;
	if (len < 4) goto badarg;
	crc = (unsigned int) i32(buf);
	crc = crc32(crc, (unsigned char*) buf+4, len-4);
	return zlib_value(crc, rbuf, rlen);
    }

    case ADLER32_1: {
	uLong adler = adler32(0L, Z_NULL, 0);
	adler = adler32(adler, (unsigned char*) buf, len);
	return zlib_value(adler, rbuf, rlen);
    }
	
    case ADLER32_2: {
       uLong adler;
       if (len < 4) goto badarg;
       adler = (unsigned int) i32(buf);
       adler = adler32(adler, (unsigned char*) buf+4, len-4);
       return zlib_value(adler, rbuf, rlen);
    }

    case CRC32_COMBINE: {
       uLong crc, crc1, crc2, len2;
       if (len != 12) goto badarg;
       crc1 = (unsigned int) i32(buf);
       crc2 = (unsigned int) i32(buf+4);
       len2 = (unsigned int) i32(buf+8);
       crc = crc32_combine(crc1, crc2, len2);
       return zlib_value(crc, rbuf, rlen);
    }

    case ADLER32_COMBINE: {
       uLong adler, adler1, adler2, len2;
       if (len != 12) goto badarg;
       adler1 = (unsigned int) i32(buf);
       adler2 = (unsigned int) i32(buf+4);
       len2   = (unsigned int) i32(buf+8);
       adler  = adler32_combine(adler1, adler2, len2);
       return zlib_value(adler, rbuf, rlen);
    }       
    }

 badarg:
    errno = EINVAL;
    return zlib_return(Z_ERRNO, rbuf, rlen);
}
Пример #15
0
/*==============================================================================
 * FUNCTION:        DfaTest::testMeetInt
 * OVERVIEW:        Test meeting IntegerTypes with various other types
 *============================================================================*/
void DfaTest::testMeetInt()
{
    IntegerType i32(32, 1);
    IntegerType j32(32, 0);
    IntegerType u32(32, -1);
    IntegerType xint(0);
    IntegerType j16(16, 0);
    SizeType s32(32);
    SizeType s64(64);
    FloatType flt(32);
    PointerType pt(&flt);
    VoidType v;

    bool ch = false;
    i32.meetWith(&i32, ch, false);
    CPPUNIT_ASSERT(ch == false);
    std::ostringstream ost1;
    ost1 << &i32;
    std::string actual(ost1.str());
    std::string expected("i32");
    CPPUNIT_ASSERT_EQUAL(expected, actual);

    i32.meetWith(&j32, ch, false);
    CPPUNIT_ASSERT(ch == false);
    j32.meetWith(&i32, ch, false);
    CPPUNIT_ASSERT(ch == true);
    std::ostringstream ost2;
    ost2 << &i32;
    actual = ost2.str();
    expected = "i32";
    CPPUNIT_ASSERT_EQUAL(expected, actual);

    ch = false;
    j32.setSigned(0);
    j32.meetWith(&v, ch, false);
    CPPUNIT_ASSERT(ch == false);
    std::ostringstream ost2a;
    ost2a << &j32;
    actual = ost2a.str();
    expected = "j32";
    CPPUNIT_ASSERT_EQUAL(expected, actual);

    ch = false;
    j32.meetWith(&u32, ch, false);
    CPPUNIT_ASSERT(ch == true);
    std::ostringstream ost3;
    ost3 << &j32;
    actual = ost3.str();
    expected = "u32";
    CPPUNIT_ASSERT_EQUAL(expected, actual);

    ch = false;
    u32.meetWith(&s32, ch, false);
    CPPUNIT_ASSERT(ch == false);
    std::ostringstream ost4;
    ost4 << &u32;
    actual = ost4.str();
    expected = "u32";
    CPPUNIT_ASSERT_EQUAL(expected, actual);

    u32.meetWith(&s64, ch, false);
    CPPUNIT_ASSERT(ch == true);
    std::ostringstream ost5;
    ost5 << &u32;
    actual = ost5.str();
    expected = "u64";
    CPPUNIT_ASSERT_EQUAL(expected, actual);

    ch = false;
    Type *res = i32.meetWith(&flt, ch, false);
    CPPUNIT_ASSERT(ch == true);
    std::ostringstream ost6;
    ost6 << res;
    actual = ost6.str();
    expected = "union";
    CPPUNIT_ASSERT_EQUAL(expected, actual);

    ch = false;
    res = i32.meetWith(&pt, ch, false);
    CPPUNIT_ASSERT(ch == true);
    std::ostringstream ost7;
    ost7 << res;
    actual = ost7.str();
    expected = "union";
    CPPUNIT_ASSERT_EQUAL(expected, actual);
}
Пример #16
0
void print_header( std::string const& model, std::string const& name, color::rgb<double>  const& r )
 {
  color_name<uint8_t>      i8   ( r );
  color_name<uint16_t>     i16  ( r );
  color_name<uint32_t>     i32  ( r );
  color_name<uint64_t>     i64  ( r );
  color_name<float>        f    ( r );
  color_name<double>       d    ( r );
  color_name<long double>  ld   ( r );

  color::rgb<uint8_t> r32( r );

  std::stringstream ss;

  ss << "#ifndef color_"<< model <<"_make_" << name                                                       << std::endl;
  ss << "#define color_"<< model <<"_make_" << name                                                       << std::endl;
  ss                                                                                                      << std::endl;
  ss << "// ::color::make::" << name << "( c )"                                                           << std::endl;
  ss                                                                                                      << std::endl;
  ss << " namespace color"                                                                                << std::endl;
  ss << "  {"                                                                                             << std::endl;
  ss << "   namespace make"                                                                               << std::endl;
  ss << "    { //RGB equivalents: ";
  ss << "std::array<double,3>( { "<< d[0]<<", "<< d[1]<<", "<< d[2]<<" } )";
  ss << " - ";
  ss << "rgb(" << std::setbase(10) <<(unsigned)r32[0] << "," << (unsigned)r32[1] << "," << (unsigned)r32[2] << ")" ;
  ss << " - ";
  ss << "#" << std::setbase(16) <<  std::setw(2) <<  std::setfill('0') << (unsigned)r32[0]
            << std::setbase(16) <<  std::setw(2) <<  std::setfill('0') << (unsigned)r32[1]
            << std::setbase(16) <<  std::setw(2) <<  std::setfill('0') << (unsigned)r32[2] ;
  ss << std::endl;
  ss                                                                                                      << std::endl;

  ss << "      inline"                                                                                    << std::endl;
  ss << "      void " << name << "( ::color::_internal::model< ::color::category::"<< model <<"_uint8 > & color_parameter )"    << std::endl;
  ss << "       {"                                                                                        << std::endl;
  ss << "        color_parameter.container() = std::array< std::uint8_t, " << i8.size() << " >( { " 
     << "0x" << std::setbase(16) <<  std::setw(2) <<  std::setfill('0') <<  (unsigned)i8[0] << ", " 
     << "0x" << std::setbase(16) <<  std::setw(2) <<  std::setfill('0') <<  (unsigned)i8[1] << ", " 
     << "0x" << std::setbase(16) <<  std::setw(2) <<  std::setfill('0') <<  (unsigned)i8[2];
  if( 4 == i8.size() ){ ss << ", 0x" << std::setbase(16) <<  std::setw(2) <<  std::setfill('0') <<  (unsigned)i8[3];  }
  ss  << " } );" << std::endl;
  ss << "       }"                                                                                        << std::endl;
  ss                                                                                                      << std::endl;
  
  
  ss << "      inline"                                                                                    << std::endl;
  ss << "      void " << name << "( ::color::_internal::model< ::color::category::"<< model <<"_uint16 > & color_parameter )"    << std::endl;
  ss << "       {"                                                                                        << std::endl;
  ss << "        color_parameter.container() = std::array< std::uint16_t, " << i16.size() << " >( { "  
   << "0x" << std::setbase(16) <<  std::setw(4) <<  std::setfill('0') << i16[0] << ", " 
   << "0x" << std::setbase(16) <<  std::setw(4) <<  std::setfill('0') << i16[1] << ", " 
   << "0x" << std::setbase(16) <<  std::setw(4) <<  std::setfill('0') << i16[2];
  if( 4 == i16.size() ){ ss << ", 0x" << std::setbase(16) <<  std::setw(4) <<  std::setfill('0') <<  i16[3];  }
  ss  << " } );" << std::endl;
  ss << "       }"                                                                                        << std::endl;
  ss                                                                                                      << std::endl;

  ss << "      inline"                                                                                    << std::endl;
  ss << "      void " << name << "( ::color::_internal::model< ::color::category::"<< model <<"_uint32 > & color_parameter )"    << std::endl;
  ss << "       {"                                                                                        << std::endl;
  ss << "        color_parameter.container() = std::array< std::uint32_t, " << f.size() << " >( { " 
     << "0x" << std::setbase(16) <<  std::setw(8) <<  std::setfill('0') << i32[0] << ", " 
     << "0x" << std::setbase(16) <<  std::setw(8) <<  std::setfill('0') << i32[1] << ", " 
     << "0x" << std::setbase(16) <<  std::setw(8) <<  std::setfill('0') << i32[2];
  if( 4 == i32.size() ){ ss << ", 0x" << std::setbase(16) <<  std::setw(8) <<  std::setfill('0') <<  i32[3];  }
  ss  << " } );" << std::endl;
  ss << "       }"                                                                                        << std::endl;
  ss                                                                                                      << std::endl;

  ss << "      inline"                                                                                    << std::endl;
  ss << "      void " << name << "( ::color::_internal::model< ::color::category::"<< model <<"_uint64 > & color_parameter )"    << std::endl;
  ss << "       {"                                                                                        << std::endl;
  ss << "        color_parameter.container() = std::array< std::uint64_t, " << i64.size() << " >( { " 
     << "0x" << std::setbase(16) <<  std::setw(16) <<  std::setfill('0') << i64[0] << "ull, " 
     << "0x" << std::setbase(16) <<  std::setw(16) <<  std::setfill('0') << i64[1] << "ull, " 
     << "0x" << std::setbase(16) <<  std::setw(16) <<  std::setfill('0') << i64[2] << "ull" ;
  if( 4 == i64.size() ){ ss << ", 0x" << std::setbase(16) <<  std::setw(16) <<  std::setfill('0') << i64[3] << "ull";  }
  ss  << " } );" << std::endl;
  ss << "       }"                                                                                        << std::endl;
  ss                                                                                                      << std::endl;

  ss << "      inline"                                                                                    << std::endl;
  ss << "      void " << name << "( ::color::_internal::model< ::color::category::"<< model <<"_float > & color_parameter )"    << std::endl;
  ss << "       {"                                                                                        << std::endl;
  ss << "        color_parameter.container() = std::array<float," << f.size() << ">( { " << f[0] << ", " << f[1] << ", " << f[2];
  if( 4 == f.size() ){ ss << ", " << f[3];  }
  ss  << " } );" << std::endl;
  ss << "       }"                                                                                        << std::endl;
  ss                                                                                                      << std::endl;

  ss << "      inline"                                                                                    << std::endl;
  ss << "      void " << name << "( ::color::_internal::model< ::color::category::"<< model <<"_double> & color_parameter )"    << std::endl;
  ss << "       {"                                                                                        << std::endl;
  ss << "        color_parameter.container() = std::array<double," << d.size() << ">( { " << d[0] << ", " << d[1] << ", " << d[2];
  if( 4 == d.size() ){ ss << ", " << d[3];  }
  ss  << " } );" << std::endl;
  ss << "       }"                                                                                        << std::endl;
  ss                                                                                                      << std::endl;
  ss << "      inline"                                                                                    << std::endl;
  ss << "      void " << name << "( ::color::_internal::model< ::color::category::"<< model <<"_ldouble> & color_parameter )"   << std::endl;
  ss << "       {"                                                                                        << std::endl;
  ss << "        color_parameter.container() = std::array<long double," << ld.size() << ">( { " << ld[0] << ", " << ld[1] << ", " << ld[2];
  if( 4 == ld.size() ){ ss << ", " << ld[3];}
  ss  << " } );" << std::endl;
  ss << "       }"                                                                                        << std::endl;
  ss                                                                                                      << std::endl;
  ss << "    }"                                                                                           << std::endl;
  ss << "  }"                                                                                             << std::endl;
  ss                                                                                                      << std::endl;
  ss << "#endif"                                                                                          << std::endl;

  //std::cout << ss.str();
  //std::cout << "-------" << std:: endl;

   {
    std::ofstream ofs( ( "./gen-"+ model +"/"+name + ".hpp" ). c_str() );
    //std::ofstream ofs( ( "../../../src/color/"+ model +"/make/"+name + ".hpp" ). c_str() );
    ofs <<  ss.str();
   }

  }