Exemplo n.º 1
0
    bool Config::Save(const string& path, ConfigFileFormat format /* = CONFIG_FORMAT_UNDEFINED */) const
    {
        if (format == CONFIG_FORMAT_UNDEFINED)
        {
            format = detect_file_format(path);
        }

        switch (format)
        {
        case CONFIG_FORMAT_INI:
            ini_parser::write_ini(path, _properties);
            return true;
        case CONFIG_FORMAT_XML:
            xml_parser::write_xml(path, _properties);
            return true;
        case CONFIG_FORMAT_JSON:
            json_parser::write_json(path, _properties);
            return true;
        case CONFIG_FORMAT_INFO:
            info_parser::write_info(path, _properties);
            return true;
        default:
            return false;
        };
    }
gboolean
set_properties_for_channel (GstElement * dvbbasebin,
    const gchar * channel_name, GError ** error)
{
  gboolean ret = FALSE;
  gchar *filename;
  const gchar *adapter;

  filename = g_strdup (g_getenv ("GST_DVB_CHANNELS_CONF"));
  if (filename == NULL) {
    filename = g_build_filename (g_get_user_config_dir (),
        "gstreamer-" GST_API_VERSION, "dvb-channels.conf", NULL);
  }

  adapter = g_getenv ("GST_DVB_ADAPTER");
  if (adapter)
    g_object_set (dvbbasebin, "adapter", atoi (adapter), NULL);

  switch (detect_file_format (filename)) {
    case CHANNEL_CONF_FORMAT_DVBV5:
      if (!parse_and_configure_from_v5_conf_file (dvbbasebin, filename,
              channel_name, error)) {
        GST_WARNING_OBJECT (dvbbasebin, "Could not parse libdvbv5 channel "
            "configuration file '%s'", filename);
      } else {
        GST_INFO_OBJECT (dvbbasebin, "Parsed libdvbv5 channel configuration "
            "file");
        ret = TRUE;
      }
      break;
    case CHANNEL_CONF_FORMAT_ZAP:
      if (!parse_and_configure_from_zap_conf_file (dvbbasebin, filename,
              channel_name, error)) {
        GST_WARNING_OBJECT (dvbbasebin, "Could not parse ZAP channel "
            "configuration file '%s'", filename);
      } else {
        GST_INFO_OBJECT (dvbbasebin, "Parsed ZAP channel configuration file");
        ret = TRUE;
      }
      break;
    default:
      GST_WARNING_OBJECT (dvbbasebin, "Unknown configuration file format. "
          "Can not get parameters for channel");
  }

  g_free (filename);
  return ret;
}
Exemplo n.º 3
0
Arquivo: tga.c Projeto: jsummers/deark
static void de_run_tga(deark *c, de_module_params *mparams)
{
	lctx *d = NULL;
	i64 pos;
	dbuf *unc_pixels = NULL;
	int saved_indent_level;
	i64 rowspan_tmp;

	de_dbg_indent_save(c, &saved_indent_level);
	d = de_malloc(c, sizeof(lctx));

	detect_file_format(c, d);

	if(d->file_format==FMT_VST) {
		de_declare_fmt(c, "TrueVista");
	}
	else {
		de_declare_fmt(c, "TGA");
	}

	pos = 0;

	if(d->file_format==FMT_VST) {
		if(!do_read_vst_headers(c, d)) goto done;
	}
	else {
		if(!do_read_tga_headers(c, d)) goto done;
	}
	pos += 18;

	if(d->id_field_len>0) {
		de_dbg(c, "image ID at %d (len=%d)", (int)pos, (int)d->id_field_len);
		pos += d->id_field_len;
	}

	if(d->color_map_type!=0) {
		d->bytes_per_pal_entry = (d->cmap_depth+7)/8;
		d->pal_size_in_bytes = d->cmap_length * d->bytes_per_pal_entry;
		de_dbg(c, "color map at %d (%d colors, %d bytes)", (int)pos,
			(int)d->cmap_length, (int)d->pal_size_in_bytes);

		de_dbg_indent(c, 1);
		if(!do_read_palette(c, d, pos)) goto done;
		de_dbg_indent(c, -1);

		pos += d->pal_size_in_bytes;
	}

	de_dbg(c, "bitmap at %d", (int)pos);
	de_dbg_indent(c, 1);

	d->bytes_per_pixel = ((d->pixel_depth+7)/8);
	if(d->pixel_depth==1) {
		rowspan_tmp = (d->main_image.width+7)/8;
	}
	else {
		rowspan_tmp = d->main_image.width * d->bytes_per_pixel;
	}
	d->main_image.img_size_in_bytes = d->main_image.height * rowspan_tmp;

	if(d->color_type!=TGA_CLRTYPE_PALETTE && d->color_type!=TGA_CLRTYPE_TRUECOLOR &&
		d->color_type!=TGA_CLRTYPE_GRAYSCALE)
	{
		de_err(c, "Unsupported color type (%d: %s)", (int)d->color_type, d->clrtype_name);
		goto done;
	}

	if( (d->color_type==TGA_CLRTYPE_PALETTE && d->pixel_depth==8) ||
		(d->color_type==TGA_CLRTYPE_TRUECOLOR && d->pixel_depth==15) ||
		(d->color_type==TGA_CLRTYPE_TRUECOLOR && d->pixel_depth==16) ||
		(d->color_type==TGA_CLRTYPE_TRUECOLOR && d->pixel_depth==24) ||
		(d->color_type==TGA_CLRTYPE_TRUECOLOR && d->pixel_depth==32) ||
		(d->color_type==TGA_CLRTYPE_GRAYSCALE && d->pixel_depth==1) ||
		(d->color_type==TGA_CLRTYPE_GRAYSCALE && d->pixel_depth==8) )
	{
		;
	}
	else {
		de_err(c, "Unsupported TGA image type (%s, depth=%d)", d->clrtype_name,
			(int)d->pixel_depth);
		goto done;
	}

	if(d->cmpr_type==TGA_CMPR_RLE) {
		if(d->pixel_depth<8) {
			de_err(c, "RLE compression not supported when depth (%d) is less than 8",
				(int)d->pixel_depth);
			goto done;
		}
		unc_pixels = dbuf_create_membuf(c, d->main_image.img_size_in_bytes, 1);
		if(!do_decode_rle(c, d, pos, unc_pixels)) goto done;
	}
	else if(d->cmpr_type==TGA_CMPR_NONE) {
		unc_pixels = dbuf_open_input_subfile(c->infile, pos, d->main_image.img_size_in_bytes);
	}
	else {
		de_err(c, "Unsupported compression type (%d, %s)", (int)d->cmpr_type, d->cmpr_name);
		goto done;
	}

	// Maybe scan the image, to help detect transparency.
	do_prescan_image(c, d, unc_pixels);

	if(d->pixel_depth==32) {
		de_dbg(c, "using alpha channel: %s", d->has_alpha_channel?"yes":"no");
	}

	// TODO: 16-bit images could theoretically have a transparency bit, but I don't
	// know how to detect that.

	do_decode_image(c, d, &d->main_image, unc_pixels, NULL, 0);

	de_dbg_indent(c, -1);

	if(d->thumbnail_offset!=0) {
		do_decode_thumbnail(c, d);
	}

done:
	dbuf_close(unc_pixels);
	de_dbg_indent_restore(c, saved_indent_level);
	de_free(c, d);
}
Exemplo n.º 4
0
static char *get_temp_file(int type, int rgb)
{
	ls_settings settings;
	tempfile *tmp;
	unsigned char *img = NULL;
	char buf[PATHBUF], nstub[NAMEBUF], ids[32], *c, *f = "tmp.png";
	int fd, cnt, idx, res;

	/* Use the original file if possible */
	if (!mem_changed && mem_filename && (!rgb ^ (mem_img_bpp == 3)) &&
		((type == FT_NONE) ||
		 (detect_file_format(mem_filename, FALSE) == type)))
		return (mem_filename);

	/* Prepare temp directory */
	if (!mt_temp_dir) mt_temp_dir = new_temp_dir();
	if (!mt_temp_dir) return (NULL); /* Temp dir creation failed */

	/* Analyze name */
	if ((type == FT_NONE) && mem_filename)
	{
		f = strrchr(mem_filename, DIR_SEP);
		if (!f) f = mem_filename;
		type = file_type_by_ext(f, FF_SAVE_MASK);
	}
	if (type == FT_NONE) type = FT_PNG;

	/* Use existing file if possible */
	for (tmp = mem_tempfiles; tmp; tmp = tmp->next)
	{
		if (tmp->id != mem_tempfiles) break;
		if ((tmp->type == type) && (tmp->rgb == rgb))
			return (tmp->name);
	}

	/* Stubify filename */
	strcpy(nstub, "tmp");
	c = strrchr(f, '.');
	if (c != f) /* Extension should not be alone */
		wjstrcat(nstub, NAMEBUF, f, c ? c - f : strlen(f), NULL);

	/* Create temp file */
	while (TRUE)
	{
		idx = last_temp_index(nstub, -1);
		ids[0] = 0;
		for (cnt = 0; cnt < 256; cnt++ , idx++)
		{
			if (idx) sprintf(ids, "%d", idx);
			snprintf(buf, PATHBUF, "%s" DIR_SEP_STR "%s%s.%s",
				mt_temp_dir, nstub, ids, file_formats[type].ext);
			fd = open(buf, O_WRONLY | O_CREAT | O_EXCL, 0644);
			if (fd >= 0) break;
		}
		last_temp_index(nstub, idx);
		if (fd >= 0) break;
		if (!strcmp(nstub, "tmp")) return (NULL); /* Utter failure */
		strcpy(nstub, "tmp"); /* Try again with "tmp" */
	}
	close(fd);

	/* Save image */
	init_ls_settings(&settings, NULL);
	memcpy(settings.img, mem_img, sizeof(chanlist));
	settings.pal = mem_pal;
	settings.width = mem_width;
	settings.height = mem_height;
	settings.bpp = mem_img_bpp;
	settings.colors = mem_cols;
	settings.ftype = type;
	if (rgb && (mem_img_bpp == 1)) /* Save indexed as RGB */
	{
		settings.img[CHN_IMAGE] = img =
			malloc(mem_width * mem_height * 3);
		if (!img) return (NULL); /* Failed to allocate RGB buffer */
		settings.bpp = 3;
		do_convert_rgb(0, 1, mem_width * mem_height, img,
			mem_img[CHN_IMAGE], mem_pal);
	}
	res = save_image(buf, &settings);
	free(img);
	if (res) return (NULL); /* Failed to save */

	return (remember_temp_file(buf, type, rgb));
}