Merge branch 'fix_jpeg' into 'master'

Fix build/image export with USE_JPEG=ON

See merge request !63
This commit is contained in:
Joachim Schöberl 2017-09-27 18:04:22 +02:00
commit 9b0e13730f
2 changed files with 31 additions and 30 deletions

View File

@ -131,6 +131,7 @@ set_vars( NETGEN_CMAKE_ARGS
USE_NATIVE_ARCH USE_NATIVE_ARCH
USE_OCC USE_OCC
USE_MPEG USE_MPEG
USE_JPEG
USE_INTERNAL_TCL USE_INTERNAL_TCL
INSTALL_PROFILES INSTALL_PROFILES
INTEL_MIC INTEL_MIC

View File

@ -2007,7 +2007,9 @@ namespace netgen
int w = Togl_Width (togl); int w = Togl_Width (togl);
int h = Togl_Height (togl); int h = Togl_Height (togl);
Array<char> buffer(w*h*3); Array<unsigned char> buffer(w*h*3);
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
glPixelStorei(GL_PACK_ALIGNMENT,1);
glReadPixels (0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, &buffer[0]); glReadPixels (0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, &buffer[0]);
#ifdef JPEGLIB #ifdef JPEGLIB
@ -2052,20 +2054,17 @@ namespace netgen
} }
#endif // JPEGLIB #endif // JPEGLIB
{ {
char str[250]; string command;
char filename2[250]; string filename2;
int len = strlen(filename);
strcpy (filename2, filename);
filename2[len-3] = 'p'; filename2 = filename;
filename2[len-2] = 'p';
filename2[len-1] = 'm'; if(filename2.substr(len-3) != ".ppm")
filename2[len] = 0; filename2 += ".ppm";
cout << "Snapshot to file '" << filename << endl; cout << "Snapshot to file '" << filename << endl;
int w = Togl_Width (togl); int w = Togl_Width (togl);
w = int((w + 1) / 4) * 4 + 4;
int h = Togl_Height (togl); int h = Togl_Height (togl);
ofstream outfile(filename2); ofstream outfile(filename2);
@ -2079,29 +2078,30 @@ namespace netgen
outfile.put (buffer[k+3*j+3*w*(h-i-1)]); outfile.put (buffer[k+3*j+3*w*(h-i-1)]);
outfile << flush; outfile << flush;
if (filename2 == string(filename))
return TCL_OK;
else
{
// convert image file (Unix/Linux only): // convert image file (Unix/Linux only):
sprintf(str,"convert -quality 100 %s %s", filename2, filename); command = string("convert -quality 100 ") + filename2 + " " + filename;
int err = system(str); int err = system(command.c_str());
if (err != 0) if (err != 0)
{ {
Tcl_SetResult (Togl_Interp(togl), (char*)"Cannot convert image file", TCL_VOLATILE); Tcl_SetResult (Togl_Interp(togl), (char*)"Cannot convert image file, stored as .ppm", TCL_VOLATILE);
return TCL_ERROR; return TCL_ERROR;
} }
sprintf(str,"rm %s", filename2);
err = system(str); command = string("rm ") + filename2;
err = system(command.c_str());
if (err != 0) if (err != 0)
{ {
Tcl_SetResult (Togl_Interp(togl), (char*)"Cannot delete temporary file", TCL_VOLATILE); Tcl_SetResult (Togl_Interp(togl), (char*)"Cannot delete temporary file", TCL_VOLATILE);
return TCL_ERROR; return TCL_ERROR;
} }
return TCL_OK;
} }
{
cout << "Snapshot to " << filename << " not supported" << endl;
return TCL_ERROR;
} }
} }