Exemplo n.º 1
2
OGRFeature *OGRDWGLayer::TranslateDIMENSION( OdDbEntityPtr poEntity )

{
    OdDbDimensionPtr poDim = OdDbDimension::cast( poEntity );
    OGRFeature *poFeature = new OGRFeature( poFeatureDefn );

    double dfHeight = CPLAtof(poDS->GetVariable("$DIMTXT", "2.5"));
    OdGePoint3d oTextPos, oTarget1, oTarget2, oArrow1;
    CPLString osText;

    TranslateGenericProperties( poFeature, poEntity );

/* -------------------------------------------------------------------- */
/*      Generic Dimension stuff.                                        */
/* -------------------------------------------------------------------- */
    osText = (const char *) poDim->dimensionText();

    oTextPos = poDim->textPosition();

/* -------------------------------------------------------------------- */
/*      Specific based on the subtype.                                  */
/* -------------------------------------------------------------------- */
    OdRxClass *poClass = poEntity->isA();
    const OdString osName = poClass->name();
    const char *pszEntityClassName = (const char *) osName;

    if( EQUAL(pszEntityClassName,"AcDbRotatedDimension") )
    {
        OdDbRotatedDimensionPtr poRDim = OdDbDimension::cast( poEntity );

        oTarget2 = poRDim->xLine1Point();
        oTarget1 = poRDim->xLine2Point();
        oArrow1 = poRDim->dimLinePoint();
    }

    else if( EQUAL(pszEntityClassName,"AcDbAlignedDimension") )
    {
        OdDbAlignedDimensionPtr poADim = OdDbDimension::cast( poEntity );

        oTarget2 = poADim->xLine1Point();
        oTarget1 = poADim->xLine2Point();
        oArrow1 = poADim->dimLinePoint();
    }

/*************************************************************************

   DIMENSION geometry layout

                  (11,21)(text center point)
        |          DimText                  |
(10,20) X<--------------------------------->X (Arrow2 - computed)
(Arrow1)|                                   |
        |                                   |
        |                                   X (13,23) (Target2)
        |
        X (14,24) (Target1)

Given:
  Locations Arrow1, Target1, and Target2 we need to compute Arrow2.

Steps:
 1) Compute direction vector from Target1 to Arrow1 (Vec1).
 2) Compute direction vector for arrow as perpendicular to Vec1 (call Vec2).
 3) Compute Arrow2 location as intersection between line defined by
    Vec2 and Arrow1 and line defined by Target2 and direction Vec1 (call Arrow2)

Then we can draw lines for the various components.

Note that Vec1 and Vec2 may be horizontal, vertical or on an angle but
the approach is as above in all these cases.

*************************************************************************/

/* -------------------------------------------------------------------- */
/*      Step 1, compute direction vector between Target1 and Arrow1.    */
/* -------------------------------------------------------------------- */
    double dfVec1X, dfVec1Y;

    dfVec1X = (oArrow1.x - oTarget1.x);
    dfVec1Y = (oArrow1.y - oTarget1.y);

/* -------------------------------------------------------------------- */
/*      Step 2, compute the direction vector from Arrow1 to Arrow2      */
/*      as a perpendicular to Vec1.                                     */
/* -------------------------------------------------------------------- */
    double dfVec2X, dfVec2Y;

    dfVec2X = dfVec1Y;
    dfVec2Y = -dfVec1X;

/* -------------------------------------------------------------------- */
/*      Step 3, compute intersection of line from target2 along         */
/*      direction vector 1, with the line through Arrow1 and            */
/*      direction vector 2.                                             */
/* -------------------------------------------------------------------- */
    double dfL1M, dfL1B, dfL2M, dfL2B;
    double dfArrowX2, dfArrowY2;

    // special case if vec1 is vertical.
    if( dfVec1X == 0.0 )
    {
        dfArrowX2 = oTarget2.x;
        dfArrowY2 = oArrow1.y;
    }

    // special case if vec2 is horizontal.
    else if( dfVec1Y == 0.0 )
    {
        dfArrowX2 = oArrow1.x;
        dfArrowY2 = oTarget2.y;
    }

    else // General case for diagonal vectors.
    {
        // first convert vec1 + target2 into y = mx + b format: call this L1

        dfL1M = dfVec1Y / dfVec1X;
        dfL1B = oTarget2.y - dfL1M * oTarget2.x;

        // convert vec2 + Arrow1 into y = mx + b format, call this L2

        dfL2M = dfVec2Y / dfVec2X;
        dfL2B = oArrow1.y - dfL2M * oArrow1.x;

        // Compute intersection x = (b2-b1) / (m1-m2)

        dfArrowX2 = (dfL2B - dfL1B) / (dfL1M-dfL2M);
        dfArrowY2 = dfL2M * dfArrowX2 + dfL2B;
    }

/* -------------------------------------------------------------------- */
/*      Compute the text angle.                                         */
/* -------------------------------------------------------------------- */
    double dfAngle = atan2(dfVec2Y,dfVec2X) * 180.0 / M_PI;

/* -------------------------------------------------------------------- */
/*      Rescale the direction vectors so we can use them in             */
/*      constructing arrowheads.  We want them to be about 3% of the    */
/*      length of line on which the arrows will be drawn.               */
/* -------------------------------------------------------------------- */
#define VECTOR_LEN(x,y) sqrt( (x)*(x) + (y)*(y) )
#define POINT_DIST(x1,y1,x2,y2)  VECTOR_LEN((x2-x1),(y2-y1))

    double dfBaselineLength = POINT_DIST(oArrow1.x,oArrow1.y,
                                         dfArrowX2,dfArrowY2);
    double dfTargetLength = dfBaselineLength * 0.03;
    double dfScaleFactor;

    // recompute vector 2 to ensure the direction is regular
    dfVec2X = (dfArrowX2 - oArrow1.x);
    dfVec2Y = (dfArrowY2 - oArrow1.y);

    // vector 1
    dfScaleFactor = dfTargetLength / VECTOR_LEN(dfVec1X,dfVec1Y);
    dfVec1X *= dfScaleFactor;
    dfVec1Y *= dfScaleFactor;

    // vector 2
    dfScaleFactor = dfTargetLength / VECTOR_LEN(dfVec2X,dfVec2Y);
    dfVec2X *= dfScaleFactor;
    dfVec2Y *= dfScaleFactor;

/* -------------------------------------------------------------------- */
/*      Create geometries for the different components of the           */
/*      dimension object.                                               */
/* -------------------------------------------------------------------- */
    OGRMultiLineString *poMLS = new OGRMultiLineString();
    OGRLineString oLine;

    // main arrow line between Arrow1 and Arrow2
    oLine.setPoint( 0, oArrow1.x, oArrow1.y );
    oLine.setPoint( 1, dfArrowX2, dfArrowY2 );
    poMLS->addGeometry( &oLine );

    // dimension line from Target1 to Arrow1 with a small extension.
    oLine.setPoint( 0, oTarget1.x, oTarget1.y );
    oLine.setPoint( 1, oArrow1.x + dfVec1X, oArrow1.y + dfVec1Y );
    poMLS->addGeometry( &oLine );

    // dimension line from Target2 to Arrow2 with a small extension.
    oLine.setPoint( 0, oTarget2.x, oTarget2.y );
    oLine.setPoint( 1, dfArrowX2 + dfVec1X, dfArrowY2 + dfVec1Y );
    poMLS->addGeometry( &oLine );

    // add arrow1 arrow head.

    oLine.setPoint( 0, oArrow1.x, oArrow1.y );
    oLine.setPoint( 1,
                    oArrow1.x + dfVec2X*3 + dfVec1X,
                    oArrow1.y + dfVec2Y*3 + dfVec1Y );
    poMLS->addGeometry( &oLine );

    oLine.setPoint( 0, oArrow1.x, oArrow1.y );
    oLine.setPoint( 1,
                    oArrow1.x + dfVec2X*3 - dfVec1X,
                    oArrow1.y + dfVec2Y*3 - dfVec1Y );
    poMLS->addGeometry( &oLine );

    // add arrow2 arrow head.

    oLine.setPoint( 0, dfArrowX2, dfArrowY2 );
    oLine.setPoint( 1,
                    dfArrowX2 - dfVec2X*3 + dfVec1X,
                    dfArrowY2 - dfVec2Y*3 + dfVec1Y );
    poMLS->addGeometry( &oLine );

    oLine.setPoint( 0, dfArrowX2, dfArrowY2 );
    oLine.setPoint( 1,
                    dfArrowX2 - dfVec2X*3 - dfVec1X,
                    dfArrowY2 - dfVec2Y*3 - dfVec1Y );
    poMLS->addGeometry( &oLine );

    poFeature->SetGeometryDirectly( poMLS );

    PrepareLineStyle( poFeature );

/* -------------------------------------------------------------------- */
/*      Is the layer disabled/hidden/frozen/off?                        */
/* -------------------------------------------------------------------- */
    CPLString osLayer = poFeature->GetFieldAsString("Layer");

    int bHidden =
        EQUAL(poDS->LookupLayerProperty( osLayer, "Hidden" ), "1");

/* -------------------------------------------------------------------- */
/*      Work out the color for this feature.                            */
/* -------------------------------------------------------------------- */
    int nColor = 256;

    if( oStyleProperties.count("Color") > 0 )
        nColor = atoi(oStyleProperties["Color"]);

    // Use layer color?
    if( nColor < 1 || nColor > 255 )
    {
        const char *pszValue = poDS->LookupLayerProperty( osLayer, "Color" );
        if( pszValue != NULL )
            nColor = atoi(pszValue);
    }

    if( nColor < 1 || nColor > 255 )
        nColor = 8;

/* -------------------------------------------------------------------- */
/*      Prepare a new feature to serve as the dimension text label      */
/*      feature.  We will push it onto the layer as a pending           */
/*      feature for the next feature read.                              */
/* -------------------------------------------------------------------- */

    // a single space suppresses labeling.
    if( osText == " " )
        return poFeature;

    OGRFeature *poLabelFeature = poFeature->Clone();

    poLabelFeature->SetGeometryDirectly( new OGRPoint( oTextPos.x, oTextPos.y ) );

    // Do we need to compute the dimension value?
    if( osText.empty() )
    {
        FormatDimension( osText, POINT_DIST( oArrow1.x, oArrow1.y,
                                             dfArrowX2, dfArrowY2 ) );
    }

    CPLString osStyle;
    char szBuffer[64];
    char* pszComma = NULL;

    osStyle.Printf("LABEL(f:\"Arial\",t:\"%s\",p:5",osText.c_str());

    if( dfAngle != 0.0 )
    {
        CPLsnprintf(szBuffer, sizeof(szBuffer), "%.3g", dfAngle);
        pszComma = strchr(szBuffer, ',');
        if (pszComma)
            *pszComma = '.';
        osStyle += CPLString().Printf(",a:%s", szBuffer);
    }

    if( dfHeight != 0.0 )
    {
        CPLsnprintf(szBuffer, sizeof(szBuffer), "%.3g", dfHeight);
        pszComma = strchr(szBuffer, ',');
        if (pszComma)
            *pszComma = '.';
        osStyle += CPLString().Printf(",s:%sg", szBuffer);
    }

    const unsigned char *pabyDWGColors = ACGetColorTable();

    snprintf( szBuffer, sizeof(szBuffer), ",c:#%02x%02x%02x",
              pabyDWGColors[nColor*3+0],
              pabyDWGColors[nColor*3+1],
              pabyDWGColors[nColor*3+2] );
    osStyle += szBuffer;

    if( bHidden )
        osStyle += "00";

    osStyle += ")";

    poLabelFeature->SetStyleString( osStyle );

    apoPendingFeatures.push( poLabelFeature );

    return poFeature;
}
Exemplo n.º 2
0
uint32_t	SystemTimerUnregisterCallBack( uint32_t handle )
{
	STSystemTimerCB *ptrTimerCB;
	uint32_t i;
	
	if ( vecSystemTimerCB[0].magic != SYSTIMER_MAGIC )
	{
		return EPERM;
	}	
	
	for ( ptrTimerCB = &vecSystemTimerCB[0], i = 0; i < VECTOR_LEN( vecSystemTimerCB ); i++, ptrTimerCB++)
	{
		if ( ptrTimerCB->handle == handle )
		{
			ptrTimerCB->handle						= SYSTIMER_ENTRY_NULL;
			ptrTimerCB->countTime					=	-1;
			ptrTimerCB->count							= ptrTimerCB->countTime;
			ptrTimerCB->lpParam 					= NULL;
			ptrTimerCB->type							= systemTimerOneShot;
			ptrTimerCB->callback_func			=	NULL;
			break;
		}
	}
		
	if ( i == VECTOR_LEN( vecSystemTimerCB ) )
	{
		return EFAULT;
	}
	
	return 0;
}
Exemplo n.º 3
0
uint32_t SysTimerInit( uint32_t dwTimeMicro )
{
	int i;
	uint32_t returnCode;
	STSystemTimerCB 			*ptrTimerCB;

	memset( (char*)&vecSystemTimerCB,	(uint8_t)-1, sizeof( vecSystemTimerCB ));
	for ( i = 0, ptrTimerCB = &vecSystemTimerCB[0]; i < VECTOR_LEN( vecSystemTimerCB ); i++, ptrTimerCB++)
	{
		ptrTimerCB->magic		= SYSTIMER_MAGIC;
		ptrTimerCB->handle	= SYSTIMER_ENTRY_NULL;
	}
	
	if ( dwTimeMicro < 10 ) 
	{
		dwTimeMicro = 10;
	}
	else if ( dwTimeMicro == (uint32_t)-1 )
	{
		dwTimeMicro = SysTick_LOAD_RELOAD_Msk/SYSTIMER_TIMEBASE_us;
	}
	
	//! interrupção para dwTimeMicro
	returnCode = SysTick_Config( SYSTIMER_TIMEBASE_us * dwTimeMicro ); 
	if ( returnCode )
	{
		return 1;
	}
	
	iSysTimerTimeBase = dwTimeMicro;
	
	return 0;
}
Exemplo n.º 4
0
/**
 *	@brief 	SysTick_Handler System Tick timer ISR
 *					decrement the count fielt in the structure vecSystemTimerCB. 
 *					Dependending on value of count fielt, call the callback function and perform some operations. 
 *					
 * 					Pay Attention!  Only one callback function is called for ISR each execution
 */
void SysTick_Handler (void)  
{
	int	i;
	STSystemTimerCB*	ptrVecTimerCB;
	uint32_t	dwExecuteCBFlag = 0;
    	
	for ( i = 0, ptrVecTimerCB = vecSystemTimerCB; i < VECTOR_LEN( vecSystemTimerCB ); i++, ptrVecTimerCB++  )
	{
		if ( ptrVecTimerCB->handle != SYSTIMER_ENTRY_NULL )
		{
			ptrVecTimerCB->count--;
			if ( !dwExecuteCBFlag )
			{
				if ( ptrVecTimerCB->count <= 0 )
				{
					if ( ptrVecTimerCB->callback_func != NULL )
					{
						dwExecuteCBFlag = 1;
						(ptrVecTimerCB->callback_func)( ptrVecTimerCB->lpParam );	// execute the callback code
						if ( ptrVecTimerCB->type  ==  systemTimerOneShot )
						{
							SystemTimerUnregisterCallBack( ptrVecTimerCB->handle );
						}
						else
						{
							ptrVecTimerCB->count = ptrVecTimerCB->countTime;
						}
					}
				}
			}
		}
	}
	return;
}
Exemplo n.º 5
0
void intercom_claim(intercom_ctx *ctx, struct client *client) {
  struct timespec now;
  clock_gettime(CLOCK_MONOTONIC, &now);

  intercom_packet_claim *packet = malloc(sizeof(intercom_packet_claim) + CLAIM_MAX * sizeof(intercom_packet_claim_entry));
  int i;

  uint32_t nonce = rand();

  packet->hdr = (intercom_packet_hdr) {
    .type = INTERCOM_CLAIM,
    .nonce = nonce,
    .ttl = 255,
  };

  memcpy(&packet->sender, ctx->ip.s6_addr, sizeof(uint8_t) * 16);
  memcpy(&packet->mac, client->mac, sizeof(uint8_t) * 6);
  packet->lastseen = now.tv_sec - client->lastseen.tv_sec;

  intercom_packet_claim_entry *entry = (intercom_packet_claim_entry*)((uint8_t*)(packet) + sizeof(intercom_packet_claim));

  for (i = 0; i < VECTOR_LEN(client->addresses) && i < CLAIM_MAX; i++) {
    struct client_ip *ip = &VECTOR_INDEX(client->addresses, i);
    entry->lastseen = now.tv_sec - ip->lastseen.tv_sec;
    memcpy(&entry->address, ip->address.s6_addr, sizeof(uint8_t) * 16);
    entry++;
  }

  packet->num_addresses = i;

  ssize_t packet_len = sizeof(intercom_packet_claim) + i * sizeof(intercom_packet_claim_entry);
  intercom_recently_seen_add(ctx, &packet->hdr);
  intercom_send_packet(ctx, (uint8_t*)packet, packet_len);
}
Exemplo n.º 6
0
static ir_type_t *
type_get(ir_unit_t *iu, unsigned int id)
{
  if(id >= VECTOR_LEN(&iu->iu_types))
    parser_error(iu, "Bad type index %d", id);
  return &VECTOR_ITEM(&iu->iu_types, id);
}
Exemplo n.º 7
0
static void
type_print_list(ir_unit_t *iu)
{
  for(int i = 0; i < VECTOR_LEN(&iu->iu_types); i++) {
    printf("Type-%-5d  %s\n", i, type_str_index(iu, i));
  }
}
Exemplo n.º 8
0
uint32_t SystemTimerRegisterCallBack( int32_t delay, TSysTimerType type, callbacktimer_func callback_func, void* lpParam, uint32_t* cbHandle )
{
	int i;
	uint32_t count;
	uint32_t reminder;
	STSystemTimerCB *ptrTimerCB;
	
	if ( vecSystemTimerCB[0].magic != SYSTIMER_MAGIC )
	{
		return EPERM;
	}
	
	if (delay < iSysTimerTimeBase )
		delay = iSysTimerTimeBase;
	
	count = delay / iSysTimerTimeBase;
	reminder = delay % iSysTimerTimeBase;
	if ( ((10*reminder) / iSysTimerTimeBase ) > 5 )
		count++;
	
	for ( ptrTimerCB = &vecSystemTimerCB[0], i = 0; i < VECTOR_LEN( vecSystemTimerCB ); i++, ptrTimerCB++)
    {
        if ( ptrTimerCB->handle == SYSTIMER_ENTRY_NULL )
        {
            ptrTimerCB->handle      =   GetUniqueCount();
            ptrTimerCB->countTime   =   count;
            ptrTimerCB->count       =   ptrTimerCB->countTime;
            ptrTimerCB->callback_func   =	callback_func;
            ptrTimerCB->lpParam         = lpParam;
            ptrTimerCB->type            = type;
            break;
        }
	}
	
	if ( i == VECTOR_LEN( vecSystemTimerCB ) )
	{
		return EFAULT;
	}
	
	if ( cbHandle != NULL )
	{
		*cbHandle = ptrTimerCB->handle;
	}
	
	return 0; 
}
Exemplo n.º 9
0
static int
type_make(ir_unit_t *iu, int type)
{
  for(int i = 0; i < VECTOR_LEN(&iu->iu_types); i++) {
    ir_type_t *it = &VECTOR_ITEM(&iu->iu_types, i);
    if(it->it_code == type)
      return i;
  }

  iu->iu_types_created = 1;

  ir_type_t it;
  int r = VECTOR_LEN(&iu->iu_types);
  it.it_code = type;
  VECTOR_PUSH_BACK(&iu->iu_types, it);
  return r;
}
Exemplo n.º 10
0
static int
type_find_by_code(ir_unit_t *iu, ir_type_code_t code)
{
  for(int i = 0; i < VECTOR_LEN(&iu->iu_types); i++) {
    if(VECTOR_ITEM(&iu->iu_types, i).it_code == code)
      return i;
  }
  parser_error(iu, "Unable to find type class %d", code);
}
Exemplo n.º 11
0
bool intercom_has_ifname(intercom_ctx *ctx, char *ifname) {
  for (int i = 0; i < VECTOR_LEN(ctx->interfaces); i++) {
    intercom_if *iface = &VECTOR_INDEX(ctx->interfaces, i);

    if (strcmp(ifname, iface->ifname) == 0)
      return true;
  }

  return false;
}
Exemplo n.º 12
0
type_print_id(char **dstp, const ir_unit_t *iu, int id)
{
  char tmpbuf[128];

  if(id < VECTOR_LEN(&iu->iu_types))
    return type_print(dstp, iu, &VECTOR_ITEM(&iu->iu_types, id));

  snprintf(tmpbuf, sizeof(tmpbuf), "[TypeId-%d]", id);
  return addstr(dstp, tmpbuf);
}
Exemplo n.º 13
0
static int
type_make_pointer(ir_unit_t *iu, int type, int may_create)
{
  for(int i = 0; i < VECTOR_LEN(&iu->iu_types); i++) {
    ir_type_t *it = &VECTOR_ITEM(&iu->iu_types, i);
    if(it->it_code == IR_TYPE_POINTER && it->it_pointer.pointee == type)
      return i;
  }
  if(!may_create)
    return -1;

  iu->iu_types_created = 1;

  ir_type_t it;
  int r = VECTOR_LEN(&iu->iu_types);
  it.it_code = IR_TYPE_POINTER;
  it.it_pointer.pointee = type;
  VECTOR_PUSH_BACK(&iu->iu_types, it);
  return r;
}
Exemplo n.º 14
0
void intercom_update_interfaces(intercom_ctx *ctx) {
  for (int i = 0; i < VECTOR_LEN(ctx->interfaces); i++) {
    intercom_if *iface = &VECTOR_INDEX(ctx->interfaces, i);

    iface->ifindex = if_nametoindex(iface->ifname);

    if (!iface->ifindex)
      continue;

    if (join_mcast(ctx->fd, ctx->groupaddr.sin6_addr, iface))
      iface->ok = true;
  }
}
Exemplo n.º 15
0
static void
write_tsb_link(tsb_link_vector_el_t *tsb_linkp, FILE *ofh) {
  tsb_link_t *tsb_link = *tsb_linkp;
  tsb_link_entry_t *entry;
  uint64_t i;

  add_object_to_physmap(&Physmap,
			tsb_link->srcfile, tsb_link->srcline, tsb_link->lineno,
			tsb_link->start_addr,
			tsb_link->start_addr + 
			VECTOR_LEN(tsb_link->entries) * LINK_SIZE,
			"TSB_LINK", tsb_link->name);

  fprintf(ofh, "@%016llx\t// TSB_LINK '%s'\n", tsb_link->start_addr,
	  tsb_link->name);

  iterate_vector(&(tsb_link->entries),
		 (vector_elem_func_t) write_tsb_link_entry,
		 ofh);


}
Exemplo n.º 16
0
FRAME *DoComposite( FRAME *dest, FRAME *src, struct gFixRectMessage *gfr,
                    MethodID how, WORD mixratio, BOOL tile, struct PPTBase *PPTBase )
{
    WORD row, col;
    WORD dcomps = dest->pix->components,
         scomps = src->pix->components;
    WORD dest_has_alpha = 0, src_has_alpha = 0;
    WORD top, bottom, left, right;

    D(bug("Doing the composite.  gfr = %d,%d,%d,%d\n",
           gfr->x, gfr->y, gfr->dim.Width, gfr->dim.Height));

    /*
     *  Initialize
     */

    if( src->pix->colorspace == CS_ARGB )
        src_has_alpha = 1;

    if( dest->pix->colorspace == CS_ARGB )
        dest_has_alpha = 1;

    if( tile ) {
        top = dest->selbox.MinY;
        left = dest->selbox.MinX;
        bottom = dest->selbox.MaxY;
        right = dest->selbox.MaxX;
    } else {
        top = gfr->y;
        bottom = gfr->y + gfr->dim.Height;
        left = gfr->x;
        right = gfr->x + gfr->dim.Width;
    }

    InitProgress( dest, "Compositing...", top, bottom );

    for( row = top; row < bottom; row++ ) {
        ROWPTR scp, dcp;
        WORD srow;

        srow = (row - gfr->y) % gfr->dim.Height;
        if( srow < 0 && tile ) srow += gfr->dim.Height;

        scp = GetPixelRow(src,  srow);
        dcp = GetPixelRow(dest, row);

        if( !dcp ) continue; /* Skip all areas that are outside */

        if( Progress(dest, row) )
            return NULL;

        for( col = left; col < right; col++ ) {
            LONG a, tr,tg,tb;
            UBYTE *s, *d;
            WORD scol;

            /*
             *  Sanitation check.  Let's not overwrite innocent
             *  memory.
             */

            if( col < 0 || col >= dest->pix->width ) continue;

            scol = ( col - gfr->x ) % gfr->dim.Width;
            if( scol < 0 && tile ) scol += gfr->dim.Width;

            if( src_has_alpha )
                a = (LONG)scp[scomps*scol];

            d = &dcp[dcomps*col+dest_has_alpha];
            s = &scp[scomps*scol+src_has_alpha];

            tr = *(d+0);
            tg = *(d+1);
            tb = *(d+2);

            switch( how ) {
                case Direct:
                    tr = *s; tg = *(s+1); tb = *(s+2);
                    break;

                case Minimum:
                    if( VECTOR_LEN(tr, tg, tb) > VECTOR_LEN(*s, *(s+1), *(s+2)) ) {
                        tr = *s; tg = *(s+1); tb = *(s+2);
                    }
                    break;

                case Maximum:
                    if( VECTOR_LEN(tr, tg, tb) < VECTOR_LEN(*s, *(s+1), *(s+2)) ) {
                        tr = *s; tg = *(s+1); tb = *(s+2);
                    }
                    break;

                case Mix:
                    tr = (mixratio * (*s) + (255-mixratio) * tr ) / 255;
                    tg = (mixratio * (*(s+1)) + (255-mixratio) * tg ) / 255;
                    tb = (mixratio * (*(s+2)) + (255-mixratio) * tb ) / 255;
                    break;

                case TransparentBlack:
                    if( *s || *(s+1) || *(s+2) ) {
                        tr = *s; tg = *(s+1); tb = *(s+2);
                    }
                    break;

                case Add:
                    tr = CLAMP_UP(*(s+0) + tr, 255);
                    tg = CLAMP_UP(*(s+1) + tg, 255);
                    tb = CLAMP_UP(*(s+2) + tb, 255);
                    break;

                case Subtract:
                    tr = CLAMP_DOWN( tr - *(s+0), 0 );
                    tg = CLAMP_DOWN( tg - *(s+1), 0 );
                    tb = CLAMP_DOWN( tb - *(s+2), 0 );
                    break;

                case Multiply:
                    tr = (tr * *(s+0)) / 256;
                    tg = (tg * *(s+1)) / 256;
                    tb = (tb * *(s+2)) / 256;
                    break;
            }

            if( src_has_alpha ) {
                tr = ((255-a) * tr + a * *(d+0) ) /256;
                tg = ((255-a) * tg + a * *(d+1) ) /256;
                tb = ((255-a) * tb + a * *(d+2) ) /256;
            }

            *d     = tr;
            if( dest->pix->colorspace != CS_GRAYLEVEL ) {
                *(d+1) = tg;
                *(d+2) = tb;
            }

#if 0
            for( pix = 0; pix < colors; pix++ ) {
                UBYTE s,d;
                LONG  t;

                d = dcp[dcomps*col+pix+dest_has_alpha];
                s = scp[scomps*(col-gfr->x)+pix+src_has_alpha];
                t = (LONG)d;

                switch(how) {
                    case Direct:
                        t = s;
                        break;

                    case Minimum:
                        if( d > s ) t = s;
                        break;

                    case Maximum:
                        if( d < s ) t = s;
                        break;

                    case Mix:
                        t = (mixratio*s + (255-mixratio)*d)/255;
                        break;

                    case TransparentBlack:
                        if( s != 0 ) t = s;
                        break;

                    case Add:
                        t = d+s;
                        if( t > 255 ) t = 255;
                        break;

                    case Subtract:
                        t = d-s;
                        if( t < 0 ) t = 0;
                        break;

                    case Multiply:
                        t = ((LONG)d * (LONG)s) / 256;
                        break;

                }

                if( src_has_alpha )
                    t = ((255-a) * t + a*d)/255;

                dcp[dcomps*col+pix+dest_has_alpha] = (UBYTE)t;
            }
#endif
        }
        PutPixelRow(dest,row,dcp);
    }

    FinishProgress(dest);

    return dest;
}
Exemplo n.º 17
0
void intercom_add_interface(intercom_ctx *ctx, char *ifname) {
  if (intercom_has_ifname(ctx, ifname))
    return;

  intercom_if iface = {
    .ok = false,
    .ifname = ifname
  };

  VECTOR_ADD(ctx->interfaces, iface);

  intercom_update_interfaces(ctx);
}

void intercom_init(intercom_ctx *ctx) {

  struct in6_addr mgroup_addr;
  inet_pton(AF_INET6, INTERCOM_GROUP, &mgroup_addr); // TODO Fehler abfangen

  ctx->groupaddr = (struct sockaddr_in6) {
    .sin6_family = AF_INET6,
    .sin6_addr = mgroup_addr,
    .sin6_port = htons(INTERCOM_PORT),
  };

  ctx->fd = socket(PF_INET6, SOCK_DGRAM | SOCK_NONBLOCK, 0);

  if (ctx->fd < 0)
    exit_error("creating socket");

  struct sockaddr_in6 server_addr = {};

  server_addr.sin6_family = AF_INET6;
  server_addr.sin6_addr = in6addr_any;
  server_addr.sin6_port = htons(INTERCOM_PORT);

  if (bind(ctx->fd, (struct sockaddr *)&server_addr, sizeof(server_addr)) < 0) {
    perror("bind failed");
    exit(EXIT_FAILURE);
  }
}

void intercom_seek(intercom_ctx *ctx, const struct in6_addr *address) {
  intercom_packet_seek packet;

  uint32_t nonce = rand();

  packet.hdr = (intercom_packet_hdr) {
    .type = INTERCOM_SEEK,
    .nonce = nonce,
    .ttl = 255,
  };

  memcpy(&packet.address, address, 16);

  intercom_recently_seen_add(ctx, &packet.hdr);

  intercom_send_packet(ctx, (uint8_t*)&packet, sizeof(packet));
}

void intercom_send_packet(intercom_ctx *ctx, uint8_t *packet, ssize_t packet_len) {
  for (int i = 0; i < VECTOR_LEN(ctx->interfaces); i++) {
    intercom_if *iface = &VECTOR_INDEX(ctx->interfaces, i);

    if (!iface->ok)
      continue;

    struct sockaddr_in6 groupaddr = ctx->groupaddr;

    groupaddr.sin6_scope_id = iface->ifindex;

    printf("intercom send %i %zi\n", iface->ifindex, packet_len);
    ssize_t rc = sendto(ctx->fd, packet, packet_len, 0, &groupaddr, sizeof(groupaddr));

    if (rc < 0)
      iface->ok = false;
  }
}

bool intercom_recently_seen(intercom_ctx *ctx, intercom_packet_hdr *hdr) {
  for (int i = 0; i < VECTOR_LEN(ctx->recent_packets); i++) {
    intercom_packet_hdr *ref_hdr = &VECTOR_INDEX(ctx->recent_packets, i);

    if (ref_hdr->nonce == hdr->nonce && ref_hdr->type == hdr->type)
        return true;
  }
  return false;
}

void intercom_recently_seen_add(intercom_ctx *ctx, intercom_packet_hdr *hdr) {
  if (VECTOR_LEN(ctx->recent_packets) > INTERCOM_MAX_RECENT)
    VECTOR_DELETE(ctx->recent_packets, 0);

  VECTOR_ADD(ctx->recent_packets, *hdr);
}

void intercom_handle_seek(struct l3ctx *ctx, intercom_packet_seek *packet) {
  icmp6_send_solicitation(ctx, (const struct in6_addr *)packet->address);
}
Exemplo n.º 18
0
elem XmlRpc_EncodeValue(elem val)
{
	char buf[256];
	int i;
	double x;
	elem t;

	char *s, *s2;

	if(ELEM_STRINGP(val))
	{
		t=val;
		t=CONS(t, MISC_EOL);
		t=CONS(MISC_EOL, t);
		t=CONS(SYM("string"), t);
		return(t);
	}
	if(ELEM_FIXNUMP(val))
	{
		i=TOINT(val);
		sprintf(buf, "%d", i);
		t=STRING(buf);
		t=CONS(t, MISC_EOL);
		t=CONS(MISC_EOL, t);
		t=CONS(SYM("i4"), t);
		return(t);
	}
	if(ELEM_FLONUMP(val))
	{
		x=TOFLOAT(val);
		sprintf(buf, "%g", x);
		t=STRING(buf);
		t=CONS(t, MISC_EOL);
		t=CONS(MISC_EOL, t);
		t=CONS(SYM("double"), t);
		return(t);
	}

	if(ELEM_CONSP(val))
	{
		if(CAR(val)==SYM("date-time:"))
		{
			t=XmlRpc_EncodeDate(val);
			return(t);
		}

		t=XmlRpc_EncodeArray(val);
		return(t);
	}

	if(ELEM_ENVOBJP(val))
	{
		t=XmlRpc_EncodeStruct(val);
		return(t);
	}

	if(ELEM_BYTEVECTORP(val))
	{
		s=TyFcn_ByteVectorBody(val);
		i=VECTOR_LEN(val);
		s2=kalloc(((i*4)/3)+5);
		HttpNode_EncodeMime(s2, s, i);

		kprint("send mime %d->%d\n", i, (i*4)/3);
		t=STRING(s2);
		kfree(s2);
		t=CONS(t, MISC_EOL);
		t=CONS(MISC_EOL, t);
		t=CONS(SYM("base64"), t);
		return(t);
	}

	if(val==MISC_TRUE)
	{
		t=STRING("1");
		t=CONS(t, MISC_EOL);
		t=CONS(MISC_EOL, t);
		t=CONS(SYM("boolean"), t);
		return(t);
	}
	if(val==MISC_FALSE)
	{
		t=STRING("0");
		t=CONS(t, MISC_EOL);
		t=CONS(MISC_EOL, t);
		t=CONS(SYM("boolean"), t);
		return(t);
	}

	if(val==MISC_NULL)
	{
		t=STRING("$null");
		t=CONS(t, MISC_EOL);
		t=CONS(MISC_EOL, t);
		t=CONS(SYM("boolean"), t);
		return(t);
	}

	t=STRING("$undefined");
	t=CONS(t, MISC_EOL);
	t=CONS(MISC_EOL, t);
	t=CONS(SYM("string"), t);
	return(t);
}