/*
 * ... FIXME: docs
 */
static void
print_unknown_tables (void)
{
  GSList         *list;
  GSList         *flist;
  QuantTableData *table_data;
  gint            num_files;
  gint            total_files = 0;

  for (list = found_tables; list; list = list->next)
    {
      table_data = list->data;

      if (option_ctable)
        {
          g_print ("  {\n");
          num_files = 0;
          for (flist = table_data->files; flist; flist = flist->next)
            {
              g_print("    /* %s */\n", (gchar *)(flist->data));
              num_files++;
            }

          { /* FIXME */
            guint    lum_sum;
            guint    chrom_sum;
            gint     i;

            total_files += num_files;
            lum_sum = 0;
            chrom_sum = 0;
            for (i = 0; i < DCTSIZE2; i++)
              lum_sum += table_data->luminance[i];
            for (i = 0; i < DCTSIZE2; i++)
              chrom_sum += table_data->chrominance[i];
            g_print ("    /* hash 0x%x, IJG %d, lum %d, chrom %d, files: %d */\n",
                     table_data->hashval,
                     table_data->ijg_qual,
                     lum_sum, chrom_sum,
                     num_files);

            if (chrom_sum == 0 && table_data->num_quant_tables == 1)
              {
                /* grayscale */
                for (i = 0; i < G_N_ELEMENTS (quant_info); i++)
                  {
                    if (quant_info[i].lum_sum == lum_sum
                        && (quant_info[i].subsmp_h == 0
                            || quant_info[i].subsmp_h
                            == table_data->subsmp_h)
                        && (quant_info[i].subsmp_v == 0
                            || quant_info[i].subsmp_v
                            == table_data->subsmp_v)
                        && quant_info[i].num_quant_tables > 0)
                      {
                        g_print("    XXX \"%s\", \"%s\",\n",
                                quant_info[i].source_name,
                                quant_info[i].setting_name);
                      }
                  }
              }
            else
              {
                /* RGB and other color spaces */
                for (i = 0; i < G_N_ELEMENTS (quant_info); i++)
                  {
                    if (quant_info[i].lum_sum == lum_sum
                        && quant_info[i].chrom_sum == chrom_sum
                        && (quant_info[i].subsmp_h == 0
                            || quant_info[i].subsmp_h
                            == table_data->subsmp_h)
                        && (quant_info[i].subsmp_v == 0
                            || quant_info[i].subsmp_v
                            == table_data->subsmp_v)
                        && (quant_info[i].num_quant_tables == table_data->num_quant_tables
                            || quant_info[i].num_quant_tables == -table_data->num_quant_tables))
                      {
                        g_print("    XXX \"%s\", \"%s\",\n",
                                quant_info[i].source_name,
                                quant_info[i].setting_name);
                      }
                  }
              }
          } /* FIXME */

          g_print ("    \"?\", \"? (hash %x)\",\n"
                   "    %hd, %hd,\n    %d,\n",
                   table_data->hashval,
                   table_data->subsmp_h,
                   table_data->subsmp_v,
                   -table_data->num_quant_tables);
          print_ctable (-1, table_data->luminance, TRUE);
          print_ctable (-1, table_data->chrominance, FALSE);
          g_print ("  },\n");
        }
    }
  g_print ("/* TOTAL FILES: %d */\n", total_files);
}
Exemple #2
0
int xmain( int argc, char* argv[] )
{
    StoreCmdArgs( argc, argv );
    ConfigFile cf( "pol.cfg" );
    ConfigElem elem;

    cf.readraw( elem );

    config.uo_datafile_root = elem.remove_string( "UoDataFileRoot" );
    config.uo_datafile_root = normalized_dir_form( config.uo_datafile_root );

	unsigned short max_tile = elem.remove_ushort( "MaxTileID", 0x3FFF );

	if (max_tile != 0x3FFF && max_tile != 0x7FFF)
		config.max_tile_id = 0x3FFF;
	else
		config.max_tile_id = max_tile;

	if (argc <= 1)
		return Usage(1);

    if (argv[1][0] == '/' || argv[1][1] == ':')
    {
        config.uo_datafile_root = argv[1];
        --argc;
        ++argv;
    }

	if (stricmp( argv[1], "tiledump" ) == 0)
	{
		return tiledump( argc, argv );
	}
	else if (stricmp( argv[1], "vertile" ) == 0)
	{
		return vertile( argc, argv );
	}
    else if (stricmp( argv[1], "verlandtile" ) == 0)
    {
        return verlandtile( argc, argv );
    }
    else if (stricmp( argv[1], "landtilehist" ) == 0)
    {
        return landtilehist( argc, argv );
    }
	else if (stricmp( argv[1], "flagsearch" ) == 0)
	{
		return flagsearch( argc, argv );
	}
	else if (stricmp( argv[1], "landtileflagsearch" ) == 0)
	{
		return landtileflagsearch( argc, argv );
	}
    else if (stricmp( argv[1], "loschange" ) == 0)
    {
        return loschange( argc, argv );
    }
	else if (stricmp( argv[1], "rawdump" ) == 0)
	{
		return rawdump( argc, argv );
	}
    else if (stricmp( argv[1], "ctable" ) == 0)
    {
        return print_ctable();
    }
    else if (stricmp( argv[1], "sndlist" ) == 0)
    {
        return print_sndlist(argc, argv);
    }
    else if (stricmp( argv[1], "statics" ) == 0)
    {
        return print_statics();
    }
    else if (stricmp( argv[1], "verdata" ) == 0)
    {
        return print_verdata_info();
    }
    else if (stricmp( argv[1], "multis" ) == 0)
    {
        return print_multis();
    }
    else if (stricmp( argv[1], "water" ) == 0)
    {
        return print_water_data();
    }
    else if (stricmp( argv[1], "newstatics" ) == 0)
    {
        return write_pol_static_files( "main" );
    }
    else if (stricmp( argv[1], "staticsmax" ) == 0)
    {
        void staticsmax();
        open_uo_data_files();
        staticsmax();
        return 0;
    }
    else if (stricmp( argv[1], "watersearch" ) == 0)
    {
        return water_search(argc,argv);
    }
    else if (stricmp( argv[1], "zhist" ) == 0)
    {
        return z_histogram();
    }
    else if (stricmp( argv[1], "staticshist" ) == 0)
    {
        return statics_histogram();
    }
    else if (stricmp( argv[1], "writedungmap" ) == 0)
    {
        return write_polmap();
    }
    else if (stricmp( argv[1], "writekeys" ) == 0)
    {
        printf( "Keys written to current.key" );
        return 0;
    }
    else if (stricmp( argv[1], "mapdump" ) == 0)
    {
        return mapdump( argc, argv );
    }
    else if (stricmp( argv[1], "contour" ) == 0)
    {
        return contour( argc, argv );
    }
    else if (stricmp( argv[1], "findlandtile" ) == 0)
    {
        return findlandtile( argc-1, argv+1 );
    }
	else if (stricmp( argv[1], "findlandtileflags" ) == 0)
	{
		return findlandtileflags( argc-1, argv+1 );
	}
    else if (stricmp( argv[1], "findgraphic" ) == 0)
    {
        return findgraphic( argc-1, argv+1 );
    }
    else if (stricmp( argv[1], "defragstatics" ) == 0)
    {
        return defragstatics( argc-1, argv+1 );
    }
    
	return 0;
}
/*
 * Analyze a JPEG file according to the command-line options.
 */
static gboolean
analyze_file (gchar *filename)
{
  struct jpeg_decompress_struct  cinfo;
  struct my_error_mgr            jerr;
  FILE                          *f;
  gint                           i;
  gint                           num_quant_tables;
  GSList                        *source_list;

  if ((f = fopen (filename, "rb")) == NULL)
    {
      g_printerr ("Cannot open '%s'\n", filename);
      return FALSE;
    }

  if (option_summary)
    g_print ("%s:\n", filename);

  cinfo.err = jpeg_std_error (&jerr.pub);
  jerr.pub.error_exit = my_error_exit;
  if (setjmp (jerr.setjmp_buffer))
    {
      /* if we get here, the JPEG code has signaled an error. */
      jpeg_destroy_decompress (&cinfo);
      fclose (f);
      return FALSE;
    }
  jpeg_create_decompress (&cinfo);

  jpeg_stdio_src (&cinfo, f);

  jpeg_read_header (&cinfo, TRUE);

  num_quant_tables = 0;
  for (i = 0; i < 4; i++)
    if (cinfo.quant_tbl_ptrs[i])
      num_quant_tables++;

  source_list = detect_source (&cinfo, num_quant_tables);
  if (! source_list)
    {
      add_unknown_table (&cinfo, filename);
    }

  if (! option_unknown)
    {
      if (option_summary)
        print_summary (&cinfo, num_quant_tables);

      if (option_ctable)
        {
          g_print ("  {\n    /* %s */\n    \"?\", \"?\",\n    %hd, %hd,\n    %d,\n",
                   filename,
                   cinfo.comp_info[0].h_samp_factor,
                   cinfo.comp_info[0].v_samp_factor,
                   num_quant_tables);
          for (i = 0; i < 4; i++)
            if (cinfo.quant_tbl_ptrs[i])
              print_ctable (i, cinfo.quant_tbl_ptrs[i]->quantval,
                            (i < 3) && cinfo.quant_tbl_ptrs[i + 1]);
          g_print ("  },\n");
        }

      if (option_table_2cols)
        {
          print_table_2cols (0, cinfo.quant_tbl_ptrs[0]->quantval,
                             1, cinfo.quant_tbl_ptrs[1]->quantval);
          if (cinfo.quant_tbl_ptrs[2] || cinfo.quant_tbl_ptrs[3])
            print_table_2cols (2, cinfo.quant_tbl_ptrs[2]->quantval,
                               3, cinfo.quant_tbl_ptrs[3]->quantval);
        }
    }

  if (source_list)
    g_slist_free (source_list);

  jpeg_destroy_decompress (&cinfo);
  fclose (f);

  return TRUE;
}