示例#1
0
int
main()
try
{
    png::image< png::index_pixel_1 > image1;
    generate_image(image1);
    image1.write("out/palette1.png.out");

    png::image< png::index_pixel_2 > image2;
    generate_image(image2);
    image2.write("out/palette2.png.out");

    png::image< png::index_pixel_4 > image4;
    generate_image(image4);
    image4.write("out/palette4.png.out");

    png::image< png::index_pixel > image8;
    generate_image(image8);
    image8.write("out/palette8.png.out");

    png::image< png::index_pixel > image8_tRNS;
    generate_image(image8_tRNS);
    png::tRNS trns(256);
    for (size_t i = 0; i < trns.size(); ++i)
    {
        trns[i] = i;
    }
    image8_tRNS.set_tRNS(trns);
    image8_tRNS.write("out/palette8_tRNS.png.out");
}
catch (std::exception const& error)
{
    std::cerr << "generate_palette: " << error.what() << std::endl;
    return EXIT_FAILURE;
}
示例#2
0
文件: main.c 项目: Vild/ImageToMap-X
void drag_received(GtkWidget * widget, GdkDragContext * context, gint x, gint y, GtkSelectionData * select_data, guint type_type, guint time, gpointer data)
{
  struct stat info;
  gchar * file = (char *) gtk_selection_data_get_data(select_data);
  int len;
  
  if (strncmp(file, "file:///", 8) != 0)
    return;

  gtk_drag_finish(context, TRUE, FALSE, time);
  
  file += 7 * sizeof(char);
#ifndef OS_LINUX
  file += 1 * sizeof(char);
#endif

  len = strlen(file) - 1;

  while ((file[len] == ' ') || (file[len] == '\n') || (file[len] == '\r'))
    {
      file[len] = '\0';
      len--;
    }

  if (stat(file, &info) < 0)
    return;

  if(srecmpend(".dat", file) == 0)
    {
      add_buffer();
      image_load_map(file);
    }
  else if(srecmpend(".bmp", file) == 0 || srecmpend(".png", file) == 0 || srecmpend(".jpg", file) == 0 || srecmpend(".jpeg", file) == 0 || srecmpend(".gif", file) == 0)
    {
      GError * err = NULL;
      add_buffer();
      if(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(FSD_checkbox)))
	generate_image_dithered(mdata[current_buffer], 128, 128, gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(YUV_checkbox)), file, colors, &err);
      else
	generate_image(mdata[current_buffer], 128, 128, gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(YUV_checkbox)), file, colors, &err);
      if(err != NULL)
	{
	  information("Error while loading image file!");
	  printf("%s\n", err->message);
	  g_error_free(err);
	}
      set_image();
    }
  else if(srecmpend(".imtm", file) == 0)
    {
      add_buffer();
      load_raw_map(file, mdata[current_buffer]);
      set_image();
    }
  else
    information("File format not supported!");
  gtk_drag_finish(context, TRUE, TRUE, time);
}
示例#3
0
int main (int argc, char const *argv[])
{
	const int N = 7;
	int **im;
	
	im = allocate2D(im, N);
	generate_image(im, N);
	print_image(im, N);

	rotate_image(im, N);
	printf("\n");
	print_image(im, N);
	release2D(im, N);
	return 0;
}
示例#4
0
文件: Ex12.c 项目: marrusian/C
int main(void)
{
   char picture[ROWS][COLS+1] = {{0}};

   srand((unsigned int) time(0));
   if(generate_file(FLNM, ROWS, COLS)==ERRGEN)
      exit(EXIT_FAILURE);
 
   if(generate_image(FLNM, (char*)picture, ROWS, COLS)==ERRGEN)
      exit(EXIT_FAILURE);

   display_image((char*)picture, ROWS, COLS);

   if(store_image(IMGNM, (char*)picture, ROWS, COLS)==ERRGEN)
      exit(EXIT_FAILURE);

   return 0;
}
示例#5
0
文件: main.c 项目: artex2000/fconv
static gboolean
expose_event (GtkWidget *widget, GdkEventExpose *event, GtkWidget *str)
{
	cairo_t *cr;
	double cw, ch;
	int i;
	char *s;

	s = (char *) gtk_entry_get_text (GTK_ENTRY (str));
	cr = gdk_cairo_create (widget->window);
	cairo_set_source_rgb (cr, 0, 0, 0);
	cairo_set_line_width (cr, 0.5);
	cw = (double)widget->allocation.width;
	ch = (double)widget->allocation.height;
	generate_image (s, cr, cw, ch);	
	cairo_stroke (cr);
	cairo_destroy (cr);
	return TRUE;
}
示例#6
0
static void draw(int which) {
  UCHAR *buf_graf;
  unsigned int buf_graf_stride, width, height;
  disp_beginUpdate(&buf_graf, &buf_graf_stride, &width, &height);
  if (which < 0) {
    writeBitmapImageToArray(buf_graf, NOAHS_FACE, width, height,
                            buf_graf_stride);
  } else {
    if (flags & DRAW_FLOAT) {
      generate_image_float(which,
                           buf_graf, width/2, height/2, width, height,
                           256, buf_graf_stride, flags & DRAW_SCALED);
    } else {
      generate_image(which,
                     buf_graf, width/2, height/2, width, height,
                     256, buf_graf_stride);
    }
  }
  disp_finishUpdate();
}
示例#7
0
static void generate_boxes(fz_context *ctx, fz_pool *pool,
                           fz_html_font_set *set, fz_archive *zip, const char *base_uri,
                           fz_xml *node, fz_html *top, fz_css_rule *rule, fz_css_match *up_match, int list_counter)
{
    fz_css_match match;
    fz_html *box;
    const char *tag;
    int display;

    while (node)
    {
        match.up = up_match;
        match.count = 0;

        tag = fz_xml_tag(node);
        if (tag)
        {
            fz_match_css(ctx, &match, rule, node);

            display = fz_get_css_match_display(&match);

            if (!strcmp(tag, "br"))
            {
                if (top->type == BOX_INLINE)
                {
                    fz_html *flow = top;
                    while (flow->type != BOX_FLOW)
                        flow = flow->up;
                    add_flow_break(ctx, pool, flow, &top->style);
                }
                else
                {
                    box = new_box(ctx, pool);
                    fz_apply_css_style(ctx, set, &box->style, &match);
                    top = insert_break_box(ctx, box, top);
                }
            }

            else if (!strcmp(tag, "img"))
            {
                const char *src = fz_xml_att(node, "src");
                if (src)
                {
                    box = new_box(ctx, pool);
                    fz_apply_css_style(ctx, set, &box->style, &match);
                    insert_inline_box(ctx, pool, box, top);
                    generate_image(ctx, pool, zip, base_uri, box, src);
                }
            }

            else if (display != DIS_NONE)
            {
                box = new_box(ctx, pool);
                fz_apply_css_style(ctx, set, &box->style, &match);

                if (display == DIS_BLOCK || display == DIS_INLINE_BLOCK)
                {
                    top = insert_block_box(ctx, box, top);
                }
                else if (display == DIS_LIST_ITEM)
                {
                    top = insert_block_box(ctx, box, top);
                    box->list_item = ++list_counter;
                }
                else if (display == DIS_INLINE)
                {
                    insert_inline_box(ctx, pool, box, top);
                }
                else
                {
                    fz_warn(ctx, "unknown box display type");
                    insert_box(ctx, box, BOX_BLOCK, top);
                }

                if (fz_xml_down(node))
                {
                    int child_counter = list_counter;
                    if (!strcmp(tag, "ul") || !strcmp(tag, "ol"))
                        child_counter = 0;
                    generate_boxes(ctx, pool, set, zip, base_uri, fz_xml_down(node), box, rule, &match, child_counter);
                }

                // TODO: remove empty flow boxes
            }
        }
        else
        {
            if (top->type != BOX_INLINE)
            {
                /* Create anonymous inline box, with the same style as the top block box. */
                box = new_box(ctx, pool);
                insert_inline_box(ctx, pool, box, top);
                box->style = top->style;
                /* Make sure not to recursively multiply font sizes. */
                box->style.font_size.value = 1;
                box->style.font_size.unit = N_SCALE;
                generate_text(ctx, pool, box, fz_xml_text(node));
            }
            else
            {
                generate_text(ctx, pool, top, fz_xml_text(node));
            }
        }

        node = fz_xml_next(node);
    }
}
示例#8
0
static void generate_boxes(fz_context *ctx, fz_html_font_set *set, fz_archive *zip, const char *base_uri,
	fz_xml *node, fz_html *top, fz_css_rule *rule, fz_css_match *up_match)
{
	fz_css_match match;
	fz_html *box;
	const char *tag;
	int display;

	while (node)
	{
		match.up = up_match;
		match.count = 0;

		tag = fz_xml_tag(node);
		if (tag)
		{
			fz_match_css(ctx, &match, rule, node);

			display = fz_get_css_match_display(&match);

			if (!strcmp(tag, "br"))
			{
				box = new_box(ctx);
				fz_apply_css_style(ctx, set, &box->style, &match);
				top = insert_break_box(ctx, box, top);
			}

			else if (!strcmp(tag, "img"))
			{
				const char *src = fz_xml_att(node, "src");
				if (src)
				{
					box = new_box(ctx);
					fz_apply_css_style(ctx, set, &box->style, &match);
					insert_inline_box(ctx, box, top);
					generate_image(ctx, zip, base_uri, box, src);
				}
			}

			else if (display != DIS_NONE)
			{
				box = new_box(ctx);
				fz_apply_css_style(ctx, set, &box->style, &match);

				if (display == DIS_BLOCK)
				{
					top = insert_block_box(ctx, box, top);
				}
				else if (display == DIS_LIST_ITEM)
				{
					top = insert_block_box(ctx, box, top);
				}
				else if (display == DIS_INLINE)
				{
					insert_inline_box(ctx, box, top);
				}
				else
				{
					fz_warn(ctx, "unknown box display type");
					insert_box(ctx, box, BOX_BLOCK, top);
				}

				if (fz_xml_down(node))
					generate_boxes(ctx, set, zip, base_uri, fz_xml_down(node), box, rule, &match);

				// TODO: remove empty flow boxes
			}
		}
		else
		{
			if (top->type != BOX_INLINE)
			{
				box = new_box(ctx);
				insert_inline_box(ctx, box, top);
				box->style = top->style;
				generate_text(ctx, box, fz_xml_text(node));
			}
			else
			{
				generate_text(ctx, top, fz_xml_text(node));
			}
		}

		node = fz_xml_next(node);
	}
}
示例#9
0
static void button_click(gpointer data)
{
  if(strcmp("button.open", (char *)data) == 0)
    {
      GtkWidget * dialog;
      dialog = gtk_file_chooser_dialog_new("Open file",
					   GTK_WINDOW(window),
					   GTK_FILE_CHOOSER_ACTION_OPEN,
					   GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
					   GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
					   NULL);
		
      if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
	{
	  char * file = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
			
	  if(srecmpend(".dat", file) == 0)
	    {
	      add_buffer();
	      image_load_map(file);
	    }
	  else if(srecmpend(".bmp", file) == 0 || srecmpend(".png", file) == 0 || srecmpend(".jpg", file) == 0 || srecmpend(".jpeg", file) == 0 || srecmpend(".gif", file) == 0)
	    {
	      GError * err = NULL;
	      add_buffer();
	      if(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(FSD_checkbox)))
		generate_image_dithered(mdata[current_buffer], file, colors, &err);
	      else
		generate_image(mdata[current_buffer], file, colors, &err);
	      if(err != NULL)
		{
		  information("Error while loading image file!");
		  printf("%s\n", err->message);
		  g_error_free(err);
		}
	      set_image();
	    }
	  else if(srecmpend(".imtm", file) == 0)
	    {
	      add_buffer();
	      load_raw_map(file, mdata[current_buffer]);
	      set_image();
	    }
	  else
	    information("File format not supported!");
	}
      gtk_widget_destroy(dialog);
    }
  else if(strcmp("button.save", (char *)data) == 0)
    {
      if(mdata[current_buffer] == NULL)
	return;
			
      GtkWidget * dialog;
		
      dialog = gtk_file_chooser_dialog_new ("Save Map",
					    GTK_WINDOW(window),
					    GTK_FILE_CHOOSER_ACTION_SAVE,
					    GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
					    GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
					    NULL);
		
      gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE);
      gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER (dialog), "map_0.dat");
		
      if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
	{
	  char * file = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
	  printf("%s\n", file);
	  if(srecmpend(".dat", file) == 0)
	    save_map(file);
	}
      gtk_widget_destroy(dialog);
      printf("bracket cleared\n");
    }
  else if(strcmp("button.exp_img", (char *)data) == 0)
    {
      if(mdata[current_buffer] == NULL)
	return;
			
      GtkWidget * dialog;
		
      dialog = gtk_file_chooser_dialog_new ("Export Image of Map",
					    GTK_WINDOW(window),
					    GTK_FILE_CHOOSER_ACTION_SAVE,
					    GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
					    GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
					    NULL);
		
      gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE);
      gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER (dialog), "map.png");
		
      if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
	{
	  char * file = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
	  printf("%s\n", file);
			
			
	  unsigned char * data = malloc(128 * 128 * 3);
	  int i;
	  for(i = 0; i < 128 * 128; i++)
	    {
	      if(mdata[current_buffer][i] > 3)
		{
		  data[i * 3] = colors[mdata[current_buffer][i]].r;
		  data[i * 3 + 1] = colors[mdata[current_buffer][i]].g;
		  data[i * 3 + 2] = colors[mdata[current_buffer][i]].b;
		}
	      else
		{
		  int x = i % 128, y = i / 128;
		  x /= 4;
		  y /= 4;
		  data[i * 3] = ((x + (y % 2)) % 2) ? 0xFF : 0xAA;
		  data[i * 3 + 1] = ((x + (y % 2)) % 2) ? 0xFF : 0xAA;
		  data[i * 3 + 2] = ((x + (y % 2)) % 2) ? 0xFF : 0xAA;
		}
	    }
			
	  GdkPixbuf * spixbuf = image_from_data(data, 0);
	  free(data);
			
	  GError * err = NULL;
			
	  gdk_pixbuf_save(spixbuf, file, "png", &err, "compression", "9", NULL);
	  if (err != NULL)
	    {
	      /* Report error to user, and free error */
	      printf("Error while saving: %s\n", err->message);
	      g_error_free(err);
	    }
			
	  g_object_unref(spixbuf);
	}
      gtk_widget_destroy(dialog);
    }
  else if(strcmp("button.save_rm", (char *)data) == 0)
    {
      if(mdata == NULL)
	return;
			
      GtkWidget * dialog;
		
      dialog = gtk_file_chooser_dialog_new("Save Map",
					   GTK_WINDOW(window),
					   GTK_FILE_CHOOSER_ACTION_SAVE,
					   GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
					   GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
					   NULL);
		
      gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER (dialog), TRUE);
      gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER (dialog), "map.imtm");
		
      if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
	{
	  char * file = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
	  printf("%s\n", file);
	  save_raw_map(file, mdata[current_buffer]);
	}
      gtk_widget_destroy(dialog);
    }
  else if(strcmp("button.palette", (char *)data) == 0)
    {
      add_buffer();
      generate_palette(mdata[current_buffer]);
      set_image();
    }
  else if(strcmp("button.random_noise", (char *)data) == 0)
    {
      add_buffer();
      generate_random_noise(mdata[current_buffer]);
      set_image();
    }
  else if(strcmp("button.mandelbrot", (char *)data) == 0)
    {
      add_buffer();
      generate_mandelbrot(mdata[current_buffer]);
      set_image();
    }
  else if(strcmp("button.julia", (char *)data) == 0)
    {
      add_buffer();
      generate_julia(mdata[current_buffer], 0.5, 0.5);
      set_image();
    }
  else if(strcmp("button.from_clipboard", (char *)data) == 0)
    {
      GtkClipboard * clipboard;
      clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);

      gtk_clipboard_request_image(clipboard, clipboard_callback, NULL);
    }
  else
    printf("Unhandeled button press: %s\n", (char *)data);
}
示例#10
0
/*
	This method generates all the textures
*/
u32 TextureSource::getTextureIdDirect(const std::string &name)
{
	//infostream<<"getTextureIdDirect(): name=\""<<name<<"\""<<std::endl;

	// Empty name means texture 0
	if(name == "")
	{
		infostream<<"getTextureIdDirect(): name is empty"<<std::endl;
		return 0;
	}
	
	/*
		Calling only allowed from main thread
	*/
	if(get_current_thread_id() != m_main_thread)
	{
		errorstream<<"TextureSource::getTextureIdDirect() "
				"called not from main thread"<<std::endl;
		return 0;
	}

	/*
		See if texture already exists
	*/
	{
		JMutexAutoLock lock(m_atlaspointer_cache_mutex);

		core::map<std::string, u32>::Node *n;
		n = m_name_to_id.find(name);
		if(n != NULL)
		{
			/*infostream<<"getTextureIdDirect(): \""<<name
					<<"\" found in cache"<<std::endl;*/
			return n->getValue();
		}
	}

	/*infostream<<"getTextureIdDirect(): \""<<name
			<<"\" NOT found in cache. Creating it."<<std::endl;*/
	
	/*
		Get the base image
	*/

	char separator = '^';

	/*
		This is set to the id of the base image.
		If left 0, there is no base image and a completely new image
		is made.
	*/
	u32 base_image_id = 0;
	
	// Find last meta separator in name
	s32 last_separator_position = -1;
	for(s32 i=name.size()-1; i>=0; i--)
	{
		if(name[i] == separator)
		{
			last_separator_position = i;
			break;
		}
	}
	/*
		If separator was found, construct the base name and make the
		base image using a recursive call
	*/
	std::string base_image_name;
	if(last_separator_position != -1)
	{
		// Construct base name
		base_image_name = name.substr(0, last_separator_position);
		/*infostream<<"getTextureIdDirect(): Calling itself recursively"
				" to get base image of \""<<name<<"\" = \""
                <<base_image_name<<"\""<<std::endl;*/
		base_image_id = getTextureIdDirect(base_image_name);
	}
	
	//infostream<<"base_image_id="<<base_image_id<<std::endl;
	
	video::IVideoDriver* driver = m_device->getVideoDriver();
	assert(driver);

	video::ITexture *t = NULL;

	/*
		An image will be built from files and then converted into a texture.
	*/
	video::IImage *baseimg = NULL;
	
	// If a base image was found, copy it to baseimg
	if(base_image_id != 0)
	{
		JMutexAutoLock lock(m_atlaspointer_cache_mutex);

		SourceAtlasPointer ap = m_atlaspointer_cache[base_image_id];

		video::IImage *image = ap.atlas_img;
		
		if(image == NULL)
		{
			infostream<<"getTextureIdDirect(): WARNING: NULL image in "
					<<"cache: \""<<base_image_name<<"\""
					<<std::endl;
		}
		else
		{
			core::dimension2d<u32> dim = ap.intsize;

			baseimg = driver->createImage(video::ECF_A8R8G8B8, dim);

			core::position2d<s32> pos_to(0,0);
			core::position2d<s32> pos_from = ap.intpos;
			
			image->copyTo(
					baseimg, // target
					v2s32(0,0), // position in target
					core::rect<s32>(pos_from, dim) // from
			);

			/*infostream<<"getTextureIdDirect(): Loaded \""
					<<base_image_name<<"\" from image cache"
					<<std::endl;*/
		}
	}
	
	/*
		Parse out the last part of the name of the image and act
		according to it
	*/

	std::string last_part_of_name = name.substr(last_separator_position+1);
	//infostream<<"last_part_of_name=\""<<last_part_of_name<<"\""<<std::endl;

	// Generate image according to part of name
	if(!generate_image(last_part_of_name, baseimg, m_device, &m_sourcecache))
	{
		errorstream<<"getTextureIdDirect(): "
				"failed to generate \""<<last_part_of_name<<"\""
				<<std::endl;
	}

	// If no resulting image, print a warning
	if(baseimg == NULL)
	{
		errorstream<<"getTextureIdDirect(): baseimg is NULL (attempted to"
				" create texture \""<<name<<"\""<<std::endl;
	}
	
	if(baseimg != NULL)
	{
		// Create texture from resulting image
		t = driver->addTexture(name.c_str(), baseimg);
	}
	
	/*
		Add texture to caches (add NULL textures too)
	*/

	JMutexAutoLock lock(m_atlaspointer_cache_mutex);
	
	u32 id = m_atlaspointer_cache.size();
	AtlasPointer ap(id);
	ap.atlas = t;
	ap.pos = v2f(0,0);
	ap.size = v2f(1,1);
	ap.tiled = 0;
	core::dimension2d<u32> baseimg_dim(0,0);
	if(baseimg)
		baseimg_dim = baseimg->getDimension();
	SourceAtlasPointer nap(name, ap, baseimg, v2s32(0,0), baseimg_dim);
	m_atlaspointer_cache.push_back(nap);
	m_name_to_id.insert(name, id);

	/*infostream<<"getTextureIdDirect(): "
			<<"Returning id="<<id<<" for name \""<<name<<"\""<<std::endl;*/
	
	return id;
}
示例#11
0
video::IImage* generate_image_from_scratch(std::string name,
		IrrlichtDevice *device, SourceImageCache *sourcecache)
{
	/*infostream<<"generate_image_from_scratch(): "
			"\""<<name<<"\""<<std::endl;*/
	
	video::IVideoDriver* driver = device->getVideoDriver();
	assert(driver);

	/*
		Get the base image
	*/

	video::IImage *baseimg = NULL;

	char separator = '^';

	// Find last meta separator in name
	s32 last_separator_position = name.find_last_of(separator);
	//if(last_separator_position == std::npos)
	//	last_separator_position = -1;

	/*infostream<<"generate_image_from_scratch(): "
			<<"last_separator_position="<<last_separator_position
			<<std::endl;*/

	/*
		If separator was found, construct the base name and make the
		base image using a recursive call
	*/
	std::string base_image_name;
	if(last_separator_position != -1)
	{
		// Construct base name
		base_image_name = name.substr(0, last_separator_position);
		/*infostream<<"generate_image_from_scratch(): Calling itself recursively"
				" to get base image of \""<<name<<"\" = \""
                <<base_image_name<<"\""<<std::endl;*/
		baseimg = generate_image_from_scratch(base_image_name, device,
				sourcecache);
	}
	
	/*
		Parse out the last part of the name of the image and act
		according to it
	*/

	std::string last_part_of_name = name.substr(last_separator_position+1);
	//infostream<<"last_part_of_name=\""<<last_part_of_name<<"\""<<std::endl;
	
	// Generate image according to part of name
	if(!generate_image(last_part_of_name, baseimg, device, sourcecache))
	{
		errorstream<<"generate_image_from_scratch(): "
				"failed to generate \""<<last_part_of_name<<"\""
				<<std::endl;
		return NULL;
	}
	
	return baseimg;
}
示例#12
0
文件: main.c 项目: Vild/ImageToMap-X
static void button_click(gpointer data)
{
  if((size_t)data == ITEM_SIGNAL_OPEN)
    {
      GtkWidget * dialog;
      dialog = gtk_file_chooser_dialog_new("Open file",
					   GTK_WINDOW(window),
					   GTK_FILE_CHOOSER_ACTION_OPEN,
					   _("_Cancel"), GTK_RESPONSE_CANCEL,
					   _("_Open"), GTK_RESPONSE_ACCEPT,
					   NULL);
      
      if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
	{
	  char * file = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
	  
	  if(srecmpend(".dat", file) == 0)
	    {
	      add_buffer();
	      image_load_map(file);
	    }
	  else if(srecmpend(".bmp", file) == 0 || srecmpend(".png", file) == 0 || srecmpend(".jpg", file) == 0 || srecmpend(".jpeg", file) == 0 || srecmpend(".gif", file) == 0)
	    {
	      GError * err = NULL;
	      add_buffer();
	      if(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(FSD_checkbox)))
		generate_image_dithered(mdata[current_buffer], 128, 128,gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(YUV_checkbox)),  file, colors, &err);
	      else
		generate_image(mdata[current_buffer], 128, 128, gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(YUV_checkbox)), file, colors, &err);
	      if(err != NULL)
		{
		  information("Error while loading image file!");
		  printf("%s\n", err->message);
		  g_error_free(err);
		}
	      set_image();
	    }
	  else if(srecmpend(".imtm", file) == 0)
	    {
	      add_buffer();
	      load_raw_map(file, mdata[current_buffer]);
	      set_image();
	    }
	  else
	    information("File format not supported!");
	}
      gtk_widget_destroy(dialog);
    }
  if((size_t)data == ITEM_SIGNAL_OPEN_GRID_IMAGE)
    {
      GtkWidget * dialog;
      dialog = gtk_file_chooser_dialog_new("Open file",
					   GTK_WINDOW(window),
					   GTK_FILE_CHOOSER_ACTION_OPEN,
					   _("_Cancel"), GTK_RESPONSE_CANCEL,
					   _("_Open"), GTK_RESPONSE_ACCEPT,
					   NULL);
      
      if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
	{
	  char * file = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
	  
	  if(srecmpend(".bmp", file) == 0 || srecmpend(".png", file) == 0 || srecmpend(".jpg", file) == 0 || srecmpend(".jpeg", file) == 0 || srecmpend(".gif", file) == 0)
	    {
	      GError * err = NULL;
	      int width = 1, height = 1;
	      int i, j;
	      int pi, pj;

	      {
		GtkWidget * dialog = gtk_dialog_new_with_buttons("Split Image",
								 GTK_WINDOW(window),
								 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
								 _("_OK"),
								 GTK_RESPONSE_ACCEPT, NULL);

		GtkWidget * content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
		GtkWidget * hbox;
		GtkWidget * label;

#ifdef GTK2
		hbox = gtk_hbox_new(FALSE, 0);
#else
		hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
#endif
		label = gtk_label_new("width");
		GtkWidget * width_entry = gtk_entry_new();
		gtk_entry_set_text(GTK_ENTRY(width_entry), "1");
		gtk_container_add(GTK_CONTAINER(hbox), width_entry);
		gtk_container_add(GTK_CONTAINER(hbox), label);
		gtk_container_add(GTK_CONTAINER(content_area), hbox);

#ifdef GTK2
		hbox = gtk_hbox_new(FALSE, 0);
#else
		hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
#endif
		label = gtk_label_new("height");
		GtkWidget * height_entry = gtk_entry_new();
		gtk_entry_set_text(GTK_ENTRY(height_entry), "1");
		gtk_container_add(GTK_CONTAINER(hbox), height_entry);
		gtk_container_add(GTK_CONTAINER(hbox), label);
		gtk_container_add(GTK_CONTAINER(content_area), hbox);

		gtk_widget_show_all(dialog);

		if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
		  {
		    width = atoi((char *)gtk_entry_get_text(GTK_ENTRY(width_entry)));
		    height = atoi((char *)gtk_entry_get_text(GTK_ENTRY(height_entry)));
		  }
		gtk_widget_destroy(dialog);
	      }
	      unsigned char tmp_buffer[width * height * 128 * 128];

	      if(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(FSD_checkbox)))
		generate_image_dithered(tmp_buffer, width * 128, height * 128, gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(YUV_checkbox)), file, colors, &err);
	      else
		generate_image(tmp_buffer, width * 128, height * 128, gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(YUV_checkbox)), file, colors, &err);
	      if(err != NULL)
		{
		  information("Error while loading image file!");
		  printf("%s\n", err->message);
		  g_error_free(err);
		}

	      for(i = 0; i < width; i++)
		for(j = 0; j < height; j++)
		  {
		    add_buffer();

		    for(pi = 0; pi < 128; pi++)
		      for(pj = 0; pj < 128; pj++)
			{
			  int buffer_i, buffer_j;

			  buffer_i = i * 128 + pi;
			  buffer_j = j * 128 + pj;

			  mdata[current_buffer][pi + pj * 128] =
			    tmp_buffer[buffer_i + (width * 128) * buffer_j];
			}
		  }

	      set_image();
	    }
	  else
	    information("File format not supported!");
	}
      gtk_widget_destroy(dialog);
    }
  else if((size_t)data == ITEM_SIGNAL_SAVE)
    {
      if(mdata[current_buffer] == NULL)
	return;
      
      GtkWidget * dialog;
      
      dialog = gtk_file_chooser_dialog_new ("Save Map",
					    GTK_WINDOW(window),
					    GTK_FILE_CHOOSER_ACTION_SAVE,
					    _("_Cancel"), GTK_RESPONSE_CANCEL,
					    _("_Save"), GTK_RESPONSE_ACCEPT,
					    NULL);
      
      gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE);
      gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER (dialog), "map_0.dat");
      
      if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
	{
	  char * file = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
	  printf("%s\n", file);
	  if(srecmpend(".dat", file) == 0)
	    {
	      save_map(file);
	      sprintf(last_file, "%s", file);
	    }
	}
      gtk_widget_destroy(dialog);
      printf("bracket cleared\n");
    }
  else if((size_t)data == ITEM_SIGNAL_SAVE_INCREMENT)
    {
      int i = 0;
      char * tmp = last_file;
      char * basename_s, * dirname_s;
      if(mdata[current_buffer] == NULL)
	return;

      basename_s = custom_basename(tmp);
      dirname_s = last_file;
      if(basename_s != NULL)
	{
	  tmp = basename_s;

	  if(strncmp("map_", tmp, 4) == 0)
	    {
	      tmp += 4;
	      i = strtol(tmp, &tmp, 10) + 1;

	      if(strcmp(".dat", tmp) == 0)
		{
#ifdef OS_LINUX
		  sprintf(last_file, "%s/map_%i.dat", dirname_s, i);
#else
		  sprintf(last_file, "%s\\map_%i.dat", dirname_s, i);
#endif

		  save_map(last_file);

		  /* save_map(last_file); */
		}
	    }
	}
    }
  else if((size_t)data == ITEM_SIGNAL_SAVE_ALL)
    {
      int old_current_buffer = current_buffer;
      GtkWidget * dialog;

      int i = 0;
      char * tmp;
      char * basename_s, * dirname_s;

      /* Gets first file name */
      dialog = gtk_file_chooser_dialog_new ("Save Map",
					    GTK_WINDOW(window),
					    GTK_FILE_CHOOSER_ACTION_SAVE,
					    _("_Cancel"), GTK_RESPONSE_CANCEL,
					    _("_Save"), GTK_RESPONSE_ACCEPT,
					    NULL);

      gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE);
      gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER (dialog), "map_0.dat");

      if(gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_ACCEPT) {
	gtk_widget_destroy(dialog);
	return;
      }

      char * file = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
      if(srecmpend(".dat", file) != 0) {
	gtk_widget_destroy(dialog);
	return;
      }
      sprintf(last_file, "%s", file);
      gtk_widget_destroy(dialog);

      /* Gets the directory and the file name */

      basename_s = custom_basename(last_file);
      dirname_s = malloc(strlen(last_file)+8); /* 8 is a magic number! Naa jk, it is just to make sure we don't overflow */
      if (dirname_s == NULL)
	return;
      strcpy(dirname_s, last_file);
      memset(dirname_s+(strlen(dirname_s)-strlen(basename_s)), strlen(basename_s), '\0');

      if(basename_s == NULL)
	return;

      tmp = basename_s;

      /* Gets the number in the file name, 10 for 'map_10.dat' */
      if(strncmp("map_", tmp, 4) != 0)
	return;

      tmp += 4;
      i = strtol(tmp, &tmp, 10);

      /* Saves all the buffers */
      for (current_buffer = 0; current_buffer < BUFFER_COUNT; current_buffer++) {
	if(mdata[current_buffer] == NULL)
	  break;
#ifdef OS_LINUX
	sprintf(last_file, "%s/map_%i.dat", dirname_s, i);
#else
	sprintf(last_file, "%s\\map_%i.dat", dirname_s, i);
#endif
	save_map(last_file);
	i++;
      }
      /* Restores the selection to the right buffer and frees the allocated memory */
      current_buffer = old_current_buffer;
      free(dirname_s);
    }
  else if((size_t)data == ITEM_SIGNAL_EXPORT_IMAGE)
    {
      if(mdata[current_buffer] == NULL)
	return;
      
      GtkWidget * dialog;
      
      dialog = gtk_file_chooser_dialog_new ("Export Image of Map",
					    GTK_WINDOW(window),
					    GTK_FILE_CHOOSER_ACTION_SAVE,
					    _("_Cancel"), GTK_RESPONSE_CANCEL,
					    _("_Save"), GTK_RESPONSE_ACCEPT,
					    NULL);
      
      gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE);
      gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER (dialog), "map.png");
      
      if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
	{
	  char * file = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
	  printf("%s\n", file);
	  
	  unsigned char * data = malloc(128 * 128 * 3);
	  int i;
	  for(i = 0; i < 128 * 128; i++)
	    {
	      if(mdata[current_buffer][i] > 3)
		{
		  data[i * 3] = colors[mdata[current_buffer][i]].r;
		  data[i * 3 + 1] = colors[mdata[current_buffer][i]].g;
		  data[i * 3 + 2] = colors[mdata[current_buffer][i]].b;
		}
	      else
		{
		  int x = i % 128, y = i / 128;
		  x /= 4;
		  y /= 4;
		  data[i * 3] = ((x + (y % 2)) % 2) ? 0xFF : 0xAA;
		  data[i * 3 + 1] = ((x + (y % 2)) % 2) ? 0xFF : 0xAA;
		  data[i * 3 + 2] = ((x + (y % 2)) % 2) ? 0xFF : 0xAA;
		}
	    }
	  
	  GdkPixbuf * spixbuf = image_from_data(data, 0);
	  free(data);
	  
	  GError * err = NULL;
	  
	  gdk_pixbuf_save(spixbuf, file, "png", &err, "compression", "9", NULL);
	  if (err != NULL)
	    {
	      /* Report error to user, and free error */
	      printf("Error while saving: %s\n", err->message);
	      g_error_free(err);
	    }
	  
	  g_object_unref(spixbuf);
	}
      gtk_widget_destroy(dialog);
    }
  else if((size_t)data == ITEM_SIGNAL_SAVE_RM)
    {
      if(mdata == NULL)
	return;
      
      GtkWidget * dialog;
      
      dialog = gtk_file_chooser_dialog_new("Save Map",
					   GTK_WINDOW(window),
					   GTK_FILE_CHOOSER_ACTION_SAVE,
					   _("_Cancel"), GTK_RESPONSE_CANCEL,
					   _("_Save"), GTK_RESPONSE_ACCEPT,
					   NULL);
      
      gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER (dialog), TRUE);
      gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER (dialog), "map.imtm");
      
      if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
	{
	  char * file = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
	  printf("%s\n", file);
	  save_raw_map(file, mdata[current_buffer]);
	}
      gtk_widget_destroy(dialog);
    }
  else if((size_t)data == ITEM_SIGNAL_GENERATE_PALETTE)
    {
      add_buffer();
      generate_palette(mdata[current_buffer]);
      set_image();
    }
  else if((size_t)data == ITEM_SIGNAL_GENERATE_RANDOM_NOISE)
    {
      add_buffer();
      generate_random_noise(mdata[current_buffer]);
      set_image();
    }
  else if((size_t)data == ITEM_SIGNAL_GENERATE_MANDELBROT)
    {
      add_buffer();
      generate_mandelbrot(mdata[current_buffer]);
      set_image();
    }
  else if((size_t)data == ITEM_SIGNAL_GENERATE_JULIA)
    {
      add_buffer();
      generate_julia(mdata[current_buffer], 0.5, 0.5);
      set_image();
    }
  else if((size_t)data == ITEM_SIGNAL_GENERATE_FROM_CLIPBOARD)
    {
      GtkClipboard * clipboard;
      clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);

      gtk_clipboard_request_image(clipboard, clipboard_callback, NULL);
    }
  else if((size_t)data == ITEM_SIGNAL_WORLD_RENDER_ITEM)
    {
      GtkWidget * dialog = gtk_dialog_new_with_buttons("Render World Map",
						       GTK_WINDOW(window),
						       GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
						       _("_OK"),
						       GTK_RESPONSE_ACCEPT,
						       _("_Cancel"),
						       GTK_RESPONSE_REJECT, NULL);

      GtkWidget * content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
      GtkWidget * scale_entry = gtk_entry_new();
      gtk_entry_set_text(GTK_ENTRY(scale_entry), "3");
      gtk_container_add(GTK_CONTAINER(content_area), scale_entry);

      GtkWidget * xpos_entry = gtk_entry_new();
      gtk_entry_set_text(GTK_ENTRY(xpos_entry), "0");
      gtk_container_add(GTK_CONTAINER(content_area), xpos_entry);

      GtkWidget * zpos_entry = gtk_entry_new();
      gtk_entry_set_text(GTK_ENTRY(zpos_entry), "0");
      gtk_container_add(GTK_CONTAINER(content_area), zpos_entry);

      GtkWidget * directory_entry = gtk_entry_new();
      gtk_entry_set_text(GTK_ENTRY(directory_entry), MINECRAFT_PATH);
      gtk_container_add(GTK_CONTAINER(content_area), directory_entry);

      gtk_widget_show_all(dialog);

      if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
	{
	  int scale = atoi((char *)gtk_entry_get_text(GTK_ENTRY(scale_entry)));
	  char * path = (char *)gtk_entry_get_text(GTK_ENTRY(directory_entry));
	  int x = atoi((char *)gtk_entry_get_text(GTK_ENTRY(xpos_entry)));
	  int z = atoi((char *)gtk_entry_get_text(GTK_ENTRY(zpos_entry)));
	  int rs = pow(2, scale) * 128;
	  block_info_t * blocks = read_region_files(path, x - (rs / 2), z - (rs / 2),
						    rs, rs);
	  add_buffer();
	  render_map(blocks, mdata[current_buffer], scale);
	  free(blocks);

	  mdata_info[current_buffer].scale = scale;
	  mdata_info[current_buffer].xpos = x;
	  mdata_info[current_buffer].zpos = z;
	  mdata_info[current_buffer].dimension = 0;
	  set_image();
	}
      gtk_widget_destroy(dialog);
    }
  else if((size_t)data == ITEM_SIGNAL_CLEAN)
    {
      while(mdata[1] != NULL)
	{
	  remove_buffer(0);
	}
      /* set_image(); */
    }
  else if((size_t)data == ITEM_SIGNAL_QUIT)
    {
      kill_window(NULL, NULL, NULL);
    }
  else
    printf("Unhandeled button press: %i\n", (int)(size_t)data);
}
示例#13
0
        void Planet::load(std::string pname,double pRadius, int px, int py, int pAtmosphereWidth, int pshinex, int pshiney, Limits pL1, Limits pL2, Limits pL3, DescA pAtmosphere, int minx, int maxx, int miny, int maxy, double **pdata, int pass) {

                //limit1=new Limits;
                //limit2=new Limits;
                //limit3=new Limits;
                //int ar=0;

                //describe();


                shiney=pshiney;
                shinex=pshinex;
                shinexm1=-1000;
                shineym1=-1234114;

                limit1=pL1;
                //std::cout <<limit1.limit;
                limit2=pL2;
                limit3=pL3;
                Atmosphere=pAtmosphere;

                radius=pRadius;
                smaxx=maxx;
                sminx=minx;
                smaxy=maxy;
                sminy=miny;
                name= pname;
                AtmosphereWidth=pAtmosphereWidth;

                if(pass==1){

                    for(int i=0; i<radius*2; i++){
                        for(int j=0; j<radius*2; j++){

                            data[i][j]=pdata[i][j];

                        }

                    }

                }



                if(pass!=1){
                //image. ///Was i going to do something here?
                int Octaves=5;


                data=PerlinNoise_Mem(xyoffset*xyoffsetmul, xyoffset*xyoffsetmul, radius*2 , radius*2 , Octaves, 2, 50);


                ///Parse data.
                parse_data(minx, maxx, miny, maxy);

                xyoffset++;
                image.create_surface(radius*2, radius*2);
                image.Transparency=1;

                generate_image();
                }




        }