1 | /* $Id: clamp.c,v 1.2 2001-09-05 14:30:44 bird Exp $ */
|
---|
2 |
|
---|
3 | /*
|
---|
4 | ** THIS SOFTWARE IS SUBJECT TO COPYRIGHT PROTECTION AND IS OFFERED ONLY
|
---|
5 | ** PURSUANT TO THE 3DFX GLIDE GENERAL PUBLIC LICENSE. THERE IS NO RIGHT
|
---|
6 | ** TO USE THE GLIDE TRADEMARK WITHOUT PRIOR WRITTEN PERMISSION OF 3DFX
|
---|
7 | ** INTERACTIVE, INC. A COPY OF THIS LICENSE MAY BE OBTAINED FROM THE
|
---|
8 | ** DISTRIBUTOR OR BY CONTACTING 3DFX INTERACTIVE INC(info@3dfx.com).
|
---|
9 | ** THIS PROGRAM IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
|
---|
10 | ** EXPRESSED OR IMPLIED. SEE THE 3DFX GLIDE GENERAL PUBLIC LICENSE FOR A
|
---|
11 | ** FULL TEXT OF THE NON-WARRANTY PROVISIONS.
|
---|
12 | **
|
---|
13 | ** USE, DUPLICATION OR DISCLOSURE BY THE GOVERNMENT IS SUBJECT TO
|
---|
14 | ** RESTRICTIONS AS SET FORTH IN SUBDIVISION (C)(1)(II) OF THE RIGHTS IN
|
---|
15 | ** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 252.227-7013,
|
---|
16 | ** AND/OR IN SIMILAR OR SUCCESSOR CLAUSES IN THE FAR, DOD OR NASA FAR
|
---|
17 | ** SUPPLEMENT. UNPUBLISHED RIGHTS RESERVED UNDER THE COPYRIGHT LAWS OF
|
---|
18 | ** THE UNITED STATES.
|
---|
19 | **
|
---|
20 | ** COPYRIGHT 3DFX INTERACTIVE, INC. 1999, ALL RIGHTS RESERVED
|
---|
21 | **
|
---|
22 | ** $Revision: 1.2 $
|
---|
23 | ** $Date: 2001-09-05 14:30:44 $
|
---|
24 | */
|
---|
25 |
|
---|
26 | #include <stdio.h>
|
---|
27 | #include <stdlib.h>
|
---|
28 | #include <string.h>
|
---|
29 | #include <math.h>
|
---|
30 |
|
---|
31 | #include "texusint.h"
|
---|
32 |
|
---|
33 | static void _txImgClamp( FxU32 *out, int ox, int oy,
|
---|
34 | const FxU32 *in, int ix, int iy )
|
---|
35 | {
|
---|
36 | int x, y;
|
---|
37 |
|
---|
38 | if( txVerbose )
|
---|
39 | {
|
---|
40 | printf( "clamping from %dx%d to %dx%d\n",
|
---|
41 | ix, iy, ox, oy );
|
---|
42 | }
|
---|
43 |
|
---|
44 | for( y = 0; y < oy; y++ )
|
---|
45 | {
|
---|
46 | for( x = 0; x < ox; x++ )
|
---|
47 | {
|
---|
48 | out[y*ox+x] = in[ ( ( y < iy )? y : ( iy - 1 ) ) * ix + ( ( x < ix ) ? x : ( ix - 1 ) ) ];
|
---|
49 | }
|
---|
50 | }
|
---|
51 | }
|
---|
52 |
|
---|
53 | void txMipClamp( TxMip *dstMip, TxMip *srcMip )
|
---|
54 | {
|
---|
55 | int i, sw, sh, dw, dh;
|
---|
56 |
|
---|
57 | if( dstMip->format != srcMip->format )
|
---|
58 | {
|
---|
59 | txPanic( "Image formats must be the same in txMipClamp." );
|
---|
60 | }
|
---|
61 |
|
---|
62 | if( dstMip->format != GR_TEXFMT_ARGB_8888 )
|
---|
63 | {
|
---|
64 | txPanic( "txMipClamp only works on GR_TEXFMT_ARGB_8888 images." );
|
---|
65 | }
|
---|
66 |
|
---|
67 | if( ( dstMip->width == srcMip->width ) && ( dstMip->height == srcMip->height ) &&
|
---|
68 | ( dstMip->data[0] == srcMip->data[0] ) )
|
---|
69 | {
|
---|
70 | if( txVerbose )
|
---|
71 | {
|
---|
72 | printf("No Clamping necessary.\n");
|
---|
73 | }
|
---|
74 | return;
|
---|
75 | }
|
---|
76 |
|
---|
77 | if ((srcMip->data[0] == NULL) || (dstMip->data[0] == NULL))
|
---|
78 | txPanic("txImageClamp: Null buffer\n");
|
---|
79 |
|
---|
80 | sw = srcMip->width;
|
---|
81 | sh = srcMip->height;
|
---|
82 | dw = dstMip->width;
|
---|
83 | dh = dstMip->height;
|
---|
84 |
|
---|
85 | for( i = 0; i < srcMip->depth; i++ )
|
---|
86 | {
|
---|
87 | if( !dstMip->data[i] )
|
---|
88 | txPanic("txImageResize: no miplevel present\n");
|
---|
89 | _txImgClamp( dstMip->data[i], dw, dh,
|
---|
90 | srcMip->data[i], sw, sh );
|
---|
91 | if( txVerbose )
|
---|
92 | {
|
---|
93 | printf(" %dx%d", sw, sh); fflush(stdout);
|
---|
94 | }
|
---|
95 |
|
---|
96 | if (sw > 1) sw >>= 1;
|
---|
97 | if (sh > 1) sh >>= 1;
|
---|
98 | if (dw > 1) dw >>= 1;
|
---|
99 | if (dh > 1) dh >>= 1;
|
---|
100 | }
|
---|
101 | if( txVerbose )
|
---|
102 | {
|
---|
103 | printf(".\n");
|
---|
104 | }
|
---|
105 | }
|
---|
106 |
|
---|