glprint.cpp
来自「ncbi源码」· C++ 代码 · 共 250 行
CPP
250 行
/* * =========================================================================== * PRODUCTION $Log: glprint.cpp,v $ * PRODUCTION Revision 1000.1 2004/06/01 20:50:58 gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.6 * PRODUCTION * =========================================================================== *//* $Id: glprint.cpp,v 1000.1 2004/06/01 20:50:58 gouriano Exp $ * =========================================================================== * * PUBLIC DOMAIN NOTICE * National Center for Biotechnology Information * * This software/database is a "United States Government Work" under the * terms of the United States Copyright Act. It was written as part of * the author's official duties as a United States Government employee and * thus cannot be copyrighted. This software/database is freely available * to the public for use. The National Library of Medicine and the U.S. * Government have not placed any restriction on its use or reproduction. * * Although all reasonable efforts have been taken to ensure the accuracy * and reliability of the software and data, the NLM and the U.S. * Government do not and cannot warrant the performance or results that * may be obtained by using this software or data. The NLM and the U.S. * Government disclaim all warranties, express or implied, including * warranties of performance, merchantability or fitness for any particular * purpose. * * Please cite the author in any work or product based on this material. * * =========================================================================== * * Authors: Peter Meric * * File Description: * GL-related printing functionality */#include <ncbi_pch.hpp>#include <gui/opengl.h>#include <gui/opengl/glprint.hpp>#include <gui/print/print.hpp>#include <gui/print/print_context.hpp>#include <gui/print/vector_buffer.hpp>#include <gui/opengl/opengl_print_buffer.hpp>#include <util/image/image.hpp>#include <util/image/image_io.hpp>BEGIN_NCBI_SCOPE void PrintVec(CFuncPtr* func, const CPrintOptions& opts){ static const size_t MB = 1024 * 1024; GLint data_len = 0; // // GL feedback requires a fixed-size buffer large enough to // hold all of the feedback data. If it's not large enough // then we have to loop, increasing the buffer size each // time by a constant factor (4) // for (size_t buffer_size = MB; ; buffer_size <<= 2) { _TRACE(Warning << "PrintVec(): feedback buffer size: " << buffer_size << " bytes"); typedef AutoPtr< GLfloat, ArrayDeleter<GLfloat> > TFloatArray; TFloatArray glbuf(new GLfloat[buffer_size]); glFeedbackBuffer(buffer_size, GL_3D_COLOR, glbuf.get()); glRenderMode(GL_FEEDBACK); // call the GL drawing function (*func)(); // switch back to render mode data_len = glRenderMode(GL_RENDER); _TRACE(Warning << "PrintVec(): GL data: " << data_len << " bytes"); if (data_len == 0) { _TRACE(Warning << "PrintVec(): no GL data rendered for print"); break; } else if (data_len < 0) { _TRACE(Warning << "PrintVec(): GL feedback buffer overflow"); continue; } CRef<COpenGLPrintBuffer> pbuffer(new COpenGLPrintBuffer()); CPrintContext ctx; ctx.AddBuffer(pbuffer); pbuffer->Parse(glbuf.get(), data_len); PrintContext(ctx, opts); ctx.RemoveBuffer(pbuffer); break; }}void PrintRas(CFuncPtr* func, const CPrintOptions& opts){ const size_t w = opts.GetRasterWidth(); const size_t h = opts.GetRasterHeight(); const size_t imgsize = (w * h) << 2; typedef unsigned char uchar; AutoPtr< uchar, ArrayDeleter<uchar> > imgbuf(new uchar[imgsize]); // call the GL drawing function (*func)(); //glReadBuffer(GL_BACK); glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, imgbuf.get()); // create the CImage // copy the image data to the CImage buffer, reversing the row order CRef<CImage> img(new CImage(w, h, 4)); unsigned char* imgptr = img->SetData(); const size_t linesize = w << 2; const unsigned char* bufptr = imgbuf.get() + imgsize - linesize; for (size_t i = 0; i < h; ++i, imgptr += linesize, bufptr -= linesize) { memcpy(imgptr, bufptr, linesize); } CPrintOptions::TOutputFormat fmt = opts.GetOutputFormat(); CImageIO::EType imgfmt; switch (fmt) { case CPrintOptions::ePng: imgfmt = CImageIO::ePng; break; case CPrintOptions::eJpeg: imgfmt = CImageIO::eJpeg; break; default: _TRACE(Error << "glprint PrintRas(): unsupported image output type"); } CImageIO::WriteImage(*img, opts.GetFilename(), imgfmt);}END_NCBI_SCOPE/* * =========================================================================== * $Log: glprint.cpp,v $ * Revision 1000.1 2004/06/01 20:50:58 gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.6 * * Revision 1.6 2004/05/21 22:27:45 gorelenk * Added PCH ncbi_pch.hpp * * Revision 1.5 2003/08/15 17:08:33 meric * Update include paths for print-related files moved from gui/utils to gui/print * * Revision 1.4 2003/08/06 20:20:20 meric * Add diagnostic messages * Differentiate buffer overflow from an empty buffer * * Revision 1.3 2003/07/16 20:43:07 meric * Updated comments * * Revision 1.2 2003/07/15 21:54:43 meric * Added PrintRas() - raster image output * * Revision 1.1 2003/06/25 16:21:33 meric * Initial version * * Revision 1.20 2003/06/24 22:46:45 meric * Temporary fix: added includes to allow MSVC++ to compile error/warning-free. * These includes are for printing functionality, which will be moved shortly. * * Revision 1.19 2003/06/19 16:34:21 meric * Pass file type parameter to CAppPopup::PopupFile * * Revision 1.18 2003/06/19 00:54:58 dicuccio * Minor reformatting. Changed LOG_POST() to _TRACE(). * * Revision 1.17 2003/06/18 19:44:40 meric * Print: loop to increase size of feedback buffer as necessary * * Revision 1.16 2003/06/18 17:26:57 meric * Final phase of print reorg: print classes now in gui/utils * * Revision 1.15 2003/06/17 19:34:32 meric * Call CAppPopup::PopupFile() instead of CAppPopup::Popup() * * Revision 1.14 2003/06/17 12:08:42 meric * Fixed CVectorOutput to include separate call to SetOutputStream() * Remove static keyword from s_Print (anachronism) * * Revision 1.13 2003/06/16 21:20:31 meric * Changed auto_ptr<> to CRef<> on a CObject-derived class (COpenGLPrintBuffer) * * Revision 1.12 2003/06/16 19:10:59 meric * Remove print buffer from print context before the context is destroyed. (this * code was 'lost' in the previous update). * * Revision 1.11 2003/06/16 16:56:10 dicuccio * Fix compiler error for MSVC * * Revision 1.10 2003/06/16 15:59:10 dicuccio * Work-in-progress: everything compiles, still much reorganization to be done. * Moved generic functionality out of opengl/print/ and into gui/utils (print * options, print dialogs, etc.). Removed interactive state from CGlCanvas. * Added hook in CView for opening standard print dialog, and for generic print * handling. Restored log for glcanvas.cpp * * Revision 1.9 2003/06/13 18:44:04 meric * Initialization in x_Init(), which is called by all c'tors * Remove print-related functinality from draw(), which can now be * overridden freely without affecting the Print() function. * Add print functions [ Print(), x_Print() etc ] * * Revision 1.8 2003/05/22 15:51:06 meric * small changes to GL Feedback code (remains commented out) * * Revision 1.7 2003/05/13 19:25:20 dicuccio * Prepare CGlCanvas for printing support (Peter Meric) * * Revision 1.6 2003/05/06 15:59:44 dicuccio * Split CGlCanvas into 2D and 3D versions; moved hardware check into CGlUtils * * Revision 1.5 2003/03/28 17:16:01 dicuccio * Added first support for testing for hardware acceleration * * Revision 1.4 2003/01/13 13:10:11 dicuccio * Namespace clean-up. Retired namespace gui -> converted all to namespace * ncbi. Moved all FLUID-generated code into namespace ncbi. * * Revision 1.3 2002/11/14 16:24:44 dicuccio * Changed to include standard OpenGL headers through 'gui/opengl.h' * * Revision 1.2 2002/11/08 13:27:45 dicuccio * Code clean-up and reformatting. * * Revision 1.1 2002/11/05 20:21:47 dicuccio * Initial revision * * =========================================================================== */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?