00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <iostream>
00029 #include <fstream>
00030
00031 #include <gdk-pixbuf/gdk-pixbuf.h>
00032
00033 #include "xshmimg.h"
00034 #include "util.h"
00035
00036 #include "glbvars.h"
00037
00038 ShmImage2D::ShmImage2D(GtkWidget* area,
00039 int Width, int Height,
00040 int xorigin, int yorigin
00041 ){
00042 x0 = xorigin;
00043 y0 = yorigin;
00044 maxcol = 0;
00045 ZoomFac = 1;
00046 imgarea = area;
00047
00048 MkPalette();
00049
00050 gdk_pixbuf = NULL;
00051 gitem_image = NULL;
00052 gitem_red_line = NULL;
00053
00054
00055 red_line_points = gnome_canvas_points_new (2);
00056 red_line_points->coords[0] = x0;
00057 red_line_points->coords[2] = x0+Width;
00058 red_line_points->coords[1] = red_line_points->coords[3] = y0;
00059
00060 Resize(Width, Height);
00061 }
00062
00063 void ShmImage2D::Resize(int Width, int Height){
00064 XSM_DEBUG(DBG_L3, "ShmImage2D::Resize" << Width << "x" << Height );
00065 width = Width;
00066 height = Height;
00067
00068
00069 red_line_points->coords[2] = red_line_points->coords[0] + width;
00070 red_line_points->coords[1] = red_line_points->coords[3] = y0;
00071
00072
00073 GdkPixbuf *gdk_pixbufold=gdk_pixbuf;
00074
00075 gdk_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, width, height);
00076 bpp = gdk_pixbuf_get_bits_per_sample(gdk_pixbuf) * gdk_pixbuf_get_n_channels(gdk_pixbuf) / 8;
00077 rowstride = gdk_pixbuf_get_rowstride(gdk_pixbuf);
00078 pixels = gdk_pixbuf_get_pixels(gdk_pixbuf);
00079
00080 if (!gitem_image)
00081 gitem_image = gnome_canvas_item_new (gnome_canvas_root( GNOME_CANVAS(imgarea)),
00082 gnome_canvas_pixbuf_get_type(),
00083 "pixbuf", gdk_pixbuf,
00084 NULL);
00085 gnome_canvas_item_lower (gitem_image, 1);
00086 if (gdk_pixbufold)
00087 gdk_pixbuf_unref (gdk_pixbufold);
00088
00089 if (!gitem_red_line){
00090 gitem_red_line = gnome_canvas_item_new (gnome_canvas_root( GNOME_CANVAS(imgarea)),
00091 GNOME_TYPE_CANVAS_LINE,
00092 "points", red_line_points,
00093 "fill_color","red",
00094 "width_pixels",ZoomFac,
00095 NULL);
00096 }else{
00097 gnome_canvas_item_set (gitem_red_line,
00098 "points", red_line_points,
00099 "width_pixels",ZoomFac,
00100 NULL);
00101 }
00102
00103 XSM_DEBUG(DBG_L3, "ShmImage2D::Resize done" );
00104 }
00105
00106 ShmImage2D::~ShmImage2D(){
00107 gtk_object_destroy (GTK_OBJECT(gitem_image));
00108 gtk_object_destroy (GTK_OBJECT(gitem_red_line));
00109 gnome_canvas_points_free (red_line_points);
00110 gdk_pixbuf_unref (gdk_pixbuf);
00111 }
00112
00113
00114 void ShmImage2D::MkPalette(char *name){
00115
00116 unsigned long r, g, b, cval;
00117
00118 if (name){
00119 std::ifstream cpal;
00120 char pline[256];
00121 int nx,ny;
00122 cpal.open(name, std::ios::in);
00123 if(cpal.good()){
00124 cpal.getline(pline, 255);
00125 cpal.getline(pline, 255);
00126 cpal >> nx >> ny;
00127 cpal.getline(pline, 255);
00128 cpal.getline(pline, 255);
00129
00130 for(maxcol = MIN(nx, IMGMAXCOLORENTRYS), cval=0; cval<maxcol; ++cval){
00131 cpal >> r >> g >> b;
00132 if (WORDS_BIGENDIAN)
00133 ULColorTable[cval] = (r << 16) | (g << 8) | b ;
00134 else
00135 ULColorTable[cval] = (b << 16) | (g << 8) | r ;
00136 }
00137 return;
00138 }
00139 XSM_SHOW_ALERT(ERR_SORRY, ERR_PALFILEREAD, name, 1);
00140 }
00141
00142 for (maxcol=64, cval=0; cval<maxcol; ++cval){
00143 r = b = g = cval * 255 / maxcol;
00144 ULColorTable[cval] = (b << 16) | (g << 8) | r ;
00145 }
00146
00147
00148 if (WORDS_BIGENDIAN){
00149 ULColorTable[IMGMAXCOLORENTRYS ] = (255 << 16) | (0 << 8) | 0 ;
00150 ULColorTable[IMGMAXCOLORENTRYS+1] = (0 << 16) | (0 << 8) | 255 ;
00151 } else {
00152 ULColorTable[IMGMAXCOLORENTRYS ] = (0 << 16) | (0 << 8) | 255 ;
00153 ULColorTable[IMGMAXCOLORENTRYS+1] = (255 << 16) | (0 << 8) | 0 ;
00154 }
00155 }
00156
00157 void ShmImage2D::saveimage(gchar *name){
00158
00159
00160
00161 }
00162
00163 void ShmImage2D::ShowPic(int xs, int ys){
00164 gnome_canvas_item_set (gitem_image,
00165 "pixbuf", gdk_pixbuf,
00166 NULL);
00167
00168 red_line_points->coords[1] = red_line_points->coords[3] = y0;
00169 gnome_canvas_item_set (gitem_red_line, "points", red_line_points, NULL);
00170
00171 }
00172
00173 void ShmImage2D::ShowSubPic(int xs, int ys, int w, int h){
00174 xs*=ZoomFac; ys*=ZoomFac;
00175 w*=ZoomFac; h*=ZoomFac;
00176 if (xs >= width || ys >= height || w > width || h > height)
00177 return;
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188 if (h>ZoomFac){
00189 gnome_canvas_item_set (gitem_image,
00190 "pixbuf", gdk_pixbuf,
00191 NULL);
00192 }
00193
00194 red_line_points->coords[1] = red_line_points->coords[3] = ys+y0 + .5*ZoomFac;
00195 gnome_canvas_item_set (gitem_red_line,
00196 "points", red_line_points,
00197 "width_pixels", ZoomFac+1,
00198 NULL);
00199 }
00200
00201 void ShmImage2D::PutPixel(unsigned long x, unsigned long y, unsigned long val){
00202 ((U24*)(pixels + rowstride*y + bpp*x))->rgb = ULColorTable[val];
00203 }
00204
00205