Main Page | Modules | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

dither-inlined-functions.h

Go to the documentation of this file.
00001 /*
00002  * "$Id: dither-inlined-functions.h,v 1.6 2004/09/17 18:38:18 rleigh Exp $"
00003  *
00004  *   Performance-critical functions that should be inlined, based on
00005  *   measurements.
00006  *
00007  *   Copyright 1997-2003 Michael Sweet (mike@easysw.com) and
00008  *      Robert Krawitz (rlk@alum.mit.edu)
00009  *
00010  *   This program is free software; you can redistribute it and/or modify it
00011  *   under the terms of the GNU General Public License as published by the Free
00012  *   Software Foundation; either version 2 of the License, or (at your option)
00013  *   any later version.
00014  *
00015  *   This program is distributed in the hope that it will be useful, but
00016  *   WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
00017  *   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00018  *   for more details.
00019  *
00020  *   You should have received a copy of the GNU General Public License
00021  *   along with this program; if not, write to the Free Software
00022  *   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00023  *
00024  * Revision History:
00025  *
00026  *   See ChangeLog
00027  */
00028 
00029 #ifndef GUTENPRINT_INTERNAL_DITHER_INLINED_FUNCTIONS_H
00030 #define GUTENPRINT_INTERNAL_DITHER_INLINED_FUNCTIONS_H
00031 
00032 /*
00033  * Inlining has yielded significant (measured) speedup, even with the
00034  * more complicated dither function. --rlk 20011219
00035  */
00036 
00037 static inline unsigned
00038 ditherpoint(const stpi_dither_t *d, stp_dither_matrix_impl_t *mat, int x)
00039 {
00040   if (mat->fast_mask)
00041     return mat->matrix[(mat->last_y_mod +
00042                         ((x + mat->x_offset) & mat->fast_mask))];
00043   /*
00044    * This rather bizarre code is an attempt to avoid having to compute a lot
00045    * of modulus and multiplication operations, which are typically slow.
00046    */
00047 
00048   if (x == mat->last_x + 1)
00049     {
00050       mat->last_x_mod++;
00051       mat->index++;
00052       if (mat->last_x_mod >= mat->x_size)
00053         {
00054           mat->last_x_mod -= mat->x_size;
00055           mat->index -= mat->x_size;
00056         }
00057     }
00058   else if (x == mat->last_x - 1)
00059     {
00060       mat->last_x_mod--;
00061       mat->index--;
00062       if (mat->last_x_mod < 0)
00063         {
00064           mat->last_x_mod += mat->x_size;
00065           mat->index += mat->x_size;
00066         }
00067     }
00068   else if (x != mat->last_x)
00069     {
00070       mat->last_x_mod = (x + mat->x_offset) % mat->x_size;
00071       mat->index = mat->last_x_mod + mat->last_y_mod;
00072     }
00073   mat->last_x = x;
00074   return mat->matrix[mat->index];
00075 }
00076 
00077 static inline void
00078 set_row_ends(stpi_dither_channel_t *dc, int x)
00079 {
00080   if (dc->row_ends[0] == -1)
00081     dc->row_ends[0] = x;
00082   dc->row_ends[1] = x;
00083 }
00084 
00085 #endif /* GUTENPRINT_INTERNAL_DITHER_INLINED_FUNCTIONS_H */

Generated on Thu Feb 10 19:29:30 2005 for libgutenprint API Reference by  doxygen 1.4.1