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_OCC
USE_MPEG
USE_JPEG
USE_INTERNAL_TCL
INSTALL_PROFILES
INTEL_MIC

View File

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