Beispiel #1
0
static int save_as_asf(ImageInfo *ii,
                       const char *out_file, int what_to_save,
                       int strict_boundary, int load)
{
    // See if we can open the output file up front
    FILE *outFp = fopen(out_file, "wb");
    if (!outFp) {
        // failed to open the output file!
        char errbuf[1024];
        snprintf(errbuf, 1024, "Failed to open %s: %s", out_file,
            strerror(errno));
        message_box(errbuf);
        strcat(errbuf, "\n");
        printf("%s", errbuf);
        return FALSE; // failure
    }

    assert (g_poly->n > 0);
    assert (crosshair_line > 0 && crosshair_samp > 0);

    meta_parameters *meta = ii->meta;

    // figure out where to chop
    int line_min, line_max, samp_min, samp_max, nl, ns;
    compute_extent(meta, &line_min, &line_max, &samp_min, &samp_max,
        &nl, &ns);

    // generate metadata
    char *out_metaname = appendExt(out_file, ".meta");
    printf("Generating %s...\n", out_metaname);

    // data will be saved as floating point, except scaled pixel values,
    // which we can make bytes.
    data_type_t data_type = REAL32;
    if (what_to_save == SCALED_PIXEL_VALUE)
      data_type = ASF_BYTE;

    meta_parameters *out_meta =
      build_metadata(meta, out_file, nl, ns, line_min, samp_min, data_type,
                     what_to_save);

    // put_float_line() will always dump BYTE data if the optical block
    // is present... we want to be in control of the data type, so we must
    // wipe out this block
    if (out_meta->optical) {
      FREE(out_meta->optical);
      out_meta->optical=NULL;
    }

    if (what_to_save == LAT_LON_2_BAND) {
      out_meta->general->band_count = 2;
      strcpy(out_meta->general->bands, "LAT,LON");
    }

    // define clipping region, if necessary
    double xp[MAX_POLY_LEN+2], yp[MAX_POLY_LEN+2];
    int i,j,n=0;

    if (strict_boundary)
        define_clipping_region(meta, &n, xp, yp);

    float ndv = 0;
    if (meta_is_valid_double(out_meta->general->no_data))
        ndv = out_meta->general->no_data;
    else if (strict_boundary) // need to set a no data value in this case
        out_meta->general->no_data = 0.;

    meta_write(out_meta, out_metaname);

    // now actually write the data
    printf("Generating %s...\n", out_file);

    if (what_to_save == LAT_LON_2_BAND) {
      // dump a 2-band image, lat & lon data
      float *lats = MALLOC(sizeof(float)*ns);
      float *lons = MALLOC(sizeof(float)*ns);
      for (i=0; i<nl; ++i) {
        int l = line_min+i;
        for (j=0; j<ns; ++j) {
            int s = samp_min+j;
            if (!strict_boundary || pnpoly(n, xp, yp, s, l)) {
                double lat, lon;
                meta_get_latLon(meta, l, s, 0, &lat, &lon);
                lats[j] = (float)lat;
                lons[j] = (float)lon;
            }
            else {
                lats[j] = ndv;
                lons[j] = ndv;
            }
        }
        put_band_float_line(outFp, out_meta, 0, i, lats);
        put_band_float_line(outFp, out_meta, 1, i, lons);
        asfLineMeter(i,nl);
      }
      free(lats);
      free(lons);
    }
    else {
      // normal case
      float *buf = MALLOC(sizeof(float)*ns);
      for (i=0; i<nl; ++i) {
        int l = line_min+i;
        for (j=0; j<ns; ++j) {
            int s = samp_min+j;
            float val;
            if (!strict_boundary || pnpoly(n, xp, yp, s, l)) {
                val = get_data(ii, what_to_save, l, s);
            }
            else {
                val = ndv;
            }
            buf[j] = val;
        }
        put_float_line(outFp, out_meta, i, buf);
        asfLineMeter(i,nl);
      }
      free(buf);
    }
    fclose(outFp);
    meta_free(out_meta);

    // load the generated file if we were told to
    if (load)
        load_file(out_file);

    return TRUE;
}
Beispiel #2
0
static GVariant *
get_player_property(GDBusConnection *connection,
		     const char *sender,
		     const char *object_path,
		     const char *interface_name,
		     const char *property_name,
		     GError **error,
		     XmrMprisPlugin *plugin)
{
	if (g_strcmp0(object_path, MPRIS_OBJECT_NAME) != 0 ||
		g_strcmp0(interface_name, MPRIS_PLAYER_INTERFACE) != 0)
	{
		g_set_error(error,
					G_DBUS_ERROR,
					G_DBUS_ERROR_NOT_SUPPORTED,
					"Property %s.%s not supported",
					interface_name,
					property_name);
		return NULL;
	}

	if (g_strcmp0 (property_name, "PlaybackStatus") == 0)
	{
		return get_playback_status(plugin);
	}
	else if (g_strcmp0 (property_name, "Metadata") == 0)
	{
		return build_metadata(plugin);
	}
	else if (g_strcmp0 (property_name, "Rate") == 0)
	{
		return g_variant_new_double(1.0);
	}
	else if (g_strcmp0(property_name, "Volume") == 0)
	{
		return g_variant_new_double(xmr_player_get_volume(plugin->player));
	}
	else if (g_strcmp0(property_name, "Position") == 0)
	{
		return g_variant_new_int64(plugin->elapsed / 1000);
	}
	else if (g_strcmp0 (property_name, "MinimumRate") == 0)
	{
		return g_variant_new_double (1.0);
	}
	else if (g_strcmp0 (property_name, "MaximumRate") == 0)
	{
		return g_variant_new_double (1.0);
	}
	else if (g_strcmp0 (property_name, "CanGoNext") == 0)
	{
		return g_variant_new_boolean(TRUE);
	}
	else if (g_strcmp0 (property_name, "CanGoPrevious") == 0)
	{
		return g_variant_new_boolean(FALSE);
	}
	else if (g_strcmp0 (property_name, "CanPlay") == 0)
	{
		return g_variant_new_boolean (TRUE);
	}
	else if (g_strcmp0 (property_name, "CanPause") == 0)
	{
		return g_variant_new_boolean(TRUE);
	}
	else if (g_strcmp0 (property_name, "CanSeek") == 0)
	{
		g_variant_new_boolean(FALSE);
	}
	else if (g_strcmp0(property_name, "CanControl") == 0)
	{
		return g_variant_new_boolean(TRUE);
	}

	g_set_error(error,
		     G_DBUS_ERROR,
		     G_DBUS_ERROR_NOT_SUPPORTED,
		     "Property %s.%s not supported",
		     interface_name,
		     property_name);
	return NULL;
}