~ubuntu-branches/ubuntu/quantal/mesa/quantal

« back to all changes in this revision

Viewing changes to src/mesa/swrast/s_zoom.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2007-02-21 12:44:07 UTC
  • mfrom: (1.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 22.
  • Revision ID: james.westby@ubuntu.com-20070221124407-rgcacs32mycrtadl
ImportĀ upstreamĀ versionĀ 6.5.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * Mesa 3-D graphics library
3
 
 * Version:  6.5
 
3
 * Version:  6.5.2
4
4
 *
5
 
 * Copyright (C) 1999-2005  Brian Paul   All Rights Reserved.
 
5
 * Copyright (C) 1999-2006  Brian Paul   All Rights Reserved.
6
6
 *
7
7
 * Permission is hereby granted, free of charge, to any person obtaining a
8
8
 * copy of this software and associated documentation files (the "Software"),
119
119
 * index/depth_span().
120
120
 */
121
121
static void
122
 
zoom_span( GLcontext *ctx, GLint imgX, GLint imgY, const struct sw_span *span,
 
122
zoom_span( GLcontext *ctx, GLint imgX, GLint imgY, const SWspan *span,
123
123
           const GLvoid *src, GLenum format )
124
124
{
125
 
   struct sw_span zoomed;
126
 
   struct span_arrays zoomed_arrays;  /* this is big! */
 
125
   SWspan zoomed;
 
126
   SWspanarrays zoomed_arrays;  /* this is big! */
127
127
   GLint x0, x1, y0, y1;
128
128
   GLint zoomedWidth;
129
129
 
144
144
   zoomed.x = x0;
145
145
   zoomed.end = zoomedWidth;
146
146
   zoomed.array = &zoomed_arrays;
 
147
   zoomed_arrays.ChanType = span->array->ChanType;
 
148
   /* XXX temporary */
 
149
#if CHAN_TYPE == GL_UNSIGNED_BYTE
 
150
   zoomed_arrays.rgba = zoomed_arrays.color.sz1.rgba;
 
151
   zoomed_arrays.spec = zoomed_arrays.color.sz1.spec;
 
152
#elif CHAN_TYPE == GL_UNSIGNED_SHORT
 
153
   zoomed_arrays.rgba = zoomed_arrays.color.sz2.rgba;
 
154
   zoomed_arrays.spec = zoomed_arrays.color.sz2.spec;
 
155
#else
 
156
   zoomed_arrays.rgba = zoomed_arrays.color.sz4.rgba;
 
157
   zoomed_arrays.spec = zoomed_arrays.color.sz4.spec;
 
158
#endif
 
159
 
147
160
 
148
161
   /* copy fog interp info */
149
162
   zoomed.fog = span->fog;
190
203
 
191
204
   /* zoom the span horizontally */
192
205
   if (format == GL_RGBA) {
193
 
      const GLchan (*rgba)[4] = (const GLchan (*)[4]) src;
194
 
      GLint i;
195
 
      for (i = 0; i < zoomedWidth; i++) {
196
 
         GLint j = unzoom_x(ctx->Pixel.ZoomX, imgX, x0 + i) - span->x;
197
 
         ASSERT(j >= 0);
198
 
         ASSERT(j < span->end);
199
 
         COPY_CHAN4(zoomed.array->rgba[i], rgba[j]);
 
206
      if (zoomed.array->ChanType == GL_UNSIGNED_BYTE) {
 
207
         const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) src;
 
208
         GLint i;
 
209
         for (i = 0; i < zoomedWidth; i++) {
 
210
            GLint j = unzoom_x(ctx->Pixel.ZoomX, imgX, x0 + i) - span->x;
 
211
            ASSERT(j >= 0);
 
212
            ASSERT(j < span->end);
 
213
            COPY_4UBV(zoomed.array->color.sz1.rgba[i], rgba[j]);
 
214
         }
 
215
      }
 
216
      else if (zoomed.array->ChanType == GL_UNSIGNED_SHORT) {
 
217
         const GLushort (*rgba)[4] = (const GLushort (*)[4]) src;
 
218
         GLint i;
 
219
         for (i = 0; i < zoomedWidth; i++) {
 
220
            GLint j = unzoom_x(ctx->Pixel.ZoomX, imgX, x0 + i) - span->x;
 
221
            ASSERT(j >= 0);
 
222
            ASSERT(j < span->end);
 
223
            COPY_4V(zoomed.array->color.sz2.rgba[i], rgba[j]);
 
224
         }
 
225
      }
 
226
      else {
 
227
         const GLfloat (*rgba)[4] = (const GLfloat (*)[4]) src;
 
228
         GLint i;
 
229
         for (i = 0; i < zoomedWidth; i++) {
 
230
            GLint j = unzoom_x(ctx->Pixel.ZoomX, imgX, x0 + i) - span->x;
 
231
            ASSERT(j >= 0);
 
232
            ASSERT(j < span->end);
 
233
            COPY_4V(zoomed.array->color.sz4.rgba[i], rgba[j]);
 
234
         }
200
235
      }
201
236
   }
202
237
   else if (format == GL_RGB) {
203
 
      const GLchan (*rgb)[3] = (const GLchan (*)[3]) src;
204
 
      GLint i;
205
 
      for (i = 0; i < zoomedWidth; i++) {
206
 
         GLint j = unzoom_x(ctx->Pixel.ZoomX, imgX, x0 + i) - span->x;
207
 
         ASSERT(j >= 0);
208
 
         ASSERT(j < span->end);
209
 
         zoomed.array->rgba[i][0] = rgb[j][0];
210
 
         zoomed.array->rgba[i][1] = rgb[j][1];
211
 
         zoomed.array->rgba[i][2] = rgb[j][2];
212
 
         zoomed.array->rgba[i][3] = CHAN_MAX;
 
238
      if (zoomed.array->ChanType == GL_UNSIGNED_BYTE) {
 
239
         const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) src;
 
240
         GLint i;
 
241
         for (i = 0; i < zoomedWidth; i++) {
 
242
            GLint j = unzoom_x(ctx->Pixel.ZoomX, imgX, x0 + i) - span->x;
 
243
            ASSERT(j >= 0);
 
244
            ASSERT(j < span->end);
 
245
            zoomed.array->color.sz1.rgba[i][0] = rgb[j][0];
 
246
            zoomed.array->color.sz1.rgba[i][1] = rgb[j][1];
 
247
            zoomed.array->color.sz1.rgba[i][2] = rgb[j][2];
 
248
            zoomed.array->color.sz1.rgba[i][3] = 0xff;
 
249
         }
 
250
      }
 
251
      else if (zoomed.array->ChanType == GL_UNSIGNED_SHORT) {
 
252
         const GLushort (*rgb)[3] = (const GLushort (*)[3]) src;
 
253
         GLint i;
 
254
         for (i = 0; i < zoomedWidth; i++) {
 
255
            GLint j = unzoom_x(ctx->Pixel.ZoomX, imgX, x0 + i) - span->x;
 
256
            ASSERT(j >= 0);
 
257
            ASSERT(j < span->end);
 
258
            zoomed.array->color.sz2.rgba[i][0] = rgb[j][0];
 
259
            zoomed.array->color.sz2.rgba[i][1] = rgb[j][1];
 
260
            zoomed.array->color.sz2.rgba[i][2] = rgb[j][2];
 
261
            zoomed.array->color.sz2.rgba[i][3] = 0xffff;
 
262
         }
 
263
      }
 
264
      else {
 
265
         const GLfloat (*rgb)[3] = (const GLfloat (*)[3]) src;
 
266
         GLint i;
 
267
         for (i = 0; i < zoomedWidth; i++) {
 
268
            GLint j = unzoom_x(ctx->Pixel.ZoomX, imgX, x0 + i) - span->x;
 
269
            ASSERT(j >= 0);
 
270
            ASSERT(j < span->end);
 
271
            zoomed.array->color.sz4.rgba[i][0] = rgb[j][0];
 
272
            zoomed.array->color.sz4.rgba[i][1] = rgb[j][1];
 
273
            zoomed.array->color.sz4.rgba[i][2] = rgb[j][2];
 
274
            zoomed.array->color.sz4.rgba[i][3] = 1.0F;
 
275
         }
213
276
      }
214
277
   }
215
278
   else if (format == GL_COLOR_INDEX) {
241
304
       * going to call _swrast_write_zoomed_span() more than once.
242
305
       * Also, clipping may change the span end value, so store it as well.
243
306
       */
244
 
      GLchan rgbaSave[MAX_WIDTH][4];
245
307
      const GLint end = zoomed.end; /* save */
 
308
      /* use specular color array for temp storage */
 
309
      void *rgbaSave = zoomed.array->spec;
 
310
      const GLint pixelSize =
 
311
         (zoomed.array->ChanType == GL_UNSIGNED_BYTE) ? 4 * sizeof(GLubyte) :
 
312
         ((zoomed.array->ChanType == GL_UNSIGNED_SHORT) ? 4 * sizeof(GLushort)
 
313
          : 4 * sizeof(GLfloat));
246
314
      if (y1 - y0 > 1) {
247
 
         MEMCPY(rgbaSave, zoomed.array->rgba, zoomed.end * 4 * sizeof(GLchan));
 
315
         MEMCPY(rgbaSave, zoomed.array->rgba, zoomed.end * pixelSize);
248
316
      }
249
317
      for (zoomed.y = y0; zoomed.y < y1; zoomed.y++) {
250
318
         _swrast_write_rgba_span(ctx, &zoomed);
251
319
         zoomed.end = end;  /* restore */
252
320
         if (y1 - y0 > 1) {
253
321
            /* restore the colors */
254
 
            MEMCPY(zoomed.array->rgba, rgbaSave, zoomed.end*4 * sizeof(GLchan));
 
322
            MEMCPY(zoomed.array->rgba, rgbaSave, zoomed.end * pixelSize);
255
323
         }
256
324
      }
257
325
   }
258
326
   else if (format == GL_COLOR_INDEX) {
259
 
      GLuint indexSave[MAX_WIDTH];
 
327
      /* use specular color array for temp storage */
 
328
      GLuint *indexSave = (GLuint *) zoomed.array->spec;
260
329
      const GLint end = zoomed.end; /* save */
261
330
      if (y1 - y0 > 1) {
262
331
         MEMCPY(indexSave, zoomed.array->index, zoomed.end * sizeof(GLuint));
274
343
 
275
344
 
276
345
void
277
 
_swrast_write_zoomed_rgba_span( GLcontext *ctx, GLint imgX, GLint imgY,
278
 
                               const struct sw_span *span,
279
 
                               CONST GLchan rgba[][4])
 
346
_swrast_write_zoomed_rgba_span(GLcontext *ctx, GLint imgX, GLint imgY,
 
347
                               const SWspan *span, const GLvoid *rgba)
280
348
{
281
 
   zoom_span(ctx, imgX, imgY, span, (const GLvoid *) rgba, GL_RGBA);
 
349
   zoom_span(ctx, imgX, imgY, span, rgba, GL_RGBA);
282
350
}
283
351
 
284
352
 
285
353
void
286
354
_swrast_write_zoomed_rgb_span(GLcontext *ctx, GLint imgX, GLint imgY,
287
 
                              const struct sw_span *span,
288
 
                              CONST GLchan rgb[][3])
 
355
                              const SWspan *span, const GLvoid *rgb)
289
356
{
290
 
   zoom_span(ctx, imgX, imgY, span, (const GLvoid *) rgb, GL_RGB);
 
357
   zoom_span(ctx, imgX, imgY, span, rgb, GL_RGB);
291
358
}
292
359
 
293
360
 
294
361
void
295
362
_swrast_write_zoomed_index_span(GLcontext *ctx, GLint imgX, GLint imgY,
296
 
                                const struct sw_span *span)
 
363
                                const SWspan *span)
297
364
{
298
365
   zoom_span(ctx, imgX, imgY, span,
299
366
             (const GLvoid *) span->array->index, GL_COLOR_INDEX);
302
369
 
303
370
void
304
371
_swrast_write_zoomed_depth_span(GLcontext *ctx, GLint imgX, GLint imgY,
305
 
                                const struct sw_span *span)
 
372
                                const SWspan *span)
306
373
{
307
374
   zoom_span(ctx, imgX, imgY, span,
308
375
             (const GLvoid *) span->array->z, GL_DEPTH_COMPONENT);