Display of a gray Image on 8 bit screen
- From: Christian Orsatti <orsatti istar fr>
- To: gtk-list gnome org
- Subject: Display of a gray Image on 8 bit screen
- Date: Wed, 06 Sep 2000 16:16:35 +0200
HI,
I am trying for 2 days now to display a gray level image
on an 8 bits screen with all its gray levels (ie 256)
I try several methods but none work and all get me at the
same point. A display with only 5 gray levels.
The only way to have something correct is to use dithering
but I don't want that. I need to see the pixel with it real value.
How can I do that ???
Here is the simplest code I came to but it still not working
properly and giving me (when I click on the window) only
5 gray levels.
Any help is welcome !!!!!!!
#include <gdk/gdk.h>
#include <gdk/gdkrgb.h>
#include <gtk/gtk.h>
#include <malloc.h>
#include <iostream.h>
#include <string.h>
#define LARGEUR (256)
#define HAUTEUR (256)
guchar *buf = (guchar*)NULL;
GdkWindow *Fenetre = (GdkWindow*)NULL;
void TraitementButton(GdkEventButton* ev);
int main(int argc, char *argv[)
{
GdkWindowAttr attr;
gdk_init(&argc, &argv);
gdk_rgb_init();
// Get gray scale Visual
GdkVisual *gs = gdk_visual_get_best_with_both(8,
GDK_VISUAL_GRAYSCALE);
if (gs == NULL) {
cerr << "Error visual not found\n";
return 1;
}
// Get a new colormap
GdkColormap *cm = gdk_colormap_new(gs, TRUE);
if (cm == NULL) {
cerr << "Error colormap not created\n";
return 1;
}
// Set colors of the colormap
GdkColor *colors = (GdkColor*)malloc(256 * sizeof(GdkColor));
for (int i=0; i<256; i++) {
colors[i].red = i;
colors[i].green = colors[i].blue = i;
if (!gdk_color_alloc(cm, &colors[i])) {
cerr << "couleur " << i << " failed\n";
}
else {
cerr << i << " -> " << colors[i].pixel << endl;
}
}
// Window creation
attr.event_mask = GDK_BUTTON_PRESS_MASK;
attr.width = LARGEUR;
attr.height = HAUTEUR;
attr.wclass = GDK_INPUT_OUTPUT;
attr.window_type = GDK_WINDOW_TOPLEVEL;
attr.visual = gs;
attr.colormap = cm;
Fenetre = gdk_window_new(NULL, &attr, 0);
// Buffer
buf = (guchar*)malloc(256*256*sizeof(guchar));
for(int i = 0; i < 256; i++) memset(&(buf[256*i]), i, 256);
// Display window
gdk_window_show(Fenetre);
// Event Loop
while(1) {
if (gdk_events_pending()) {
GdkEvent *ev = gdk_event_get();
if (ev) {
switch (ev->type) {
case GDK_BUTTON_PRESS:
TraitementButton((GdkEventButton*)ev);
default:
cerr << ev->type << endl;
}
gdk_event_free(ev);
}
}
}
}
void TraitementButton(GdkEventButton* ev)
{
cerr << "Button pressed\n";
// Draw imagw
gdk_draw_gray_image(Fenetre,
gdk_gc_new(Fenetre),
0,0, LARGEUR, HAUTEUR,
GDK_RGB_DITHER_NONE,
buf, 256);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]