Main Page   Modules   Alphabetical List   Data Structures   File List   Data Fields   Globals  

src/main/dither-inlined-functions.h

Go to the documentation of this file.
00001 /*
00002  * "$Id: dither-inlined-functions.h,v 1.5 2004/04/27 23:23:46 rlk 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 
00030 /*
00031  * Inlining has yielded significant (measured) speedup, even with the
00032  * more complicated dither function. --rlk 20011219
00033  */
00034 
00035 static inline unsigned
00036 ditherpoint(const stpi_dither_t *d, stp_dither_matrix_impl_t *mat, int x)
00037 {
00038   if (mat->fast_mask)
00039     return mat->matrix[(mat->last_y_mod +
00040                         ((x + mat->x_offset) & mat->fast_mask))];
00041   /*
00042    * This rather bizarre code is an attempt to avoid having to compute a lot
00043    * of modulus and multiplication operations, which are typically slow.
00044    */
00045 
00046   if (x == mat->last_x + 1)
00047     {
00048       mat->last_x_mod++;
00049       mat->index++;
00050       if (mat->last_x_mod >= mat->x_size)
00051         {
00052           mat->last_x_mod -= mat->x_size;
00053           mat->index -= mat->x_size;
00054         }
00055     }
00056   else if (x == mat->last_x - 1)
00057     {
00058       mat->last_x_mod--;
00059       mat->index--;
00060       if (mat->last_x_mod < 0)
00061         {
00062           mat->last_x_mod += mat->x_size;
00063           mat->index += mat->x_size;
00064         }
00065     }
00066   else if (x != mat->last_x)
00067     {
00068       mat->last_x_mod = (x + mat->x_offset) % mat->x_size;
00069       mat->index = mat->last_x_mod + mat->last_y_mod;
00070     }
00071   mat->last_x = x;
00072   return mat->matrix[mat->index];
00073 }
00074 
00075 static inline void
00076 set_row_ends(stpi_dither_channel_t *dc, int x)
00077 {
00078   if (dc->row_ends[0] == -1)
00079     dc->row_ends[0] = x;
00080   dc->row_ends[1] = x;
00081 }

Generated on Wed May 12 20:21:28 2004 for libgimpprint API Reference by doxygen1.2.17