Example #1
0
    static BitmapPtr create_jpeg(const uint8_t* source, int jpeg_size, int alpha_size)
    {
        struct jpeg_decompress_struct jds;
        struct jpeg_error_mgr jem;
        JSAMPARRAY buffer;

        jds.err = jpeg_std_error(&jem);
        jpeg_create_decompress(&jds);
        jpeg_mem_src(&jds, (unsigned char*)source, (unsigned long)jpeg_size);

        (void)jpeg_read_header(&jds, TRUE);
        jpeg_start_decompress(&jds);

        auto width  = jds.output_width;
        auto height = jds.output_height;
        auto depth  = jds.output_components;

        buffer = (*jds.mem->alloc_sarray)((j_common_ptr)&jds, JPOOL_IMAGE, width*depth, 1);
        
        if( alpha_size <= 0 )
        {
            auto bitmap = BitmapRGB8::create(width, height);
            uint8_t* iterator = bitmap->get_ptr();
            while( jds.output_scanline < height )
            {
                (void)jpeg_read_scanlines(&jds, buffer, 1);
                memcpy(iterator, *buffer, width*depth);
                iterator += width*depth;
            }

            jpeg_finish_decompress(&jds);
            jpeg_destroy_decompress(&jds);
            return std::move(bitmap);
        }

        auto bitmap = BitmapRGBA8::create(width, height);
        auto iterator = bitmap->get_ptr();
        while( jds.output_scanline < height )
        {
            (void)jpeg_read_scanlines(&jds, buffer, 1);
            for( auto i=0; i < width; i++ )
            {
                memcpy(iterator, *buffer+i*3, 3);
                iterator += 4;
            }
        }

        auto bytes = new uint8_t[width*height];
        decompress(source+jpeg_size, alpha_size, bytes, width*height);

        for( int i=0; i<height; i++ )
            for( int j=0; j<width; j++ )
                bitmap->get(i, j).a = bytes[i*width+j];

        delete[] bytes;

        jpeg_finish_decompress(&jds);
        jpeg_destroy_decompress(&jds);
        return std::move(bitmap);
    }
Example #2
0
int _lru_free_mem(cache_t *c, segment_t *pseg, ex_off_t bytes_to_free)
{
    cache_lru_t *cp = (cache_lru_t *)c->fn.priv;
    cache_segment_t *s;
    cache_page_t *p;
    page_lru_t *lp;
    Stack_ele_t *ele;
    apr_thread_mutex_t *plock;
    ex_off_t total_bytes, pending_bytes;
    int gotlock, count, bits, err;

    total_bytes = 0;
    err = 0;

    log_printf(15, "START seg=" XIDT " bytes_to_free=" XOT " bytes_used=" XOT " stack_size=%d\n", segment_id(pseg), bytes_to_free, cp->bytes_used, stack_size(cp->stack));

    move_to_bottom(cp->stack);
    ele = get_ptr(cp->stack);
    while ((total_bytes < bytes_to_free) && (ele != NULL) && (err == 0)) {
        p = (cache_page_t *)get_stack_ele_data(ele);
        lp = (page_lru_t *)p->priv;
        plock = p->seg->lock;
        gotlock = apr_thread_mutex_trylock(plock);
        if ((gotlock == APR_SUCCESS) || (p->seg == pseg)) {
            bits = atomic_get(p->bit_fields);
            if ((bits & C_TORELEASE) == 0) { //** Skip it if already flagged for removal
                count = atomic_get(p->access_pending[CACHE_READ]) + atomic_get(p->access_pending[CACHE_WRITE]) + atomic_get(p->access_pending[CACHE_FLUSH]);
                if (count == 0) { //** No one is using it
                    s = (cache_segment_t *)p->seg->priv;
                    if ((bits & C_ISDIRTY) == 0) {  //** Don't have to flush it
                        total_bytes += s->page_size;
                        log_printf(15, "lru_free_mem: freeing page seg=" XIDT " p->offset=" XOT " bits=%d\n", segment_id(p->seg), p->offset, bits);
                        list_remove(s->pages, &(p->offset), p);  //** Have to do this here cause p->offset is the key var
                        delete_current(cp->stack, 1, 0);
                        if (p->data[0].ptr) free(p->data[0].ptr);
                        if (p->data[1].ptr) free(p->data[1].ptr);
                        free(lp);
                    } else {         //** Got to flush the page first
                        err = 1;
                    }
                } else {
                    err = 1;
                }
            }
            if (gotlock == APR_SUCCESS) apr_thread_mutex_unlock(plock);
        } else {
            err = 1;
        }

        if ((total_bytes < bytes_to_free) && (err == 0)) ele = get_ptr(cp->stack);
    }

    cp->bytes_used -= total_bytes;
    pending_bytes = bytes_to_free - total_bytes;
    log_printf(15, "END seg=" XIDT " bytes_to_free=" XOT " pending_bytes=" XOT " bytes_used=" XOT "\n", segment_id(pseg), bytes_to_free, pending_bytes, cp->bytes_used);

    return(pending_bytes);
}
Example #3
0
//--------- Begin of function UnitArray::update_selected_trade_unit_info ---------//
// update trade information of trading units if these units are selected
//
void UnitArray::update_selected_trade_unit_info()
{
	short playerNationRecno = nation_array.player_recno;

	Unit *unitPtr;
	UnitMarine *marinePtr;
	if(remote.is_enable())
	{
		for(int i=size(); i>0; --i)
		{
			if(is_deleted(i))
				continue;

			unitPtr = (Unit*)get_ptr(i);
			if(!unitPtr->is_visible())
				continue;

			switch(unitPtr->unit_id)
			{
				case UNIT_CARAVAN:
						if(mp_is_selected_caravan(i))
							((UnitCaravan*) unitPtr)->update_stop_and_goods_info();
						break;

				case UNIT_VESSEL: case UNIT_CARAVEL: case UNIT_GALLEON:
						marinePtr = ((UnitMarine*) unitPtr);
						if(marinePtr->auto_mode && mp_is_selected_ship(i))
							marinePtr->update_stop_and_goods_info();
						break;

				default: break;
			}
		}
	}
	else if(selected_recno && !is_deleted(selected_recno))
	{
		unitPtr = (Unit*)get_ptr(selected_recno);
		if(unitPtr->nation_recno==playerNationRecno || config.show_ai_info)
		{
			switch(unitPtr->unit_id)
			{
				case UNIT_CARAVAN:
					((UnitCaravan*) unitPtr)->update_stop_and_goods_info();
					break;

				case UNIT_VESSEL: case UNIT_CARAVEL: case UNIT_GALLEON:
					marinePtr = ((UnitMarine*) unitPtr);
					if(marinePtr->auto_mode)
						marinePtr->update_stop_and_goods_info();
					break;

				default:
					break;
			}
		}
	}
}
Example #4
0
/*DefineFunction2("memcopy",'i',PTIF mem_copy,"mem_copy","33uuui"); */
int mem_copy() /*bcopy( a, b, n )*/
{
int n;
char *a,*b;
    a=(char *)get_ptr(1);
    b=(char *)get_ptr(2);
    n = (int)RtnLong(3);
    if(!a && !b) {memcpy(b,a,n); return(0);}
    else printf("[memcopy nil ptr]");
    return(1);
}
Example #5
0
/*ret:   1st element at the ptr memory location*/
VOID deref(DATA_OBJECT_PTR rp)
{
int n,i,j,*npi,ret=0,t;
float *npf;
char tstr[89],type,*sp;
    n = RtnArgCount(); 
    printf("[ac=%d]",n);
    sprintf(tstr,"%s",(char *)RtnLexeme(1)); 
    type = tolower(tstr[0]);
    switch(type)
    {
	case 'i':  npi = (int *)get_ptr(2);  
		   break;
	case 'f':  npf = (float *)get_ptr(2); 
		   break;
	case 'b':  sp = (char *)get_ptr(2); 
		   break;
        default:   printf("bad type %s\n",tstr);
		   break;
    }
    if(n > 2)   /*then set the values*/
    {
	for(i=3; i<=n; i++)
	{
	  switch(type)
	  {
	    case 'i':  printf("[set%d at%d]",(npi[i-3] = get_int(i)),i);  break;
	    case 'f': printf("[set%f at%d]",(npf[i-3] = get_float(i)),i); break;
	    case 'b':  get_str(i,tstr);     /*fix-finish*/
			t = strlen(tstr);
			for(j=0; j<t; j++)
			 printf("[%c]",(sp[j] = tstr[j])); 
			break;
	  }
	}
	switch(type)  /*if setting want ptr, which might be newly malloced*/
	{
	  case 'i' : set_long(rp,(long)npi);	break;
	  case 'f' : set_long(rp,(long)npf);	break;
	  case 'b' : set_long(rp,(long)sp);	break;
	}
    } 
    else
    switch(type)
    {
      case 'i' : set_int(rp,(int)npi[0]);	break;
      case 'f' : set_float(rp,(float)npf[0]);	break;
      case 'b' : printf("[str=%s]",sp); 
		 set_symb(rp,(char *)sp);	break;
    }
    return;
}
Example #6
0
static int start_hline(void)
{
    struct COOR *new_ptr1, *new_ptr2;

    new_ptr1 = get_ptr();
    new_ptr2 = get_ptr();
    new_ptr1->bptr = new_ptr2->bptr = new_ptr1;
    new_ptr1->fptr = new_ptr2;
    new_ptr2->fptr = NULPTR;
    h_ptr = new_ptr2;

    return 0;
}
Example #7
0
static struct COOR *start_line(int node)
{
    struct COOR *new_ptr1, *new_ptr2;

    G_debug(3, "start_line: node %d", node);

    new_ptr1 = get_ptr();
    new_ptr2 = get_ptr();
    new_ptr1->bptr = new_ptr1;
    new_ptr1->fptr = new_ptr2;
    new_ptr1->node = node;
    new_ptr2->bptr = new_ptr1;

    return (new_ptr2);
}
Example #8
0
    static Image* create_bits_lossless(Stream& stream, TagHeader& header)
    {
        auto cid = stream.read_uint16();
        auto format = (BitmapFormat)stream.read_uint8();
        auto width = stream.read_uint16();
        auto height = stream.read_uint16();

        if( format == BitmapFormat::COLOR_MAPPED )
        {
            auto table_size = stream.read_uint8();
            auto src_size = header.end_pos - stream.get_position();
            auto dst_size = table_size*3+width*height; // color table + indices
            auto bytes = BytesPtr(new (std::nothrow) uint8_t[dst_size]);
            decompress(stream.get_current_ptr(), src_size, bytes.get(), dst_size);

            auto bitmap = BitmapRGB8::create(width, height);
            for( auto i=0; i<height; i++ )
                for( auto j=0; j<width; j++ )
                {
                    auto base = bytes[table_size*3+i*width+j]*3;
                    bitmap->set(i, j, bytes.get()+base);
                }

            return Image::create(cid, std::move(bitmap));
        }
        else if( format == BitmapFormat::RGB15)
        {
            auto src_size = header.end_pos - stream.get_position();
            auto bitmap = BitmapRGB565::create(width, height);
            decompress(stream.get_current_ptr(), src_size, bitmap->get_ptr(), bitmap->get_size());

            for( auto i=0; i<height; i++ )
                for( auto j=0; j<width; j++ )
                    bitmap->get(i, j).cast_from_1555();

            return Image::create(cid, std::move(bitmap));
        }
        else if( format == BitmapFormat::RGB24 )
        {
            auto src_size = header.end_pos - stream.get_position();
            auto bitmap = BitmapRGB8::create(width, height);
            decompress(stream.get_current_ptr(), src_size, bitmap->get_ptr(), bitmap->get_size());

            return Image::create(cid, std::move(bitmap));
        }

        return nullptr;
    }
Example #9
0
void *mjs_get_ptr(struct mjs *mjs, mjs_val_t v) {
  (void) mjs;
  if (!mjs_is_foreign(v)) {
    return NULL;
  }
  return get_ptr(v);
}
Example #10
0
cache_page_t *_lru_new_page(cache_t *c, segment_t *seg)
{
    cache_lru_t *cp = (cache_lru_t *)c->fn.priv;
    cache_segment_t *s = (cache_segment_t *)seg->priv;
    page_lru_t *lp;
    cache_page_t *p;

    type_malloc_clear(lp, page_lru_t, 1);
    p = &(lp->page);
    p->curr_data = &(p->data[0]);
    p->current_index = 0;
    type_malloc_clear(p->curr_data->ptr, char, s->page_size);

    cp->bytes_used += s->page_size;

    p->priv = (void *)lp;
    p->seg = seg;
//  p->offset = -1;
    p->offset = atomic_dec(lru_dummy);
    atomic_set(p->bit_fields, C_EMPTY);  //** This way it's not accidentally deleted

    //** Store my position
    push(cp->stack, p);
    lp->ele = get_ptr(cp->stack);

    log_printf(15, " seg=" XIDT " page created initial->offset=" XOT " page_size=" XOT " data[0]=%p bytes_used=" XOT " stack_size=%d\n", segment_id(seg), p->offset, s->page_size, p->curr_data->ptr, cp->bytes_used, stack_size(cp->stack));
    return(p);
}
Example #11
0
bool rsa_ssh1_decrypt_pkcs1(mp_int *input, RSAKey *key,
                            strbuf *outbuf)
{
    strbuf *data = strbuf_new_nm();
    bool success = false;
    BinarySource src[1];

    {
        mp_int *b = rsa_ssh1_decrypt(input, key);
        for (size_t i = (mp_get_nbits(key->modulus) + 7) / 8; i-- > 0 ;) {
            put_byte(data, mp_get_byte(b, i));
        }
        mp_free(b);
    }

    BinarySource_BARE_INIT(src, data->u, data->len);

    /* Check PKCS#1 formatting prefix */
    if (get_byte(src) != 0) goto out;
    if (get_byte(src) != 2) goto out;
    while (1) {
        unsigned char byte = get_byte(src);
        if (get_err(src)) goto out;
        if (byte == 0)
            break;
    }

    /* Everything else is the payload */
    success = true;
    put_data(outbuf, get_ptr(src), get_avail(src));

  out:
    strbuf_free(data);
    return success;
}
void Polyhedron::preprocessAdjacency()
{
	DEBUG_START;
	int i;
	DEBUG_PRINT("Cleaning facets");
	for (i = 0; i < numFacets; ++i)
	{
		if (facets[i].numVertices < 1)
			continue;
		facets[i].preprocess_free();
	}

	DEBUG_PRINT("Facets preprocessing");
	for (i = 0; i < numFacets; ++i)
	{
		if (facets[i].numVertices < 1)
			continue;
		facets[i].preprocess();
	}

	DEBUG_PRINT("VertexInfos preprocessing");
	if (vertexInfos != NULL)
	{
		delete[] vertexInfos;
	}
	vertexInfos = new VertexInfo[numVertices];
	for (i = 0; i < numVertices; ++i)
	{
		vertexInfos[i] = VertexInfo(i, vertices[i], get_ptr());
		vertexInfos[i].preprocess();
	}
	DEBUG_END;
}
Example #13
0
void
Dbtup::tuxFreeNode(Uint32 fragPtrI,
                   Uint32 pageId,
                   Uint32 pageOffset,
                   Uint32* node)
{
  jamEntry();
  FragrecordPtr fragPtr;
  fragPtr.i= fragPtrI;
  ptrCheckGuard(fragPtr, cnoOfFragrec, fragrecord);
  TablerecPtr tablePtr;
  tablePtr.i= fragPtr.p->fragTableId;
  ptrCheckGuard(tablePtr, cnoOfTablerec, tablerec);

  Local_key key;
  key.m_page_no = pageId;
  key.m_page_idx = pageOffset;
  PagePtr pagePtr;
  Tuple_header* ptr = (Tuple_header*)get_ptr(&pagePtr, &key, tablePtr.p);

  Uint32 attrDescIndex= tablePtr.p->tabDescriptor + (0 << ZAD_LOG_SIZE);
  Uint32 attrDataOffset= AttributeOffset::getOffset(tableDescriptor[attrDescIndex + 1].tabDescr);
  ndbrequire(node == (Uint32*)ptr + attrDataOffset);

  free_fix_rec(fragPtr.p, tablePtr.p, &key, (Fix_page*)pagePtr.p);
}
Example #14
0
int
Stream::get_string_ptr( char const *&s ) {
	char	c;
	void 	*tmp_ptr = 0;
    int     len;

	s = NULL;
	switch(_code){
		case internal:
		case external:
                    // For 6.2 compatibility, we had to put this code back 
                    if (!get_encryption()) {
                        if (!peek(c)) return FALSE;
                        if (c == '\255'){
                            if (get_bytes(&c, 1) != 1) return FALSE;
							s = NULL;
                        }
                        else{
                            if (get_ptr(tmp_ptr, '\0') <= 0) return FALSE;
							s = (char *)tmp_ptr;
                        }
                    }
                    else { // 6.3 with encryption support
                        // First, get length
                        if (get(len) == FALSE) {
                            return FALSE;
                        }

						if( !decrypt_buf || decrypt_buf_len < len ) {
							free( decrypt_buf );
							decrypt_buf = (char *)malloc(len);
							ASSERT( decrypt_buf );
							decrypt_buf_len = len;
						}

                        if( get_bytes(decrypt_buf, len) != len ) {
                            return FALSE;
                        }

                        if( *decrypt_buf == '\255' ) {
							s = NULL;
                        }
                        else {
							s = decrypt_buf;
                        }
                    }
                    break;

		case ascii:
			return FALSE;
	}
	if( s ) {
		NETWORK_TRACE("get string ptr " << s);
	}
	else {
		NETWORK_TRACE("get string ptr NULL");
	}
	return TRUE;
}
Example #15
0
void metadb_handle_list::delete_all()
{
	if (get_count()>0)
	{
		metadb::get()->handle_release_multi(get_ptr(),get_count());
		remove_all();
	}
}
Example #16
0
 template<class Bdl, class Delta> void operator()(Bdl& ref, const Delta& refdelta) const
 {
   assert(ref.size()==refdelta.size());
   for(auto i = ref.first() ; i < ref.size() ; ++i)
   {
     detail::internal_apply_increment(ref.reference(i),get_ptr(refdelta(i)));
   }
 }
void Polyhedron::intersect(Plane iplane)
{
	DEBUG_START;
	Intersector* intersector = new Intersector(get_ptr());
	intersector->run(iplane);
	delete intersector;
	DEBUG_END;
}
void Polyhedron::intersectCoalesceMode(Plane iplane, int jfid)
{
	DEBUG_START;
	Intersector* intersector = new Intersector(get_ptr());
	intersector->runCoalesceMode(iplane, jfid);
	delete intersector;
	DEBUG_END;
}
Example #19
0
Bullet* BulletArray::operator[](int recNo)
{
	Bullet* bulletPtr = (Bullet*) get_ptr(recNo);

	if( !bulletPtr )
		err.run( "BulletArray[] is deleted" );

	return bulletPtr;
}
Example #20
0
/* DefineFunction2("cf0v"",'i',PTIF cf0v,"cf0v","11ii"); */ 
int
cf0v()
{
void (*fncptr)();   /*might only be wrapping fnc that rtn ints anyway*/
    fncptr = VPTIF get_ptr(1);
    printf("[cf0v:calling %d]\n",(int)fncptr);
    fncptr();
    return(1);
}
Example #21
0
Tornado* TornadoArray::operator[](int recNo)
{
	Tornado* tornadoPtr = (Tornado*) get_ptr(recNo);

	if( !tornadoPtr )
		err.run( "TornadoArray[] is deleted" );

	return tornadoPtr;
}
Example #22
0
int main(void)
{
	struct m real;
	struct m *m = get_ptr(&real);
	m->a = 13;

	test_assert(real.a == 13);
	return 0;
}
Example #23
0
Nation* NationArray::operator[](int recNo)
{
	Nation* nationPtr = (Nation*) get_ptr(recNo);

	if( !nationPtr )
		err.run( "NationArray[] is deleted" );

	return nationPtr;
}
Example #24
0
        static inline stream_reader* from_frame(astra_reader_frame_t& frame)
        {
            if (frame == nullptr)
            {
                return nullptr;
            }

            return get_ptr(frame->reader);
        }
Example #25
0
Firm* FirmArray::operator()()
{
   Firm* firmPtr = (Firm*) get_ptr();   // if recno()==0, get_ptr() returns NULL

	err_if( !firmPtr )
      err_now( "FirmArray[recno()] is deleted" );

   return firmPtr;
}
Example #26
0
Town* TownArray::operator[](int recNo)
{
	Town* townPtr = (Town*) get_ptr(recNo);

	if( !townPtr )
		err.run( "TownArray[] is deleted" );

	return townPtr;
}
Example #27
0
Unit* UnitArray::operator[](int recNo)
{
	Unit* unitPtr = (Unit*) get_ptr(recNo);

	if( !unitPtr )
		err.run( "UnitArray[] is deleted" );

	return unitPtr;
}
Example #28
0
 template<class derived> void del(derived val) {
     base_type * p = get_ptr(val);
     scoped_lock lk(m_cs);
     for ( typename array_type::iterator b = m_array.begin(), e = m_array.end(); b != e; ++b)
         if ( b->get() == p) {
             m_array.erase(b);
             return ;
         }
 }
Example #29
0
Firm* FirmArray::operator[](int recNo)
{
	Firm* firmPtr = (Firm*) get_ptr(recNo);

	if( !firmPtr )
      err.run( "FirmArray[] is deleted" );

   return firmPtr;
}
Example #30
0
int main()
{
    int* ptr = get_ptr();
    assert(ptr[20] == 50);
    print(ptr[20]);

    free(ptr);
    free(ptr); // erreur !!
}