git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@10892 f3b2605a-c512-4ea7-a41b-209d697bcdaa

This commit is contained in:
sjplimp 2013-10-30 15:03:13 +00:00
parent ee61fe3043
commit 86e30ba171
3 changed files with 83 additions and 9 deletions

View File

@ -28,16 +28,12 @@
#include "error.h"
#include "memory.h"
#ifdef LAMMPS_JPEG
#include "jpeglib.h"
#endif
using namespace LAMMPS_NS;
using namespace MathConst;
#define BIG 1.0e20
enum{PPM,JPG};
enum{PPM,JPG,PNG};
enum{NUMERIC,ATOM,TYPE,ELEMENT,ATTRIBUTE};
enum{STATIC,DYNAMIC};
enum{NO,YES};
@ -58,12 +54,25 @@ DumpImage::DumpImage(LAMMPS *lmp, int narg, char **arg) :
int n = strlen(filename);
if (strlen(filename) > 4 && strcmp(&filename[n-4],".jpg") == 0)
filetype = JPG;
else if (strlen(filename) > 4 && strcmp(&filename[n-4],".JPG") == 0)
filetype = JPG;
else if (strlen(filename) > 5 && strcmp(&filename[n-5],".jpeg") == 0)
filetype = JPG;
else if (strlen(filename) > 5 && strcmp(&filename[n-5],".JPEG") == 0)
filetype = JPG;
else if (strlen(filename) > 4 && strcmp(&filename[n-4],".png") == 0)
filetype = PNG;
else if (strlen(filename) > 4 && strcmp(&filename[n-4],".PNG") == 0)
filetype = PNG;
else filetype = PPM;
#ifndef LAMMPS_JPEG
if (filetype == JPG) error->all(FLERR,"Cannot dump JPG file");
if (filetype == JPG)
error->all(FLERR,"Support for writing images in JPEG format not included");
#endif
#ifndef LAMMPS_PNG
if (filetype == PNG)
error->all(FLERR,"Support for writing images in PNG format not included");
#endif
// atom color,diameter settings
@ -536,6 +545,7 @@ void DumpImage::write()
if (me == 0) {
if (filetype == JPG) image->write_JPG(fp);
else if (filetype == PNG) image->write_PNG(fp);
else image->write_PPM(fp);
fclose(fp);
}

View File

@ -32,6 +32,13 @@
#include "jpeglib.h"
#endif
#ifdef LAMMPS_PNG
#include <png.h>
#include <zlib.h>
#include <setjmp.h>
#include "version.h"
#endif
using namespace LAMMPS_NS;
using namespace MathConst;
@ -1005,8 +1012,8 @@ void Image::write_JPG(FILE *fp)
cinfo.in_color_space = JCS_RGB;
jpeg_set_defaults(&cinfo);
jpeg_set_quality(&cinfo, 100, 1);
jpeg_start_compress(&cinfo, 1);
jpeg_set_quality(&cinfo,85,true);
jpeg_start_compress(&cinfo,true);
while (cinfo.next_scanline < cinfo.image_height) {
row_pointer = (JSAMPROW)
@ -1021,6 +1028,62 @@ void Image::write_JPG(FILE *fp)
/* ---------------------------------------------------------------------- */
void Image::write_PNG(FILE *fp)
{
#ifdef LAMMPS_PNG
png_structp png_ptr;
png_infop info_ptr;
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (!png_ptr) return;
info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr) {
png_destroy_write_struct(&png_ptr, NULL);
return;
}
if (setjmp(png_jmpbuf(png_ptr))) {
png_destroy_write_struct(&png_ptr, &info_ptr);
return;
}
png_init_io(png_ptr, fp);
png_set_compression_level(png_ptr,Z_BEST_COMPRESSION);
png_set_IHDR(png_ptr,info_ptr,width,height,8,PNG_COLOR_TYPE_RGB,
PNG_INTERLACE_NONE,PNG_COMPRESSION_TYPE_DEFAULT,PNG_FILTER_TYPE_DEFAULT);
png_text text_ptr[2];
memset(text_ptr,0,2*sizeof(png_text));
char key0[] = "Software";
char text0[] = "LAMMPS " LAMMPS_VERSION;
char key1[] = "Description";
char text1[] = "Dump image snapshot";
text_ptr[0].key = key0;
text_ptr[0].text = text0;
text_ptr[1].key = key1;
text_ptr[1].text = text1;
text_ptr[0].compression = PNG_TEXT_COMPRESSION_NONE;
text_ptr[1].compression = PNG_TEXT_COMPRESSION_NONE;
png_set_text(png_ptr,info_ptr,text_ptr,1);
png_write_info(png_ptr,info_ptr);
png_bytep row_pointers[height];
for (int i=0; i < height; ++i)
row_pointers[i] = (png_bytep) &writeBuffer[(height-i-1)*3*width];
png_write_image(png_ptr, row_pointers);
png_write_end(png_ptr, info_ptr);
png_destroy_write_struct(&png_ptr, &info_ptr);
#endif
}
/* ---------------------------------------------------------------------- */
void Image::write_PPM(FILE *fp)
{
fprintf (fp,"P6\n%d %d\n255\n",width,height);

View File

@ -41,6 +41,7 @@ class Image : protected Pointers {
void clear();
void merge();
void write_JPG(FILE *);
void write_PNG(FILE *);
void write_PPM(FILE *);
void view_params(double, double, double, double, double, double);
@ -71,7 +72,7 @@ class Image : protected Pointers {
double *depthBuffer,*surfaceBuffer;
double *depthcopy,*surfacecopy;
char *imageBuffer,*rgbcopy,*writeBuffer;
unsigned char *imageBuffer,*rgbcopy,*writeBuffer;
// constant view params