Beispiel #1
0
int G_read_colors(const char *name, const char *mapset, struct Colors *colors)
{
    int fp;
    char buf[GNAME_MAX];
    char *err;
    char xname[GNAME_MAX];
    struct Range range;
    struct FPRange drange;
    CELL min, max;
    DCELL dmin, dmax;

    fp = G_raster_map_is_fp(name, mapset);
    G_init_colors(colors);

    strcpy(xname, name);
    mapset = G_find_cell(xname, mapset);
    name = xname;

    if (fp)
	G_mark_colors_as_fp(colors);

    /* first look for secondary color table in current mapset */
    sprintf(buf, "colr2/%s", mapset);
    if (read_colors(buf, name, G_mapset(), colors) >= 0)
	return 1;

    /* now look for the regular color table */
    switch (read_colors("colr", name, mapset, colors)) {
    case -2:
	if (!fp) {
	    if (G_read_range(name, mapset, &range) >= 0) {
		G_get_range_min_max(&range, &min, &max);
		if (!G_is_c_null_value(&min) && !G_is_c_null_value(&max))
		    G_make_rainbow_colors(colors, min, max);
		return 0;
	    }
	}
	else {
	    if (G_read_fp_range(name, mapset, &drange) >= 0) {
		G_get_fp_range_min_max(&drange, &dmin, &dmax);
		if (!G_is_d_null_value(&dmin) && !G_is_d_null_value(&dmax))
		    G_make_rainbow_fp_colors(colors, dmin, dmax);
		return 0;
	    }
	}
	err = "missing";
	break;
    case -1:
	err = "invalid";
	break;
    default:
	return 1;
    }

    G_warning(_("color support for [%s] in mapset [%s] %s"), name, mapset,
	      err);
    return -1;
}
Beispiel #2
0
// ----------------------------------------------------------------------------
//
ScenePixelAnimator* VenueReader::read( TiXmlElement* self, ScenePixelAnimator* animation )
{
    animation = new ScenePixelAnimator();

    animation->m_uid = (UID)read_dword_attribute( self, "uid" );

    animation->m_name = read_text_element( self, "name" );
    animation->m_description = read_text_element( self, "description" );
    animation->m_effect = (PixelEffect)read_unsigned_attribute( self, "pixel_effect", 1 );
    animation->m_generations = read_unsigned_attribute( self, "generations", 1 );
    animation->m_num_pixels = read_unsigned_attribute( self, "pixels", 1 );
    animation->m_increment = read_unsigned_attribute( self, "increment", 1 );
    animation->m_color_fade = read_bool_attribute( self, "fade", 1 );
    animation->m_combine_fixtures = read_bool_attribute( self, "combine", 1 );
    animation->m_empty_color = read_rgbw_attribute( self, "pixel_off_color" );

    TiXmlElement* signal_element = self->FirstChildElement( "signal" );
    if ( signal_element ) {
        AnimationSignal* signal = read( signal_element, (AnimationSignal*)NULL );
        animation->m_signal = *signal;
        delete signal;
    }

    read_uids( self, "pfuids", animation->m_actors );

    read_colors( self, "custom_colors", animation->m_custom_colors );

    return animation;
}
Beispiel #3
0
// ----------------------------------------------------------------------------
//
SceneColorFader* VenueReader::read( TiXmlElement* self, SceneColorFader* animation )
{
    animation = new SceneColorFader();

    animation->m_uid = (UID)read_dword_attribute( self, "uid" );
    animation->m_fader_effect = (FaderEffect)read_unsigned_attribute( self, "fader_effect", FaderEffect::FADER_EFFECT_ALL );
    animation->m_strobe_neg_color = read_rgbw_attribute( self, "strobe_neg_color" );
    animation->m_strobe_pos_ms = read_unsigned_attribute( self, "strobe_pos_ms" );
    animation->m_strobe_neg_ms = read_unsigned_attribute( self, "strobe_neg_ms"  );
    animation->m_strobe_flashes = read_unsigned_attribute(self, "strobe_flashes", 1 );

    animation->m_name = read_text_element( self, "name" );
    animation->m_description = read_text_element( self, "description" );

    TiXmlElement* signal_element = self->FirstChildElement( "signal" );
    if ( signal_element ) {
        AnimationSignal* signal = read( signal_element, (AnimationSignal*)NULL );
        animation->m_signal = *signal;
        delete signal;
    }

    read_uids( self, "pfuids", animation->m_actors );

    read_colors( self, "custom_colors", animation->m_custom_colors );

    return animation;
}
Beispiel #4
0
int
Rast3d_read_colors(const char *name, const char *mapset, struct Colors *colors)
 /* adapted from Rast_read_colors */
{
    const char *err;
    struct FPRange drange;
    DCELL dmin, dmax;

    Rast_init_colors(colors);

    Rast_mark_colors_as_fp(colors);

    switch (read_colors(name, mapset, colors)) {
    case -2:
	if (Rast3d_read_range(name, mapset, &drange) >= 0) {
	    Rast_get_fp_range_min_max(&drange, &dmin, &dmax);
	    if (!Rast_is_d_null_value(&dmin) && !Rast_is_d_null_value(&dmax))
		Rast_make_rainbow_fp_colors(colors, dmin, dmax);
	    return 0;
	}
	err = "missing";
	break;
    case -1:
	err = "invalid";
	break;
    default:
	return 1;
    }

    G_warning("color support for [%s] in mapset [%s] %s", name, mapset, err);
    return -1;
}
Beispiel #5
0
/**
 * Each substructure in the M2 has a variable size except the header.
 * Memory for each substructure must therefore be allocated at reading depending on header values.
 * @param lk_m2_file The file to read data.
 * @param ptr Pointer to a M2/WotLK structure.
 */
int read_model(FILE *lk_m2_file, LKM2 *ptr) {
	//Header
	fseek(lk_m2_file, 0, SEEK_SET);
	fread(&ptr->header, sizeof(LKModelHeader), 1, lk_m2_file);
	char real_id[5];
	real_id[0] = ptr->header.id[0];
	real_id[1] = ptr->header.id[1];
	real_id[2] = ptr->header.id[2];
	real_id[3] = ptr->header.id[3];
	real_id[4] = '\0';
	if (strcmp("MD20", real_id)) {
		fprintf(stderr, "This is not an M2 file.\n");
		exit(EXIT_FAILURE);
	}
	if (ptr->header.version != 264) {
		fprintf(stderr, "Incorrect model version (%d).\n", ptr->header.version);
		fprintf(stderr, "A WotLK model (264) is expected.\n");
		exit(EXIT_FAILURE);
	}

	//Name
	ptr->filename = malloc(ptr->header.nameLength);
	fseek(lk_m2_file, ptr->header.nameOfs, SEEK_SET);
	fread(ptr->filename, sizeof(char), ptr->header.nameLength, lk_m2_file);

	//Global Sequences
	ptr->globalsequences = malloc(
			ptr->header.nGlobalSequences * sizeof(unsigned int));
	if (ptr->header.nGlobalSequences > 0) {
		fseek(lk_m2_file, ptr->header.ofsGlobalSequences, SEEK_SET);
		fread(ptr->globalsequences, sizeof(unsigned int),
				ptr->header.nGlobalSequences, lk_m2_file);
	}

	//Animations
	ptr->animations = malloc(
			ptr->header.nAnimations * sizeof(LKModelAnimation));
	fseek(lk_m2_file, ptr->header.ofsAnimations, SEEK_SET);
	fread(ptr->animations, sizeof(LKModelAnimation), ptr->header.nAnimations,
			lk_m2_file);

	//Animation Files
	FILE **anim_files;
	anim_files = malloc(ptr->header.nAnimations * sizeof(FILE *));
	int i;
	for (i = 0; i < ptr->header.nAnimations; i++) {
		if (((ptr->animations[i].flags & 0x40) == 0)
				&& ((ptr->animations[i].flags & 0x130) == 0)) { //If anim[i] is not an alias and is not stored in the model
			printf("\t%s\n",
					animfile_name(model_name, ptr->animations[i].animID,
							ptr->animations[i].subAnimID));
			anim_files[i] = (FILE *) fcaseopen(
					animfile_name(model_name, ptr->animations[i].animID,
							ptr->animations[i].subAnimID), "r+b");
			if (anim_files[i] == NULL) {
				fprintf(stderr, KRED "[Error] " RESET
				"[Anim #%d, ID%d, Flags %d] %s file not found.\n", i,
						ptr->animations[i].animID, ptr->animations[i].flags,
						animfile_name(model_name, ptr->animations[i].animID,
								ptr->animations[i].subAnimID));
				fprintf(stderr, "[aliasNext %d]\n", ptr->animations[i].Index);
				exit(EXIT_FAILURE);
			}
		}
	}

	//Animations Lookup Table
	ptr->AnimLookup = malloc(ptr->header.nAnimationLookup * sizeof(short));
	fseek(lk_m2_file, ptr->header.ofsAnimationLookup, SEEK_SET);
	fread(ptr->AnimLookup, sizeof(short), ptr->header.nAnimationLookup,
			lk_m2_file);

	//Bones
	read_bones(lk_m2_file, ptr, anim_files);

	//Skeleton Bone Lookup
	ptr->keybonelookup = malloc(ptr->header.nKeyBoneLookup * sizeof(short));
	fseek(lk_m2_file, ptr->header.ofsKeyBoneLookup, SEEK_SET);
	fread(ptr->keybonelookup, sizeof(short), ptr->header.nKeyBoneLookup,
			lk_m2_file);

	//Vertices
	ptr->vertices = malloc(ptr->header.nVertices * sizeof(ModelVertex));
	fseek(lk_m2_file, ptr->header.ofsVertices, SEEK_SET);
	fread(ptr->vertices, sizeof(ModelVertex), ptr->header.nVertices,
			lk_m2_file);

	//Colors
	read_colors(lk_m2_file, ptr, anim_files);

	//Textures Definition
	if (ptr->header.nTextures > 0) {
		ptr->textures_def = malloc(
				ptr->header.nTextures * sizeof(ModelTextureDef));
		fseek(lk_m2_file, ptr->header.ofsTextures, SEEK_SET);
		fread(ptr->textures_def, sizeof(ModelTextureDef), ptr->header.nTextures,
				lk_m2_file);
		//textures names
		ptr->texture_names = malloc(ptr->header.nTextures * sizeof(char *));
		int i;
		for (i = 0; i < ptr->header.nTextures; i++) {
			if (ptr->textures_def[i].type == 0) { //Filename is referenced in the m2 only when the type is 0
				if (ptr->textures_def[i].nameLen >= 256) {
					fprintf(stderr,
							"nameLen too large : %d\nPlease report this issue.",
							ptr->textures_def[i].nameLen);
					return -1;
				}
				ptr->texture_names[i] = malloc(ptr->textures_def[i].nameLen);
				fseek(lk_m2_file, ptr->textures_def[i].nameOfs,
				SEEK_SET);
				fread(ptr->texture_names[i], sizeof(char),
						ptr->textures_def[i].nameLen, lk_m2_file);
			}
		}
	}

	//Transparency
	read_transparency(lk_m2_file, ptr, anim_files);

	//TexReplace
	ptr->TexReplace = malloc(ptr->header.nTexReplace * sizeof(short));
	fseek(lk_m2_file, ptr->header.ofsTexReplace, SEEK_SET);
	fread(ptr->TexReplace, sizeof(short), ptr->header.nTexReplace, lk_m2_file);

	//Render Flags
	ptr->renderflags = malloc(ptr->header.nRenderFlags * sizeof(int));
	fseek(lk_m2_file, ptr->header.ofsRenderFlags, SEEK_SET);
	fread(ptr->renderflags, sizeof(int), ptr->header.nRenderFlags, lk_m2_file);

	//Bone Lookup Table
	ptr->BoneLookupTable = malloc(ptr->header.nBoneLookupTable * sizeof(int16));
	fseek(lk_m2_file, ptr->header.ofsBoneLookupTable, SEEK_SET);
	fread(ptr->BoneLookupTable, sizeof(int16), ptr->header.nBoneLookupTable,
			lk_m2_file);

	//Texture Lookup Table
	ptr->TexLookupTable = malloc(ptr->header.nTexLookup * sizeof(short));
	fseek(lk_m2_file, ptr->header.ofsTexLookup, SEEK_SET);
	fread(ptr->TexLookupTable, sizeof(short), ptr->header.nTexLookup,
			lk_m2_file);

	//TexUnit
	ptr->TexUnit = malloc(ptr->header.nTexUnitLookup * sizeof(short));
	fseek(lk_m2_file, ptr->header.ofsTexUnitLookup, SEEK_SET);
	fread(ptr->TexUnit, sizeof(short), ptr->header.nTexUnitLookup, lk_m2_file);

	//TransLookup
	ptr->TransparencyLookup = malloc(
			ptr->header.nTransparencyLookup * sizeof(short));
	fseek(lk_m2_file, ptr->header.ofsTransparencyLookup, SEEK_SET);
	fread(ptr->TransparencyLookup, sizeof(short),
			ptr->header.nTransparencyLookup, lk_m2_file);

	//TexAnimLookup
	ptr->TexAnimLookup = malloc(ptr->header.nTexAnimLookup * sizeof(short));
	fseek(lk_m2_file, ptr->header.ofsTexAnimLookup, SEEK_SET);
	fread(ptr->TexAnimLookup, sizeof(short), ptr->header.nTexAnimLookup,
			lk_m2_file);

	//BoundingTriangles
	ptr->BoundingTriangles = malloc(
			ptr->header.nBoundingTriangles / 3 * sizeof(Triangle));
	fseek(lk_m2_file, ptr->header.ofsBoundingTriangles, SEEK_SET);
	fread(ptr->BoundingTriangles, sizeof(Triangle),
			ptr->header.nBoundingTriangles / 3, lk_m2_file);

	//BoundingVertices
	ptr->BoundingVertices = malloc(
			ptr->header.nBoundingVertices * sizeof(Vec3D));
	fseek(lk_m2_file, ptr->header.ofsBoundingVertices, SEEK_SET);
	fread(ptr->BoundingVertices, sizeof(Vec3D), ptr->header.nBoundingVertices,
			lk_m2_file);

	//BoundingNormals
	ptr->BoundingNormals = malloc(ptr->header.nBoundingNormals * sizeof(Vec3D));
	fseek(lk_m2_file, ptr->header.ofsBoundingNormals, SEEK_SET);
	fread(ptr->BoundingNormals, sizeof(Vec3D), ptr->header.nBoundingNormals,
			lk_m2_file);

	//Attachments
	read_attachments(lk_m2_file, ptr, anim_files);

	//Attachment Lookup Table
	ptr->AttachLookup = malloc(ptr->header.nAttachLookup * sizeof(short));
	fseek(lk_m2_file, ptr->header.ofsAttachLookup, SEEK_SET);
	fread(ptr->AttachLookup, sizeof(short), ptr->header.nAttachLookup,
			lk_m2_file);

	//Events
	read_events(lk_m2_file, ptr);

	//Lights
	read_lights(lk_m2_file, ptr, anim_files);

	//Cameras
	read_cameras(lk_m2_file, ptr, anim_files);

	//Cameras Lookup
	ptr->CameraLookup = malloc(ptr->header.nCameraLookup * sizeof(short));
	fseek(lk_m2_file, ptr->header.ofsCameraLookup, SEEK_SET);
	fread(ptr->CameraLookup, sizeof(short), ptr->header.nCameraLookup,
			lk_m2_file);

	//TexAnims
	read_texanims(lk_m2_file, ptr, anim_files);
	/*TODO
	 Ribbons;
	 Particles
	 */
	return 0;
}
Beispiel #6
0
int main (int argc, char **argv)
{
  gtk_init (&argc, &argv);

  read_config ();

  // Read options from command-line arguments.
  GError *error = NULL;
  GOptionContext *context;
  context = g_option_context_new (" - show X11 windows as colour mosaic");
  g_option_context_add_main_entries (context, entries, NULL);
  g_option_context_add_group (context, gtk_get_option_group (TRUE));
  if (!g_option_context_parse (context, &argc, &argv, &error)) {
    g_printerr ("option parsing failed: %s\n", error->message);
    exit (1);
  }
  g_option_context_free (context);

  if(options.format && !options.read_stdin) {
    g_printerr("You must provide option --read-stdin!");
    exit(1);
  }

#ifdef X11
  atoms_init ();
#endif

  if (already_opened ()) {
    g_printerr ("Another instance of xwinmosaic is opened.\n");
    exit (1);
  }

  if (options.read_stdin) {
    if(!options.format) {
      options.show_icons = FALSE;
      options.show_desktop = FALSE;
    }
    read_stdin ();
  } else {
#ifdef X11
    // Checks whether WM supports EWMH specifications.
    if (!wm_supports_ewmh ()) {
      GtkWidget *dialog = gtk_message_dialog_new
	(NULL,
	 GTK_DIALOG_MODAL,
	 GTK_MESSAGE_ERROR,
	 GTK_BUTTONS_CLOSE,
	 "Error: your WM does not support EWMH specifications.");

      gtk_dialog_run (GTK_DIALOG (dialog));
      g_signal_connect_swapped (dialog, "response",
				G_CALLBACK (gtk_main_quit), NULL);
      return 1;
    }

    active_window = (Window *) property (gdk_x11_get_default_root_xwindow (),
					 a_NET_ACTIVE_WINDOW,
					 XA_WINDOW,
					 NULL);
#endif
  }

  if (options.color_file)
    read_colors ();

#ifdef WIN32
  if (options.persistent) {
#ifdef DEBUG
      g_printerr ("Installing Alt-Tab hook");
#endif
      install_alt_tab_hook();
  }
#endif

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title (GTK_WINDOW (window), "XWinMosaic");

  GdkRectangle rect = current_monitor_size ();
  width = rect.width;
  height = rect.height;

  if (options.at_pointer) {
    gdk_display_get_pointer (gdk_display_get_default (), NULL, &options.center_x, &options.center_y, NULL);

    gint monitors = gdk_screen_get_n_monitors (gdk_screen_get_default ());
    if (monitors > 1) {
      guint xm = 0, ym = 0;
      gint current_monitor = gdk_screen_get_monitor_at_point (gdk_screen_get_default (),
							      options.center_x, options.center_y);
      for (int i = 0; i < current_monitor; i++) {
	GdkRectangle mon_rect;
	gdk_screen_get_monitor_geometry (gdk_screen_get_default (), i, &mon_rect);
	xm += mon_rect.width;
	ym += mon_rect.height;
      }
      if (xm && ym) {
	options.center_x %= xm;
	options.center_y %= ym;
      }
    }

    if (options.center_x < options.box_width/2)
      options.center_x = options.box_width/2 + 1;
    else if (options.center_x > width - options.box_width/2)
      options.center_x = width - options.box_width/2 - 1;
    if (options.center_y < options.box_height/2)
      options.center_y = options.box_height/2 + 1;
    else if (options.center_y > height - options.box_height/2)
      options.center_y = height - options.box_height/2 - 1;
  } else {
    options.center_x = width/2;
    options.center_y = height/2;
  }

  gtk_window_set_default_size (GTK_WINDOW (window), width, height);
  gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);
  gtk_window_set_decorated (GTK_WINDOW (window), 0);
  gtk_window_set_type_hint (GTK_WINDOW (window), GDK_WINDOW_TYPE_HINT_DIALOG);
  gtk_window_set_skip_taskbar_hint (GTK_WINDOW (window), 1);
  gtk_window_set_skip_pager_hint (GTK_WINDOW (window), 1);
/**/
  gtk_widget_add_events (GTK_WIDGET (window), GDK_FOCUS_CHANGE);
  g_signal_connect (G_OBJECT (window), "focus-out-event",
        	    G_CALLBACK (on_focus_change), NULL);
/**/
  layout = gtk_layout_new (NULL, NULL);
  gtk_container_add (GTK_CONTAINER (window), layout);

  if (options.screenshot) {
    gtk_window_fullscreen (GTK_WINDOW (window));

    GdkPixbuf *screenshot;
    GdkPixmap *background = NULL;
    GtkStyle *style = NULL;
    screenshot = get_screenshot ();

    gdk_pixbuf_render_pixmap_and_mask (screenshot, &background, NULL, 0);
    style = gtk_style_new ();
    style->bg_pixmap [0] = background;

    gtk_widget_set_style (window, style);
    gtk_widget_set_style (layout, style);
  }

  search = mosaic_search_box_new ();
  mosaic_box_set_font (MOSAIC_BOX (search), options.font);
  gtk_widget_set_can_focus (search, FALSE);
  GtkRequisition s_req;
  gtk_widget_size_request (search, &s_req);
  gtk_layout_put (GTK_LAYOUT (layout), search,
		  (width - s_req.width)/2, height - s_req.height - options.box_height);
  g_signal_connect (G_OBJECT (search), "changed",
		    G_CALLBACK (refilter), NULL);

  g_signal_connect (G_OBJECT (window), "key-press-event",
		    G_CALLBACK (on_key_press), NULL);
  g_signal_connect_swapped(G_OBJECT (window), "destroy",
        		   G_CALLBACK(gtk_main_quit), NULL);

  if (!options.screenshot) {
    window_shape_bitmap = (GdkDrawable *) gdk_pixmap_new (NULL, width, height, 1);
    draw_mask (window_shape_bitmap, 0);
    gtk_widget_shape_combine_mask (window, window_shape_bitmap, 0, 0);
  }

  gtk_widget_show_all (window);
  gtk_widget_hide (search);
  gtk_window_present (GTK_WINDOW (window));
  gtk_window_set_keep_above (GTK_WINDOW (window), TRUE);
  
  if (options.persistent)
    gtk_widget_hide (window);

  GdkWindow *gdk_window = gtk_widget_get_window (GTK_WIDGET (window));
#ifdef X11
  myown_window = GDK_WINDOW_XID (gdk_window);

  if (!options.read_stdin) {
    // Get PropertyNotify events from root window.
    XSelectInput (gdk_x11_get_default_xdisplay (),
		  gdk_x11_get_default_root_xwindow (),
		  PropertyChangeMask);
    gdk_window_add_filter (NULL, (GdkFilterFunc) event_filter, NULL);
  }
#endif
#ifdef WIN32
  myown_window = GDK_WINDOW_HWND (gdk_window);
#endif
  update_box_list ();
  draw_mosaic (GTK_LAYOUT (layout), boxes, wsize, 0,
	       options.box_width, options.box_height);

#ifdef X11
  // Window will be shown on all desktops (and so hidden in windows list)
  unsigned int desk = 0xFFFFFFFF; // -1
  XChangeProperty(gdk_x11_get_default_xdisplay (), myown_window, a_NET_WM_DESKTOP, XA_CARDINAL,
		  32, PropModeReplace, (unsigned char *)&desk, 1);
#endif

  gtk_main ();

#ifdef X11
  if (!options.read_stdin)
    XFree (wins);
#endif

  return 0;
}