- Timestamp:
- Jun 2, 2006, 9:38:14 PM (18 years ago)
- Location:
- trunk/gui/vizservers/nanovis
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/vizservers/nanovis/Makefile
r453 r455 15 15 NANOSCALESRC = ./nanoscale 16 16 17 LIB_NANOVIS = -ltcl8. 4-L/opt/render/lib -lGL -lglut -lglui -lGLEW -lCg -lCgGL -pthread -lstdc++17 LIB_NANOVIS = -ltcl8.3 -L/opt/render/lib -lGL -lglut -lglui -lGLEW -lCg -lCgGL -pthread -lstdc++ 18 18 LIB_CLIENT = -L/opt/render/lib -lGL -lglut -pthread -lstdc++ 19 INCLUDES = -I../ core -I/opt/render/include -I/autohome/u76/qiaow/Cg/usr/include19 INCLUDES = -I../../src2/core -I/opt/render/include -I/autohome/u76/qiaow/Cg/usr/include 20 20 CFLAG = -g -c $(INCLUDES) 21 21 … … 26 26 27 27 nanovis: $(OBJ_NANOVIS) 28 gcc -g -o nanovis $(OBJ_NANOVIS) $(LIB_NANOVIS) ../ core/*.o28 gcc -g -o nanovis $(OBJ_NANOVIS) $(LIB_NANOVIS) ../../src2/core/*.o 29 29 30 30 ColorGradient.o: Color.o $(TFSRC)/ColorGradient.cpp -
trunk/gui/vizservers/nanovis/PlaneRenderer.cpp
r432 r455 56 56 } 57 57 58 void 59 PlaneRenderer::remove_plane(int index) { 60 vector<Texture2D*>::iterator piter = plane.begin()+index; 61 vector<TransferFunction*>::iterator tfiter = tf.begin()+index; 62 63 plane.erase(piter); 64 tf.erase(tfiter); 65 66 n_planes--; 67 } 68 58 69 59 70 void PlaneRenderer::render(){ 60 if (n_planes == 0)71 if (n_planes == 0) 61 72 return; 62 73 … … 108 119 } 109 120 110 void PlaneRenderer::set_active_plane(int index) { active_plane = index; } 111 void PlaneRenderer::set_screen_size(int w, int h) { render_width = w; render_height = h;} 121 void 122 PlaneRenderer::set_active_plane(int index) { 123 active_plane = index; 124 } 112 125 126 void 127 PlaneRenderer::set_screen_size(int w, int h) { 128 render_width = w; 129 render_height = h; 130 } -
trunk/gui/vizservers/nanovis/PlaneRenderer.h
r432 r455 63 63 //we require a transfer function when a 64 64 //plane is added. 65 void remove_plane(int index); 65 66 void set_active_plane(int index); //set the active plane to be rendered 66 67 void set_screen_size(int w, int h); //change the rendering size -
trunk/gui/vizservers/nanovis/Volume.cpp
r449 r455 20 20 Volume::Volume(float x, float y, float z, 21 21 int w, int h, int d, float s, 22 int n, float* data ):22 int n, float* data, double v0, double v1): 23 23 width(w), 24 24 height(h), … … 26 26 size(s), 27 27 n_components(n), 28 vmin(v0), 29 vmax(v1), 28 30 enabled(true), 29 31 n_slice(256), // default value -
trunk/gui/vizservers/nanovis/Volume.h
r449 r455 46 46 47 47 Texture3D* tex; //OpenGL texture storing the volume 48 double vmin; //minimum (unscaled) value in data 49 double vmax; //maximum (unscaled) value in data 50 48 51 float specular; //specular lighting parameter 49 52 float diffuse; //diffuse lighting parameter … … 79 82 Volume(float x, float y, float z, 80 83 int width, int height, int depth, float size, 81 int n_component, float* data );84 int n_component, float* data, double vmin, double vmax); 82 85 ~Volume(); 83 86 … … 87 90 bool is_enabled(); 88 91 Vector3* get_location(); 92 93 double range_min() { return vmin; } 94 double range_max() { return vmax; } 89 95 90 96 void set_n_slice(int val); //set number of slices -
trunk/gui/vizservers/nanovis/VolumeRenderer.cpp
r452 r455 74 74 } 75 75 } 76 } 77 78 TransferFunction* 79 VolumeRenderer::get_volume_shading(Volume* _vol) 80 { 81 for (int i=0; i < volume.size(); i++) { 82 if (volume[i] == _vol) { 83 return tf[i]; 84 } 85 } 86 return NULL; 76 87 } 77 88 … … 891 902 892 903 //x 893 glColor3f(0. , 0., 0.5);894 895 int length = strlen(vol->label[0]);904 glColor3f(0.5, 0.5, 0.5); 905 906 int length = vol->label[0].size(); 896 907 glPushMatrix(); 897 908 898 glTranslatef(.5*vol->aspect_ratio_width, vol->aspect_ratio_height, -0. 2*vol->aspect_ratio_depth);909 glTranslatef(.5*vol->aspect_ratio_width, vol->aspect_ratio_height, -0.1*vol->aspect_ratio_depth); 899 910 glRotatef(180, 0, 0, 1); 900 911 glRotatef(90, 1, 0, 0); 901 912 902 glScalef(0.000 35, 0.00035, 0.00035);913 glScalef(0.0008, 0.0008, 0.0008); 903 914 for(int i=0; i<length; i++){ 904 glutStrokeCharacter(GLUT_STROKE_ROMAN, vol->label[0] [i]);915 glutStrokeCharacter(GLUT_STROKE_ROMAN, vol->label[0].c_str()[i]); 905 916 glTranslatef(0.04, 0., 0.); 906 917 } … … 908 919 909 920 //y 910 length = strlen(vol->label[1]);921 length = vol->label[1].size(); 911 922 glPushMatrix(); 912 glTranslatef(vol->aspect_ratio_width, 0.5*vol->aspect_ratio_height, -0. 2*vol->aspect_ratio_depth);923 glTranslatef(vol->aspect_ratio_width, 0.5*vol->aspect_ratio_height, -0.1*vol->aspect_ratio_depth); 913 924 glRotatef(90, 0, 1, 0); 914 925 glRotatef(90, 0, 0, 1); 915 926 916 glScalef(0.000 35, 0.00035, 0.00035);927 glScalef(0.0008, 0.0008, 0.0008); 917 928 for(int i=0; i<length; i++){ 918 glutStrokeCharacter(GLUT_STROKE_ROMAN, vol->label[1] [i]);929 glutStrokeCharacter(GLUT_STROKE_ROMAN, vol->label[1].c_str()[i]); 919 930 glTranslatef(0.04, 0., 0.); 920 931 } … … 923 934 924 935 //z 925 length = strlen(vol->label[2]);936 length = vol->label[2].size(); 926 937 glPushMatrix(); 927 938 glTranslatef(0., 1.*vol->aspect_ratio_height, 0.5*vol->aspect_ratio_depth); 928 939 glRotatef(90, 0, 1, 0); 929 940 930 glScalef(0.000 35, 0.00035, 0.00035);941 glScalef(0.0008, 0.0008, 0.0008); 931 942 for(int i=0; i<length; i++){ 932 glutStrokeCharacter(GLUT_STROKE_ROMAN, vol->label[2] [i]);943 glutStrokeCharacter(GLUT_STROKE_ROMAN, vol->label[2].c_str()[i]); 933 944 glTranslatef(0.04, 0., 0.); 934 945 } -
trunk/gui/vizservers/nanovis/VolumeRenderer.h
r451 r455 87 87 //volume is added. 88 88 void shade_volume(Volume* _vol, TransferFunction* _tf); 89 TransferFunction* get_volume_shading(Volume* _vol); 90 89 91 void render(int volume_index); 90 92 void render_all(); //render all enabled volumes; -
trunk/gui/vizservers/nanovis/nanovis.cpp
r453 r455 94 94 void get_slice_vectors(); 95 95 Rappture::Outcome load_volume_file(int index, char *fname); 96 void load_volume(int index, int width, int height, int depth, int n_component, float* data );96 void load_volume(int index, int width, int height, int depth, int n_component, float* data, double vmin, double vmax); 97 97 TransferFunction* get_transfunc(char *name); 98 void resize_offscreen_buffer(int w, int h); 99 void bmp_header_add_int(unsigned char* header, int& pos, int data); 100 void bmp_write(const char* cmd); 98 101 99 102 ParticleSystem* psys; … … 149 152 static int CameraCmd _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[])); 150 153 static int CutplaneCmd _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[])); 151 static int ClearCmd _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[]));154 static int LegendCmd _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[])); 152 155 static int ScreenCmd _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[])); 153 156 static int TransfuncCmd _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[])); 154 157 static int VolumeCmd _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[])); 155 static int VolumeLinkCmd _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[]));156 static int VolumeMoveCmd _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[]));157 static int RefreshCmd _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[]));158 158 static int PlaneNewCmd _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[])); 159 159 static int PlaneLinkCmd _ANSI_ARGS_((ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[])); … … 367 367 } 368 368 369 void resize_offscreen_buffer(int w, int h); 370 371 //change screen size 369 /* 370 * ---------------------------------------------------------------------- 371 * CLIENT COMMAND: 372 * legend <volumeIndex> <width> <height> 373 * 374 * Clients use this to generate a legend image for the specified 375 * transfer function. The legend image is a color gradient from 0 376 * to one, drawn in the given transfer function. The resulting image 377 * is returned in the size <width> x <height>. 378 * ---------------------------------------------------------------------- 379 */ 380 static int 381 LegendCmd(ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[]) 382 { 383 if (argc != 4) { 384 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 385 " transfunc width height\"", (char*)NULL); 386 return TCL_ERROR; 387 } 388 389 TransferFunction *tf = NULL; 390 int ivol; 391 if (Tcl_GetInt(interp, argv[1], &ivol) != TCL_OK) { 392 return TCL_ERROR; 393 } 394 if (ivol < n_volumes) { 395 tf = vol_render->get_volume_shading(volume[ivol]); 396 } 397 if (tf == NULL) { 398 Tcl_AppendResult(interp, "transfer function not defined for volume ", argv[1], (char*)NULL); 399 return TCL_ERROR; 400 } 401 402 int old_width = win_width; 403 int old_height = win_height; 404 405 int width, height; 406 if (Tcl_GetInt(interp, argv[2], &width) != TCL_OK) { 407 return TCL_ERROR; 408 } 409 if (Tcl_GetInt(interp, argv[3], &height) != TCL_OK) { 410 return TCL_ERROR; 411 } 412 413 resize_offscreen_buffer(width, height); 414 415 // generate data for the legend 416 float data[512]; 417 for (int i=0; i < 256; i++) { 418 data[i] = data[i+256] = (float)(i/255.0); 419 } 420 plane[0] = new Texture2D(256, 2, GL_FLOAT, GL_LINEAR, 1, data); 421 int index = plane_render->add_plane(plane[0], tf); 422 plane_render->set_active_plane(index); 423 plane_render->set_screen_size(width, height); 424 plane_render->render(); 425 426 glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, screen_buffer); 427 428 std::ostringstream result; 429 result << "nv>legend " << argv[1]; 430 result << " " << volume[ivol]->range_min(); 431 result << " " << volume[ivol]->range_max(); 432 bmp_write(result.str().c_str()); 433 write(0, "\n", 1); 434 435 plane_render->remove_plane(index); 436 resize_offscreen_buffer(old_width, old_height); 437 438 return TCL_OK; 439 } 440 441 442 443 /* 444 * ---------------------------------------------------------------------- 445 * CLIENT COMMAND: 446 * screen <width> <height> 447 * 448 * Clients send this command to set the size of the rendering area. 449 * Future images are generated at the specified width/height. 450 * ---------------------------------------------------------------------- 451 */ 372 452 static int 373 453 ScreenCmd(ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[]) 374 454 { 375 376 fprintf(stderr, "screen size cmd\n"); 377 double w, h; 378 379 if (argc != 3) { 380 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 381 " width height \"", (char*)NULL); 382 return TCL_ERROR; 383 } 384 if (Tcl_GetDouble(interp, argv[1], &w) != TCL_OK) { 385 return TCL_ERROR; 386 } 387 if (Tcl_GetDouble(interp, argv[2], &h) != TCL_OK) { 388 return TCL_ERROR; 389 } 390 391 resize_offscreen_buffer((int)w, (int)h); 392 fprintf(stdin,"new screen size: %d %d\n",w,h); 393 return TCL_OK; 394 } 395 396 397 static int 398 RefreshCmd(ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[]) 399 { 400 fprintf(stderr, "refresh cmd\n"); 401 return TCL_OK; 402 } 403 404 void set_object(float x, float y, float z){ 405 live_obj_x = x; 406 live_obj_y = y; 407 live_obj_z = z; 455 int w, h; 456 457 if (argc != 3) { 458 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 459 " width height\"", (char*)NULL); 460 return TCL_ERROR; 461 } 462 if (Tcl_GetInt(interp, argv[1], &w) != TCL_OK) { 463 return TCL_ERROR; 464 } 465 if (Tcl_GetInt(interp, argv[2], &h) != TCL_OK) { 466 return TCL_ERROR; 467 } 468 resize_offscreen_buffer(w, h); 469 470 return TCL_OK; 408 471 } 409 472 … … 953 1016 } 954 1017 955 static int956 VolumeLinkCmd(ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[])957 {958 fprintf(stderr, "link volume command\n");959 960 double volume_index, tf_index;961 962 if (argc != 3) {963 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],964 " volume_index tf_index \"", (char*)NULL);965 return TCL_ERROR;966 }967 if (Tcl_GetDouble(interp, argv[1], &volume_index) != TCL_OK) {968 return TCL_ERROR;969 }970 if (Tcl_GetDouble(interp, argv[2], &tf_index) != TCL_OK) {971 return TCL_ERROR;972 }973 974 //vol_render->add_volume(volume[(int)volume_index], tf[(int)tf_index]);975 976 return TCL_OK;977 }978 979 980 static int981 VolumeResizeCmd(ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[])982 {983 fprintf(stderr, "resize drawing size of the volume command\n");984 985 double volume_index, size;986 987 if (argc != 3) {988 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],989 " volume_index size \"", (char*)NULL);990 return TCL_ERROR;991 }992 if (Tcl_GetDouble(interp, argv[1], &volume_index) != TCL_OK) {993 return TCL_ERROR;994 }995 if (Tcl_GetDouble(interp, argv[2], &size) != TCL_OK) {996 return TCL_ERROR;997 }998 999 volume[(int)volume_index]->set_size((float) size);1000 return TCL_OK;1001 }1002 1003 static int1004 VolumeMoveCmd(ClientData cdata, Tcl_Interp *interp, int argc, CONST84 char *argv[])1005 {1006 1007 fprintf(stderr, "move volume cmd\n");1008 double index, x, y, z;1009 1010 if (argc != 5) {1011 Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],1012 " index x_coord y_coord z_coord\"", (char*)NULL);1013 return TCL_ERROR;1014 }1015 if (Tcl_GetDouble(interp, argv[1], &index) != TCL_OK) {1016 return TCL_ERROR;1017 }1018 if (Tcl_GetDouble(interp, argv[2], &x) != TCL_OK) {1019 return TCL_ERROR;1020 }1021 if (Tcl_GetDouble(interp, argv[3], &y) != TCL_OK) {1022 return TCL_ERROR;1023 }1024 if (Tcl_GetDouble(interp, argv[4], &z) != TCL_OK) {1025 return TCL_ERROR;1026 }1027 1028 //set_object(x, y, z);1029 volume[(int)index]->move(Vector3(x, y, z));1030 return TCL_OK;1031 }1032 1033 1018 /* 1034 1019 * ---------------------------------------------------------------------- … … 1152 1137 fprintf(stderr, "load plane for 2D visualization command\n"); 1153 1138 1154 doubleindex, w, h;1139 int index, w, h; 1155 1140 1156 1141 if (argc != 4) { … … 1159 1144 return TCL_ERROR; 1160 1145 } 1161 if (Tcl_Get Double(interp, argv[1], &index) != TCL_OK) {1146 if (Tcl_GetInt(interp, argv[1], &index) != TCL_OK) { 1162 1147 return TCL_ERROR; 1163 1148 } 1164 if (Tcl_Get Double(interp, argv[2], &w) != TCL_OK) {1149 if (Tcl_GetInt(interp, argv[2], &w) != TCL_OK) { 1165 1150 return TCL_ERROR; 1166 1151 } 1167 if (Tcl_Get Double(interp, argv[3], &h) != TCL_OK) {1152 if (Tcl_GetInt(interp, argv[3], &h) != TCL_OK) { 1168 1153 return TCL_ERROR; 1169 1154 } … … 1177 1162 } 1178 1163 1179 plane[ (int)index] = new Texture2D(w, h, GL_FLOAT, GL_LINEAR, 1, (float*)tmp);1164 plane[index] = new Texture2D(w, h, GL_FLOAT, GL_LINEAR, 1, (float*)tmp); 1180 1165 1181 1166 delete[] tmp; … … 1188 1173 fprintf(stderr, "link the plane to the 2D renderer command\n"); 1189 1174 1190 doubleplane_index, tf_index;1175 int plane_index, tf_index; 1191 1176 1192 1177 if (argc != 3) { … … 1195 1180 return TCL_ERROR; 1196 1181 } 1197 if (Tcl_Get Double(interp, argv[1], &plane_index) != TCL_OK) {1182 if (Tcl_GetInt(interp, argv[1], &plane_index) != TCL_OK) { 1198 1183 return TCL_ERROR; 1199 1184 } 1200 if (Tcl_Get Double(interp, argv[2], &tf_index) != TCL_OK) {1185 if (Tcl_GetInt(interp, argv[2], &tf_index) != TCL_OK) { 1201 1186 return TCL_ERROR; 1202 1187 } 1203 1188 1204 //plane_render->add_plane(plane[ (int)plane_index], tf[(int)tf_index]);1189 //plane_render->add_plane(plane[plane_index], tf[tf_index]); 1205 1190 1206 1191 return TCL_OK; … … 1214 1199 fprintf(stderr, "enable a plane so the 2D renderer can render it command\n"); 1215 1200 1216 doubleplane_index, mode;1201 int plane_index, mode; 1217 1202 1218 1203 if (argc != 3) { … … 1221 1206 return TCL_ERROR; 1222 1207 } 1223 if (Tcl_Get Double(interp, argv[1], &plane_index) != TCL_OK) {1208 if (Tcl_GetInt(interp, argv[1], &plane_index) != TCL_OK) { 1224 1209 return TCL_ERROR; 1225 1210 } 1226 if (Tcl_Get Double(interp, argv[2], &mode) != TCL_OK) {1211 if (Tcl_GetInt(interp, argv[2], &mode) != TCL_OK) { 1227 1212 return TCL_ERROR; 1228 1213 } … … 1397 1382 } 1398 1383 1399 load_volume(index, nx, ny, nz, 3, data );1384 load_volume(index, nx, ny, nz, 3, data, vmin, vmax); 1400 1385 delete [] data; 1401 1386 } else { … … 1624 1609 } 1625 1610 1626 load_volume(index, nx, ny, nz, 4, data); 1611 load_volume(index, nx, ny, nz, 4, data, 1612 field.valueMin(), field.valueMax()); 1613 1627 1614 delete [] data; 1628 1615 … … 1728 1715 } 1729 1716 1730 load_volume(index, nx, ny, nz, 4, data); 1717 load_volume(index, nx, ny, nz, 4, data, 1718 field.valueMin(), field.valueMax()); 1719 1731 1720 delete [] data; 1732 1721 } … … 1755 1744 * width, height and depth: number of points in each dimension 1756 1745 */ 1757 void load_volume(int index, int width, int height, int depth, int n_component, float* data){ 1746 void load_volume(int index, int width, int height, int depth, 1747 int n_component, float* data, double vmin, double vmax) { 1758 1748 if(volume[index]!=0){ 1759 1749 delete volume[index]; … … 1761 1751 } 1762 1752 1763 volume[index] = new Volume(0.f, 0.f, 0.f, width, height, depth, 1., n_component, data );1753 volume[index] = new Volume(0.f, 0.f, 0.f, width, height, depth, 1., n_component, data, vmin, vmax); 1764 1754 assert(volume[index]!=0); 1765 1755 … … 2132 2122 (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); 2133 2123 2124 // request the legend for a plot (transfer function) 2125 Tcl_CreateCommand(interp, "legend", LegendCmd, 2126 (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); 2127 2134 2128 // change the size of the screen (size of picture generated) 2135 2129 Tcl_CreateCommand(interp, "screen", ScreenCmd, … … 2149 2143 fprintf(stdin, Tcl_GetStringResult(interp)); 2150 2144 } 2151 2152 2153 //link an EXISTING volume and transfer function to the volume renderer.2154 //Only after being added, can a volume be rendered. This command does not create a volume nor a transfer function2155 Tcl_CreateCommand(interp, "volume_link", VolumeLinkCmd, (ClientData)0, (Tcl_CmdDeleteProc*)NULL);2156 //move an volume2157 Tcl_CreateCommand(interp, "volume_move", VolumeMoveCmd, (ClientData)0, (Tcl_CmdDeleteProc*)NULL);2158 //resize volume2159 Tcl_CreateCommand(interp, "volume_resize", VolumeResizeCmd, (ClientData)0, (Tcl_CmdDeleteProc*)NULL);2160 2161 //refresh the screen (render again)2162 Tcl_CreateCommand(interp, "refresh", RefreshCmd, (ClientData)0, (Tcl_CmdDeleteProc*)NULL);2163 2145 } 2164 2146 … … 2218 2200 header[pos++] = (data >> 16) & 0xff; 2219 2201 header[pos++] = (data >> 24) & 0xff; 2202 } 2203 2204 void 2205 bmp_write(const char* cmd) 2206 { 2207 unsigned char header[54]; 2208 int pos = 0; 2209 header[pos++] = 'B'; 2210 header[pos++] = 'M'; 2211 2212 // file size in bytes 2213 int fsize = win_width*win_height*3 + sizeof(header); 2214 bmp_header_add_int(header, pos, fsize); 2215 2216 // reserved value (must be 0) 2217 bmp_header_add_int(header, pos, 0); 2218 2219 // offset in bytes to start of bitmap data 2220 bmp_header_add_int(header, pos, sizeof(header)); 2221 2222 // size of the BITMAPINFOHEADER 2223 bmp_header_add_int(header, pos, 40); 2224 2225 // width of the image in pixels 2226 bmp_header_add_int(header, pos, win_width); 2227 2228 // height of the image in pixels 2229 bmp_header_add_int(header, pos, win_height); 2230 2231 // 1 plane + 24 bits/pixel << 16 2232 bmp_header_add_int(header, pos, 1572865); 2233 2234 // no compression 2235 // size of image for compression 2236 bmp_header_add_int(header, pos, 0); 2237 bmp_header_add_int(header, pos, 0); 2238 2239 // x pixels per meter 2240 // y pixels per meter 2241 bmp_header_add_int(header, pos, 0); 2242 bmp_header_add_int(header, pos, 0); 2243 2244 // number of colors used (0 = compute from bits/pixel) 2245 // number of important colors (0 = all colors important) 2246 bmp_header_add_int(header, pos, 0); 2247 bmp_header_add_int(header, pos, 0); 2248 2249 // BE CAREFUL: BMP format wants BGR ordering for screen data 2250 for (int i=0; i < 3*win_width*win_height; i += 3) { 2251 unsigned char tmp = screen_buffer[i+2]; 2252 screen_buffer[i+2] = screen_buffer[i]; 2253 screen_buffer[i] = tmp; 2254 } 2255 2256 std::ostringstream result; 2257 result << cmd << " " << fsize << "\n"; 2258 write(0, result.str().c_str(), result.str().size()); 2259 2260 write(0, header, sizeof(header)); 2261 write(0, screen_buffer, 3*win_width*win_height); 2220 2262 } 2221 2263 … … 2295 2337 write(0, rle, rle_size); //unsigned byte 2296 2338 #else 2297 unsigned char header[54]; 2298 int pos = 0; 2299 header[pos++] = 'B'; 2300 header[pos++] = 'M'; 2301 2302 // file size in bytes 2303 int fsize = win_width*win_height*3 + sizeof(header); 2304 bmp_header_add_int(header, pos, fsize); 2305 2306 // reserved value (must be 0) 2307 bmp_header_add_int(header, pos, 0); 2308 2309 // offset in bytes to start of bitmap data 2310 bmp_header_add_int(header, pos, sizeof(header)); 2311 2312 // size of the BITMAPINFOHEADER 2313 bmp_header_add_int(header, pos, 40); 2314 2315 // width of the image in pixels 2316 bmp_header_add_int(header, pos, win_width); 2317 2318 // height of the image in pixels 2319 bmp_header_add_int(header, pos, win_height); 2320 2321 // 1 plane + 24 bits/pixel << 16 2322 bmp_header_add_int(header, pos, 1572865); 2323 2324 // no compression 2325 // size of image for compression 2326 bmp_header_add_int(header, pos, 0); 2327 bmp_header_add_int(header, pos, 0); 2328 2329 // x pixels per meter 2330 // y pixels per meter 2331 bmp_header_add_int(header, pos, 0); 2332 bmp_header_add_int(header, pos, 0); 2333 2334 // number of colors used (0 = compute from bits/pixel) 2335 // number of important colors (0 = all colors important) 2336 bmp_header_add_int(header, pos, 0); 2337 bmp_header_add_int(header, pos, 0); 2338 2339 // BE CAREFUL: BMP format wants BGR ordering for screen data 2340 for (int i=0; i < 3*win_width*win_height; i += 3) { 2341 unsigned char tmp = screen_buffer[i+2]; 2342 screen_buffer[i+2] = screen_buffer[i]; 2343 screen_buffer[i] = tmp; 2344 } 2345 2346 std::ostringstream result; 2347 result << "nv>image -bytes " << fsize << "\n"; 2348 write(0, result.str().c_str(), result.str().size()); 2349 2350 write(0, header, sizeof(header)); 2351 write(0, screen_buffer, 3*win_width*win_height); 2339 bmp_write("nv>image -bytes"); 2352 2340 #endif 2353 2341 }
Note: See TracChangeset
for help on using the changeset viewer.