Ejemplo n.º 1
0
EXTERN int
Nap_Polyline(
    NapClientData       *nap_cd,
    int *px,		/* x polygon points  */
    int *py,		/* y polygon points  */
    size_t n,		/* number of polygon points */
    float *dataPtr,	/* place to draw line */
    float value,	/* value to write line */
    size_t x_dim,	/* x dimension size	*/
    size_t y_dim,	/* y dimension size	*/
    int close)		/* Close the polygon? */
{
    size_t i;	/* counter	*/
    int	status;	/* error code */



    for(i = 1; i < n; i++) {
        status = Nap_DrawLine(nap_cd, px[i-1], py[i-1], px[i], py[i], dataPtr,
		value, x_dim, y_dim);
	CHECK2(status == TCL_OK, "Nap_Polyline: error calling Nap_DrawLine");
    }
    if(close) {
        status = Nap_DrawLine(nap_cd, px[n-1], py[n-1], px[0], py[0], dataPtr,
		value, x_dim, y_dim);
	CHECK2(status == TCL_OK, "Nap_Polyline: error calling Nap_DrawLine");
    }
    return TCL_OK;
}
Ejemplo n.º 2
0
static void *dongle_f(void *arg) {
	struct dongle_struct *ds = arg;
	rtlsdr_dev_t *dev = NULL;

	fprintf(stderr, "Initializing %d\n", ds->id);
#ifdef PURKKA1
	CHECK1(rtlsdr_open(&dev, (ds->id + 1) % 3));
#define trigger_id 2
#else
	CHECK1(rtlsdr_open(&dev, ds->id));
#define trigger_id 0
#endif
	ds->dev = dev;
	CHECK1(rtlsdr_set_sample_rate(dev, samprate));
	CHECK1(rtlsdr_set_dithering(dev, 0));
	CHECK1(rtlsdr_set_center_freq(dev, frequency));
	CHECK1(rtlsdr_set_tuner_gain_mode(dev, 1));
	CHECK1(rtlsdr_set_tuner_gain(dev, gain));
	CHECK1(rtlsdr_reset_buffer(dev));

	fprintf(stderr, "Initialized %d\n", ds->id);
	
	donglesok++;
	for(;;) {
		int task;
		pthread_mutex_lock(&dongle_m);
		if(dongle_task == DONGLE_EXIT)
			break; 
		sem_post(&dongle_sem);
		pthread_cond_wait(&dongle_c, &dongle_m);
		task = dongle_task;
		pthread_mutex_unlock(&dongle_m);

		if(task == DONGLE_READ) {
			int ret;
			int blocksize = ds->blocksize, n_read = 0;
			n_read = 0;
			errno = 0;
			CHECK2(ret = rtlsdr_read_sync(dev, ds->buffer, blocksize, &n_read));
			if(ret < 0) {
			} else if(n_read < blocksize) {
				fprintf(stderr, "Short read %d: %d/%d\n", ds->id, n_read, blocksize);
			} else if(coherent_debug) {
				fprintf(stderr, "Read %d\n", ds->id);
			}
		} else if(task == DONGLE_EXIT)
			break;
	}
	donglesok--;

	err:
	fprintf(stderr, "Exiting %d\n", ds->id);
	if(dev)
		CHECK2(rtlsdr_close(dev));
	sem_post(&dongle_sem);
	return NULL;
}
Ejemplo n.º 3
0
static int
FileWriteNAO(
    Tcl_Interp		*interp,
    CONST char		*naoName,
    Tcl_Obj		*format,
    Tk_PhotoImageBlock	*blockPtr)
{
    register long w, h,pixelSize;
    long greenOffset, blueOffset;
    unsigned char *pixelPtr, *pixLinePtr;
    char *str;
    Nap_NAO *naoPtr; 
    size_t shape[3];
    register Nap_u8 *red,*green,*blue;
    NapClientData *nap_cd = Nap_GetClientData(interp);
 
    shape[0] = 3;
    shape[1] = blockPtr->height;
    shape[2] = blockPtr->width;
    naoPtr = Nap_NewNAO(nap_cd, NAP_U8, 3, shape);
    CHECK2(naoPtr,"FileWriteNAO: error calling Nap_NewNAO");
    str = Nap_Assign(nap_cd, (char *) naoName, naoPtr->id);
    CHECK2(str,"FileWriteNAO: error calling Nap_Assign");
    pixLinePtr = blockPtr->pixelPtr + blockPtr->offset[0];
    greenOffset = blockPtr->offset[1] - blockPtr->offset[0];
    blueOffset = blockPtr->offset[2] - blockPtr->offset[0];
    red = naoPtr->data.U8; 
    green = red + shape[1]*shape[2];
    blue = green + shape[1]*shape[2];

/* red,green,blue,red,green,blue,red.... */

/*
 * Terribly inefficient write process
 */

    pixelSize = blockPtr->pixelSize;
    for (h = blockPtr->height; h > 0; h--) {
        pixelPtr = pixLinePtr;
        for (w = blockPtr->width; w > 0; w--) {
            *red = pixelPtr[0];
            *green = pixelPtr[greenOffset];
            *blue = pixelPtr[blueOffset];
            pixelPtr = pixelPtr + pixelSize;
            red++; green++; blue++;
        }
        pixLinePtr = pixLinePtr + blockPtr->pitch;
    }
    return TCL_OK;
}
Ejemplo n.º 4
0
static void check_widget_rect( LCUI_SysEvent ev, void *arg )
{
	int ret = 0;
	LCUI_RectF rectf;
	LCUI_Rect rect, old_rect;
	LCUI_Rect *paint_rect = &ev->paint.rect;

	rectf.x = self.x;
	rectf.y = self.y;
	rectf.width = WIDGET_WIDTH;
	rectf.height = WIDGET_WIDTH;
	LCUIMetrics_ComputeRectActual( &old_rect, &rectf );
	LCUIMetrics_ComputeRectActual( &rect, &self.widget->box.canvas );
	LCUIRect_MergeRect( &rect, &rect, &old_rect );
	CHECK2( check_rect_correct( &rect, paint_rect ) );
	if( ret != 0 ) {
		TEST_LOG( "[%d] correct: (%d, %d, %d, %d),"
			  " actual: (%d, %d, %d, %d)\n", self.step,
			  rect.x, rect.y, rect.width, rect.height,
			  paint_rect->x, paint_rect->y,
			  paint_rect->width, paint_rect->height );
	} else {
		self.pass += 1;
	}
	self.count += 1;
	self.x = self.widget->x;
	self.y = self.widget->y;
	LCUI_PostSimpleTask( test_move_widget, NULL, NULL );
}
Ejemplo n.º 5
0
static int napFillPolygon(
    NapClientData       	*nap_cd,
    struct PointListHeader	*VertexList,	/* Polygon points */
    int				XOffset,	/* offsets to x values */
    int				YOffset)	/* ofset to y values */
{
    struct EdgeState *EdgeTableBuffer;
    int CurrentY;

/*
 * It takes a minimum of 3 vertices to cause any pixels to be
 * drawn; reject polygons that are guaranteed to be invisible
 * In this case nap_PolyLine will draw, nothing, a point or a line. 
 */

    if(VertexList->Length < 3) {
        return TCL_OK;
    }

/*
 *  Get enough memory to store the entire edge table
 */

    if((EdgeTableBuffer =
        (struct EdgeState *) (NAP_ALLOC(nap_cd, sizeof(struct EdgeState) *
        VertexList->Length))) == NULL) {
        CHECK2(0, "napFillPolygon: Couldn't get memory for the edge table");
    }

/*
 * Build the global edge table
 */

    napBuildGET(VertexList, EdgeTableBuffer, XOffset, YOffset);

/*
 * Scan down through the polygon edges, one scan line at a time,
 * so long as at least one edge remains in either the GET or AET
 */

    AETPtr = NULL;    /* initialize the active edge table to empty */
    CurrentY = GETPtr->StartY; /* start at the top polygon vertex */

    while ((GETPtr != NULL) || (AETPtr != NULL)) {
       napMoveXSortedToAET(CurrentY);  /* update AET for this scan line */
       napScanOutAET(nap_cd, CurrentY);        /* draw this scan line from AET */
       napAdvanceAET();                /* advance AET edges 1 scan line */
       napXSortAET();                  /* resort on X */
       CurrentY++;                     /* advance to the next scan line */
    }

/*
 * Release the memory we've allocated and we're done
 */

    NAP_FREE(nap_cd, EdgeTableBuffer);
    return TCL_OK;
}
Ejemplo n.º 6
0
int main4()
{
	int cnt = 1000000;
	start_pres_server();
	struct sched_pres *sp = (struct sched_pres*)buf;
	uint8 no = 0;
		
	while(1)
	{
		INFO("\033[1;33mtcp server... main4\033[0m \n");
		if(!is_client_connected() && !have_packet())
		{
			no = 0;
			DEBUG("no client!\n");
			usleep(1000000);
		}
		if(have_packet())
		{
			int len = get_packet(buf, MAX_LEN);
			CHECK2(len >=23 && len == sp->pkt_len);
			INFO("Get a packet!\n dst_tel_code:%x\nsrc_tel_code:%x\n"
				 "pkt_len:%d\nno%d\ntime:%s\ndata_type:%x\ndata_sub_type:%x\n"
				 "test_len:%d\n",
				 sp->dst_tel_code, sp->src_tel_code, sp->pkt_len, sp->no, ctime(&sp->time),
				 sp->data_type, sp->data_sub_type, sp->text_len);
			int i;
			uint8 c = 0;
			no++;
		//	DEBUG("should no:%d  RECV_NO:%d\n", no, sp->no);
	//		CHECK2(no==sp->no);
			for(i = 0; i < sp->text_len; i++)
			{
				if(sp->data[i] != c)
				{
					DEBUG("i = %d sp->data[i]==%d  c==%d\n", i, sp->data[i], c);
					CHECK2(sp->data[i]==c);
				}
				c++;
			}
		}
			usleep(10000);
	}
	stop_pres_server();
}
Ejemplo n.º 7
0
int main()
{
	CHECK2(pthread_create(&tid1, NULL, thread1, NULL) == 0);
	//CHECK2(pthread_create(&tid2, NULL, thread2, NULL) == 0);
	//CHECK2(pthread_create(&tid3, NULL, thread3, NULL) == 0);

	pthread_join(tid1, NULL);
	//pthread_join(tid2, NULL);
	//pthread_join(tid3, NULL);
}
Ejemplo n.º 8
0
static int GameStatusToReturnCode() {
    CHECK2((game_status & flag_quit) == 0, "status: %x", game_status);
    if (game_status & flag_mated) {
        return R_CHECKMATE;
    }
    if (game_status & flag_drawn) {
        return R_DRAW;
    }
    if (game_status & flag_resigned) {
        return R_RESIGNED;
    }
    return R_OK;
}
Ejemplo n.º 9
0
static int ParseCsaMove(JNIEnv* env,
                        jstring jmove_str,
                        unsigned int* move,
                        MoveBuf move_str) {
    const char* tmp = (*env)->GetStringUTFChars(env, jmove_str, NULL);
    CHECK(tmp != NULL);
    CHECK2(strlen(tmp) < sizeof(MoveBuf) - 1, "move: %s", tmp);
    strcpy(move_str, tmp);

    int r = interpret_CSA_move(&tree, move, move_str);
    if (r < 0) {
        LOG_DEBUG("Failed to parse move: %s: %s", move_str, str_error);
    }
    (*env)->ReleaseStringUTFChars(env, jmove_str, tmp);
    return r;
}
Ejemplo n.º 10
0
EXTERN int
Nap_Polyfill(
    NapClientData       *nap_cd,
    int *px,           /* polygon x values */
    int *py,           /* polygon y values */
    size_t n,           /* number of polygon points */
    float *dataPtr,     /* pointer to data start */
    float fill,         /* polygon draw value  */
    size_t x_dim,       /* x dimension of data */
    size_t y_dim)       /* y dimension of data */

{
    typedef struct Point point;
    typedef struct PointListHeader polygon;
    point *xyPtr;
    polygon *Polygon;

    int status;
    int i;

    status = Nap_Polyline(nap_cd, px,py,n,dataPtr,fill, x_dim, y_dim, 1);
    CHECK(status == TCL_OK);

    status = Nap_InitFill(fill,fill,dataPtr,x_dim,y_dim);
    CHECK2(status == TCL_OK, "Nap_Polyfill: error calling Nap_InitFill");

    xyPtr = (point *)NAP_ALLOC(nap_cd, sizeof(point)*n);
    Polygon = (polygon *)NAP_ALLOC(nap_cd, sizeof(polygon));

    for(i=0; i < n; i++) {
        xyPtr[i].X = px[i];
        xyPtr[i].Y = py[i];
    }
    Polygon->Length = n; 
    Polygon->PointPtr = xyPtr;

    status = napFillPolygon(nap_cd, Polygon,0,0);
    CHECK(status == TCL_OK);

    NAP_FREE(nap_cd, xyPtr);
    NAP_FREE(nap_cd, Polygon);

    return(TCL_OK);
}
Ejemplo n.º 11
0
int test_main(int, char*[])
{
    // An all-blank string is treated as zero.
    {
    int const n = 9;
    double const d[n] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
    std::string e(" ");
    CHECK0(d, n, e);
    }

    // Make sure example in comment at top works.
    //   1 3; 7 5;0; --> 1 1 1 7 7 0...
    {
    int const n = 9;
    double const d[n] = {1, 1, 1, 7, 7, 0, 0, 0, 0};
    std::string e("1 3; 7 5;0");
    CHECK0(d, n, e);
    }

    // Numbers separated by semicolons mean values; the last is
    // replicated to fill the vector.
    {
    int const n = 5;
    double const d[n] = {1, 2, 3, 3, 3};
    std::string e("1; 2; 3");
    CHECK0(d, n, e);
    }

    // Number-pairs separated by semicolons mean {value, end-duration}.
    {
    int const n = 10;
    double const d[n] = {1, 1, 1, 3, 3, 3, 5, 5, 5, 7};
    std::string e("1 3; 3 6; 5 9; 7");
    CHECK0(d, n, e);
    }

    // {value, @ attained_age}
    {
    int const n = 10;
    double const d[n] = {1, 1, 1, 3, 3, 3, 5, 5, 5, 7};
    std::string e("1 @93; 3 @96; 5 @99; 7");
    CHECK0(d, n, e);
    }

    // {value, # number_of_years_since_last_interval_endpoint}
    {
    int const n = 10;
    double const d[n] = {1, 1, 1, 3, 3, 3, 5, 5, 5, 7};
    std::string e("1 #3; 3 #3; 5 #3; 7");
    CHECK0(d, n, e);
    }

    // {value [|( begin-duration, end-duration ]|) }

    // Test [x,y).
    {
    int const n = 9;
    double const d[n] = {1, 1, 3, 3, 3, 5, 7, 7, 7};
    std::string e("1 [0, 2); 3 [2, 5); 5 [5, 6); 7");
    CHECK0(d, n, e);
    }

    // Test (x,y].
    {
    int const n = 9;
    double const d[n] = {1, 1, 1, 3, 3, 3, 5, 7, 7};
    std::string e("1; 1 (0, 2]; 3 (2, 5]; 5 (5, 6]; 7");
    CHECK0(d, n, e);
    }

    // Test a mixture of all five ways of specifying duration.
    {
    int const n = 9;
    double const d[n] = {1, 1, 1, 1, 2, 3, 4, 5, 5};
    std::string e("1 [0, 4); 2 5; 3 #1; 4 @97; 5");
    CHECK0(d, n, e);
    }

    // Test intervals of length one.
    {
    int const n = 5;
    double const d[n] = {1, 3, 5, 7, 7};
    std::string e("1 [0, 1); 3 [1, 2); 5 (1, 2]; 7");
    CHECK0(d, n, e);
    }

    // Test empty intervals.
    {
    int const n = 5;
    double const d[n] = {1, 3, 5, 7, 7};
    std::string e("1 [0, 1); 3 [1, 1]; 5 (1, 2]; 7");
    CHECK0(d, n, e);
    }

    // Test subtly improper intervals.
    {
    int const n = 5;
    double const d[n] = {0, 0, 0, 0, 0};
    std::string e("1 [0, 0); 3 (1, 2); 5 (2, 2]; 7");
    CHECK0(d, n, e);
    }

    // Test grossly improper intervals.
    {
    int const n = 9;
    double const d[n] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
    std::string e("1; 9 (2, 0]; 3 [7, 3); 5 (5, 5); 7");
    CHECK0(d, n, e);
    }

    // Test intervals with 'holes'. Since the last element is replicated,
    // there can be no 'hole' at the end.
    {
    int const n = 9;
    double const d[n] = {0, 1, 0, 3, 0, 5, 7, 7, 7};
    std::string e("1 [1, 2); 3 [3, 3]; 5 (4, 5]; 7");
    CHECK0(d, n, e);
    }

    // Test overlapping intervals.
    // TODO ?? Treat these as an error?
    {
    int const n = 9;
    double const d[n] = {1, 1, 1, 3, 3, 5, 5, 7, 7};
    std::string e("1; 1 (0, 8]; 3 (2, 7]; 5 (4, 6]; 7");
    CHECK0(d, n, e);
    }

    // Test intervals with decreasing begin-points.
    // TODO ?? Should this case be allowed?
    {
    int const n = 9;
    double const d[n] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
    std::string e("5 [5, 6); 3 [2, 5); 1 [0, 2); 7");
    CHECK0(d, n, e);
    }

    // Durations with '@' prefix mean attained age.
    {
    int const n = 10;
    double const d[n] = {0, 12, 0, 27, 0, 1, 7, 7, 7, 7};
    std::string e("12 [1, @92); 27 [@93, @93]; 1 (@94, 5]; 7");
    CHECK0(d, n, e);
    }

    // Test floating-point values; we choose values that we know
    // must be exactly representable on a binary machine, so that a
    // simple test for equality suffices.
    {
    int const n = 10;
    double const d[n] = {0, 12.25, 0, 27.875, 0, 1.0625, 7.5, 7.5, 7.5, 7.5};
    std::string e("12.25 [1, @92); 27.875 [@93, @93]; 1.0625 (@94, 5]; 7.5");
    CHECK0(d, n, e);
    }

    // {value, @ age} means {value, to-attained-age}
    {
    int const n = 10;
    double const d[n] = {1, 1, 1, 3, 3, 3, 5, 5, 5, 7};
    std::string e("1 @93; 3 @96; 5 @99; 7");
    CHECK0(d, n, e);
    }

// TODO ?? Also support and test:
//   additive expressions e.g. retirement-10 ?

    // Test construction from vector.
    //   1 1 1 2 2 --> 1 [0,3);2 [3,5)
    // TODO ?? Test against canonical representation once we define that.
    {
    int const n = 5;
    double const d[n] = {1, 1, 1, 2, 2};
    std::vector<double> v(d, d + n);
    BOOST_TEST(v == InputSequence(v).linear_number_representation());
    }

    // Test (enumerative) extra keywords.
    {
    int const n = 9;
    char const* c[n] = {"a", "a", "ccc", "ccc", "b", "b", "b", "b", "b"};
    double const d[n] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
    std::string e("a[0, 2); ccc [2, 4);b[4, 6);");
    std::vector<std::string> k;
    k.push_back("not_used");
    k.push_back("a");
    k.push_back("b");
    k.push_back("c");
    k.push_back("cc");
    k.push_back("ccc");
    CHECK1(d, n, e, k, c);
    }

    // Test numbers mixed with (enumerative) extra keywords.
    {
    int const n = 9;
    char const* c[n] = {"", "", "keyword_00", "keyword_00", "", "", "", "", ""};
    double const d[n] = {1, 1, 0, 0, 5, 5, 7, 7, 7};
    std::string e("1 [0, 2); keyword_00 [2, 4); 5 [4, 6); 7");
    std::vector<std::string> k;
    k.push_back("keyword_00");
    CHECK1(d, n, e, k, c);
    }

    // Test numbers mixed with (enumerative) extra keywords, with
    // a default keyword.
    {
    int const n = 10;
    char const* c[n] =  {"b", "b", "x", "a", "x", "x", "a", "x", "x", "x"};
    double const d[n] = {  0,   0,   0,   0,   5,   5,   0,   7,   7,   7};
    std::string e("b [0, 2); a [3, 4); 5 [4, 6); a; 7");
    std::vector<std::string> k;
    k.push_back("a");
    k.push_back("b");
    k.push_back("x");
    std::string w("x");
    CHECK2(d, n, e, k, c, w);
    }

// TODO ?? Also test keyword as scalar duration.

    // Duration keywords: {retirement, maturity}
    {
    int const n = 10;
    double const d[n] = {7, 7, 7, 7, 7, 4, 4, 4, 4, 4};
    std::string e("7, retirement; 4");
    CHECK0(d, n, e);
    InputSequence seq("7, retirement; 4", 10, 90, 95, 0, 2002, 0);
    std::vector<ValueInterval> const& i(seq.interval_representation());
    BOOST_TEST(e_inception  == i[0].begin_mode);
    BOOST_TEST(e_retirement == i[0].end_mode  );
    BOOST_TEST(e_retirement == i[1].begin_mode);
    BOOST_TEST(e_maturity   == i[1].end_mode  );
    }

// TODO ?? Also test default keyword.

// TODO ?? Also test keywords-only switch.

    return 0;
}
Ejemplo n.º 12
0
static int
Nap_DrawLine(
    NapClientData       *nap_cd,
    int x1,	/* first x coordinate  */
    int y1,	/* first y coordinate  */
    int x2,	/* second x coordinate */
    int y2,	/* second y coordinate */
    float *dataPtr,	/* place to draw line */
    float value,	/* value to write line */
    size_t x_dim,	/* x dimension size	*/
    size_t y_dim)	/* y dimension size	*/
{
    int xt;	/* temporary x value */
    int yt;	/* temporary y value */
    int dx;	/* x difference (x2 - x1) */
    int dy;	/* y difference (y2 - y1) */
    int x;	/* x position	*/
    int y;	/* y position	*/
    int yincr;	/* increment in y direction */
    int xincr;	/* increment in x direction */
    int aincr;	/* increment in y direction */
    int bincr;	/* increment in y direction */
    int d;	/* variable       */
    float *pixelPtr;	/* place to write value */
    float *maxPtr;	/* upper limit on the pointer address */

    maxPtr = dataPtr + x_dim * y_dim;

/*
 * First decide if we should increment x or y!
 */

    if (abs(x2 - x1) >= abs(y2 - y1)) { 

/*
 * Force x1 < x2
 */

        if (x1 > x2) {
            xt = x1; x1 = x2; x2 = xt;
            yt = y1; y1 = y2; y2 = yt;
        }
    
        if (y2 > y1) { 
            yincr = 1; 
        } else {
            yincr = -1;
        }
            
    
        dx = x2 - x1;
        dy = abs(y2 - y1);
        d = 2 * dy - dx;
    
        aincr = 2 * (dy - dx);
        bincr = 2 * dy;
        
        x = x1;
        y = y1;
    
/*
 * Locate and set the value of the first pixel in the line
 */
    
        pixelPtr = dataPtr + x_dim * y + x;
        CHECK4((pixelPtr >= dataPtr) && (pixelPtr <= maxPtr),
                  "attempt to draw a pixel outside the data area %d,%d",x,y);

/*
 * Setting a float pixel value
 */

        *pixelPtr = value; 
    
        for(x = x1+1; x <= x2; x++) {
            if(d >= 0) {
                y = y + yincr;
                d = d + aincr;
            } else {
                d = d + bincr;
            }
    
/*
 * Setting a float pixel value
 */
    
            pixelPtr = dataPtr + x_dim * y + x;
            CHECK2((pixelPtr >= dataPtr) && (pixelPtr <= maxPtr),
                  "attempt to draw a pixel outside the data area");
            *pixelPtr = value; 
        }
    } else {

/*
 * Force y1 < y2
 */

        if (y1 > y2) {
            xt = x1; x1 = x2; x2 = xt;
            yt = y1; y1 = y2; y2 = yt;
        }
    
        if (x2 > x1) { 
            xincr = 1; 
        } else {
            xincr = -1;
        }
            
    
        dy = y2 - y1;
        dx = abs(x2 - x1);
        d = 2 * dx - dy;
    
        aincr = 2 * (dx - dy);
        bincr = 2 * dx;
        
        x = x1;
        y = y1;
    
    /*   draw the first pixel  */
    
        pixelPtr = dataPtr + x_dim * y + x;
        CHECK2((pixelPtr >= dataPtr) && (pixelPtr <= maxPtr),
              "attempt to draw a pixel outside the data area");
        *pixelPtr = value; 
    
        for(y = y1+1; y <= y2; y++) {
            if(d >= 0) {
                x = x + xincr;
                d = d + aincr;
            } else {
                d = d + bincr;
            }
    
    /*  draw a pixel  */
    
            pixelPtr = dataPtr + x_dim * y + x;
            CHECK2((pixelPtr >= dataPtr) && (pixelPtr <= maxPtr),
                  "attempt to draw a pixel outside the data area");
            *pixelPtr = value; 
        }
    }

    return TCL_OK;
}
Ejemplo n.º 13
0
static int
StringReadNAO(
    Tcl_Interp		*interp,
    Tcl_Obj		*nap_expr,	/* string containing NAP expression */
    Tcl_Obj		*format,	/* format string not used */
    Tk_PhotoHandle	imageHandle,
    int			destX,
    int			destY,
    int			width,
    int			height,
    int			srcX,
    int			srcY)
{
    int			naoWidth;
    int			naoHeight;
    int			naoDepth;
    Nap_NAO		*naoPtr;
    Nap_NAO		*naoPtr0;
    int			rank;
    Tk_PhotoImageBlock	block;
    NapClientData	*nap_cd = Nap_GetClientData(interp);

    naoPtr0 = Nap_GetNaoFromObj(nap_cd, nap_expr);
    CHECK2(naoPtr0, "StringReadNAO: error calling Nap_GetNaoFromObj");
    Nap_IncrRefCount(nap_cd, naoPtr0);
    naoPtr = Nap_CastNAO(nap_cd, naoPtr0, NAP_U8);
    Nap_IncrRefCount(nap_cd, naoPtr);
    Nap_DecrRefCount(nap_cd, naoPtr0);
    rank = naoPtr->rank;
    switch (rank) {
    case 2:
        naoWidth = naoPtr->shape[1]; 
        naoHeight = naoPtr->shape[0]; 
	break;
    case 3:
        naoWidth = naoPtr->shape[2]; 
        naoHeight = naoPtr->shape[1]; 
        naoDepth = naoPtr->shape[0];
	break;
    default:
	CHECK2(0, "StringReadNAO: Rank is not 1 or 2");
    }

/*
 * Setup the dimensions for the display
 */

    if ((srcX + width) > naoWidth) {
        width = naoWidth - srcX;
    }  
    if ((srcY + height) > naoHeight) {
        height = naoHeight - srcY;
    }
    if ((width <= 0) || (height <= 0)
            || (srcX >= naoWidth) || (srcY >= naoHeight)) {
        return TCL_OK;
    }

/*
 * Get the output window open to the correct size
 */

    Tk_PhotoExpand(imageHandle, destX + width, destY + height);


/*
 * setup the supporting image data structure
 */

    block.width = naoWidth;
    block.height = naoHeight;
    block.pitch = naoWidth;     /* Address difference between corresponding
                                 * pixels in successive lines */
    block.pixelSize = 1;	/* Address difference successive pixels
                                 * in the same line */
      /* Address differences between the red, green
                                 * and blue components of the pixel and the
                                 * pixel as a whole. */

    block.offset[0] = 0;  
    block.offset[1] = 0;
    block.offset[2] = 0;
    if (rank == 3) {
        if(naoDepth >= 3) {
            block.offset[1] = naoHeight*naoWidth;
            block.offset[2] = 2 * naoWidth*naoHeight;
        } else if(naoDepth == 2) {
            block.offset[2] =  naoWidth*naoHeight;
        }
    }   

    /* Pointer to the first part of the first pixel */
    block.pixelPtr = (unsigned char *) naoPtr->data.U8;

    Tk_PhotoPutBlock(imageHandle, &block, destX, destY, naoWidth, naoHeight,
	    TK_PHOTO_COMPOSITE_OVERLAY);
    Nap_DecrRefCount(nap_cd, naoPtr);
    return TCL_OK;
}
Ejemplo n.º 14
0
QVariant MetaInfoModel::data(const QModelIndex &index, int role) const
{
	if(role == Qt::DisplayRole)
	{
		switch(index.row() + m_offset)
		{
		case 0:
			return (!index.column()) ? tr("Full Path") : CHECK1(QDir::toNativeSeparators(m_fullInfo->filePath()));
			break;
		case 1:
			return (!index.column()) ? tr("Format") : CHECK1(m_fullInfo->audioBaseInfo());
			break;
		case 2:
			return (!index.column()) ? tr("Container") : CHECK1(m_fullInfo->containerInfo());
			break;
		case 3:
			return (!index.column()) ? tr("Compression") : CHECK1(m_fullInfo->audioCompressInfo());
			break;
		case 4:
			return (!index.column()) ? tr("Duration") : CHECK1(m_fullInfo->durationInfo());
			break;
		case 5:
			return (!index.column()) ? tr("Title") : CHECK1(m_metaInfo->title());
			break;
		case 6:
			return (!index.column()) ? tr("Artist") : CHECK1(m_metaInfo->artist());
			break;
		case 7:
			return (!index.column()) ? tr("Album") : CHECK1(m_metaInfo->album());
			break;
		case 8:
			return (!index.column()) ? tr("Genre") : CHECK1(m_metaInfo->genre());
			break;
		case 9:
			return (!index.column()) ? tr("Year") : CHECK2(m_metaInfo->year());
			break;
		case 10:
			return (!index.column()) ? tr("Position") : ((m_metaInfo->position() == UINT_MAX) ? tr("Generate from list position") : CHECK2(m_metaInfo->position()));
			break;
		case 11:
			return (!index.column()) ? tr("Comment") : CHECK1(m_metaInfo->comment());
			break;
		default:
			return QVariant();
			break;
		}
	}
	else if(role == Qt::DecorationRole && index.column() == 0)
	{
		switch(index.row() + m_offset)
		{
		case 0:
			return QIcon(":/icons/folder_page.png");
			break;
		case 1:
			return QIcon(":/icons/sound.png");
			break;
		case 2:
			return QIcon(":/icons/package.png");
			break;
		case 3:
			return QIcon(":/icons/compress.png");
			break;
		case 4:
			return QIcon(":/icons/clock_play.png");
			break;
		case 5:
			return QIcon(":/icons/music.png");
			break;
		case 6:
			return QIcon(":/icons/user.png");
			break;
		case 7:
			return QIcon(":/icons/cd.png");
			break;
		case 8:
			return QIcon(":/icons/star.png");
			break;
		case 9:
			return QIcon(":/icons/date.png");
			break;
		case 10:
			return QIcon(":/icons/timeline_marker.png");
			break;
		case 11:
			return QIcon(":/icons/comment.png");
			break;
		default:
			return QVariant();
			break;
		}
	}
	else if(role == Qt::TextColorRole && index.column() == 1)
	{
		switch(index.row() + m_offset)
		{
		case 0:
			return CHECK3(m_fullInfo->filePath());
			break;
		case 1:
			return CHECK3(m_fullInfo->audioBaseInfo());
			break;
		case 2:
			return CHECK3(m_fullInfo->containerInfo());
			break;
		case 3:
			return CHECK3(m_fullInfo->audioCompressInfo());
			break;
		case 4:
			return CHECK4(m_fullInfo->durationInfo());
			break;
		case 5:
			return CHECK3(m_metaInfo->title());
			break;
		case 6:
			return CHECK3(m_metaInfo->artist());
			break;
		case 7:
			return CHECK3(m_metaInfo->album());
			break;
		case 8:
			return CHECK3(m_metaInfo->genre());
			break;
		case 9:
			return CHECK4(m_metaInfo->year());
			break;
		case 10:
			return CHECK4(m_metaInfo->position());
			break;
		case 11:
			return CHECK3(m_metaInfo->comment());
			break;
		default:
			return QVariant();
			break;
		}
	}
	else
	{
		return QVariant();
	}
}