Exemplo n.º 1
0
static void
print_totals_robot(void)
{
	char checks[CHECKS_STR_SIZE];
	get_check_names(checks, totals.checks, false);

	printf("totals\t%" PRIu64 "\t%" PRIu64 "\t%" PRIu64 "\t%" PRIu64
			"\t%s\t%s\t%" PRIu64 "\t%" PRIu64,
			totals.streams,
			totals.blocks,
			totals.compressed_size,
			totals.uncompressed_size,
			get_ratio(totals.compressed_size,
				totals.uncompressed_size),
			checks,
			totals.stream_padding,
			totals.files);

	if (message_verbosity_get() >= V_DEBUG)
		printf("\t%" PRIu64 "\t%s\t%" PRIu32,
				totals.memusage_max,
				totals.all_have_sizes ? "yes" : "no",
				totals.min_version);

	putchar('\n');

	return;
}
Exemplo n.º 2
0
static void
print_adv_helper(uint64_t stream_count, uint64_t block_count,
		uint64_t compressed_size, uint64_t uncompressed_size,
		uint32_t checks, uint64_t stream_padding)
{
	char checks_str[CHECKS_STR_SIZE];
	get_check_names(checks_str, checks, true);

	printf(_("  Streams:            %s\n"),
			uint64_to_str(stream_count, 0));
	printf(_("  Blocks:             %s\n"),
			uint64_to_str(block_count, 0));
	printf(_("  Compressed size:    %s\n"),
			uint64_to_nicestr(compressed_size,
				NICESTR_B, NICESTR_TIB, true, 0));
	printf(_("  Uncompressed size:  %s\n"),
			uint64_to_nicestr(uncompressed_size,
				NICESTR_B, NICESTR_TIB, true, 0));
	printf(_("  Ratio:              %s\n"),
			get_ratio(compressed_size, uncompressed_size));
	printf(_("  Check:              %s\n"), checks_str);
	printf(_("  Stream padding:     %s\n"),
			uint64_to_nicestr(stream_padding,
				NICESTR_B, NICESTR_TIB, true, 0));
	return;
}
Exemplo n.º 3
0
int main(int argc, char * argv[]) {
    struct cmd_options opts = parse_cmd_options(argc, argv);

    FILE * fin = fopen(opts.infname, "r");
    handle_fopen_error(fin, argv[0], "error opening input file");
    FILE * fout = fopen(opts.outfname, "w");
    handle_fopen_error(fout, argv[0], "error opening output file");

    int64_t orig_width = 0, orig_height = 0;
    size_t entriesn = get_orig_dimensions(&orig_width, &orig_height, fin);

    fseek(fin, 0, SEEK_SET);

    struct point_set set = {};

    set.ratio.x = get_ratio(opts.width, orig_width);
    set.ratio.y = get_ratio(opts.height, orig_height);

    size_t alloc_size = MAX(set.ratio.x, set.ratio.y) * entriesn;

    set.vec = calloc(alloc_size, sizeof *set.vec);
    if (set.vec == NULL) {
        fprintf(stderr, "%s: not enough memory\n", argv[0]);
        return EXIT_FAILURE;
    }

    fill_set(&set, fin);
    fclose(fin);

    for (size_t i = 0; i < set.size; i++) {
        fprintf(fout, "%.100Lg %.100Lg\n", set.vec[i].x, set.vec[i].y);
    }

    // kernel will take a better care of this:
    // free(set.vec);
    // free(opts.infname);
    // free(opts.outfname);
    // fclose(fout);
    // so don't mind the valgrind "leaks"

    return EXIT_SUCCESS;
}
Exemplo n.º 4
0
int determine_phrase_direction(pedphrase * phrase) {
	peddirection dir;
	float ratio;
	pedbox *box;
	if (phrase == NULL)
		return PEDDIRECT_UNSET;
	box = phrase->phrasebox;
	
	dir = PEDDIRECT_UNSET;
	ratio = get_ratio (box);
	if ( ratio > 2.0 ) {
		dir = PEDDIRECT_HOR;
	}
	else if ( ratio < 0.5) {
		dir = PEDDIRECT_VER;
	}
	phrase->dir = dir;
	return dir;
}
Exemplo n.º 5
0
static bool
print_info_basic(const xz_file_info *xfi, file_pair *pair)
{
	static bool headings_displayed = false;
	if (!headings_displayed) {
		headings_displayed = true;
		// TRANSLATORS: These are column headings. From Strms (Streams)
		// to Ratio, the columns are right aligned. Check and Filename
		// are left aligned. If you need longer words, it's OK to
		// use two lines here. Test with "xz -l foo.xz".
		puts(_("Strms  Blocks   Compressed Uncompressed  Ratio  "
				"Check   Filename"));
	}

	char checks[CHECKS_STR_SIZE];
	get_check_names(checks, lzma_index_checks(xfi->idx), false);

	const char *cols[7] = {
		uint64_to_str(lzma_index_stream_count(xfi->idx), 0),
		uint64_to_str(lzma_index_block_count(xfi->idx), 1),
		uint64_to_nicestr(lzma_index_file_size(xfi->idx),
			NICESTR_B, NICESTR_TIB, false, 2),
		uint64_to_nicestr(lzma_index_uncompressed_size(xfi->idx),
			NICESTR_B, NICESTR_TIB, false, 3),
		get_ratio(lzma_index_file_size(xfi->idx),
			lzma_index_uncompressed_size(xfi->idx)),
		checks,
		pair->src_name,
	};
	printf("%*s %*s  %*s  %*s  %*s  %-*s %s\n",
			tuklib_mbstr_fw(cols[0], 5), cols[0],
			tuklib_mbstr_fw(cols[1], 7), cols[1],
			tuklib_mbstr_fw(cols[2], 11), cols[2],
			tuklib_mbstr_fw(cols[3], 11), cols[3],
			tuklib_mbstr_fw(cols[4], 5), cols[4],
			tuklib_mbstr_fw(cols[5], 7), cols[5],
			cols[6]);

	return false;
}
Exemplo n.º 6
0
static void
print_totals_basic(void)
{
	// Print a separator line.
	char line[80];
	memset(line, '-', sizeof(line));
	line[sizeof(line) - 1] = '\0';
	puts(line);

	// Get the check names.
	char checks[CHECKS_STR_SIZE];
	get_check_names(checks, totals.checks, false);

	// Print the totals except the file count, which needs
	// special handling.
	printf("%5s %7s  %11s  %11s  %5s  %-7s ",
			uint64_to_str(totals.streams, 0),
			uint64_to_str(totals.blocks, 1),
			uint64_to_nicestr(totals.compressed_size,
				NICESTR_B, NICESTR_TIB, false, 2),
			uint64_to_nicestr(totals.uncompressed_size,
				NICESTR_B, NICESTR_TIB, false, 3),
			get_ratio(totals.compressed_size,
				totals.uncompressed_size),
			checks);

	// Since we print totals only when there are at least two files,
	// the English message will always use "%s files". But some other
	// languages need different forms for different plurals so we
	// have to translate this with ngettext().
	//
	// TRANSLATORS: %s is an integer. Only the plural form of this
	// message is used (e.g. "2 files"). Test with "xz -l foo.xz bar.xz".
	printf(ngettext("%s file\n", "%s files\n",
			totals.files <= ULONG_MAX ? totals.files
				: (totals.files % 1000000) + 1000000),
			uint64_to_str(totals.files, 0));

	return;
}
Exemplo n.º 7
0
/*******************************************************************
 * 
 * NAME :               update_inverse(); 
 * 
 *
 * DESCRIPTION :        Updates the inverse matrix for the 
 *                      active particle.
 * 
 */
void Slater::update_inverse() {

    int i = active_particle;
    Dp_inv_new = Dp_inv;
    Dm_inv = Dm_inv_new;

    double S;
    // TMP solution for the inverse.

    double R = get_ratio();

    if (i < N) { // Spin up
        for (int j = 0; j < N; j++) {
            if (j != i) {
                S = 0;
                for (int l = 0; l < N; l++)
                    S += Dp_new(l, i) * Dp_inv(l, j);
            }
            for (int l = 0; l < N; l++)
                Dp_inv_new(l, j) = Dp_inv(l, j) - (Dp_inv(l, i) / R) * S;
        }
        for (int l = 0; l < N; l++)
            Dp_inv_new(l, i) = Dp_inv(l, i) / R;
    } else { // Spin down
        for (int j = 0; j < N; j++) {
            if (j != i - N) {
                S = 0;
                for (int l = 0; l < N; l++)
                    S += Dm_new(l, i - N) * Dm_inv(l, j);
            }
            for (int l = 0; l < N; l++)
                Dm_inv_new(l, j) = Dm_inv(l, j) - (Dm_inv(l, i - N) / R) * S;
        }
        for (int l = 0; l < N; l++)
            Dm_inv_new(l, i - N) = Dm_inv(l, i - N) / R;
    }

}
Exemplo n.º 8
0
void Scene::build_laplacian(const FT scale,
                            const std::map<unsigned, unsigned>& indices,
                            SparseMatrix& A) const
{
    unsigned nb = A.numRows();
    for (unsigned k = 0; k < m_vertices.size(); ++k)
    {
        Vertex_handle vi = m_vertices[k];
        if (vi->is_hidden()) continue;
        unsigned i = indices.find(vi->get_index())->second;
        
        double diagi = 0.0;
        SparseArray rowi(nb);        
        Edge_circulator ecirc = m_rt.incident_edges(vi);
        Edge_circulator eend  = ecirc;
        CGAL_For_all(ecirc, eend)
        {
            Edge edge = *ecirc;
            if (!m_rt.is_inside(edge)) continue;
            
            Vertex_handle vj = m_rt.get_source(edge);
            if (vj == vi) vj = m_rt.get_target(edge);
            
            unsigned j = vj->get_index();
            j = indices.find(j)->second;
            
            double coef = scale * get_ratio(edge);
            if (std::abs(coef) < EPS) continue;
            
            rowi.setValue(j, -coef);
            diagi += coef;
        }
        
        rowi.setValue(i, diagi);
        A.setRow(i, rowi);
    }
Exemplo n.º 9
0
void main(int argc, char **argv)
{
    int row, col, row_size, col_size;
    char input_image[512], qimage[512];
    unsigned char **imgin;
    int *bound, *reco, input, label, output, numlev, numbits, c;
    int minvalue, maxvalue, range, level, stepsize, temp, end_flag;
    FILE *ofp;
  extern int  optind;
  extern char *optarg;

    fprintf(stderr,"\n\n\t\tUniform Quantization of Images - Encoder\n");

  ofp = stdout;
  strcpy(qimage,"standard out");
  numlev = -1;
  numbits = -1;
  minvalue = 0;
  maxvalue = 255;

  while((c=getopt(argc,argv,"i:o:l:b:m:t:h"))!=EOF)
  {
   switch (c){
   case 'i':
         strcpy(input_image,optarg);
         break;
   case 'o':
         strcpy(qimage,optarg);
         ofp = fopen(optarg,"wb");
         break;
   case 'l':
         sscanf(optarg,"%d", &numlev);
         break;
   case 'b':
         sscanf(optarg,"%d", &numbits);
         break;
   case 'm':
         sscanf(optarg,"%d", &maxvalue);
         break;
   case 't':
         sscanf(optarg,"%d", &minvalue);
         break;
   case 'x':
         sscanf(optarg,"%d", &row_size);
         break;
   case 'y':
         sscanf(optarg,"%d", &col_size);
         break;
   case 'h':
         usage();
         exit(1);
    }
   }

   if(numlev > 0 && numbits > 0)
   {
    temp = (int) pow((double) 2,(double) numbits);  
    if(temp != numlev)
    {
     fprintf(stderr,"\n You have entered values for the number of levels and\n");
     fprintf(stderr,"number of bits that are not compatible.  The number of\n");
     fprintf(stderr,"levels should be 2^(number of bits).  If you want to use\n");
     fprintf(stderr,"a number of levels which is not a power of 2 then only\n");
     fprintf(stderr,"enter a value for the number of levels.\n");
     exit(1);
    }
   }

   if(numlev < 0 && numbits < 0)
   {
    fprintf(stderr,"\n Enter number of bits per pixel: ");
    scanf("%d",&numbits);
    numlev = (int) pow((double) 2,(double) numbits);  
   }

   if (numbits <= 0 || numbits >= 8) {
    fprintf(stderr,"\n You have entered values for the number of bits that\n");
    fprintf(stderr,"are not compatible.  The number of bits should between\n");
    fprintf(stderr,"1 (one) - 7 (seven).\n");
    exit(1);
   }

   if(numlev < 0 && numbits > 0)
    numlev = (int) pow((double) 2,(double) numbits);  
  
   if(numlev > 0 && numbits < 0)
     numbits = (int) (log((double)numlev)/log((double) 2.) + 0.99999);
 
/* Determine range, and stepsize for the quantizer
*/

   range = maxvalue - minvalue + 1;
   stepsize = range/(numlev);

/* Allocate space for the boundary values */

   bound = (int *) calloc((numlev+1),sizeof(int));

/* Construct the boundary tables   */

   bound[0] = minvalue;
   for(level=1; level<=numlev; level++)
     {
      bound[level] = bound[level-1] + stepsize;
     }

/* Find out how large the image is */

    image_size(input_image, &row_size, &col_size);   

/* Allocate space for input image  */

    imgin  = (unsigned char **) calloc(row_size,sizeof(char *));  
    for(row=0; row<row_size; row++)
     imgin[row] = (unsigned char *) calloc((col_size),sizeof(char));

/* Read the input image */

    readimage(input_image, imgin, row_size, col_size);  

/*  Store coding parameters in the output file */

   fwrite(&numlev,1,sizeof(int),ofp);
   fwrite(&numbits,1,sizeof(int),ofp);
   fwrite(&maxvalue,1,sizeof(int),ofp);
   fwrite(&minvalue,1,sizeof(int),ofp);
   fwrite(&row_size,1,sizeof(int),ofp);
   fwrite(&col_size,1,sizeof(int),ofp);

   struct Queue* code_write;
   code_write = (struct Queue*) malloc(sizeof(struct Queue));
   code_write->front = NULL;
   code_write->rear = NULL;
   code_write->size = 0;
	
//   Print(&(code_write)->front);

/* encode each pixel into an integer label and store  */
   end_flag = 0;
   for(row=0; row<row_size; row++)
      for(col=0; col<col_size; col++)
         {
          if(row == row_size-1 && col == col_size - 1)
            end_flag = 1;
          input = imgin[row][col];
          label = encuqi(input,bound,numlev);
//          printf("%d %d, ", input, label);
//          printf("%d ", &ofp);
//          stuffit(label,numbits,&ofp,end_flag);
          stuffit(label,numbits,&code_write,end_flag);
         }

//   Print(&code_write->front);
   while(code_write->size >= 8) {
     write_to_file(&ofp, &code_write);
   }
	
//   printf("%d", code_write->size);

   FILE *fp;
   fp = fopen(input_image, "rb");
   double ratio_com = get_ratio(&fp, &ofp);
   
   printf("\n Ratio compression := %lf %%\n", ratio_com);
   
   fclose(fp);
   fclose(ofp);

}
Exemplo n.º 10
0
static bool
print_info_robot(xz_file_info *xfi, file_pair *pair)
{
	char checks[CHECKS_STR_SIZE];
	get_check_names(checks, lzma_index_checks(xfi->idx), false);

	printf("name\t%s\n", pair->src_name);

	printf("file\t%" PRIu64 "\t%" PRIu64 "\t%" PRIu64 "\t%" PRIu64
			"\t%s\t%s\t%" PRIu64 "\n",
			lzma_index_stream_count(xfi->idx),
			lzma_index_block_count(xfi->idx),
			lzma_index_file_size(xfi->idx),
			lzma_index_uncompressed_size(xfi->idx),
			get_ratio(lzma_index_file_size(xfi->idx),
				lzma_index_uncompressed_size(xfi->idx)),
			checks,
			xfi->stream_padding);

	if (message_verbosity_get() >= V_VERBOSE) {
		lzma_index_iter iter;
		lzma_index_iter_init(&iter, xfi->idx);

		while (!lzma_index_iter_next(&iter, LZMA_INDEX_ITER_STREAM))
			printf("stream\t%" PRIu64 "\t%" PRIu64 "\t%" PRIu64
				"\t%" PRIu64 "\t%" PRIu64 "\t%" PRIu64
				"\t%s\t%s\t%" PRIu64 "\n",
				iter.stream.number,
				iter.stream.block_count,
				iter.stream.compressed_offset,
				iter.stream.uncompressed_offset,
				iter.stream.compressed_size,
				iter.stream.uncompressed_size,
				get_ratio(iter.stream.compressed_size,
					iter.stream.uncompressed_size),
				check_names[iter.stream.flags->check],
				iter.stream.padding);

		lzma_index_iter_rewind(&iter);
		block_header_info bhi;

		while (!lzma_index_iter_next(&iter, LZMA_INDEX_ITER_BLOCK)) {
			if (message_verbosity_get() >= V_DEBUG
					&& parse_details(
						pair, &iter, &bhi, xfi))
				return true;

			printf("block\t%" PRIu64 "\t%" PRIu64 "\t%" PRIu64
					"\t%" PRIu64 "\t%" PRIu64
					"\t%" PRIu64 "\t%" PRIu64 "\t%s\t%s",
					iter.stream.number,
					iter.block.number_in_stream,
					iter.block.number_in_file,
					iter.block.compressed_file_offset,
					iter.block.uncompressed_file_offset,
					iter.block.total_size,
					iter.block.uncompressed_size,
					get_ratio(iter.block.total_size,
						iter.block.uncompressed_size),
					check_names[iter.stream.flags->check]);

			if (message_verbosity_get() >= V_DEBUG)
				printf("\t%s\t%" PRIu32 "\t%s\t%" PRIu64
						"\t%" PRIu64 "\t%s",
						check_value,
						bhi.header_size,
						bhi.flags,
						bhi.compressed_size,
						bhi.memusage,
						bhi.filter_chain);

			putchar('\n');
		}
	}

	if (message_verbosity_get() >= V_DEBUG)
		printf("summary\t%" PRIu64 "\t%s\t%" PRIu32 "\n",
				xfi->memusage_max,
				xfi->all_have_sizes ? "yes" : "no",
				xfi->min_version);

	return false;
}
Exemplo n.º 11
0
static bool
print_info_adv(xz_file_info *xfi, file_pair *pair)
{
	// Print the overall information.
	print_adv_helper(lzma_index_stream_count(xfi->idx),
			lzma_index_block_count(xfi->idx),
			lzma_index_file_size(xfi->idx),
			lzma_index_uncompressed_size(xfi->idx),
			lzma_index_checks(xfi->idx),
			xfi->stream_padding);

	// Size of the biggest Check. This is used to calculate the width
	// of the CheckVal field. The table would get insanely wide if
	// we always reserved space for 64-byte Check (128 chars as hex).
	uint32_t check_max = 0;

	// Print information about the Streams.
	//
	// TRANSLATORS: The second line is column headings. All except
	// Check are right aligned; Check is left aligned. Test with
	// "xz -lv foo.xz".
	puts(_("  Streams:\n    Stream    Blocks"
			"      CompOffset    UncompOffset"
			"        CompSize      UncompSize  Ratio"
			"  Check      Padding"));

	lzma_index_iter iter;
	lzma_index_iter_init(&iter, xfi->idx);

	while (!lzma_index_iter_next(&iter, LZMA_INDEX_ITER_STREAM)) {
		const char *cols1[4] = {
			uint64_to_str(iter.stream.number, 0),
			uint64_to_str(iter.stream.block_count, 1),
			uint64_to_str(iter.stream.compressed_offset, 2),
			uint64_to_str(iter.stream.uncompressed_offset, 3),
		};
		printf("    %*s %*s %*s %*s ",
				tuklib_mbstr_fw(cols1[0], 6), cols1[0],
				tuklib_mbstr_fw(cols1[1], 9), cols1[1],
				tuklib_mbstr_fw(cols1[2], 15), cols1[2],
				tuklib_mbstr_fw(cols1[3], 15), cols1[3]);

		const char *cols2[5] = {
			uint64_to_str(iter.stream.compressed_size, 0),
			uint64_to_str(iter.stream.uncompressed_size, 1),
			get_ratio(iter.stream.compressed_size,
				iter.stream.uncompressed_size),
			_(check_names[iter.stream.flags->check]),
			uint64_to_str(iter.stream.padding, 2),
		};
		printf("%*s %*s  %*s  %-*s %*s\n",
				tuklib_mbstr_fw(cols2[0], 15), cols2[0],
				tuklib_mbstr_fw(cols2[1], 15), cols2[1],
				tuklib_mbstr_fw(cols2[2], 5), cols2[2],
				tuklib_mbstr_fw(cols2[3], 10), cols2[3],
				tuklib_mbstr_fw(cols2[4], 7), cols2[4]);

		// Update the maximum Check size.
		if (lzma_check_size(iter.stream.flags->check) > check_max)
			check_max = lzma_check_size(iter.stream.flags->check);
	}

	// Cache the verbosity level to a local variable.
	const bool detailed = message_verbosity_get() >= V_DEBUG;

	// Information collected from Block Headers
	block_header_info bhi;

	// Print information about the Blocks but only if there is
	// at least one Block.
	if (lzma_index_block_count(xfi->idx) > 0) {
		// Calculate the width of the CheckVal field.
		const int checkval_width = my_max(8, 2 * check_max);

		// TRANSLATORS: The second line is column headings. All
		// except Check are right aligned; Check is left aligned.
		printf(_("  Blocks:\n    Stream     Block"
			"      CompOffset    UncompOffset"
			"       TotalSize      UncompSize  Ratio  Check"));

		if (detailed) {
			// TRANSLATORS: These are additional column headings
			// for the most verbose listing mode. CheckVal
			// (Check value), Flags, and Filters are left aligned.
			// Header (Block Header Size), CompSize, and MemUsage
			// are right aligned. %*s is replaced with 0-120
			// spaces to make the CheckVal column wide enough.
			// Test with "xz -lvv foo.xz".
			printf(_("      CheckVal %*s Header  Flags        "
					"CompSize    MemUsage  Filters"),
					checkval_width - 8, "");
		}

		putchar('\n');

		lzma_index_iter_init(&iter, xfi->idx);

		// Iterate over the Blocks.
		while (!lzma_index_iter_next(&iter, LZMA_INDEX_ITER_BLOCK)) {
			if (detailed && parse_details(pair, &iter, &bhi, xfi))
					return true;

			const char *cols1[4] = {
				uint64_to_str(iter.stream.number, 0),
				uint64_to_str(
					iter.block.number_in_stream, 1),
				uint64_to_str(
					iter.block.compressed_file_offset, 2),
				uint64_to_str(
					iter.block.uncompressed_file_offset, 3)
			};
			printf("    %*s %*s %*s %*s ",
				tuklib_mbstr_fw(cols1[0], 6), cols1[0],
				tuklib_mbstr_fw(cols1[1], 9), cols1[1],
				tuklib_mbstr_fw(cols1[2], 15), cols1[2],
				tuklib_mbstr_fw(cols1[3], 15), cols1[3]);

			const char *cols2[4] = {
				uint64_to_str(iter.block.total_size, 0),
				uint64_to_str(iter.block.uncompressed_size,
						1),
				get_ratio(iter.block.total_size,
					iter.block.uncompressed_size),
				_(check_names[iter.stream.flags->check])
			};
			printf("%*s %*s  %*s  %-*s",
				tuklib_mbstr_fw(cols2[0], 15), cols2[0],
				tuklib_mbstr_fw(cols2[1], 15), cols2[1],
				tuklib_mbstr_fw(cols2[2], 5), cols2[2],
				tuklib_mbstr_fw(cols2[3], detailed ? 11 : 1),
					cols2[3]);

			if (detailed) {
				const lzma_vli compressed_size
						= iter.block.unpadded_size
						- bhi.header_size
						- lzma_check_size(
						iter.stream.flags->check);

				const char *cols3[6] = {
					check_value,
					uint64_to_str(bhi.header_size, 0),
					bhi.flags,
					uint64_to_str(compressed_size, 1),
					uint64_to_str(
						round_up_to_mib(bhi.memusage),
						2),
					bhi.filter_chain
				};
				// Show MiB for memory usage, because it
				// is the only size which is not in bytes.
				printf("%-*s  %*s  %-5s %*s %*s MiB  %s",
					checkval_width, cols3[0],
					tuklib_mbstr_fw(cols3[1], 6), cols3[1],
					cols3[2],
					tuklib_mbstr_fw(cols3[3], 15),
						cols3[3],
					tuklib_mbstr_fw(cols3[4], 7), cols3[4],
					cols3[5]);
			}

			putchar('\n');
		}
	}

	if (detailed) {
		printf(_("  Memory needed:      %s MiB\n"), uint64_to_str(
				round_up_to_mib(xfi->memusage_max), 0));
		printf(_("  Sizes in headers:   %s\n"),
				xfi->all_have_sizes ? _("Yes") : _("No"));
		printf(_("  Minimum XZ Utils version: %s\n"),
				xz_ver_to_str(xfi->min_version));
	}

	return false;
}
Exemplo n.º 12
0
GnashImage*
Video::getVideoFrame()
{


	// If this is a video from a NetStream_as object, retrieve a video
    // frame from there.
	if (_ns)
	{
		std::auto_ptr<GnashImage> tmp = _ns->get_video();
		if ( tmp.get() ) _lastDecodedVideoFrame = tmp;
	}

	// If this is a video from a VideoFrame tag, retrieve a video frame
    // from there.
	else if (_embeddedStream)
	{

        // Don't try to do anything if there is no decoder. If it was
        // never constructed (most likely), we'll return nothing,
        // otherwise the last decoded frame.
        if (!_decoder.get()) return _lastDecodedVideoFrame.get();

		int current_frame = get_ratio(); 

#ifdef DEBUG_EMBEDDED_VIDEO_DECODING
		log_debug("Video instance %s need display video frame (ratio) %d",
			getTarget(), current_frame);
#endif

		// If current frame is the same then last decoded
		// we don't need to decode more
		if ( _lastDecodedVideoFrameNum == current_frame )
		{
#ifdef DEBUG_EMBEDDED_VIDEO_DECODING
			log_debug("  current frame == _lastDecodedVideoFrameNum (%d)",
                    current_frame);
#endif
			return _lastDecodedVideoFrame.get();
		}

		int from_frame = _lastDecodedVideoFrameNum < 0 ?
            0 : _lastDecodedVideoFrameNum + 1;

		// If current frame is smaller then last decoded frame
		// we restart decoding from scratch
		if ( current_frame < _lastDecodedVideoFrameNum )
		{
#ifdef DEBUG_EMBEDDED_VIDEO_DECODING
			log_debug("  current frame (%d) < _lastDecodedVideoFrameNum (%d)",
                    current_frame, _lastDecodedVideoFrameNum);
#endif
			from_frame = 0;
		}

		// Reset last decoded video frame number now, so it's correct 
		// on early return (ie: nothing more to decode)
		_lastDecodedVideoFrameNum = current_frame;

#ifdef DEBUG_EMBEDDED_VIDEO_DECODING
		log_debug("  decoding embedded frames from %d to %d for Video "
                "object %s", from_frame, current_frame, getTarget());
#endif

		typedef SWF::DefineVideoStreamTag::EmbeddedFrames EncodedFrames;

		EncodedFrames toDecode;
		m_def->getEncodedFrameSlice(from_frame, current_frame, toDecode);

		// Nothing more to decode, return last decoded (possibly null)
		if ( toDecode.empty() )
		{
#ifdef DEBUG_EMBEDDED_VIDEO_DECODING
			log_debug("    no defined frames, we'll return last one");
#endif
			return _lastDecodedVideoFrame.get();
		}

		for (EncodedFrames::iterator it=toDecode.begin(),
                itEnd=toDecode.end(); it!=itEnd; ++it)
		{
			media::EncodedVideoFrame* frame = *it;
#ifdef DEBUG_EMBEDDED_VIDEO_DECODING
			log_debug("    pushing frame %d to decoder", frame->frameNum());
#endif
			_decoder->push(*frame);
		}

		_lastDecodedVideoFrame = _decoder->pop();
	}

	return _lastDecodedVideoFrame.get();
}
Exemplo n.º 13
0
static void menu_create_item(GooCanvasItem *parent, MenuItems *menuitems, GcomprisBoard *board)
{
    GdkPixbuf *menu_pixmap = NULL;
    GooCanvasItem *menu_button;
    int difficulty;
    gdouble ratio, pixmap_w, pixmap_h;

    menu_pixmap = gc_pixmap_load(board->icon_name);

    ratio = get_ratio (menu_pixmap, icon_size);

    pixmap_w = gdk_pixbuf_get_width(menu_pixmap) * ratio;
    pixmap_h = gdk_pixbuf_get_height(menu_pixmap) * ratio;

    next_spot();

    menu_button = goo_canvas_image_new (parent,
                                        menu_pixmap,
                                        current_x - pixmap_w/2,
                                        current_y - pixmap_h/2,
                                        NULL);
    goo_canvas_item_scale(menu_button, ratio, ratio);

    // display board availability due to sound voice not present
    if(board->mandatory_sound_file)
    {
        gchar *soundfile = NULL;

        /* We search a fixed path sound file */
        soundfile = gc_file_find_absolute(board->mandatory_sound_file);

        if (!soundfile || !gc_prop_get()->fx) {
            GooCanvasItem *item =			\
                                            goo_canvas_svg_new (parent,
                                                    gc_skin_rsvg_get(),
                                                    "svg-id", "#SOUND_UNCHECKED",
                                                    "pointer-events", GOO_CANVAS_EVENTS_NONE,
                                                    NULL);

            GooCanvasBounds bounds;
            goo_canvas_item_get_bounds(item, &bounds);

            SET_ITEM_LOCATION(item,
                              current_x - pixmap_w/2 - 25 -
                              (bounds.x2 - bounds.x1)/2,
                              current_y - pixmap_h/2 + 28-
                              (bounds.y2 - bounds.y1)/2);
        }

        g_free(soundfile);
    }

    // display menu icon ========================== BEGIN
    if(g_ascii_strcasecmp(board->type, "menu") == 0)
    {
        GooCanvasItem *item = goo_canvas_svg_new (parent,
                              gc_skin_rsvg_get(),
                              "svg-id", "#MENUICON",
                              "pointer-events", GOO_CANVAS_EVENTS_NONE,
                              NULL);
        SET_ITEM_LOCATION(item,
                          current_x - pixmap_w/2 - 25,
                          current_y - pixmap_h/2);
    }
    else
    {
        // display difficulty stars
        if (board->difficulty != NULL)
        {
            difficulty = atoi(board->difficulty);
            menu_difficulty_display(parent,
                                    (double)current_x - pixmap_w/2 - 25,
                                    (double)current_y - pixmap_h/2,
                                    (double) 0.6,
                                    difficulty);
        }

        if ( gc_board_is_demo_only(board) )
            menu_demo_display(parent,
                              (gdouble)(current_x - pixmap_w/2 - 20),
                              (gdouble)(current_y - pixmap_h/2 + 60) );
    }


#if GDK_PIXBUF_MAJOR <= 2 && GDK_PIXBUF_MINOR <= 24
    gdk_pixbuf_unref(menu_pixmap);
#else
    g_object_unref(menu_pixmap);
#endif

    // display menu icon ========================== END

    /*
     * Now everything ready, map the events
     * -------------------------------------
     */
    g_object_set_data (G_OBJECT (menu_button), "board", board);

    g_signal_connect(menu_button, "button_press_event",
                     (GCallback) item_event,
                     menuitems);
    g_signal_connect (menu_button, "enter_notify_event",
                      (GCallback) on_enter_notify, menuitems);
    g_signal_connect (menu_button, "leave_notify_event",
                      (GCallback) on_leave_notify, menuitems);

    gc_item_focus_init(menu_button, NULL);

}
Exemplo n.º 14
0
int mc_simm::step(Plasma &Gas){
  int i,j;


  Vector_3 *tmp=newc;

  static int sttype=1;

  int m;
  if(one_particle){
    m=(int)(Gas.n*(0.5+random1()));
    if(m>=Gas.n)m=Gas.n-1;
    if(sttype){
      newc[0]=Gas.x[m];
      for(j=0;j<3;j++){
      	Gas.x[m][j]+=dc[sttype]*random1();
      }
    }
    else{
      newc[0]=Gas.v[m];
      for(j=0;j<3;j++){
       	Gas.x[m][j]+=dc[sttype]*random1();
      }
    }
  }
  else{
    m=-1;
    if(sttype)tmp=Gas.x;
    else tmp=Gas.v;
    for(i=0;i<Gas.n;i++){
      for(j=0;j<3;j++){
        	newc[i][j]=tmp[i][j]+dc[sttype]*random1();
      }
    }
    if(sttype)Gas.x=newc;
    else Gas.v=newc;
  }


  int mult=1;
  double Epot_old=Gas.Epotent;
  if(momentum_depend){
    Gas.interaction(m);
    T=Gas.getT();
    Epotent=Gas.Epotent;
    mult=2;
  }
  else{
    if(sttype){
      Gas.interaction(m,1);
      Epotent=Gas.Epotent;
    }
    else T=Gas.getT();
  }

  double E2;
  if(!diff_temp)E2=1.5*T*Gas.n+Epotent;
  else E2=1.5*Gas.Ti*Gas.ni+1.5*Gas.Te*Gas.ne+Epotent;

  double Temp=1.;
  if(diff_temp && m>=0){
    if(m<Gas.ni)Temp=Gas.ini_Ti;
    else Temp=Gas.ini_Te;
  }


  int ac =0;
  if(E2<=E1)ac=1;
  else{
     if(exp((E1-E2)/Temp)>0.5+random1())ac=1;
  }
  (accept[sttype])+=ac;
  nstp++;

  if(nstp%nav==0){
    aold[0]=accept[0];
    aold[1]=accept[1];
    accept[1]=accept[0]=0;
    nstp=nav;
  }


  double ratio=mult*get_ratio(sttype);

  if(auto_adjust){
   double k;
   double kmax=1.1,kmax_inv=1./kmax;
   if((nstp/2)%5==0){
     if(ratio<0.5*kmax_inv)k=kmax_inv;
     else if(ratio>0.5*kmax)k=kmax;
     else k=ratio/0.5;

     dc[sttype]*=k;
     if(sttype && dc[sttype]>Gas.L/2)dc[sttype]=Gas.L/2;
   }
   //printf("%d, %f, %f\n",(one_particle ? m : sttype),ratio,dc[sttype]);
  }

  if(ac){
    if(!one_particle)newc=tmp;
    E1=E2;
  }
  else{ // restoring previous
    if(one_particle){

      for(i=0;i<Gas.n;i++){
	      (*Gas.umatr)(i,m)=(*Gas.umatr)(i,i);
	       //printf("%i -> (%d, %d) [%f]\n",i,i,m,fucktmp[i]);
      }
      if(sttype){
	      Gas.x[m]=newc[0];
       Gas.rcell(m);
      }
      else Gas.v[m]=newc[0];

      //Gas.Epotent=Epot_old;
      //Gas.interaction(m);
      // printf("%f\n",Gas.Epotent-Epot_old);

    }
    else{
      if(sttype)Gas.x=tmp;
      else Gas.v=tmp;
    }

    Gas.Epotent=Epot_old;
    //Gas.Epotent=E1-1.5*T*Gas.n;
  }

  if(momentum_depend)sttype=1-sttype;

  /*
  if(nstp%4==0){
    //Gas.is_matr=0;
    Gas.interaction(m,1); //to check!
    //Gas.is_matr=1;
  }*/

  return ac;
}
Exemplo n.º 15
0
inline double
MorphShape::currentRatio() const
{
    return get_ratio() / 65535.0;
}
Exemplo n.º 16
0
image::GnashImage*
Video::getVideoFrame()
{
    // If this is a video from a NetStream_as object, retrieve a video
    // frame from there.
    if (_ns) {
        std::unique_ptr<image::GnashImage> tmp = _ns->get_video();
        if (tmp.get()) _lastDecodedVideoFrame = std::move(tmp);
    }

    // If this is a video from a VideoFrame tag, retrieve a video frame
    // from there.
    else if (_embeddedStream) {

        // Don't try to do anything if there is no decoder. If it was
        // never constructed (most likely), we'll return nothing,
        // otherwise the last decoded frame.
        if (!_decoder.get()) {
            LOG_ONCE(log_error(_("No Video info in video definition")));
            return _lastDecodedVideoFrame.get();
        }

        const std::uint16_t current_frame = get_ratio();

#ifdef DEBUG_EMBEDDED_VIDEO_DECODING
        log_debug("Video instance %s need display video frame (ratio) %d",
                  getTarget(), current_frame);
#endif

        // If current frame is the same then last decoded
        // we don't need to decode more
        if (_lastDecodedVideoFrameNum >= 0 &&
                _lastDecodedVideoFrameNum == current_frame) {
#ifdef DEBUG_EMBEDDED_VIDEO_DECODING
            log_debug("  current frame == _lastDecodedVideoFrameNum (%d)",
                      current_frame);
#endif
            return _lastDecodedVideoFrame.get();
        }

        // TODO: find a better way than using -1 to show that no
        // frames have been decoded yet.
        assert(_lastDecodedVideoFrameNum >= -1);
        std::uint16_t from_frame = _lastDecodedVideoFrameNum + 1;

        // If current frame is smaller then last decoded frame
        // we restart decoding from scratch
        if (current_frame < static_cast<size_t>(_lastDecodedVideoFrameNum)) {
#ifdef DEBUG_EMBEDDED_VIDEO_DECODING
            log_debug("  current frame (%d) < _lastDecodedVideoFrameNum (%d)",
                      current_frame, _lastDecodedVideoFrameNum);
#endif
            from_frame = 0;
        }

        // Reset last decoded video frame number now, so it's correct
        // on early return (ie: nothing more to decode)
        _lastDecodedVideoFrameNum = current_frame;

#ifdef DEBUG_EMBEDDED_VIDEO_DECODING
        log_debug("  decoding embedded frames from %d to %d "
                  "for Video object %s", from_frame,
                  current_frame, getTarget());
#endif

        const size_t frames = m_def->visitSlice(
                                  std::bind(std::mem_fn(&media::VideoDecoder::push),
                                            _decoder.get(), std::placeholders::_1),
                                  from_frame, current_frame);

        if (!frames) return _lastDecodedVideoFrame.get();

        _lastDecodedVideoFrame = _decoder->pop();
    }

    return _lastDecodedVideoFrame.get();
}
Exemplo n.º 17
0
static void
create_top(GooCanvasItem *parent, gchar *path)
{
    gchar **splitted_section;
    gint i = 1;
    GdkPixbuf *pixmap = NULL;
    gdouble ratio;
    GcomprisBoard *board;
    gchar *path1, *path2;

    GooCanvasItem *item;

    GcomprisProperties *properties = gc_prop_get();

    if (!path)
        return;

    splitted_section = g_strsplit (path, "/", 0);

    path1 = g_strdup("");

    /* splitted_section[0] is always "" */
    i = 1;

    while (splitted_section[i] != NULL)
    {

        path2 = g_strdup_printf("%s/%s", path1, splitted_section[i]);

        g_free(path1);
        path1 = path2;

        if (strcmp(path1, properties->root_menu)<0) {
            i++;
            continue;
        }

        if (current_top_x == 0.0)
        {
            current_top_x = top_x;
            current_top_y = top_y;
        }
        else
        {
            item = \
                   goo_canvas_svg_new (parent,
                                       gc_skin_rsvg_get(),
                                       "svg-id", "#MENUICON",
                                       "pointer-events", GOO_CANVAS_EVENTS_NONE,
                                       NULL);

            SET_ITEM_LOCATION(item,
                              current_top_x,
                              current_top_y + top_arrow_size);
            //	  goo_canvas_item_scale(item, ratio, ratio);

            current_top_x += top_arrow_size + top_int_x;
        }

        board = gc_menu_section_get(path1);

        pixmap = gc_pixmap_load(board->icon_name);

        ratio = get_ratio( pixmap, icon_size_top);

        item = goo_canvas_image_new (parent,
                                     pixmap,
                                     0, 0,
                                     NULL);
        goo_canvas_item_translate(item,
                                  current_top_x,
                                  current_top_y);
        goo_canvas_item_scale(item, ratio, ratio);
#if GDK_PIXBUF_MAJOR <= 2 && GDK_PIXBUF_MINOR <= 24
        gdk_pixbuf_unref(pixmap);
#else
        g_object_unref(pixmap);
#endif

        current_top_x += top_int_x + icon_size_top;

        g_object_set_data (G_OBJECT (item), "board", board);

        g_signal_connect(item, "button_press_event",
                         (GCallback) item_event,
                         menuitems);

        gc_item_focus_init(item, NULL);

        i++;
    }

    g_strfreev(splitted_section);
    g_free(path1);

}