Beispiel #1
0
void revmem(void)
{
  long i_mem;
  double data;
  
  for (i_mem=0; i_mem<n_memories; i_mem++) {
    fprintf(stderr, "%s", Memory[i_mem]->name);
    if (Memory[i_mem]->is_string)
      fprintf(stderr,"\t %s\n", str_memoryData[Memory[i_mem]->index]);
    else {
      data = memoryData[Memory[i_mem]->index];
      fprintf(stderr, choose_format(format_flag, data), '\t', data, '\n');
    }
  }
}
Beispiel #2
0
static HRESULT
drm_resource_from_present( struct d3dadapter9_context *ctx,
                           struct pipe_screen *screen,
                           ID3DPresent *present,
                           HWND ovr,
                           const RECT *dest,
                           RECT *rect,
                           RGNDATA **rgn,
                           struct pipe_resource **res_out )
{
    struct pipe_resource templ;
    struct winsys_handle handle;
    D3DDRM_BUFFER drmbuf;
    HRESULT hr;

    /* get a real backbuffer handle from the windowing system */
    hr = ID3DPresent_GetBuffer(present, ovr, &drmbuf, dest, rect, rgn);
    if (FAILED(hr)) {
        DBG("Unable to get presentation backend display buffer.\n");
        return hr;
    } else if (hr == D3DOK_WINDOW_OCCLUDED) {
        return hr;
    }

    handle.type = DRM_API_HANDLE_TYPE_SHARED;
    handle.handle = drmbuf.iName;
    handle.stride = drmbuf.dwStride;

    memset(&templ, 0, sizeof(templ));
    templ.target = PIPE_TEXTURE_2D;
    templ.last_level = 0;
    templ.width0 = drmbuf.dwWidth;
    templ.height0 = drmbuf.dwHeight;
    templ.depth0 = 1;
    templ.array_size = 1;
    templ.format = choose_format(screen, drmbuf.dwCPP);
    templ.bind = PIPE_BIND_DISPLAY_TARGET | PIPE_BIND_RENDER_TARGET;

    *res_out = screen->resource_from_handle(screen, &templ, &handle);
    if (!*res_out) {
        DBG("Invalid resource obtained from ID3DPresent backend.\n");
        return D3DERR_DRIVERINTERNALERROR;
    }
    
    return D3D_OK;
}
Beispiel #3
0
int QNX_InitGL(void)
{
    int usage = SCREEN_USAGE_OPENGL_ES1;
	int transp = SCREEN_TRANSPARENCY_NONE;
	EGLint interval = 1;
	int size[2] = { -1, -1 };
	int pos[2] = { 0, 0 };
	int nbuffers = 2;
	int format;
	EGLConfig config;
    EGLint           err;

    config = choose_config(eglDisplay, "rgb565");
    if (config == (EGLConfig)0) {
        Com_Printf( "Demo Thread Init: failed to find config!" );
        return FALSE;
	}

    // Create EGL rendering context
    eglContext = eglCreateContext( eglDisplay, config, EGL_NO_CONTEXT, NULL );
    err = eglGetError( );
    if ( eglContext == EGL_NO_CONTEXT ) {
        Com_Printf( "Demo Thread Init: can't create gles2 context!" );
        PrintEglError( err );
		return FALSE;
    }

    err = screen_create_context(&screen_ctx, 0);
	if (err) {
		Com_Printf("screen_create_context");
		return FALSE;
	}

    err = screen_create_window(&screen_win, screen_ctx);
	if (err) {
		Com_Printf("screen_create_window");
		return FALSE;
	}

	format = choose_format(eglDisplay, config);
	err = screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_FORMAT, &format);
	if (err) {
		Com_Printf("screen_set_window_property_iv(SCREEN_PROPERTY_FORMAT)");
		return FALSE;
	}



	err = screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_USAGE, &usage);
	if (err) {
		Com_Printf("screen_set_window_property_iv(SCREEN_PROPERTY_USAGE)");
		return FALSE;
	}

	size[0]=1024;
	size[1]=768;

	err = screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_BUFFER_SIZE, size);
	if (err) {
		Com_Printf("screen_set_window_property_iv(screen_set_window_property_iv)");
		return FALSE;
	}

	if (size[0] > 0 && size[1] > 0) {
		err = screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_SIZE, size);
		if (err) {
			Com_Printf("screen_set_window_property_iv(SCREEN_PROPERTY_SIZE)");
			return FALSE;
		}
	} else {
		err = screen_get_window_property_iv(screen_win, SCREEN_PROPERTY_SIZE, size);
		if (err) {
			Com_Printf("screen_get_window_property_iv(SCREEN_PROPERTY_SIZE)");
			return FALSE;
		}
	}

	glConfig.vidWidth = size[0];
	glConfig.vidHeight = size[1];

	InitControls();

	bz[0] = size[0];
	bz[1] = size[1];

	if (pos[0] != 0 || pos[1] != 0) {
		err = screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_POSITION, pos);
		if (err) {
			Com_Printf("screen_set_window_property_iv(SCREEN_PROPERTY_POSITION)");
			return FALSE;
		}
	}

	err = screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_TRANSPARENCY, &transp);
	if (err) {
		Com_Printf("screen_set_window_property_iv(SCREEN_PROPERTY_TRANSPARENCY)");
		return FALSE;
	}

	err = screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_SWAP_INTERVAL, &interval);
	if (err) {
		Com_Printf("screen_set_window_property_iv(SCREEN_PROPERTY_SWAP_INTERVAL)");
		return FALSE;
	}

	err = screen_create_window_buffers(screen_win, nbuffers);
	if (err) {
		Com_Printf("screen_create_window_buffers");
		return FALSE;
	}

	size[0] = 1024;
	size[1] = 600;
	err = screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_SIZE, size);
	if (err) {
		Com_Printf("screen_set_window_property_iv(SCREEN_PROPERTY_SIZE)");
		return FALSE;
	}

	err = screen_create_event(&screen_ev);
	if (err) {
		Com_Printf("screen_create_event");
		return FALSE;
	}

	eglSurface = eglCreateWindowSurface(eglDisplay, config, screen_win, NULL);
	if (eglSurface == EGL_NO_SURFACE) {
        Com_Printf( "Demo Thread Init: can't create surface!" );
        PrintEglError( err );
        return FALSE;
	}

	err = eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext);
	if (err != EGL_TRUE) {
        Com_Printf( "Demo Thread Init: can't make current!" );
		return FALSE;
	}

	pps_decoder_init(&decoder, NULL, 0);
	ppsfd = open("/pps/services/navigator/control", O_RDWR);
	if (ppsfd == -1) {
		Com_Printf("warning: failed to open PPS\n");
	}
    return TRUE;
}
Beispiel #4
0
int
archive_read_open1(struct archive *_a)
{
	struct archive_read *a = (struct archive_read *)_a;
	struct archive_read_filter *filter;
	int slot, e;

	archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW,
	    "archive_read_open");
	archive_clear_error(&a->archive);

	if (a->client.reader == NULL) {
		archive_set_error(&a->archive, EINVAL,
		    "No reader function provided to archive_read_open");
		a->archive.state = ARCHIVE_STATE_FATAL;
		return (ARCHIVE_FATAL);
	}

	/* Open data source. */
	if (a->client.opener != NULL) {
		e =(a->client.opener)(&a->archive, a->client.data);
		if (e != 0) {
			/* If the open failed, call the closer to clean up. */
			if (a->client.closer)
				(a->client.closer)(&a->archive, a->client.data);
			return (e);
		}
	}

	filter = calloc(1, sizeof(*filter));
	if (filter == NULL)
		return (ARCHIVE_FATAL);
	filter->bidder = NULL;
	filter->upstream = NULL;
	filter->archive = a;
	filter->data = a->client.data;
	filter->read = client_read_proxy;
	filter->skip = client_skip_proxy;
	filter->seek = client_seek_proxy;
	filter->close = client_close_proxy;
	filter->name = "none";
	filter->code = ARCHIVE_COMPRESSION_NONE;
	a->filter = filter;

	/* Build out the input pipeline. */
	e = choose_filters(a);
	if (e < ARCHIVE_WARN) {
		a->archive.state = ARCHIVE_STATE_FATAL;
		return (ARCHIVE_FATAL);
	}

	slot = choose_format(a);
	if (slot < 0) {
		close_filters(a);
		a->archive.state = ARCHIVE_STATE_FATAL;
		return (ARCHIVE_FATAL);
	}
	a->format = &(a->formats[slot]);

	a->archive.state = ARCHIVE_STATE_HEADER;
	return (e);
}
Beispiel #5
0
/*
 * Read header of next entry.
 */
int
archive_read_next_header2(struct archive *_a, struct archive_entry *entry)
{
	struct archive_read *a = (struct archive_read *)_a;
	int slot, ret;

	__archive_check_magic(_a, ARCHIVE_READ_MAGIC,
	    ARCHIVE_STATE_HEADER | ARCHIVE_STATE_DATA,
	    "archive_read_next_header");

	++_a->file_count;
	archive_entry_clear(entry);
	archive_clear_error(&a->archive);

	/*
	 * If no format has yet been chosen, choose one.
	 */
	if (a->format == NULL) {
		slot = choose_format(a);
		if (slot < 0) {
			a->archive.state = ARCHIVE_STATE_FATAL;
			return (ARCHIVE_FATAL);
		}
		a->format = &(a->formats[slot]);
	}

	/*
	 * If client didn't consume entire data, skip any remainder
	 * (This is especially important for GNU incremental directories.)
	 */
	if (a->archive.state == ARCHIVE_STATE_DATA) {
		ret = archive_read_data_skip(&a->archive);
		if (ret == ARCHIVE_EOF) {
			archive_set_error(&a->archive, EIO, "Premature end-of-file.");
			a->archive.state = ARCHIVE_STATE_FATAL;
			return (ARCHIVE_FATAL);
		}
		if (ret != ARCHIVE_OK)
			return (ret);
	}

	/* Record start-of-header. */
	a->header_position = a->archive.file_position;

	ret = (a->format->read_header)(a, entry);

	/*
	 * EOF and FATAL are persistent at this layer.  By
	 * modifying the state, we guarantee that future calls to
	 * read a header or read data will fail.
	 */
	switch (ret) {
	case ARCHIVE_EOF:
		a->archive.state = ARCHIVE_STATE_EOF;
		break;
	case ARCHIVE_OK:
		a->archive.state = ARCHIVE_STATE_DATA;
		break;
	case ARCHIVE_WARN:
		a->archive.state = ARCHIVE_STATE_DATA;
		break;
	case ARCHIVE_RETRY:
		break;
	case ARCHIVE_FATAL:
		a->archive.state = ARCHIVE_STATE_FATAL;
		break;
	}

	a->read_data_output_offset = 0;
	a->read_data_remaining = 0;
	return (ret);
}
Beispiel #6
0
int
archive_read_open1(struct archive *_a)
{
	struct archive_read *a = (struct archive_read *)_a;
	struct archive_read_filter *filter, *tmp;
	int slot;
	int e = 0;
	unsigned int i;

	archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW,
	    "archive_read_open");
	archive_clear_error(&a->archive);

	if (a->client.reader == NULL) {
		archive_set_error(&a->archive, EINVAL,
		    "No reader function provided to archive_read_open");
		a->archive.state = ARCHIVE_STATE_FATAL;
		return (ARCHIVE_FATAL);
	}

	/* Open data source. */
	if (a->client.opener != NULL) {
		e = (a->client.opener)(&a->archive, a->client.dataset[0].data);
		if (e != 0) {
			/* If the open failed, call the closer to clean up. */
			if (a->client.closer) {
				for (i = 0; i < a->client.nodes; i++)
					(a->client.closer)(&a->archive,
					    a->client.dataset[i].data);
			}
			return (e);
		}
	}

	filter = calloc(1, sizeof(*filter));
	if (filter == NULL)
		return (ARCHIVE_FATAL);
	filter->bidder = NULL;
	filter->upstream = NULL;
	filter->archive = a;
	filter->data = a->client.dataset[0].data;
	filter->open = client_open_proxy;
	filter->read = client_read_proxy;
	filter->skip = client_skip_proxy;
	filter->seek = client_seek_proxy;
	filter->close = client_close_proxy;
	filter->sswitch = client_switch_proxy;
	filter->name = "none";
	filter->code = ARCHIVE_FILTER_NONE;

	a->client.dataset[0].begin_position = 0;
	if (!a->filter || !a->bypass_filter_bidding)
	{
		a->filter = filter;
		/* Build out the input pipeline. */
		e = choose_filters(a);
		if (e < ARCHIVE_WARN) {
			a->archive.state = ARCHIVE_STATE_FATAL;
			return (ARCHIVE_FATAL);
		}
	}
	else
	{
		/* Need to add "NONE" type filter at the end of the filter chain */
		tmp = a->filter;
		while (tmp->upstream)
			tmp = tmp->upstream;
		tmp->upstream = filter;
	}

	if (!a->format)
	{
		slot = choose_format(a);
		if (slot < 0) {
			__archive_read_close_filters(a);
			a->archive.state = ARCHIVE_STATE_FATAL;
			return (ARCHIVE_FATAL);
		}
		a->format = &(a->formats[slot]);
	}

	a->archive.state = ARCHIVE_STATE_HEADER;

	/* Ensure libarchive starts from the first node in a multivolume set */
	client_switch_proxy(a->filter, 0);
	return (e);
}
GeglBuffer *
gimp_image_contiguous_region_by_seed (GimpImage           *image,
                                      GimpDrawable        *drawable,
                                      gboolean             sample_merged,
                                      gboolean             antialias,
                                      gfloat               threshold,
                                      gboolean             select_transparent,
                                      GimpSelectCriterion  select_criterion,
                                      gint                 x,
                                      gint                 y)
{
  GimpPickable *pickable;
  GeglBuffer   *src_buffer;
  GeglBuffer   *mask_buffer;
  const Babl   *format;
  gint          n_components;
  gboolean      has_alpha;
  gfloat        start_col[MAX_CHANNELS];

  g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
  g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);

  if (sample_merged)
    pickable = GIMP_PICKABLE (image);
  else
    pickable = GIMP_PICKABLE (drawable);

  gimp_pickable_flush (pickable);

  src_buffer = gimp_pickable_get_buffer (pickable);

  format = choose_format (src_buffer, select_criterion,
                          &n_components, &has_alpha);

  gegl_buffer_sample (src_buffer, x, y, NULL, start_col, format,
                      GEGL_SAMPLER_NEAREST, GEGL_ABYSS_NONE);

  if (has_alpha)
    {
      if (select_transparent)
        {
          /*  don't select transparent regions if the start pixel isn't
           *  fully transparent
           */
          if (start_col[n_components - 1] > 0)
            select_transparent = FALSE;
        }
    }
  else
    {
      select_transparent = FALSE;
    }

  mask_buffer = gegl_buffer_new (gegl_buffer_get_extent (src_buffer),
                                 babl_format ("Y float"));

  find_contiguous_region_helper (src_buffer, mask_buffer,
                                 format, n_components, has_alpha,
                                 select_transparent, select_criterion,
                                 antialias, threshold,
                                 x, y, start_col);

  return mask_buffer;
}
GeglBuffer *
gimp_image_contiguous_region_by_color (GimpImage            *image,
                                       GimpDrawable         *drawable,
                                       gboolean              sample_merged,
                                       gboolean              antialias,
                                       gfloat                threshold,
                                       gboolean              select_transparent,
                                       GimpSelectCriterion   select_criterion,
                                       const GimpRGB        *color)
{
  /*  Scan over the image's active layer, finding pixels within the
   *  specified threshold from the given R, G, & B values.  If
   *  antialiasing is on, use the same antialiasing scheme as in
   *  fuzzy_select.  Modify the image's mask to reflect the
   *  additional selection
   */
  GeglBufferIterator *iter;
  GimpPickable       *pickable;
  GeglBuffer         *src_buffer;
  GeglBuffer         *mask_buffer;
  const Babl         *format;
  gint                n_components;
  gboolean            has_alpha;
  gfloat              start_col[MAX_CHANNELS];

  g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
  g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL);
  g_return_val_if_fail (color != NULL, NULL);

  if (sample_merged)
    pickable = GIMP_PICKABLE (image);
  else
    pickable = GIMP_PICKABLE (drawable);

  gimp_pickable_flush (pickable);

  src_buffer = gimp_pickable_get_buffer (pickable);

  format = choose_format (src_buffer, select_criterion,
                          &n_components, &has_alpha);

  gimp_rgba_get_pixel (color, format, start_col);

  if (has_alpha)
    {
      if (select_transparent)
        {
          /*  don't select transparancy if "color" isn't fully transparent
           */
          if (start_col[n_components - 1] > 0.0)
            select_transparent = FALSE;
        }
    }
  else
    {
      select_transparent = FALSE;
    }

  mask_buffer = gegl_buffer_new (gegl_buffer_get_extent (src_buffer),
                                 babl_format ("Y float"));

  iter = gegl_buffer_iterator_new (src_buffer,
                                   NULL, 0, format,
                                   GEGL_BUFFER_READ, GEGL_ABYSS_NONE);

  gegl_buffer_iterator_add (iter, mask_buffer,
                            NULL, 0, babl_format ("Y float"),
                            GEGL_BUFFER_WRITE, GEGL_ABYSS_NONE);

  while (gegl_buffer_iterator_next (iter))
    {
      const gfloat *src   = iter->data[0];
      gfloat       *dest  = iter->data[1];
      gint          count = iter->length;

      while (count--)
        {
          /*  Find how closely the colors match  */
          *dest = pixel_difference (start_col, src,
                                    antialias,
                                    threshold,
                                    n_components,
                                    has_alpha,
                                    select_transparent,
                                    select_criterion);

          src  += n_components;
          dest += 1;
        }
    }

  return mask_buffer;
}
int main(int argc, char *argv[])
{
	static const char opts[] = "chopv";
	static struct option options[] = {
		{ "cursor", 0, 0, 'c' },
		{ "help", 0, 0, 'h' },
		{ "overlay", 0, 0, 'o' },
		{ "primary", 0, 0, 'p' },
		{ "verbose", 0, 0, 'v' },
		{ 0, 0, 0, 0 },
	};
	struct kms_framebuffer *cursor = NULL;
	struct kms_framebuffer *root = NULL;
	struct kms_framebuffer *fb = NULL;
	struct kms_device *device;
	bool use_overlay = false;
	bool use_primary = false;
	struct kms_plane *plane;
	bool use_cursor = false;
	bool verbose = false;
	unsigned int i;
	int opt, idx;
	int fd, err;

	while ((opt = getopt_long(argc, argv, opts, options, &idx)) != -1) {
		switch (opt) {
		case 'c':
			use_cursor = true;
			break;

		case 'h':
			break;

		case 'o':
			use_overlay = true;
			break;

		case 'p':
			use_primary = true;
			break;

		case 'v':
			verbose = true;
			break;

		default:
			printf("unknown option \"%c\"\n", opt);
			return 1;
		}
	}

	if (optind >= argc) {
		fprintf(stderr, "usage: %s [options] DEVICE\n", argv[0]);
		return 1;
	}

	fd = open(argv[optind], O_RDWR);
	if (fd < 0) {
		fprintf(stderr, "open() failed: %m\n");
		return 1;
	}

	err = drmSetClientCap(fd, DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1);
	if (err < 0) {
		fprintf(stderr, "drmSetClientCap() failed: %d\n", err);
		return 1;
	}

	device = kms_device_open(fd);
	if (!device)
		return 1;

	if (verbose) {
		printf("Screens: %u\n", device->num_screens);

		for (i = 0; i < device->num_screens; i++) {
			struct kms_screen *screen = device->screens[i];
			const char *status = "disconnected";

			if (screen->connected)
				status = "connected";

			printf("  %u: %x\n", i, screen->id);
			printf("    Status: %s\n", status);
			printf("    Name: %s\n", screen->name);
			printf("    Resolution: %ux%u\n", screen->width,
			       screen->height);
		}

		printf("Planes: %u\n", device->num_planes);

		for (i = 0; i < device->num_planes; i++) {
			struct kms_plane *plane = device->planes[i];
			const char *type = NULL;

			switch (plane->type) {
			case DRM_PLANE_TYPE_OVERLAY:
				type = "overlay";
				break;

			case DRM_PLANE_TYPE_PRIMARY:
				type = "primary";
				break;

			case DRM_PLANE_TYPE_CURSOR:
				type = "cursor";
				break;
			}

			printf("  %u: %p\n", i, plane);
			printf("    ID: %x\n", plane->id);
			printf("    CRTC: %x\n", plane->crtc->id);
			printf("    Type: %x (%s)\n", plane->type, type);
		}
	}

	if (use_cursor) {
		unsigned int x, y;
		uint32_t format;

		plane = kms_device_find_plane_by_type(device,
						      DRM_PLANE_TYPE_CURSOR,
						      0);
		if (!plane) {
			fprintf(stderr, "no cursor plane found\n");
			return 1;
		}

		format = choose_format(plane);
		if (!format) {
			fprintf(stderr, "no matching format found\n");
			return 1;
		}

		cursor = kms_framebuffer_create(device, 32, 32, format);
		if (!cursor) {
			fprintf(stderr, "failed to create cursor buffer\n");
			return 1;
		}

		prepare_framebuffer(cursor, false);

		x = (device->screens[0]->width - cursor->width) / 2;
		y = (device->screens[0]->height - cursor->height) / 2;

		kms_plane_set(plane, cursor, x, y);
	}

	if (use_overlay) {
		uint32_t format;

		plane = kms_device_find_plane_by_type(device,
						      DRM_PLANE_TYPE_OVERLAY,
						      0);
		if (!plane) {
			fprintf(stderr, "no overlay plane found\n");
			return 1;
		}

		format = choose_format(plane);
		if (!format) {
			fprintf(stderr, "no matching format found\n");
			return 1;
		}

		fb = kms_framebuffer_create(device, 320, 240, format);
		if (!fb)
			return 1;

		prepare_framebuffer(fb, false);

		kms_plane_set(plane, fb, 0, 0);
	}

	if (use_primary) {
		unsigned int x, y;
		uint32_t format;

		plane = kms_device_find_plane_by_type(device,
						      DRM_PLANE_TYPE_PRIMARY,
						      0);
		if (!plane) {
			fprintf(stderr, "no primary plane found\n");
			return 1;
		}

		format = choose_format(plane);
		if (!format) {
			fprintf(stderr, "no matching format found\n");
			return 1;
		}

		root = kms_framebuffer_create(device, 640, 480, format);
		if (!root)
			return 1;

		prepare_framebuffer(root, true);

		x = (device->screens[0]->width - root->width) / 2;
		y = (device->screens[0]->height - root->height) / 2;

		kms_plane_set(plane, root, x, y);
	}

	while (1) {
		struct timeval timeout = { 1, 0 };
		fd_set fds;

		FD_ZERO(&fds);
		FD_SET(STDIN_FILENO, &fds);

		err = select(STDIN_FILENO + 1, &fds, NULL, NULL, &timeout);
		if (err < 0) {
			fprintf(stderr, "select() failed: %m\n");
			break;
		}

		/* timeout */
		if (err == 0)
			continue;

		if (FD_ISSET(STDIN_FILENO, &fds))
			break;
	}

	if (cursor)
		kms_framebuffer_free(cursor);

	if (root)
		kms_framebuffer_free(root);

	if (fb)
		kms_framebuffer_free(fb);

	kms_device_close(device);
	close(fd);

	return 0;
}
Beispiel #10
0
int main(int argc, char **argv)
{
    long i, return_code;
    char *ptr;
    static char *input;
    static char *rpn_defns;
#if defined(LINUX)
    struct stat sts;
#endif

#ifdef VAX_VMS
    /* initialize collection of computer usage statistics--required by
     * user-callable function 'rs'
     */
    init_stats();
#endif

    puts("Welcome to rpn version 6, by Michael Borland and Robert Soliday (June 1999).");

    /* sort the command table for faster access */
    /*qsort(func, NFUNCS, sizeof(struct FUNCTION), func_compare); */
    qsort(funcRPN, sizeof(funcRPN)/sizeof(funcRPN[0]), sizeof(struct FUNCTION), func_compare);
    /* initialize stack pointers--empty stacks */
    stackptr = 0;
    sstackptr = 0;
    lstackptr = 0;
    astackptr = 0;
    dstackptr = 0;
    astack = NULL;
    udf_stackptr = 0;
    max_udf_stackptr = 0;
    udf_stack = NULL;
    udf_cond_stackptr = 0;
    max_udf_cond_stackptr = 0;
    udf_cond_stack = NULL;
    udf_id = NULL;	
    udf_unknown = NULL;

    /* The first item on the command input stack is the standard input.
     * Input from this source is echoed to the screen. */
    istackptr = 1;
    input_stack[0].fp = stdin;
    input_stack[0].filemode = ECHO;

    /* Initialize variables use in keeping track of what 'code' is being
     * executed.  code_ptr is a global pointer to the currently used
     * code structure.  The code is kept track of in a linked list of
     * code structures.
     */
    code_ptr = &code;
    input = code_ptr->text = tmalloc(sizeof(*(code_ptr->text))*CODE_LEN);
    code_ptr->position = 0;
    code_ptr->token = NULL;
    code_ptr->storage_mode = STATIC;
    code_ptr->buffer = tmalloc(sizeof(*(code_ptr->buffer))*LBUFFER);
    code_ptr->pred = code_ptr->succ = NULL;
    code_lev = 1;

    /* Initialize array of IO file structures.  Element 0 is for terminal
     * input, while element 1 is for terminal output.
     */
    for (i=0; i<FILESTACKSIZE; i++)
        io_file[i].fp = NULL;
    io_file[0].fp = stdin;
    cp_str(&(io_file[0].name), "stdin");
    io_file[0].mode = INPUT;
    io_file[1].fp = stdout;
    cp_str(&(io_file[1].name), "stdout");
    io_file[1].mode = OUTPUT;

    /* initialize variables for UDF storage */
    udf_changed = num_udfs = max_udfs = 0;
    udf_list = NULL;

    /* Initialize flags for user memories */
    n_memories = memory_added = 0;

    /* If there are arguments push them onto the input stack
     * so that it will be run to set up the program.
     */
    while (argc-- >= 2) {
        input_stack[istackptr].fp = fopen_e(argv[argc], "r", 0);
        input_stack[istackptr++].filemode = NO_ECHO;
        }

    /*add default setting for a linux system, G. Shen, Dec 31, 2009 */
    rpn_defns=getenv("RPN_DEFNS");
    if(!rpn_defns) {
#if defined(LINUX)
	if (!(stat(rpn_default, &sts) == -1 && errno == ENOENT)) { /* check whether default file exists */
	    rpn_defns = rpn_default;
	}
#endif
    }
    if (rpn_defns && (long)strlen(rpn_defns)>0 ) {
        /* push rpn definitions file onto top of the stack */
        input_stack[istackptr].fp = fopen_e(rpn_defns, "r", 0);
        input_stack[istackptr++].filemode = NO_ECHO;
        }

    /* This is the main loop. Code is read in and executed here. */
    while (istackptr!=0) {
        /* istackptr-1 gives index of most recently pushed input file. */
        /* This loop implements the command input file stacking. */
#ifdef DEBUG
        fprintf(stderr, "istackptr = %ld\n", istackptr);
#endif
        while (prompt("rpn> ", !(istackptr-1)),
                ptr=fgets((code_ptr->text=input), CODE_LEN,
                input_stack[istackptr-1].fp)) {
            /* Loop while there's still data in the (istackptr-1)th file. *
             * The data is put in the code list.                          */
#ifdef DEBUG
            fprintf(stderr, "input string: >%s<\n", ptr);
#endif
            /* If we are at the terminal input level and a UDF has been changed
             * or a memory added, relink the udfs to get any references to the
             * new udf or memory translated into 'pcode'.
             */
            if ((udf_changed) || memory_added) {
#ifdef DEBUG
                fputs("re-linking udfs", stderr);
#endif
                link_udfs();
                udf_changed = memory_added = 0;
                }
            code_ptr->position = 0;

            /* Get rid of new-lines in data from files, and echo data to  *
             * screen if appropriate.                                     */
            if (istackptr!=1 && ptr!=NULL) {
#ifdef DEBUG
                fputs("truncating input line", stderr);
#endif
                chop_nl(ptr);
                if (input_stack[istackptr-1].filemode==ECHO)
                    puts(ptr);
                }

            /* Check for and ignore comment lines. */
#ifdef DEBUG
            fputs("checking for comment line", stderr);
#endif
            if (strncmp(ptr, "/*", 2)==0)
                continue;

            /* Finally, push input line onto the code stack & execute it.   */
#ifdef DEBUG
            fputs("pushing onto stack and executing", stderr);
#endif
            return_code = execute_code();
	    cycle_counter = 0;

            if (code_lev!=1) {
                fputs("error: code level on return from execute_code is not 1\n", stderr);
                exit(1);
                }
            /* Reset pointers in the current code structure to indicate that the
             * stuff has been executed.
             */
#ifdef DEBUG
            fputs("reseting pointers", stderr);
#endif
            *(code_ptr->text) = 0;
            code_ptr->position = 0;

            /* If it's appropriate to print the top of the numeric or logical *
             * stacks, do so here.                                            */
            if (stackptr>=1 && return_code==NUMERIC_FUNC )
                printf(choose_format(format_flag, stack[stackptr-1]),
                                    ' ', stack[stackptr-1], '\n');
            if (lstackptr>=1 && return_code==LOGICAL_FUNC)
                printf("%s\n", (logicstack[lstackptr-1])?"true":"false");
            }

        /* Close the current input file and go to the one below it on the *
         * stack.  This constitutes popping the command input stack.      *
         */
#ifdef DEBUG
        fputs("closing input file", stderr);
#endif
        fclose(input_stack[--istackptr].fp);
        }
    return(0);
    }
Beispiel #11
0
static enum piglit_result
exec_test(struct test_info *info, int sample_count)
{
    GLuint fb, tex, rb;
    GLint result;
    struct attachment_info *att;
    GLint maxColorSamples, maxDepthSamples;

    glGetIntegerv(GL_MAX_COLOR_TEXTURE_SAMPLES, &maxColorSamples);
    glGetIntegerv(GL_MAX_DEPTH_TEXTURE_SAMPLES, &maxDepthSamples);

    glGenFramebuffers(1, &fb);
    glBindFramebuffer(GL_FRAMEBUFFER, fb);

    printf("Testing fbo completeness for config '%s'\n", info->name);

    for (att=info->attachments; att->target; att++) {
        int attachment_sample_count = att->multisample ? sample_count : 0;
        printf("  Att target=%s att=%s samples=%d dims=%d,%d,%d fixed=%d\n",
               piglit_get_gl_enum_name(att->target),
               piglit_get_gl_enum_name(att->attachment),
               attachment_sample_count,
               SURFACE_WIDTH, SURFACE_HEIGHT,
               att->target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY ? SURFACE_DEPTH : 1,
               att->fixedsamplelocations);

        switch (att->target) {
        case GL_TEXTURE_2D_MULTISAMPLE:
        case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
            if (att->attachment == GL_DEPTH_ATTACHMENT && sample_count > maxDepthSamples)
                return PIGLIT_SKIP;
            if ((att->attachment == GL_COLOR_ATTACHMENT0 ||
                att->attachment == GL_COLOR_ATTACHMENT1) && sample_count > maxColorSamples)
                return PIGLIT_SKIP;
        }

        switch (att->target) {
        case GL_TEXTURE_2D_MULTISAMPLE:
            glGenTextures(1, &tex);
            glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, tex);
            glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE,
                                    attachment_sample_count, choose_format(att),
                                    SURFACE_WIDTH, SURFACE_HEIGHT,
                                    att->fixedsamplelocations);

            if (!piglit_check_gl_error(GL_NO_ERROR))
                return PIGLIT_FAIL;

            glFramebufferTexture2D(GL_FRAMEBUFFER, att->attachment,
                                   att->target, tex, 0);
            break;

        case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
            glGenTextures(1, &tex);
            glBindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, tex);
            glTexImage3DMultisample(GL_TEXTURE_2D_MULTISAMPLE_ARRAY,
                    attachment_sample_count, choose_format(att),
                    SURFACE_WIDTH, SURFACE_HEIGHT, SURFACE_DEPTH,
                    att->fixedsamplelocations);

            if (!piglit_check_gl_error(GL_NO_ERROR))
                return PIGLIT_FAIL;

            glFramebufferTextureLayer(GL_FRAMEBUFFER, att->attachment,
                    tex, 0, att->layer);
            break;

        case GL_RENDERBUFFER:
            /* RENDERBUFFER has fixedsamplelocations implicitly */
            assert(att->fixedsamplelocations);
            glGenRenderbuffers(1, &rb);
            glBindRenderbuffer(GL_RENDERBUFFER, rb);
            if (att->multisample) {
                glRenderbufferStorageMultisample(GL_RENDERBUFFER,
                                                 attachment_sample_count, choose_format(att),
                                                 SURFACE_WIDTH, SURFACE_HEIGHT);
            }
            else {
                /* non-MSAA renderbuffer */
                glRenderbufferStorage(GL_RENDERBUFFER, choose_format(att),
                                      SURFACE_WIDTH, SURFACE_HEIGHT);
            }

            glFramebufferRenderbuffer(GL_FRAMEBUFFER,
                                      att->attachment, att->target, rb);

            if (!piglit_check_gl_error(GL_NO_ERROR))
                return PIGLIT_FAIL;
            break;

        default:
            assert(!"Unsupported target");
        }
    }

    result = glCheckFramebufferStatus(GL_FRAMEBUFFER);
    if (result != info->expected) {
        printf("glCheckFramebufferStatus: expected %s, got %s\n",
               piglit_get_gl_enum_name(info->expected),
               piglit_get_gl_enum_name(result));
        return PIGLIT_FAIL;
    }

    if (result == GL_FRAMEBUFFER_COMPLETE && info->attachments->multisample)
        return check_sample_positions(sample_count);

    return PIGLIT_PASS;
}
GeglBuffer *
gimp_pickable_contiguous_region_by_seed (GimpPickable        *pickable,
                                         gboolean             antialias,
                                         gfloat               threshold,
                                         gboolean             select_transparent,
                                         GimpSelectCriterion  select_criterion,
                                         gboolean             diagonal_neighbors,
                                         gint                 x,
                                         gint                 y)
{
  GeglBuffer    *src_buffer;
  GeglBuffer    *mask_buffer;
  const Babl    *format;
  GeglRectangle  extent;
  gint           n_components;
  gboolean       has_alpha;
  gfloat         start_col[MAX_CHANNELS];

  g_return_val_if_fail (GIMP_IS_PICKABLE (pickable), NULL);

  gimp_pickable_flush (pickable);

  src_buffer = gimp_pickable_get_buffer (pickable);

  format = choose_format (src_buffer, select_criterion,
                          &n_components, &has_alpha);

  gegl_buffer_sample (src_buffer, x, y, NULL, start_col, format,
                      GEGL_SAMPLER_NEAREST, GEGL_ABYSS_NONE);

  if (has_alpha)
    {
      if (select_transparent)
        {
          /*  don't select transparent regions if the start pixel isn't
           *  fully transparent
           */
          if (start_col[n_components - 1] > 0)
            select_transparent = FALSE;
        }
    }
  else
    {
      select_transparent = FALSE;
    }

  extent = *gegl_buffer_get_extent (src_buffer);

  mask_buffer = gegl_buffer_new (&extent, babl_format ("Y float"));

  if (x >= extent.x && x < (extent.x + extent.width) &&
      y >= extent.y && y < (extent.y + extent.height))
    {
      GIMP_TIMER_START();

      find_contiguous_region (src_buffer, mask_buffer,
                              format, n_components, has_alpha,
                              select_transparent, select_criterion,
                              antialias, threshold, diagonal_neighbors,
                              x, y, start_col);

      GIMP_TIMER_END("foo");
    }

  return mask_buffer;
}