jpgprgrs.cpp

Go to the documentation of this file.
00001 // $Id: jpgprgrs.cpp 1282 2006-06-09 09:46:49Z alex $
00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
00003 ================================XARAHEADERSTART===========================
00004  
00005                Xara LX, a vector drawing and manipulation program.
00006                     Copyright (C) 1993-2006 Xara Group Ltd.
00007        Copyright on certain contributions may be held in joint with their
00008               respective authors. See AUTHORS file for details.
00009 
00010 LICENSE TO USE AND MODIFY SOFTWARE
00011 ----------------------------------
00012 
00013 This file is part of Xara LX.
00014 
00015 Xara LX is free software; you can redistribute it and/or modify it
00016 under the terms of the GNU General Public License version 2 as published
00017 by the Free Software Foundation.
00018 
00019 Xara LX and its component source files are distributed in the hope
00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the
00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00022 See the GNU General Public License for more details.
00023 
00024 You should have received a copy of the GNU General Public License along
00025 with Xara LX (see the file GPL in the root directory of the
00026 distribution); if not, write to the Free Software Foundation, Inc., 51
00027 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00028 
00029 
00030 ADDITIONAL RIGHTS
00031 -----------------
00032 
00033 Conditional upon your continuing compliance with the GNU General Public
00034 License described above, Xara Group Ltd grants to you certain additional
00035 rights. 
00036 
00037 The additional rights are to use, modify, and distribute the software
00038 together with the wxWidgets library, the wxXtra library, and the "CDraw"
00039 library and any other such library that any version of Xara LX relased
00040 by Xara Group Ltd requires in order to compile and execute, including
00041 the static linking of that library to XaraLX. In the case of the
00042 "CDraw" library, you may satisfy obligation under the GNU General Public
00043 License to provide source code by providing a binary copy of the library
00044 concerned and a copy of the license accompanying it.
00045 
00046 Nothing in this section restricts any of the rights you have under
00047 the GNU General Public License.
00048 
00049 
00050 SCOPE OF LICENSE
00051 ----------------
00052 
00053 This license applies to this program (XaraLX) and its constituent source
00054 files only, and does not necessarily apply to other Xara products which may
00055 in part share the same code base, and are subject to their own licensing
00056 terms.
00057 
00058 This license does not apply to files in the wxXtra directory, which
00059 are built into a separate library, and are subject to the wxWindows
00060 license contained within that directory in the file "WXXTRA-LICENSE".
00061 
00062 This license does not apply to the binary libraries (if any) within
00063 the "libs" directory, which are subject to a separate license contained
00064 within that directory in the file "LIBS-LICENSE".
00065 
00066 
00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
00068 ----------------------------------------------
00069 
00070 Subject to the terms of the GNU Public License (see above), you are
00071 free to do whatever you like with your modifications. However, you may
00072 (at your option) wish contribute them to Xara's source tree. You can
00073 find details of how to do this at:
00074   http://www.xaraxtreme.org/developers/
00075 
00076 Prior to contributing your modifications, you will need to complete our
00077 contributor agreement. This can be found at:
00078   http://www.xaraxtreme.org/developers/contribute/
00079 
00080 Please note that Xara will not accept modifications which modify any of
00081 the text between the start and end of this header (marked
00082 XARAHEADERSTART and XARAHEADEREND).
00083 
00084 
00085 MARKS
00086 -----
00087 
00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
00089 designs are registered or unregistered trademarks, design-marks, and/or
00090 service marks of Xara Group Ltd. All rights in these marks are reserved.
00091 
00092 
00093       Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
00094                         http://www.xara.com/
00095 
00096 =================================XARAHEADEREND============================
00097  */
00098 // 
00099 
00100 
00101 #include "camtypes.h"
00102 //#include "filters.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00103 #include "progress.h"
00104 
00105 #include "jinclude.h"
00106 #include "jpeglib.h"
00107 #include "jpgprgrs.h"
00108 
00109 
00110 
00111 // Place any IMPLEMENT type statements here
00112 //CC_IMPLEMENT_MEMDUMP(CCWobJob, CC_CLASS_MEMDUMP)
00113 
00114 
00115 // We want better memory tracking
00116 #define new CAM_DEBUG_NEW
00117 
00118 
00119 // Functions follow
00120 
00121 
00122 /********************************************************************************************
00123 
00124 >   JPEGProgressMonitor::JPEGProgressMonitor(j_decompress_ptr cinfo)
00125 
00126     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00127     Created:    02/08/96
00128     Inputs:     cinfo : the structure provided by the IJG library
00129     Purpose:    Derived classes should call this prior to their own construction to construct
00130                 a safe base class.
00131     Scope:      protected
00132 
00133 ********************************************************************************************/
00134 JPEGProgressMonitor::JPEGProgressMonitor(j_decompress_ptr cinfo)
00135 {
00136     // Set "base class" member...
00137     progress_monitor = Update;
00138 
00139     m_pcinfo            = cinfo;
00140     m_bContinueOp       = TRUE;
00141 }
00142 
00143 
00144 /********************************************************************************************
00145 
00146 >   JPEGProgressMonitor::~JPEGProgressMonitor()
00147 
00148     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00149     Created:    02/08/96
00150     Purpose:    Provides bizarre pure implementation for derived class destructors
00151     Scope:      protected
00152 
00153 ********************************************************************************************/
00154 JPEGProgressMonitor::~JPEGProgressMonitor()
00155 {
00156 }
00157 
00158 
00159 /********************************************************************************************
00160 
00161 >   void JPEGProgressMonitor::Update(j_common_ptr cinfo)
00162 
00163     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00164     Created:    02/08/96
00165     Inputs:     cinfo : data provided by the IJG Library
00166     Purpose:    Callback function for the IJG library.
00167                 It updates the Camelot Progress bar
00168     Scope:      static
00169     Notes:      This member is static because the IJG library is written in C, so requiring
00170                 classless pointers to functions
00171 
00172 ********************************************************************************************/
00173 void JPEGProgressMonitor::Update(j_common_ptr cinfo)
00174 {
00175     JPEGProgressMonitor* pThis = (JPEGProgressMonitor*) cinfo->progress;
00176     pThis->OnUpdate();
00177 }
00178 
00179 
00180 
00181 
00182 
00183 /********************************************************************************************
00184 
00185 >   JPEGProgressBySelf::JPEGProgressBySelf(j_decompress_ptr cinfo, 
00186                                             const StringBase& BarString)
00187 
00188     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00189     Created:    02/08/96
00190     Inputs:     BarString: a reference to the string to be used on the progress bar during
00191                 the time-consuming operation
00192     Purpose:    Constructor for a class providing a progress callback to the IJG Library
00193                 JPEG filter.
00194     Notes:      A progress bar will be constructed via this constructor.
00195     See Also:   JPEGProgressByFilter
00196 
00197 ********************************************************************************************/
00198 JPEGProgressBySelf::JPEGProgressBySelf(j_decompress_ptr cinfo, const StringBase& BarString)
00199     : JPEGProgressMonitor(cinfo)
00200 {
00201     m_BarString         = BarString;
00202     m_uLastPercentDone  = 0;
00203 
00204     // Create a new progress bar. Actually not that bothered if it doesn't construct
00205     m_pProgressBar      = new Progress(&m_BarString, 100);
00206 }
00207 
00208 
00209 /********************************************************************************************
00210 
00211 >   JPEGProgressBySelf::~JPEGProgressBySelf()
00212 
00213     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00214     Created:    02/08/96
00215     Purpose:    Destructor - stops the progress bar
00216     Notes:      Derived classes should call this subsequent to any specialized destruction
00217                 code of their own.
00218 
00219 ********************************************************************************************/
00220 JPEGProgressBySelf::~JPEGProgressBySelf()
00221 {
00222     // If started, then stop then progress bar
00223     if (m_pProgressBar != NULL)
00224     {
00225         delete m_pProgressBar;
00226         m_pProgressBar = NULL;
00227     }
00228 }
00229 
00230 
00231 /********************************************************************************************
00232 
00233 >   virtual void JPEGProgressBySelf::OnUpdate()
00234 
00235     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00236     Created:    02/08/96
00237     Purpose:    Called by JPEGProgressMonitor::Update() to provide feedback on the filter
00238                 progress. Derived classes should provide an implementation for this.
00239                 JPEGProgressBySelf calls the contained Progress::Update member with the
00240                 percentage done.
00241 
00242 ********************************************************************************************/
00243 void JPEGProgressBySelf::OnUpdate()
00244 {
00245     /*
00246         Fraction done =
00247 
00248             completed_passes + (pass_counter/pass_limit)
00249             --------------------------------------------
00250                         total_passes
00251     */
00252     UINT32 PercentDone = (UINT32) (100L * completed_passes + (100L * pass_counter) / pass_limit)
00253                             / total_passes;
00254 
00255     // Update the progress count, if required
00256     // but don't bother if the user aborted
00257     if (PercentDone != m_uLastPercentDone && m_bContinueOp)
00258     {
00259         m_bContinueOp = m_pProgressBar->Update(PercentDone);
00260         m_uLastPercentDone = PercentDone;
00261     }
00262 }
00263 
00264 
00265 
00266 
00267 
00268 /********************************************************************************************
00269 
00270 >   JPEGProgressByFilter::JPEGProgressByFilter(j_decompress_ptr cinfo, Filter* pFilterToUse,
00271                                                 UINT32 Increment);
00272 
00273     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00274     Created:    02/08/96
00275     Inputs:     cinfo : the structure provided by the IJG library
00276                 pFilterToUse : a pointer to a Filter with an IncProgressBarCount(UINT32 ...) 
00277                 member, which will be called with an update of the percentage progress made.
00278                 ImportSize : the size of the file we are importing
00279 
00280     Purpose:    Constructor for a class providing a progress callback to the IJG Library
00281                 JPEG filter.
00282     Notes:      No progress bar will be constructed via this constructor. The given filter
00283                 is expected to provide one.
00284     See Also:   JPEGProgressBySelf
00285 
00286 ********************************************************************************************/
00287 JPEGProgressByFilter::JPEGProgressByFilter(j_decompress_ptr cinfo, Filter* pFilterToUse,
00288                         UINT32 ImportSize)
00289     : JPEGProgressMonitor(cinfo)
00290 {
00291     m_pFilterForUpdate  = pFilterToUse;
00292     m_uLastScanLineDone = 0;
00293     m_uImportSize = ImportSize;
00294 }
00295 
00296 
00297 /********************************************************************************************
00298 
00299 >   virtual void JPEGProgressByFilter::OnUpdate()
00300 
00301     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00302     Created:    02/08/96
00303     Purpose:    Called by JPEGProgressMonitor::Update() to provide feedback on the filter
00304                 progress. Derived classes should provide an implementation for this.
00305                 JPEGProgressByFilter calls the contained Filter's Update member with the
00306                 number of scanlines processed.
00307 
00308 ********************************************************************************************/
00309 void JPEGProgressByFilter::OnUpdate()
00310 {
00311     INT32 Difference = m_pcinfo->output_scanline - m_uLastScanLineDone;
00312     if (Difference > 0)
00313     {
00314         UINT32 PerLineIncrement = m_uImportSize / m_pcinfo->output_height;
00315         m_pFilterForUpdate->IncProgressBarCount(Difference * PerLineIncrement);
00316         m_uLastScanLineDone += Difference;
00317     }
00318 }

Generated on Sat Nov 10 03:45:34 2007 for Camelot by  doxygen 1.4.4