|
|
1.1 root 1: #! /bin/sh
2:
1.1.1.2 ! root 3: # $Id: fb-xlat-auto.sh,v 1.9 2005/05/14 19:02:20 fredette Exp $
1.1 root 4:
5: # generic/fb-xlat-auto.sh - automatically generates C code
6: # for many framebuffer translation functions:
7:
8: #
1.1.1.2 ! root 9: # Copyright (c) 2003, 2005 Matt Fredette
1.1 root 10: # All rights reserved.
11: #
12: # Redistribution and use in source and binary forms, with or without
13: # modification, are permitted provided that the following conditions
14: # are met:
15: # 1. Redistributions of source code must retain the above copyright
16: # notice, this list of conditions and the following disclaimer.
17: # 2. Redistributions in binary form must reproduce the above copyright
18: # notice, this list of conditions and the following disclaimer in the
19: # documentation and/or other materials provided with the distribution.
20: # 3. All advertising materials mentioning features or use of this software
21: # must display the following acknowledgement:
22: # This product includes software developed by Matt Fredette.
23: # 4. The name of the author may not be used to endorse or promote products
24: # derived from this software without specific prior written permission.
25: #
26: # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
27: # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28: # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29: # DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
30: # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31: # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
32: # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33: # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
34: # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35: # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36: # POSSIBILITY OF SUCH DAMAGE.
37: #
38:
39: # this script generates one or more C functions. each function
40: # translates an image from a source image format into a destination
41: # image format, optionally halving or doubling the image size in the
42: # process.
43: #
44: # the source and destination image formats are represented by "keys",
45: # strings that describe the different attributes of a format.
46: #
1.1.1.2 ! root 47: # a source image format key has the form: WxHdDbBsSpPoO[cC][mMS][_rR_gG_bB][_X]
1.1 root 48: #
1.1.1.2 ! root 49: # a destination image format key has the form: dDbBsSpPoO[mM][_rR_gG_bB]
1.1 root 50: #
51: # all of the lowercase letters and underscores are literals, and all
52: # of the uppercase letters represent attribute values. the different
53: # attributes are:
54: #
55: # W is the width of the source image. if zero, the generated function
56: # will be able to translate source images of any width, but it will be
57: # suboptimal. if nonzero, the generated function will only be able to
58: # translate source images of that width, but it will have some
59: # optimization. this attribute is only used in source keys, since the
60: # destination width is always the scaled source width.
61: #
62: # H is the height of the source image. if zero, the generated
63: # function will be able to translate source images of any height, but
64: # it will be suboptimal. if nonzero, the generated function will only
65: # be able to translate source images of that height, but it will have
66: # some optimization. this attribute is only used in source keys,
67: # since the destination height is always the scaled source height.
68: #
69: # D is the color (d)epth, in bits, of the source/destination image.
70: # if zero, the generated function will be able to handle
71: # source/destination images of any depth, but it will be suboptimal.
72: # if nonzero, the generated function will only be able to handle
73: # source/destination images of that depth, but it will have some
74: # optimization.
75: #
76: # B is the (b)its-per-pixel of the source/destination image. this
77: # must be at least as large as the depth, and it may be larger. if
78: # zero, the generated function will be able to handle
79: # source/destination images of any bits-per-pixel, but it will be
80: # suboptimal. if nonzero, the generated function will only be able to
81: # handle source/destination images of that bits-per-pixel, but it will
82: # have some optimization.
83: #
84: # S is the (s)kip-x-bits of the source/destination image. this is the
85: # number of bits at the beginning of each image scanline that are not
86: # displayed. if an underscore, the generated function will be able to
87: # handle source/destination images with any skip-x-bits, but it will
88: # be suboptimal. if not an underscore, the generated function will
89: # only be able to handle source/destination images with that many
90: # skip-x-bits, but it will have some optimization.
91: #
92: # P is the (p)adding of the source/destination image. this is how
93: # many bits each image scanline is padded to. if zero, the generated
94: # function will be able to handle source/destination images with any
95: # padding, but it will be suboptimal. if nonzero, the generated
96: # function will only be able to handle source/destination images with
97: # that padding, but it will have some optimization.
98: #
99: # O is the byte and bit (o)rder of the source/destination image. this
100: # is always m or l for most- or least-significant, respectively.
101: # there is no "any" wildcard value. this script cannot handle image
102: # formats where a word-unit of pixels has one order for its bytes in
103: # memory, but the opposite order for its pixels within the word-unit.
104: #
1.1.1.2 ! root 105: # C is the optional class. it is 'm' for a monochrome (grayscale) image,
! 106: # and 'c' for a color image. if not given, an image with a depth of
! 107: # one is considered monochrome, and any other image is considered color.
! 108: #
! 109: # M is the optional mapping type. it is 'l' for a monochrome image
! 110: # that linearly maps pixels into intensities and for a color image
! 111: # that linearly maps pixel subfields into intensities. it is 'i' for
! 112: # images that index pixels or pixel subfields into intensities. if
! 113: # not given, monochrome images and color images with subfields are
! 114: # assumed to be linear, and color images without subfields are assumed
! 115: # to be indexed.
! 116: #
! 117: # S is the optional mapping size. if the mapping type is given, this
! 118: # must be given, and it is the size of the mapping range - i.e., the
! 119: # number of bits per intensity. if the mapping type is not given, and
! 120: # the image is linearly mapped monochrome, the mapping size is assumed
! 121: # to be the same as the image depth.
! 122: #
! 123: # R, G, and B are the optional subfield masks. if an image's pixels
! 124: # can be decomposed into subfields for red, green, and blue, these are
! 125: # the masks for the subfields.
! 126: #
1.1 root 127: # X is the optional scaling. it is `h' to halve the source image,
128: # or `d' to double it. this attribute is only used in source keys.
129:
130: # this script generates a set of functions for the product of all
131: # source image formats and all destination image formats.
132: #
133: # "all source image formats" includes all source image formats given
134: # on the command line, plus:
135: #
136: # the "any" source image format, unscaled
137: # the "any" source image format, halved
138: # the "any" source image format, doubled
139: #
140: # "all destination image formats" includes all destination
141: # image formats given on the command line, plus:
142: #
143: # the "any" destination image format
144: #
145: src_all=
146: dst_all=
147: for order in m l; do
1.1.1.2 ! root 148: src_key="0x0d0b0s_p0o${order}_r0x0_g0x0_b0x0"
1.1 root 149: src_all="${src_all} ${src_key} ${src_key}_h ${src_key}_d"
1.1.1.2 ! root 150: dst_all="${dst_all} d0b0s_p0o${order}_r0x0_g0x0_b0x0"
1.1 root 151: done
152:
153: which=
154: for arg
155: do
156: case $arg in
157: src|dst) which=$arg ;;
158: *)
159: if test "x${which}" != x; then
160: eval "${which}_all=\"$arg \$${which}_all\""
161: fi
162: ;;
163: esac
164: done
165:
166: PROG=`basename $0`
167: cat <<EOF
168: /* automatically generated by $PROG, do not edit! */
169:
170: /*
1.1.1.2 ! root 171: * Copyright (c) 2003, 2005 Matt Fredette
1.1 root 172: * All rights reserved.
173: *
174: * Redistribution and use in source and binary forms, with or without
175: * modification, are permitted provided that the following conditions
176: * are met:
177: * 1. Redistributions of source code must retain the above copyright
178: * notice, this list of conditions and the following disclaimer.
179: * 2. Redistributions in binary form must reproduce the above copyright
180: * notice, this list of conditions and the following disclaimer in the
181: * documentation and/or other materials provided with the distribution.
182: * 3. All advertising materials mentioning features or use of this software
183: * must display the following acknowledgement:
184: * This product includes software developed by Matt Fredette.
185: * 4. The name of the author may not be used to endorse or promote products
186: * derived from this software without specific prior written permission.
187: *
188: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
189: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
190: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
191: * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
192: * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
193: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
194: * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
195: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
196: * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
197: * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
198: * POSSIBILITY OF SUCH DAMAGE.
199: */
200:
1.1.1.2 ! root 201: _TME_RCSID("\$Id: fb-xlat-auto.sh,v 1.9 2005/05/14 19:02:20 fredette Exp $");
1.1 root 202:
203: /* the central feature of these translation functions is the "bit
204: FIFO", a first-in, first-out stream of bits. source bit FIFOs are
205: used to read pixel bits out of source images, and destination bit
206: FIFOs are used to write pixel bits into destination images.
207:
208: a bit FIFO has a visible part and an invisible part.
209:
210: the visible part of a bit FIFO is 32 bits wide, meaning the
211: translation code can read (for a source bit FIFO) or write (for a
212: destination bit FIFO) up to 32 bits of pixel data before a bit
213: FIFO shift.
214:
215: the invisible part of a source bit FIFO contains pixel bits that
216: have already been read from the source image memory, but that have
217: yet to be shifted in to the visible part.
218:
219: the invisible part of a destination bit FIFO contains the pixel
220: bits that have been shifted out of the visible part, but that have
221: yet to be written to the destination image memory.
222:
223: depending on various attributes of an image format, it may be
224: possible for the translation code to always read or write the
225: entire 32 visible bits of a bit FIFO at a time, and as a result
226: always shift the bit FIFO 32 bits at a time. this is desirable
227: because it minimizes bit FIFO shifts.
228:
229: when this does happen, it may also be the case that the visible
230: part of the bit FIFO always perfectly corresponds to an aligned
231: 32-bit word in the image buffer.
232:
233: this is the optimal situation, as it makes it unnecessary to track
234: the invisible part in C local variables at all - each 32-bit FIFO
235: shift of a source bit FIFO just reads the next 32-bit word directly
236: into the visible part, and each 32-bit FIFO shift of a destination
237: bit FIFO just writes the next 32-bit word directly out of the
238: visible part.
239:
240: within the visible part of a bit FIFO, which bits belong to which
241: pixels depends on the "order" of the image format. most-significant
242: (big-endian) images have earlier (more to the left on the screen)
243: pixels in more-significant bit positions. least-significant
244: (little-endian) images have earlier pixels in less-significant bit
245: bit positions.
246:
247: bit significance *within* a pixel never depends on image order.
248: once the bits belonging to a pixel have been identified according
249: to image order, the least significant bit in that pixel's value is
250: always the bit with the least absolute value.
251:
252: some pictures may help explain this better. each picture shows the
253: 32 bit visible part of a bit FIFO, with the bits marked from 0
254: (least significant) to 31 (most significant). all of these
255: examples are for a two-bit-deep/two-bits-per-pixel image, and in
256: the visible part sixteen pixels are numbered. lesser numbered
257: pixels are earlier (more to the left on the screen). some of the
258: invisible part is also shown, along with the direction that the bit
259: FIFO shifts in:
260:
261: a source bit FIFO for a little-endian source image with two bits
262: per pixel looks like:
263:
264: |
265: | 31 30 29 28 7 6 5 4 3 2 1 0
266: --+--+--+--+--+--+|+--+--+--+--+- --+--+--+--+--+--+--+--+
267: .. p18 | p17 | p16 ||| p15 | p14 | .. p3 | p2 | p1 | p0 |
268: --+--+--+--+--+--+|+--+--+--+--+- --+--+--+--+--+--+--+--+
269: |
270: invisible part | visible part
271:
272: shift -> shift -> shift -> shift -> shift ->
273:
274: a source bit FIFO for a big-endian source image with two bits per
275: pixel looks like:
276:
277: |
278: 31 30 29 28 27 26 25 26 4 3 2 1 0 |
279: +--+--+--+--+--+--+--+-- -+--+--+--+--+|+--+--+--+--+--+--
280: | p0 | p1 | p2 | p3 .. | p14 | p15 ||| p16 | p17 | p18 ..
281: +--+--+--+--+--+--+--+-- -+--+--+--+--+|+--+--+--+--+--+--
282: |
283: visible part | invisible part
284:
285: <- shift <- shift <- shift <- shift <- shift
286:
287: a destination bit FIFO for a little-endian destination image with
288: two bits per pixel looks like:
289:
290: |
291: 31 30 29 28 27 26 25 26 4 3 2 1 0 |
292: +--+--+--+--+--+--+--+-- -+--+--+--+--+|+--+--+--+--+--+--
293: | p23 | p22 | p21 | p20 .. | p9 | p8 ||| p7 | p6 | p5 ..
294: +--+--+--+--+--+--+--+-- -+--+--+--+--+|+--+--+--+--+--+--
295: |
296: visible part | invisible part
297:
298: shift -> shift -> shift -> shift -> shift ->
299:
300: a destination bit FIFO for a big-endian destination image with
301: two bits per pixel looks like:
302:
303: |
304: | 31 30 29 28 7 6 5 4 3 2 1 0
305: --+--+--+--+--+--+|+--+--+--+--+- --+--+--+--+--+--+--+--+
306: .. p5 | p6 | p7 ||| p8 | p9 | .. p20 | p21 | p22 | p23 |
307: --+--+--+--+--+--+|+--+--+--+--+- --+--+--+--+--+--+--+--+
308: |
309: invisible part | visible part
310:
311: <- shift <- shift <- shift <- shift <- shift
312:
313: each translation function has at least one source bit FIFO and at
314: least one destination bit FIFO. the general idea is to read source
315: pixel value(s) from the source image, map those source pixel
316: value(s) somehow into destination pixel value(s), and write those
317: destination pixel value(s) to the destination image.
318:
319: translation functions that do not scale the image have exactly one
320: source bit FIFO and exactly one destination bit FIFO. one pixel
321: read from the source bit FIFO becomes one pixel written to the
322: destination bit FIFO.
323:
324: translation functions that halve the image size have two source bit
325: FIFOs and one destination bit FIFO. one source bit FIFO sources
326: bits from an even-numbered scanline, and the other sources bits from
327: an odd-numbered scanline. four pixels read from the source bit
328: FIFOs - two from each source bit FIFO, making a 2x2 square - become
329: one pixel written to the destination bit FIFO.
330:
331: translation functions that double the image size have one source
332: bit FIFO and two destination bit FIFOs. one destination bit FIFO
333: sinks bits for an even-numbered scanline, and the other sinks bits
334: for an odd-numbered scanline. one pixel read from the source bit
335: FIFO becomes four pixels written to the destination bit FIFOs -
336: two to each destination bit FIFO, making a 2x2 square.
337:
338: translation functions don't necessarily always translate the entire
339: source image into the entire destination image. instead, the buffer
340: holding the current source image is expected to be twice as large as
341: necessary (plus some overhead), with the second half of the buffer
342: holding a copy of the last translated ("old") source image.
343:
344: before setting up and translating pixels using bit FIFOs, a
345: translation function treats the the current and old source images as
346: an array of aligned 32-bit words and compares them. if it finds no
347: 32-bit word that has changed, no translation is done and the
348: function returns.
349:
350: otherwise, initial source pixel x and y coordinates are derived from
351: the offset of the 32-bit word that failed comparison, and the source
352: primary bit FIFO is primed. if this translation function halves the
353: image size, the source secondary bit FIFO is primed from the same x
354: coordinate on the "other" (think y ^ 1) scanline.
355:
356: then, initial destination pixel x and y coordinates are derived from
357: the initial source x and y coordinates, and the destination primary
358: bit FIFO is primed. if this translation function doubles the image
359: size, the destination secondary bit FIFO is primed from the same x
360: coordinate on the "other" (think y ^ 1) scanline.
361:
362: as mentioned previously, the buffer holding the current source image
363: is expected to be twice as large as necessary (plus some overhead),
364: with the second half of the buffer holding a copy of the last
365: translated ("old") source image.
366:
367: this "overhead" is approximately two extra scanlines worth of data,
368: that is initialized to all-bits-zero and must always remain zero.
369: this extra data is present at the end of both the current ("new")
370: and last translated ("old") source images.
371:
372: these extra, always-blank scanlines guarantee that the pixel
373: translation loop terminates. the pixel translation loop *never*
374: checks for the end of the image buffer. instead, it terminates only
375: after it has read in TME_FB_XLAT_RUN consecutive aligned 32-bit
376: words that have *not* changed between the new and old source images.
377: this small amount of extra memory overhead simplifies the pixel
378: translation loop, because it doesn't have to worry about going past
379: the end of the actual image.
380: */
381:
382:
383: /* macros: */
384:
385: /* given a 32-bit aligned pointer into the current source image, this
386: returns the corresponding 32-bit aligned pointer in the last
387: translated ("old") source image. since the old source image
388: follows the current source image, this is simple pointer arithmetic
389: using src_bypb: */
390: #define TME_FB_XLAT_SRC_OLD(raw) \\
391: ((tme_uint32_t *) (((tme_uint8_t *) (raw)) + src_bypb))
392:
393: /* when the fast, aligned 32-bit word comparison loop finds a word
394: that has changed in the source image, pixels are translated until
395: TME_FB_XLAT_RUN consecutive aligned 32-bit words are processed that
396: have *not* changed in the source image, at which point the fast
397: comparison loop resumes.
398:
399: the idea is that after you've started translating pixels, once the
400: FIFO shift operation has read TME_FB_XLAT_RUN consecutive raw,
401: unchanged 32-bit words, all of the pixels from previous, changed
402: 32-bit words have been translated and shifted out of the source bit
403: FIFO(s), and all bits remaining in the source bit FIFO(s) are for
404: pixels in those unchanged 32-bit words. since the pixels are
405: unchanged, pixel translation can stop, and the entire state of the
406: source bit FIFO(s) can be discarded.
407:
408: so, each time a raw, changed 32-bit word is read, xlat_run is
409: reloaded with TME_FB_XLAT_RUN, and each time 32 bits worth of
410: source image pixels are processed, it is decremented. when it
411: reaches zero, the source bit FIFO(s) are discarded, the destination
412: bit FIFO(s) are flushed, the pixel translation loop breaks and the
413: fast comparison loop continues: */
414: #define TME_FB_XLAT_RUN (2)
415:
416: /* this shifts a source FIFO: */
417: #define TME_FB_XLAT_SHIFT_SRC(unaligned, fifo, next, bits, shift, raw, order)\\
418: do { \\
419: \\
420: /* if the source FIFO may not be 32-bit aligned: */ \\
421: if (unaligned) { \\
422: \\
423: /* we must be shifting between 1 and 32 bits: */ \\
424: assert ((shift) >= 1 && (shift) <= 32); \\
425: \\
426: /* the FIFO must have more than 32 bits in it already: */ \\
427: assert (bits > 32); \\
428: \\
429: /* shift the FIFO: */ \\
430: if ((shift) == 32) { \\
431: fifo = next; \\
432: } \\
433: else if (order == TME_ENDIAN_BIG) { \\
434: fifo = (fifo << ((shift) & 31)) | (next >> (32 - (shift)));\\
435: next <<= ((shift) & 31); \\
436: } \\
437: else { \\
438: fifo = (fifo >> ((shift) & 31)) | (next << (32 - (shift)));\\
439: next >>= ((shift) & 31); \\
440: } \\
441: bits -= (shift); \\
442: \\
443: /* if we have a new 32-bit word to read: */ \\
444: if (bits <= 32) { \\
445: next = *raw; \\
446: if (*TME_FB_XLAT_SRC_OLD(raw) != next) { \\
447: *TME_FB_XLAT_SRC_OLD(raw) = next; \\
448: xlat_run = TME_FB_XLAT_RUN; \\
449: } \\
450: raw++; \\
451: next = (order == TME_ENDIAN_BIG \\
452: ? tme_betoh_u32(next) \\
453: : tme_letoh_u32(next)); \\
454: \\
455: /* before the load, if there were fewer than 32 bits \\
456: remaining in the FIFO, shift bits from the word \\
457: we just loaded into their proper positions: */ \\
458: if (bits < 32) { \\
459: if (order == TME_ENDIAN_BIG) { \\
460: fifo |= (next >> bits); \\
461: next <<= (32 - bits); \\
462: } \\
463: else { \\
464: fifo |= (next << bits); \\
465: next >>= (32 - bits); \\
466: } \\
467: } \\
468: \\
469: /* there are now 32 more bits in the FIFO: */ \\
470: bits += 32; \\
471: } \\
472: } \\
473: \\
474: /* otherwise, if the source FIFO is always 32-bit aligned: */ \\
475: else { \\
476: \\
477: /* we must be shifting exactly 32 bits: */ \\
478: assert((shift) == 32); \\
479: \\
480: /* load the next 32-bit word: */ \\
481: fifo = *raw; \\
482: if (*TME_FB_XLAT_SRC_OLD(raw) != fifo) { \\
483: *TME_FB_XLAT_SRC_OLD(raw) = fifo; \\
484: xlat_run = TME_FB_XLAT_RUN; \\
485: } \\
486: raw++; \\
487: fifo = (order == TME_ENDIAN_BIG \\
488: ? tme_betoh_u32(fifo) \\
489: : tme_letoh_u32(fifo)); \\
490: } \\
491: } while (/* CONSTCOND */ 0)
492:
493: /* this shifts a destination FIFO: */
494: #define TME_FB_XLAT_SHIFT_DST(unaligned, fifo, next, bits, shift, raw, order)\\
495: do { \\
496: \\
497: /* if the destination FIFO may not be 32-bit aligned: */ \\
498: if (unaligned) { \\
499: \\
500: /* we must be shifting between 1 and 32 bits: */ \\
501: assert ((shift) >= 1 && (shift) <= 32); \\
502: \\
503: /* the FIFO must have fewer than 32 bits in it: */ \\
504: assert (bits < 32); \\
505: \\
506: /* shift the FIFO: */ \\
507: if (order == TME_ENDIAN_BIG) { \\
508: next |= (fifo >> bits); \\
509: fifo <<= (32 - bits); \\
510: } \\
511: else { \\
512: next |= (fifo << bits); \\
513: fifo >>= (32 - bits); \\
514: } \\
515: bits += (shift); \\
516: \\
517: /* if we have a completed 32-bit word to write: */ \\
518: if (bits >= 32) { \\
519: *(raw++) = (order == TME_ENDIAN_BIG \\
520: ? tme_htobe_u32(next) \\
521: : tme_htole_u32(next)); \\
522: bits -= 32; \\
523: assert(bits != 0 || fifo == 0); \\
524: next = fifo; \\
525: } \\
526: } \\
527: \\
528: /* the destination FIFO is always 32-bit aligned: */ \\
529: else { \\
530: \\
531: /* we must be shifting exactly 32 bits: */ \\
532: assert((shift) == 32); \\
533: \\
534: /* store the next 32-bit word: */ \\
535: *(raw++) = (order == TME_ENDIAN_BIG \\
536: ? tme_htobe_u32(fifo) \\
537: : tme_htole_u32(fifo)); \\
538: \\
539: } \\
540: \\
541: /* clear the writable part of the FIFO: */ \\
542: fifo = 0; \\
543: } while (/* CONSTCOND */ 0)
1.1.1.2 ! root 544:
! 545: /* _TME_FB_XLAT_MAP_LINEAR_SCALE gives the factor needed to scale a
! 546: masked value up or down to a given size in bits. for example, if a
! 547: value's mask is 0xf800 (a five bit mask), and the value needs to be
! 548: scaled up to seven bits, this gives an factor of four. if a
! 549: value's mask is 0x7e0 (a six bit mask), and the value needs to be
! 550: scaled down to three bits, this gives a factor of eight: */
! 551: #define _TME_FB_XLAT_MAP_LINEAR_SCALE(mask_in, mask_out) \\
! 552: (TME_FB_XLAT_MAP_BASE_MASK(mask_in) \\
! 553: ^ TME_FB_XLAT_MAP_BASE_MASK(mask_out))
! 554: #define TME_FB_XLAT_MAP_LINEAR_SCALE(mask_in, mask_out) \\
! 555: (_TME_FB_XLAT_MAP_LINEAR_SCALE(mask_in, mask_out) \\
! 556: ? (TME_FB_XLAT_MAP_BASE_MASK(_TME_FB_XLAT_MAP_LINEAR_SCALE(mask_in, mask_out))\\
! 557: + 1) \\
! 558: : 1)
! 559:
! 560: /* this linearly maps a value from one mask to another: */
! 561: #define _TME_FB_XLAT_MAP_LINEAR(value, mask_in, mask_out) \\
! 562: \\
! 563: /* if the value does not need to be scaled up: */ \\
! 564: (((TME_FB_XLAT_MAP_BASE_MASK(mask_out) \\
! 565: <= TME_FB_XLAT_MAP_BASE_MASK(mask_in)) \\
! 566: ? \\
! 567: \\
! 568: /* extract the value and scale it down: */ \\
! 569: (TME_FIELD_MASK_EXTRACTU(value, mask_in) \\
! 570: / TME_FB_XLAT_MAP_LINEAR_SCALE(mask_in, mask_out)) \\
! 571: \\
! 572: /* otherwise, the value needs to be scaled up: */ \\
! 573: : \\
! 574: \\
! 575: /* extract the value: */ \\
! 576: ((TME_FIELD_MASK_EXTRACTU(value, mask_in) \\
! 577: \\
! 578: /* scale it up: */ \\
! 579: * TME_FB_XLAT_MAP_LINEAR_SCALE(mask_in, mask_out)) \\
! 580: \\
! 581: /* if the least significant bit of the value is set, add \\
! 582: in the scale minus one. this makes the linear mapping \\
! 583: at least cover the entire range: */ \\
! 584: + (((value / \\
! 585: _TME_FIELD_MASK_FACTOR(mask_in)) \\
! 586: & 1) \\
! 587: * (TME_FB_XLAT_MAP_LINEAR_SCALE(mask_in, mask_out) \\
! 588: - 1)))) \\
! 589: \\
! 590: /* finally, shift the value into position: */ \\
! 591: * _TME_FIELD_MASK_FACTOR(mask_out))
! 592:
! 593: /* this indexes a value: */
! 594: #define _TME_FB_XLAT_MAP_INDEX(value, mask_out, index) \\
! 595: \\
! 596: /* intensities are either stored as 8 or 16 bits: */ \\
! 597: (((TME_FB_XLAT_MAP_BASE_MASK(mask_out) <= 0xff) \\
! 598: ? ((const tme_uint8_t *) (index))[(value)] \\
! 599: : ((const tme_uint16_t *) (index))[(value)]) \\
! 600: \\
! 601: /* shift the value into position: */ \\
! 602: * _TME_FIELD_MASK_FACTOR(mask_out))
! 603:
! 604: /* this maps one subfield or intensity value into another subfield or
! 605: intensity value: */
! 606: #define TME_FB_XLAT_MAP(value, mask_in, mask_out, indexed, index)\\
! 607: \\
! 608: /* do the linear mapping or the index mapping: */ \\
! 609: ((!(indexed)) \\
! 610: ? _TME_FB_XLAT_MAP_LINEAR(value, mask_in, mask_out) \\
! 611: : _TME_FB_XLAT_MAP_INDEX(TME_FIELD_MASK_EXTRACTU(value, mask_in), mask_out, index))
1.1 root 612: EOF
613:
614: # the next function number:
615: xlat_next=0
616: xlat_array=
617:
618: # permute over the source possibilities:
619: for src_key in ${src_all}; do
620:
621: # take apart the source possibility:
622: src_parts=${src_key}
623:
624: # get the width:
625: width=`echo ${src_parts} | sed -e 's/^\([0-9][0-9]*\)\(.*\)$/\1/'`
626: src_parts=`echo ${src_parts} | sed -e 's/^\([0-9][0-9]*\)\(.*\)$/\2/'`
627:
628: # get the height:
629: height=`echo ${src_parts} | sed -e 's/^x\([0-9][0-9]*\)\(.*\)$/\1/'`
630: src_parts=`echo ${src_parts} | sed -e 's/^x\([0-9][0-9]*\)\(.*\)$/\2/'`
631:
632: # get the source depth:
633: src_depth=`echo ${src_parts} | sed -e 's/^d\([0-9][0-9]*\)\(.*\)$/\1/'`
634: src_parts=`echo ${src_parts} | sed -e 's/^d\([0-9][0-9]*\)\(.*\)$/\2/'`
635:
636: # get the source bits per pixel:
637: src_bipp=`echo ${src_parts} | sed -e 's/^b\([0-9][0-9]*\)\(.*\)$/\1/'`
638: src_parts=`echo ${src_parts} | sed -e 's/^b\([0-9][0-9]*\)\(.*\)$/\2/'`
639:
640: # get the source skip pixel count:
641: src_skipx=`echo ${src_parts} | sed -e 's/^s\([_0-9][0-9]*\)\(.*\)$/\1/'`
642: src_parts=`echo ${src_parts} | sed -e 's/^s\([_0-9][0-9]*\)\(.*\)$/\2/'`
643:
644: # get the source scanline pad:
645: src_pad=`echo ${src_parts} | sed -e 's/^p\([0-9][0-9]*\)\(.*\)$/\1/'`
646: src_parts=`echo ${src_parts} | sed -e 's/^p\([0-9][0-9]*\)\(.*\)$/\2/'`
647:
648: # get the source "order" - i.e., byte order and leftmost (first)
649: # pixel significance:
650: src_order=`echo ${src_parts} | sed -e 's/^o\([ml]\)\(.*\)$/\1/'`
651: src_parts=`echo ${src_parts} | sed -e 's/^o\([ml]\)\(.*\)$/\2/'`
652:
1.1.1.2 ! root 653: # get the optional source "class" - monochrome or color:
! 654: src_class=`echo ${src_parts} | sed -e 's/^c\([mc]\)\(.*\)$/\1/'`
! 655: if test "x${src_class}" = "x${src_parts}"; then src_class= ; fi
! 656: src_parts=`echo ${src_parts} | sed -e 's/^c\([mc]\)\(.*\)$/\2/'`
! 657:
! 658: # get the optional source pixel mapping - linear or indexed, and
! 659: # the optional number of bits in the map range:
! 660: src_map=`echo ${src_parts} | sed -e 's/^m\([li]\)\([0-9]*\)\(.*\)$/\1/'`
! 661: src_map_bits=`echo ${src_parts} | sed -e 's/^m\([li]\)\([0-9]*\)\(.*\)$/\2/'`
! 662: if test "x${src_map}" = "x${src_parts}"; then src_map= ; src_map_bits= ; fi
! 663: src_parts=`echo ${src_parts} | sed -e 's/^m\([li]\)\([0-9]*\)\(.*\)$/\3/'`
! 664:
! 665: # get the optional source pixel subfield masks:
! 666: src_mask_g= ; src_mask_r= ; src_mask_b=
! 667: while true; do
! 668: src_mask=`echo ${src_parts} | sed -e 's/^\(_[rgb]\)\(0x[0-9A-Fa-f][0-9A-Fa-f]*\)\(.*\)$/src_mask\1=\2/'`
! 669: if test "x${src_mask}" = "x${src_parts}"; then break; fi
! 670: eval ${src_mask}
! 671: src_parts=`echo ${src_parts} | sed -e 's/^\(_[rgb]\)\(0x[0-9A-Fa-f][0-9A-Fa-f]*\)\(.*\)$/\3/'`
! 672: done
! 673:
1.1 root 674: # get the source scaling:
675: scale="${src_parts}_"
676:
1.1.1.2 ! root 677: # if the source class is not given, but the source depth is
! 678: # known, assume monochrome if the source depth is one, else
! 679: # assume color:
! 680: #
! 681: if test "x${src_class}" = x; then
! 682: case "${src_depth}" in
! 683: 0) src_class= ;;
! 684: 1) src_class=m ;;
! 685: *) src_class=c ;;
! 686: esac
! 687: fi
! 688:
! 689: # if the source mapping type is not given:
! 690: #
! 691: if test "x${src_map}" = x; then
! 692:
! 693: # if the source class is known as color:
! 694: #
! 695: if test "x${src_class}" = "xc"; then
! 696:
! 697: # if it is known that there are not any subfield masks, assume an indexed
! 698: # mapping, else if it is known that there are subfield masks, assume a
! 699: # linear mapping:
! 700: #
! 701: case "x${src_mask_r}" in
! 702: x0x0) ;;
! 703: x) src_map=i ;;
! 704: *) src_map=l ;;
! 705: esac
! 706:
! 707: # if the source class is known as monochrome:
! 708: #
! 709: elif test "x${src_class}" = "xm"; then
! 710:
! 711: # assume a linear mapping:
! 712: #
! 713: src_map=l
! 714: fi
! 715: fi
! 716:
! 717: # if the size of the source mapping range in bits is not given:
! 718: #
! 719: if test "x${src_map_bits}" = x; then
! 720:
! 721: # if the source class is known as mono and the source mapping
! 722: # type is known as linear, assume that the source depth is the
! 723: # size of the mapping range in bits:
! 724: #
! 725: if test "x${src_class}" = xm && test "x${src_map}" = xl; then
! 726: src_map_bits=${src_depth}
! 727:
! 728: # otherwise, set the size of the mapping range to zero to indicate
! 729: # unknown:
! 730: #
! 731: else
! 732: src_map_bits=0
! 733: fi
! 734: fi
! 735:
1.1 root 736: # permute over the destination possibilities:
737: for dst_key in ${dst_all}; do
738:
739: # take apart the destination possibility:
740: dst_parts=${dst_key}
741:
742: # get the destination depth:
743: dst_depth=`echo ${dst_parts} | sed -e 's/^d\([0-9][0-9]*\)\(.*\)$/\1/'`
744: dst_parts=`echo ${dst_parts} | sed -e 's/^d\([0-9][0-9]*\)\(.*\)$/\2/'`
745:
746: # get the destination bits per pixel:
747: dst_bipp=`echo ${dst_parts} | sed -e 's/^b\([0-9][0-9]*\)\(.*\)$/\1/'`
748: dst_parts=`echo ${dst_parts} | sed -e 's/^b\([0-9][0-9]*\)\(.*\)$/\2/'`
749:
750: # get the destination skip pixel count:
751: dst_skipx=`echo ${dst_parts} | sed -e 's/^s\([_0-9][0-9]*\)\(.*\)$/\1/'`
752: dst_parts=`echo ${dst_parts} | sed -e 's/^s\([_0-9][0-9]*\)\(.*\)$/\2/'`
753:
754: # get the destination scanline pad:
755: dst_pad=`echo ${dst_parts} | sed -e 's/^p\([0-9][0-9]*\)\(.*\)$/\1/'`
756: dst_parts=`echo ${dst_parts} | sed -e 's/^p\([0-9][0-9]*\)\(.*\)$/\2/'`
757:
758: # get the destination "order" - i.e., byte order and leftmost
759: # (first) pixel significance:
760: dst_order=`echo ${dst_parts} | sed -e 's/^o\([ml]\)\(.*\)$/\1/'`
761: dst_parts=`echo ${dst_parts} | sed -e 's/^o\([ml]\)\(.*\)$/\2/'`
762:
1.1.1.2 ! root 763: # get the optional destination pixel mapping - linear or indexed:
! 764: dst_map=`echo ${dst_parts} | sed -e 's/^m\([li]\)\(.*\)$/\1/'`
! 765: if test "x${dst_map}" = "x${dst_parts}"; then dst_map= ; fi
! 766: dst_parts=`echo ${dst_parts} | sed -e 's/^m\([li]\)\(.*\)$/\2/'`
! 767:
! 768: # get the optional destination pixel subfield masks:
! 769: dst_mask_g= ; dst_mask_r= ; dst_mask_b=
! 770: while true; do
! 771: dst_mask=`echo ${dst_parts} | sed -e 's/^\(_[rgb]\)\(0x[0-9A-Fa-f][0-9A-Fa-f]*\)\(.*\)$/dst_mask\1=\2/'`
! 772: if test "x${dst_mask}" = "x${dst_parts}"; then break; fi
! 773: eval ${dst_mask}
! 774: dst_parts=`echo ${dst_parts} | sed -e 's/^\(_[rgb]\)\(0x[0-9A-Fa-f][0-9A-Fa-f]*\)\(.*\)$/\3/'`
! 775: done
1.1 root 776:
777: # allocate the xlat number:
778: xlat=${xlat_next}
779: xlat_next=`expr ${xlat_next} + 1`
780: xlat_info="tme_fb_xlat${xlat}"
781:
782: # start the function:
783: echo ""
784: echo "/* this translates frame buffer contents from this source format:"
785: case "${width}x${height}" in
786: 0x0) echo -n " any dimensions" ;;
787: *x0) echo -n " width $width, any height" ;;
788: 0x*) echo -n " any width, height ${height}" ;;
789: *) echo -n " ${width}x${height}" ;;
790: esac
791: xlat_info="${xlat_info}, ${width}, ${height}"
792: case ${scale} in
793: _h_) echo " (image will be halved)" ; value="HALF" ;;
794: _d_) echo " (image will be doubled)" ; value="DOUBLE" ;;
795: *) echo "" ; value="NONE" ;;
796: esac
797: xlat_info="${xlat_info}, TME_FB_XLAT_SCALE_${value}"
798: echo -n " "
799: case ${src_depth} in
800: 0) echo -n "any depth" ;;
801: 1) echo -n "1 bit deep" ;;
802: *) echo -n "${src_depth} bits deep" ;;
803: esac
804: xlat_info="${xlat_info}, ${src_depth}"
805: case ${src_bipp} in
806: 0) echo -n ", any bits per pixel" ;;
807: 1) echo -n ", 1 bit per pixel" ;;
808: *) echo -n ", ${src_bipp} bits per pixel" ;;
809: esac
810: xlat_info="${xlat_info}, ${src_bipp}"
811: case ${src_skipx} in
812: _) echo -n ", any number of pixels skipped" ; value="-1";;
813: *) echo -n ", ${src_skipx} pixels skipped" ; value=${src_skipx} ;;
814: esac
815: xlat_info="${xlat_info}, ${value}"
816: case ${src_pad} in
817: 0) echo -n ", any scanline padding" ;;
818: *) echo -n ", ${src_pad}-bit scanline padding" ;;
819: esac
820: xlat_info="${xlat_info}, ${src_pad}"
821: case ${src_order} in
822: m) echo -n ", MSB-first" ; value="BIG" ;;
823: l) echo -n ", LSB-first" ; value="LITTLE" ;;
824: esac
825: xlat_info="${xlat_info}, TME_ENDIAN_${value}"
1.1.1.2 ! root 826: case "x${src_class}" in
! 827: xm) echo -n ", monochrome" ; value="MONOCHROME" ;;
! 828: xc) echo -n ", color" ; value="COLOR" ;;
! 829: *) echo -n ", either color or monochrome" ; value="ANY" ;;
! 830: esac
! 831: xlat_info="${xlat_info}, TME_FB_XLAT_CLASS_${value}"
! 832: case "x${src_map}" in
! 833: xl) echo -n ", linearly mapped pixels" ; value="LINEAR" ;;
! 834: xi) echo -n ", index mapped pixels" ; value="INDEX" ;;
! 835: *) echo -n ", any pixel mapping" ; value="ANY" ;;
! 836: esac
! 837: xlat_info="${xlat_info}, TME_FB_XLAT_MAP_${value}"
! 838: value=${src_map_bits}
! 839: case "${src_map_bits}" in
! 840: 0) echo -n ", any bits per mapped intensity" ;;
! 841: 1) echo -n ", 1 bit per mapped intensity" ;;
! 842: *) echo -n ", ${src_map_bits} bits per mapped intensity" ;;
! 843: esac
! 844: xlat_info="${xlat_info}, ${value}"
! 845: for primary in g r b; do
! 846: eval "src_mask=\$src_mask_${primary}"
! 847: case "x${src_mask}" in
! 848: x) echo -n ", no ${primary} mask" ; value=0 ;;
! 849: x0x0) echo -n ", any ${primary} mask" ; value=TME_FB_XLAT_MASK_ANY ;;
! 850: *) echo -n ", a ${primary} mask of ${src_mask}" ; value=${src_mask} ;;
! 851: esac
! 852: xlat_info="${xlat_info}, ${value}"
! 853: done
1.1 root 854: echo ""
855: echo " to this destination format:"
856: echo -n " "
857: case ${dst_depth} in
858: 0) echo -n "any depth" ;;
859: 1) echo -n "1 bit deep" ;;
860: *) echo -n "${dst_depth} bits deep" ;;
861: esac
862: xlat_info="${xlat_info}, ${dst_depth}"
863: case ${dst_bipp} in
864: 0) echo -n ", any bits per pixel" ;;
865: 1) echo -n ", 1 bit per pixel" ;;
866: *) echo -n ", ${dst_bipp} bits per pixel" ;;
867: esac
868: xlat_info="${xlat_info}, ${dst_bipp}"
869: case ${dst_skipx} in
870: _) echo -n ", any number of pixels skipped" ; value="-1";;
871: *) echo -n ", ${dst_skipx} pixels skipped" ; value=${dst_skipx} ;;
872: esac
873: xlat_info="${xlat_info}, ${value}"
874: case ${dst_pad} in
875: 0) echo -n ", any scanline padding" ;;
876: *) echo -n ", ${dst_pad}-bit scanline padding" ;;
877: esac
878: xlat_info="${xlat_info}, ${dst_pad}"
879: case ${dst_order} in
880: m) echo -n ", MSB-first" ; value="BIG" ;;
881: l) echo -n ", LSB-first" ; value="LITTLE" ;;
882: esac
883: xlat_info="${xlat_info}, TME_ENDIAN_${value}"
1.1.1.2 ! root 884: case "x${dst_map}" in
! 885: xl) echo -n ", linearly mapped pixels" ; value="LINEAR" ;;
! 886: xi) echo -n ", index mapped pixels" ; value="INDEX" ;;
! 887: *) echo -n ", any pixel mapping" ; value="ANY" ;;
! 888: esac
! 889: xlat_info="${xlat_info}, TME_FB_XLAT_MAP_${value}"
! 890: for primary in g r b; do
! 891: eval "dst_mask=\$dst_mask_${primary}"
! 892: case "x${dst_mask}" in
! 893: x) echo -n ", no ${primary} mask" ; value=0 ;;
! 894: x0x0) echo -n ", any ${primary} mask" ; value=TME_FB_XLAT_MASK_ANY ;;
! 895: *) echo -n ", a ${primary} mask of ${dst_mask}" ; value=${dst_mask} ;;
! 896: esac
! 897: xlat_info="${xlat_info}, ${value}"
! 898: done
1.1 root 899: save_IFS=$IFS
900: IFS=
901: xlat_array="${xlat_array}
902: { $xlat_info }, "
903: IFS=$save_IFS
904: echo ""
905: echo "*/"
906: echo "static int"
907: echo "tme_fb_xlat${xlat}(struct tme_fb_connection *src,"
908: echo " struct tme_fb_connection *dst)"
909: echo "{"
910: undef_macros=
911:
912: echo ""
913: echo " /* whenever possible we define macros instead of declaring"
914: echo " variables, for optimization: */"
915:
916: echo ""
917: echo " /* declare src_x and src_y. these are the current translation"
918: echo " coordinates in the source image: */"
919: echo " unsigned int src_x, src_y;"
920:
921: echo ""
922: echo " /* declare dst_x and dst_y. these are the current translation"
923: echo " coordinates in the destination image. since this function"
924: if test $scale = _; then
925: echo " does not scale the image, these coordinates are always"
926: echo " the same as the coordinates in the source image: */"
927: echo "#define dst_x (src_x)"
928: echo "#define dst_y (src_y)"
929: undef_macros="${undef_macros} dst_x dst_y"
930: scale_op=
931: scale_math=
932: else
933: if test $scale = _h_; then
934: scale_op='/'
935: scale_name='halves'
936: else
937: scale_op='*'
938: scale_name='doubles'
939: fi
940: scale_math=" ${scale_op} 2"
941: echo " ${scale_name} the image, the coordinates in the destination image"
942: echo " are always the coordinates in the source image${scale_math}: */"
943: echo " unsigned int dst_x, dst_y;"
944: fi
945:
946: echo ""
947: echo " /* declare pixel. this holds a single pixel value being translated"
948: echo " for the destination image: */"
949: echo " tme_uint32_t pixel;"
950:
951: echo ""
952: echo " /* declare src_width and dst_width. these are in terms of pixels: */"
953: value="(src_width${scale_math})"
954: if test ${width} = 0; then
955: echo " const unsigned int src_width = src->tme_fb_connection_width;"
956: if test $scale != _; then
957: echo " const unsigned int dst_width = ${value};"
958: else
959: echo "#define dst_width ${value}"
960: undef_macros="${undef_macros} dst_width"
961: fi
962: else
963: echo "#define src_width (${width})"
964: echo "#define dst_width ${value}"
965: undef_macros="${undef_macros} src_width dst_width"
966: fi
967:
968: echo ""
969: echo " /* declare src_depth, the source pixel depth, which is in"
970: echo " terms of bits. declare src_mask, which is the corresponding"
971: echo " mask of one bits: */"
972: value="(0xffffffff >> (32 - src_depth))"
973: if test ${src_depth} = 0; then
974: echo " const unsigned int src_depth = src->tme_fb_connection_depth;"
975: echo " const tme_uint32_t src_mask = ${value};"
976: else
977: echo "#define src_depth (${src_depth})"
978: echo "#define src_mask ${value}"
979: undef_macros="${undef_macros} src_depth src_mask"
980: fi
981:
1.1.1.2 ! root 982: # if we are halving, or if source pixels may have subfields,
! 983: # we may need to deal with intensities:
! 984: #
! 985: if test ${scale} = _h_ || test "x${src_mask_g}" != x; then
! 986:
! 987: echo ""
! 988: echo " /* declare src_indexed. this is nonzero if source pixel subfields"
! 989: echo " are index-mapped into intensities: */"
! 990: if test "x${src_map}" = x; then
! 991: echo " const unsigned int src_indexed = (src->tme_fb_connection_map_g != NULL);"
! 992: else
! 993: if test "x${src_map}" = xi; then value=TRUE; else value=FALSE; fi
! 994: echo "#define src_indexed (${value})"
! 995: undef_macros="${undef_macros} src_indexed"
! 996: fi
! 997:
! 998: echo ""
! 999: echo " /* declare src_mask_i, which is the mask for a source intensity: */"
! 1000: if test "${src_map_bits}" = 0; then
! 1001: echo " const tme_uint32_t src_mask_i = (0xffffffff >> (32 - src->tme_fb_connection_map_bits));"
! 1002: else
! 1003: echo "#define src_mask_i (0xffffffff >> (32 - ${src_map_bits}))"
! 1004: undef_macros="${undef_macros} src_mask_i"
! 1005: fi
! 1006:
! 1007: if test "x${src_class}" != xm; then
! 1008: echo ""
! 1009: echo " /* declare dst_indexed. this is nonzero if intensities are index-mapped"
! 1010: echo " into destination pixel subfields: */"
! 1011: if test "x${dst_map}" = x; then
! 1012: echo " const unsigned int dst_indexed = (dst->tme_fb_connection_map_g != NULL);"
! 1013: else
! 1014: if test "x${dst_map}" = xi; then value=TRUE; else value=FALSE; fi
! 1015: echo "#define dst_indexed (${value})"
! 1016: undef_macros="${undef_macros} dst_indexed"
! 1017: fi
! 1018:
! 1019: echo ""
! 1020: echo " /* declare dst_masks_default. this is nonzero if the destination"
! 1021: echo " subfield masks are the default: */"
! 1022: if test "x${dst_mask_g}" = "x0x0"; then
! 1023: echo " const unsigned int dst_masks_default = (dst->tme_fb_connection_mask_g == 0);"
! 1024: else
! 1025: if test "x${dst_mask_g}" = x; then value=TRUE; else value=FALSE; fi
! 1026: echo "#define dst_masks_default (${value})"
! 1027: undef_macros="${undef_macros} dst_masks_default"
! 1028: fi
! 1029: fi
! 1030:
! 1031: for primary in g r b; do
! 1032: primary_cap=`echo ${primary} | tr a-z A-Z`
! 1033: echo ""
! 1034: echo " /* declare src_mask_${primary}, the mask for the ${primary} subfield in a source pixel: */"
! 1035: eval "src_mask=\$src_mask_${primary}"
! 1036: if test "x${src_mask}" = x0x0; then
! 1037: echo " const tme_uint32_t src_mask_${primary}"
! 1038: echo " = (src->tme_fb_connection_mask_${primary} != 0"
! 1039: echo " ? src->tme_fb_connection_mask_${primary}"
! 1040: echo " : src_mask);"
! 1041: else
! 1042: if test "x${src_mask}" = x; then src_mask="src_mask"; fi
! 1043: echo "#define src_mask_${primary} (${src_mask})"
! 1044: undef_macros="${undef_macros} src_mask_${primary}"
! 1045: fi
! 1046: echo ""
! 1047: echo " /* declare value_${primary}, the intensity value for the ${primary} subfield in a pixel: */"
! 1048: echo " tme_uint32_t value_${primary};"
! 1049: if test "x${src_class}" = xm; then break; fi
! 1050: echo ""
! 1051: echo " /* declare dst_mask_${primary}, the mask for the ${primary} subfield in a destination pixel: */"
! 1052: eval "dst_mask=\$dst_mask_${primary}"
! 1053: if test "x${dst_mask}" = x0x0; then
! 1054: echo " const tme_uint32_t dst_mask_${primary}"
! 1055: echo " = (dst->tme_fb_connection_mask_${primary} != 0"
! 1056: echo " ? dst->tme_fb_connection_mask_${primary}"
! 1057: echo " : TME_FB_XLAT_MASK_DEFAULT_${primary_cap});"
! 1058: else
! 1059: if test "x${dst_mask}" = x; then dst_mask="TME_FB_XLAT_MASK_DEFAULT_${primary_cap}"; fi
! 1060: echo "#define dst_mask_${primary} (${dst_mask})"
! 1061: undef_macros="${undef_macros} dst_mask_${primary}"
! 1062: fi
! 1063: done
! 1064: fi
! 1065:
1.1 root 1066: echo ""
1067: echo " /* declare src_bipp and dst_bipp. these are the bits-per-pixel"
1068: echo " values for the source and destination images: */"
1069: if test ${src_bipp} = 0; then
1070: echo " const unsigned int src_bipp = src->tme_fb_connection_bits_per_pixel;"
1071: else
1072: echo "#define src_bipp (${src_bipp})"
1073: undef_macros="${undef_macros} src_bipp"
1074: fi
1075: if test ${dst_bipp} = 0; then
1076: echo " const unsigned int dst_bipp = dst->tme_fb_connection_bits_per_pixel;"
1077: else
1078: echo "#define dst_bipp (${dst_bipp})"
1079: undef_macros="${undef_macros} dst_bipp"
1080: fi
1081:
1082: echo ""
1083: echo " /* declare src_skipx and dst_skipx. these are the counts of"
1084: echo " undisplayed pixels at the beginning of each scanline in the"
1085: echo " source and destination images: */"
1086: if test ${src_skipx} = _; then
1087: echo " const unsigned int src_skipx = src->tme_fb_connection_skipx;"
1088: else
1089: echo "#define src_skipx (${src_skipx})"
1090: undef_macros="${undef_macros} src_skipx"
1091: fi
1092: if test ${dst_skipx} = _; then
1093: echo " const unsigned int dst_skipx = dst->tme_fb_connection_skipx;"
1094: else
1095: echo "#define dst_skipx (${dst_skipx})"
1096: undef_macros="${undef_macros} dst_skipx"
1097: fi
1098:
1099: echo ""
1100: echo " /* declare src_pad and dst_pad. these are the paddings, in bits,"
1101: echo " of each scanline in the source and destination images: */"
1102: if test ${src_pad} = 0; then
1103: echo " const unsigned int src_pad = src->tme_fb_connection_scanline_pad;"
1104: else
1105: echo "#define src_pad (${src_pad})"
1106: undef_macros="${undef_macros} src_pad"
1107: fi
1108: if test ${dst_pad} = 0; then
1109: echo " const unsigned int dst_pad = dst->tme_fb_connection_scanline_pad;"
1110: else
1111: echo "#define dst_pad (${dst_pad})"
1112: undef_macros="${undef_macros} dst_pad"
1113: fi
1114:
1115: echo ""
1116: echo " /* declare src_order and dst_order. these are the bit and byte"
1117: echo " orders (either TME_ENDIAN_BIG or TME_ENDIAN_LITTLE) of the"
1118: echo " source and destination images. since these values profoundly"
1119: echo " affect optimization, they are always constant: */"
1120: if test ${src_order} = m; then value=BIG; else value=LITTLE; fi
1121: echo "#define src_order (TME_ENDIAN_${value})"
1122: undef_macros="${undef_macros} src_order"
1123: if test ${dst_order} = m; then value=BIG; else value=LITTLE; fi
1124: echo "#define dst_order (TME_ENDIAN_${value})"
1125: undef_macros="${undef_macros} dst_order"
1126:
1127: echo ""
1128: echo " /* declare src_bypl and dst_bypl. these are the bytes per scanline"
1129: echo " in the source and destination images. these values are calculated"
1130: echo " from the count of undisplayed and displayed pixels per scanline,"
1131: echo " the number of bits per pixel, and the scanline padding: */"
1132: value="(((((src_skipx + src_width) * src_bipp) + (src_pad - 1)) & -src_pad) / 8)"
1133: if test ${src_skipx} = _ || test ${width} = 0 || test ${src_bipp} = 0 || test ${src_pad} = 0; then
1134: echo " const unsigned int src_bypl = ${value};"
1135: src_bypl_var=true
1136: else
1137: echo "#define src_bypl ${value}"
1138: undef_macros="${undef_macros} src_bypl"
1139: src_bypl_var=false
1140: fi
1141: value="(((((dst_skipx + dst_width) * dst_bipp) + (dst_pad - 1)) & -dst_pad) / 8)"
1142: if test ${dst_skipx} = _ || test ${width} = 0 || test ${dst_bipp} = 0 || test ${dst_pad} = 0; then
1143: echo " const unsigned int dst_bypl = ${value};"
1144: dst_bypl_var=true
1145: else
1146: echo "#define dst_bypl ${value}"
1147: undef_macros="${undef_macros} dst_bypl"
1148: dst_bypl_var=false
1149: fi
1150:
1151: echo ""
1152: echo " /* declare src_packed and dst_packed. these are nonzero iff"
1153: echo " every last bit in a scanline belongs to a displayed pixel."
1154: echo " put another way, this is zero iff a scanline has undisplayed"
1155: echo " pixels at its beginning or padding bits at its end. when"
1156: echo " a source image or destination image is packed, translation"
1157: echo " doesn't have to worry about skipping FIFO bits to get to"
1158: echo " bits belonging to displayed pixels: */"
1159: value="((src_width * src_bipp) == (src_bypl * 8))"
1160: if $src_bypl_var; then
1161: echo " const unsigned int src_packed = ${value};"
1162: else
1163: echo "#define src_packed ${value}"
1164: undef_macros="${undef_macros} src_packed"
1165: fi
1166: value="((dst_width * dst_bipp) == (dst_bypl * 8))"
1167: if $dst_bypl_var; then
1168: echo " const unsigned int dst_packed = ${value};"
1169: else
1170: echo "#define dst_packed ${value}"
1171: undef_macros="${undef_macros} dst_packed"
1172: fi
1173:
1174: echo ""
1175: echo " /* declare src_bypb and src_bypb_real. src_bypb is the bytes"
1176: echo " per source image buffer with the \"translation termination"
1177: echo " overhead\" of approximately two extra scanlines. src_bypb_real"
1178: echo " is the real bytes per source image buffer with no overhead."
1179: echo " both values are padded to a multiple of 4 bytes (32 bits): */"
1180: if test ${height} = 0; then
1181: value="src->tme_fb_connection_height"
1182: else
1183: value="${height}"
1184: fi
1185: value_real="(((${value} * src_bypl) + 3) & -4)"
1186: value="((src_bypb_real + (src_bypl * 2)) & -4)"
1187: if test ${height} = 0 || $src_bypl_var; then
1188: echo " const unsigned int src_bypb_real = ${value_real};"
1189: echo " const unsigned int src_bypb = ${value};"
1190: else
1191: echo "#define src_bypb_real ${value_real}"
1192: echo "#define src_bypb ${value}"
1193: undef_macros="${undef_macros} src_bypb_real src_bypb"
1194: fi
1195:
1196: echo ""
1197: echo " /* declare the source primary bit FIFO:"
1198: echo ""
1199: echo " src_raw0 points to the next aligned 32-bit word to be"
1200: echo " read from the image buffer."
1201: echo ""
1202: echo " src_fifo0 is the visible part of the bit FIFO."
1203: echo ""
1204: echo " src_fifo0_next and src_fifo0_bits are only used when the"
1205: echo " visible part of the bit FIFO is not guaranteed to always"
1206: echo " correspond to an aligned 32-bit word in the image buffer."
1207: echo " src_fifo0_next is the invisible part of the bit FIFO,"
1208: echo " and src_fifo0_bits tracks the total number of bits in the"
1209: echo " visible and invisible parts of the FIFO. */"
1210: echo " const tme_uint32_t *src_raw0;"
1211: echo " tme_uint32_t src_fifo0, src_fifo0_next;"
1212: echo " unsigned int src_fifo0_bits;"
1213:
1214: if test ${scale} = _h_; then
1215: echo ""
1216: echo " /* since this function ${scale_name} the image, declare the"
1217: echo " source secondary bit FIFO. these variables work in "
1218: echo " exactly the same way that their primary counterparts do: */"
1219: echo " const tme_uint32_t *src_raw1;"
1220: echo " tme_uint32_t src_fifo1, src_fifo1_next;"
1221: echo " unsigned int src_fifo1_bits;"
1222: fi
1223:
1224: echo ""
1225: echo " /* declare the destination primary bit FIFO:"
1226: echo ""
1227: echo " dst_raw0 points to the next aligned 32-bit word to be"
1228: echo " written into the image buffer."
1229: echo ""
1230: echo " dst_fifo0 is the visible part of the bit FIFO."
1231: echo ""
1232: echo " dst_fifo0_next and dst_fifo0_bits are only used when the"
1233: echo " visible part of the bit FIFO is not guaranteed to always"
1234: echo " correspond to an aligned 32-bit word in the image buffer."
1235: echo " dst_fifo0_next is the invisible part of the bit FIFO,"
1236: echo " and dst_fifo0_bits tracks the total number of bits in the"
1237: echo " invisible part of the FIFO. */"
1238: echo " tme_uint32_t *dst_raw0;"
1239: echo " tme_uint32_t dst_fifo0, dst_fifo0_next;"
1240: echo " unsigned int dst_fifo0_bits;"
1241:
1242: if test ${scale} = _d_; then
1243: echo ""
1244: echo " /* since this function ${scale_name} the image, declare"
1245: echo " the destination secondary bit FIFO. these variables work"
1246: echo " in exactly the same way that their primary counterparts"
1247: echo " do: */"
1248: echo " tme_uint32_t *dst_raw1;"
1249: echo " tme_uint32_t dst_fifo1, dst_fifo1_next;"
1250: echo " unsigned int dst_fifo1_bits;"
1251: fi
1252:
1253: echo ""
1254: echo " /* declare src_off and dst_off. these are used when priming a"
1255: echo " source or destination bit FIFO, to identify an initial aligned"
1256: echo " 32-bit word in the source or destination image buffer, and an"
1257: echo " initial bit offset within that word: */"
1258: echo " unsigned int src_off, dst_off;"
1259:
1260: echo ""
1261: echo " /* declare src_fifo0_may_be_unaligned. this is zero iff all"
1262: echo " aligned 32-bit words in the source buffer contain a whole"
1.1.1.2 ! root 1263: echo " number of displayed pixels, and at *all times during the"
! 1264: echo " translation* the visible part of the bit FIFO is guaranteed"
! 1265: echo " to correspond to an aligned 32-bit word in the image buffer."
! 1266: echo ""
! 1267: echo " this is *not* so if any of the following are true:"
! 1268: echo ""
! 1269: echo " - the source bits-per-pixel value is not known at compile"
! 1270: echo " time. in this case, we can't unroll the translation loop"
! 1271: echo " for source pixels, and are forced to shift the FIFO after"
! 1272: echo " each one."
! 1273: echo ""
! 1274: echo " - if the source image is not packed. in this case, there may"
! 1275: echo " be undisplayed pixels in the FIFO, which we will need to"
! 1276: echo " shift out."
! 1277: echo ""
! 1278: echo " - if there are 24 bits per source pixel. in this case, a"
! 1279: echo " source pixel may cross a 32-bit boundary: */"
! 1280: src_fifo0_may_be_unaligned_var=false
! 1281: if test ${src_bipp} = 0; then
! 1282: value=TRUE
! 1283: else
! 1284: value="(!src_packed || (src_bipp == 24))"
! 1285: src_fifo0_may_be_unaligned_var=${src_bypl_var}
! 1286: fi
! 1287: if $src_fifo0_may_be_unaligned_var; then
1.1 root 1288: echo " const unsigned int src_fifo0_may_be_unaligned = ${value};"
1289: else
1290: echo "#define src_fifo0_may_be_unaligned ${value}"
1291: undef_macros="${undef_macros} src_fifo0_may_be_unaligned"
1292: fi
1293:
1294: if test $scale = _h_; then
1295: echo ""
1296: echo " /* declare src_fifo1_may_be_unaligned. this is zero iff all"
1297: echo " aligned 32-bit words in the source buffer contain a"
1298: echo " whole number of displayed pixels, *and* for every aligned"
1299: echo " 32-bit word on one scanline all other scanlines have an"
1300: echo " aligned 32-bit word corresponding to the same x coordinate: */"
1301: value="(src_fifo0_may_be_unaligned || (src_bypl & 3))"
1302: if $src_bypl_var; then
1303: echo " const unsigned int src_fifo1_may_be_unaligned = ${value};"
1304: else
1305: echo "#define src_fifo1_may_be_unaligned ${value}"
1306: undef_macros="${undef_macros} src_fifo1_may_be_unaligned"
1307: fi
1308: fi
1309:
1310: echo ""
1.1.1.2 ! root 1311: echo " /* declare dst_fifo0_may_be_unaligned. this is zero iff all"
! 1312: echo " aligned 32-bit words in the destination buffer contain a whole"
! 1313: echo " number of displayed pixels, and at *all times during the"
! 1314: echo " translation* the visible part of the bit FIFO is guaranteed"
! 1315: echo " to correspond to an aligned 32-bit word in the image buffer."
! 1316: echo ""
! 1317: echo " this is *not* so if any of the following are true:"
! 1318: echo ""
! 1319: echo " - the destination bits-per-pixel value is not known at compile"
! 1320: echo " time. in this case, we can't unroll the translation loop"
! 1321: echo " for destination pixels, and are forced to shift the FIFO"
! 1322: echo " after each one."
! 1323: echo ""
! 1324: echo " - if src_fifo0_may_be_unaligned is true. in this case, we"
! 1325: echo " definitely can't guarantee that any initial dst_x will"
! 1326: echo " correspond to an aligned 32-bit word in the destination buffer."
! 1327: echo ""
! 1328: echo " - if the destination image is not packed. in this case, there may"
! 1329: echo " be undisplayed pixels in the FIFO, which we will need to"
! 1330: echo " shift out."
! 1331: echo ""
! 1332: echo " - if there are 24 bits per destination pixel. in this case,"
! 1333: echo " a destination pixel may cross a 32-bit boundary."
! 1334: echo ""
! 1335: echo " - if a possible initial dst_x doesn't correspond to an aligned"
! 1336: echo " 32-bit word in the destination buffer. for this last one:"
1.1 root 1337: echo ""
1338: echo " since we require that src_fifo0_may_be_unaligned is zero, we"
1339: echo " know that the initial src_x = (Z * 32) / src_bipp for "
1340: echo " some Z. we also have the initial dst_x = src_x${scale_math}."
1341: echo " the initial destination bit offset will then be:"
1342: echo ""
1343: echo " (dst_skipx + dst_x) * dst_bipp"
1344: echo " = (dst_skipx * dst_bipp) + (dst_x * dst_bipp)"
1345: echo ""
1346: echo " if we additionally require that (dst_skipx * dst_bipp)"
1347: echo " be 32-bit aligned, this reduces things to:"
1348: echo ""
1349: echo " dst_x * dst_bipp"
1350: echo " = (src_x${scale_math}) * dst_bipp"
1351: echo " = (((Z * 32) / src_bipp)${scale_math}) * dst_bipp"
1352: echo ""
1353: echo " which will be a multiple of 32 iff:"
1354: echo ""
1355: echo " ((1 / src_bipp)${scale_math}) * dst_bipp >= 1 and integral"
1.1.1.2 ! root 1356: echo ""
! 1357: echo " or, equivalently:"
! 1358: echo ""
1.1 root 1359: denom="src_bipp"
1360: numer="dst_bipp"
1361: case $scale in
1362: _) ;;
1363: _h_) denom="(${denom} * 2)" ;;
1364: _d_) numer="(${numer} * 2)" ;;
1365: esac
1.1.1.2 ! root 1366: echo " (${numer} % ${denom}) == 0"
! 1367: echo " */"
! 1368: dst_fifo0_may_be_unaligned_var=false
! 1369: if test ${dst_bipp} = 0; then
! 1370: value=TRUE
! 1371: else
! 1372: value="(src_fifo0_may_be_unaligned || !dst_packed || (dst_bipp == 24) || (dst_bypl % 4) || ((dst_skipx * dst_bipp) % 32) || (${numer} % ${denom}))"
! 1373: if $src_bypl_var || $dst_bypl_var; then
! 1374: dst_fifo0_may_be_unaligned_var=true
! 1375: fi
! 1376: fi
! 1377: if $dst_fifo0_may_be_unaligned_var; then
1.1 root 1378: echo " const unsigned int dst_fifo0_may_be_unaligned = ${value};"
1379: else
1380: echo "#define dst_fifo0_may_be_unaligned ${value}"
1381: undef_macros="${undef_macros} dst_fifo0_may_be_unaligned"
1382: fi
1383:
1384: if test $scale = _d_; then
1385: echo ""
1386: echo " /* declare dst_fifo1_may_be_unaligned. this is zero iff all"
1387: echo " 32-bit aligned values in the destination buffer contain a"
1388: echo " whole number of displayed pixels, and for every 32-bit"
1389: echo " aligned value on one scanline all other scanlines have a"
1390: echo " 32-bit aligned value corresponding to the same x coordinate: */"
1391: value="(dst_fifo0_may_be_unaligned || (dst_bypl & 3))"
1392: if $src_bypl_var || $dst_bypl_var; then
1393: echo " const unsigned int dst_fifo1_may_be_unaligned = ${value};"
1394: else
1395: echo "#define dst_fifo1_may_be_unaligned ${value}"
1396: undef_macros="${undef_macros} dst_fifo1_may_be_unaligned"
1397: fi
1398: fi
1399:
1400: echo ""
1401: echo " /* declare src_raw0_end. when treating the source image as"
1402: echo " an array of aligned 32-bit words, this variable holds the"
1403: echo " address of the first word after the real source image."
1404: echo " if the fast, aligned 32-bit word comparison loop passes"
1405: echo " this point, the entire source image has been processed and"
1406: echo " the function terminates: */"
1407: echo " const tme_uint32_t *src_raw0_end;"
1408:
1409: echo ""
1410: echo " /* declare xlat_run. see the comment for the TME_FB_XLAT_RUN"
1411: echo " macro for an explanation of what this variable does: */"
1412: echo " int xlat_run;"
1413:
1414: echo ""
1415: echo " /* this silences gcc -Wuninitialized: */"
1416: echo " src_fifo0_next = 0;"
1417: echo " src_fifo0_bits = 0;"
1418: if test ${scale} = _h_; then
1419: echo " src_fifo1_next = 0;"
1420: echo " src_fifo1_bits = 0;"
1421: fi
1422: echo " dst_fifo0_next = 0;"
1423: echo " dst_fifo0_bits = 0;"
1424: if test ${scale} = _d_; then
1425: echo " dst_fifo1_next = 0;"
1426: echo " dst_fifo1_bits = 0;"
1427: fi
1428:
1429: echo ""
1430: echo " /* initialize src_raw0 and src_raw0_end for the fast aligned 32-bit"
1431: echo " word comparison loop. on entry to (and when continuing) that loop,"
1432: echo " src_raw0 always points to the aligned 32-bit word *before* the"
1433: echo " next word to check. src_raw0_end always points after the last"
1434: echo " word to check."
1435: echo ""
1436: echo " src_raw0 is actually part of the source primary bit FIFO, which"
1437: echo " is good, because when the fast comparison fails on a word, src_raw0"
1438: echo " is already primed and ready to work for that bit FIFO: */"
1439: echo " src_raw0 = ((const tme_uint32_t *) src->tme_fb_connection_buffer) - 1;"
1440: echo " src_raw0_end = (const tme_uint32_t *) (src->tme_fb_connection_buffer + src_bypb_real);"
1441:
1442: echo ""
1443: echo " /* initialize xlat_run to -1. it can never go negative inside the"
1444: echo " pixel translation loop, so if xlat_run stays negative for the"
1445: echo " entire translation, it means that the source image hasn't changed"
1446: echo " since the last translation. this information is returned to the"
1447: echo " caller to hopefully save more work in updating the display: */"
1448: echo " xlat_run = -1;"
1449:
1450: echo ""
1451: echo " /* this is the main translation loop, which contains the fast aligned"
1452: echo " 32-bit word comparison loop, and the pixel translation loop: */"
1453: echo " for (;;) {"
1454:
1455: echo ""
1456: echo " /* this is the fast aligned 32-bit word comparison loop. it"
1457: echo " terminates either when a word fails comparison, or when the"
1458: echo " entire source image has been compared. the if test that"
1459: echo " follows checks for the latter case and breaks the main"
1460: echo " translation loop: */"
1461: echo " for (; (++src_raw0 < src_raw0_end"
1462: echo " && *src_raw0 == *TME_FB_XLAT_SRC_OLD(src_raw0)); );"
1463: echo " if (src_raw0 >= src_raw0_end) {"
1464: echo " break;"
1465: echo " }"
1466:
1467: echo ""
1468: echo " /* calculate the byte offset into the source buffer of the"
1469: echo " 32-bit word that failed comparison: */"
1470: echo " src_off = ((tme_uint8_t *) src_raw0) - src->tme_fb_connection_buffer;"
1471:
1472: echo ""
1473: echo " /* calculate the source y pixel coordinate, and reduce"
1474: echo " src_off from the byte offset into the buffer to the"
1475: echo " byte offset into that scanline: */"
1476: echo " src_y = src_off / src_bypl;"
1477: echo " src_off = src_off % src_bypl;"
1478:
1479: echo ""
1480: echo " /* while translating pixels, we use one or more \"bit FIFOs\","
1481: echo " each composed of one or more 32-bit integers. we load these"
1482: echo " FIFOs 32 bits at a time. */"
1483: echo ""
1484: echo " /* prime the visible part of the source primary bit FIFO: */"
1485: echo " src_fifo0 = *src_raw0;"
1486: echo " *TME_FB_XLAT_SRC_OLD(src_raw0) = src_fifo0;"
1487: echo " src_raw0++;"
1488: echo " src_fifo0 = ((src_order == TME_ENDIAN_BIG)"
1489: echo " ? tme_betoh_u32(src_fifo0)"
1490: echo " : tme_letoh_u32(src_fifo0));"
1491: echo ""
1492: echo " /* if the source primary bit FIFO may be unaligned: */"
1493: echo " if (src_fifo0_may_be_unaligned) {"
1494: echo ""
1495: echo " /* prime the invisible part of the source primary bit FIFO and"
1496: echo " assume that we will not have to shift it to finish: */"
1497: echo " src_fifo0_next = *src_raw0;"
1498: echo " *TME_FB_XLAT_SRC_OLD(src_raw0) = src_fifo0_next;"
1499: echo " src_raw0++;"
1500: echo " src_fifo0_next = ((src_order == TME_ENDIAN_BIG)"
1501: echo " ? tme_betoh_u32(src_fifo0_next)"
1502: echo " : tme_letoh_u32(src_fifo0_next));"
1503: echo " src_fifo0_bits = 0;"
1504: echo ""
1505: echo " /* if there are pixels that need to be skipped, the first 32 bits"
1506: echo " we loaded into the FIFO may have first bits that belong to"
1507: echo " those undisplayed (skipped) pixels. it is *not* possible for"
1508: echo " it to have first bits that belong to the scanline pad; there"
1509: echo " might be pad bits in the *middle* of the first 32 bits, but any"
1510: echo " first bits *must* belong to pixels, displayed or not: */"
1511: echo " if (src_skipx > 0"
1512: echo " && (src_off * 8) < (src_skipx * src_bipp)) {"
1513: echo ""
1514: echo " /* see how many bits we will need to skip: */"
1515: echo " src_fifo0_bits = (src_skipx * src_bipp) - (src_off * 8);"
1516: echo ""
1517: echo " /* if it is more than 31 bits, this is an entire 32 bits of"
1518: echo " undisplayed pixels. just advance: */"
1519: echo " if (src_fifo0_bits > 31) {"
1520: echo " src_raw0--;"
1521: echo " continue;"
1522: echo " }"
1523: echo ""
1524: echo " /* set the source x coordinate to zero: */"
1525: echo " src_x = 0;"
1526: echo " }"
1527: echo ""
1528: echo " /* otherwise, the first 32 bits we load will have first bits for"
1529: echo " a displayable pixel: */"
1530: echo " else {"
1531: echo ""
1532: echo " /* if the source bits per pixel is 24, calculate the number of"
1533: echo " bytes *before* the original src_raw0 of any split pixel, and"
1534: echo " subtract this from src_off, to leave src_off as the byte offset"
1535: echo " into the scanline of the beginning of a pixel: */"
1536: echo " if (src_bipp == 24) {"
1537: echo " src_fifo0_bits = (src_off % 3);"
1538: echo " src_off -= src_fifo0_bits;"
1539: echo ""
1540: echo " /* if this is a split pixel, we need to prime the source primary"
1541: echo " bit FIFO starting with the part *before* the original src_raw0."
1542: echo " we do not have to copy to the old; it passed comparison: */"
1543: echo " if (src_fifo0_bits) {"
1544: echo " src_raw0--;"
1545: echo " src_fifo0_next = src_fifo0;"
1546: echo " src_fifo0 = ((src_order == TME_ENDIAN_BIG)"
1547: echo " ? tme_betoh_u32(*(src_raw0 - 2))"
1548: echo " : tme_letoh_u32(*(src_raw0 - 2)));"
1549: echo " }"
1550: echo " }"
1551: echo ""
1552: echo " /* calculate the source x coordinate: */"
1553: echo " src_x = ((src_off * 8) / src_bipp) - src_skipx;"
1554: echo " }"
1555: echo ""
1556: echo " /* do any shifting to finish priming the source primary FIFO: */"
1557: echo " if (src_fifo0_bits) {"
1558: echo " if (src_order == TME_ENDIAN_BIG) {"
1559: echo " src_fifo0 = (src_fifo0 << src_fifo0_bits) | (src_fifo0_next >> (32 - src_fifo0_bits));"
1560: echo " src_fifo0_next <<= src_fifo0_bits;"
1561: echo " }"
1562: echo " else {"
1563: echo " src_fifo0 = (src_fifo0 >> src_fifo0_bits) | (src_fifo0_next << (32 - src_fifo0_bits));"
1564: echo " src_fifo0_next >>= src_fifo0_bits;"
1565: echo " }"
1566: echo " }"
1567: echo " src_fifo0_bits = 64 - src_fifo0_bits;"
1568: echo " }"
1569: echo ""
1570: echo " /* otherwise, the source primary FIFO is aligned: */"
1571: echo " else {"
1572: echo " src_x = ((src_off * 8) / src_bipp) - src_skipx;"
1573: echo " }"
1574:
1575: if test $scale = _h_; then
1576: echo ""
1577: echo " /* when halving the image, we have a source secondary bit "
1578: echo " FIFO, providing pixel values at the same source x coordinate"
1579: echo " but on the \"other\" line. prime the source secondary"
1580: echo " bit FIFO: */"
1581: echo " if (src_fifo1_may_be_unaligned) {"
1582: echo ""
1583: echo " /* calculate the bit offset into the source buffer of"
1584: echo " this exact same pixel on the other line: */"
1585: echo " src_off = ((src_y ^ 1) * src_bypl * 8) + ((src_skipx + src_x) * src_bipp);"
1586: echo ""
1587: echo " /* calculate how many bits offset from a 32-bit boundary the pixel is: */"
1588: echo " src_fifo1_bits = src_off % 32;"
1589: echo ""
1590: echo " /* set src_raw1: */"
1591: echo " src_raw1 = (const tme_uint32_t *)"
1592: echo " (src->tme_fb_connection_buffer"
1593: echo " + ((src_off - src_fifo1_bits) / 8));"
1594: echo ""
1595: echo " /* actually prime the FIFO by loading the first two words and"
1596: echo " shifting off any offset bits: */"
1597: echo " src_fifo1 = *src_raw1;"
1598: echo " *TME_FB_XLAT_SRC_OLD(src_raw1) = src_fifo1;"
1599: echo " src_raw1++;"
1600: echo " src_fifo1_next = *src_raw1;"
1601: echo " *TME_FB_XLAT_SRC_OLD(src_raw1) = src_fifo1_next;"
1602: echo " src_raw1++;"
1603: echo " if (src_order == TME_ENDIAN_BIG) {"
1604: echo " src_fifo1 = tme_betoh_u32(src_fifo1);"
1605: echo " src_fifo1_next = tme_betoh_u32(src_fifo1_next);"
1606: echo " if (src_fifo1_bits) {"
1607: echo " src_fifo1 = (src_fifo1 << src_fifo1_bits) | (src_fifo1_next >> (32 - src_fifo1_bits));"
1608: echo " src_fifo1_next <<= src_fifo1_bits;"
1609: echo " }"
1610: echo " }"
1611: echo " else {"
1612: echo " src_fifo1 = tme_letoh_u32(src_fifo1);"
1613: echo " src_fifo1_next = tme_letoh_u32(src_fifo1_next);"
1614: echo " if (src_fifo1_bits) {"
1615: echo " src_fifo1 = (src_fifo1 >> src_fifo1_bits) | (src_fifo1_next << (32 - src_fifo1_bits));"
1616: echo " src_fifo1_next >>= src_fifo1_bits;"
1617: echo " }"
1618: echo " }"
1619: echo " src_fifo1_bits = 64 - src_fifo1_bits;"
1620: echo " }"
1621: echo ""
1622: echo " /* otherwise the source secondary FIFO is aligned: */"
1623: echo " else {"
1624: echo " src_raw1 = (const tme_uint32_t *)"
1625: echo " (((tme_uint8_t *) src_raw0)"
1626: echo " + (("
1627: echo " /* if src_y is even, this addend is now src_bypl * 4,"
1628: echo " else if src_y is odd, this addend is now src_bypl * 2: */"
1629: echo " ((src_bypl * 4) >> (src_y & 1))"
1630: echo " /* if src_y is even, this addend is now src_bypl,"
1631: echo " else if src_y is odd, this addend is now -src_bypl: */"
1632: echo " - (src_bypl * 3))"
1633: echo " /* this -4 compensates for src_raw0 already having"
1634: echo " been advanced by one: */"
1635: echo " - 4));"
1636: echo " src_fifo1 = *src_raw1;"
1637: echo " *TME_FB_XLAT_SRC_OLD(src_raw1) = src_fifo1;"
1638: echo " src_raw1++;"
1639: echo " src_fifo1 = ((src_order == TME_ENDIAN_BIG)"
1640: echo " ? tme_betoh_u32(src_fifo1)"
1641: echo " : tme_letoh_u32(src_fifo1));"
1642: echo " }"
1643: fi
1644:
1645: if test $scale != _; then
1646: echo ""
1647: echo " /* calculate the destination coordinates: */"
1648: echo " dst_y = src_y${scale_math};"
1649: echo " dst_x = src_x${scale_math};"
1650: fi
1651:
1652: echo ""
1653: echo " /* prime the destination primary bit FIFO: */"
1654: echo " dst_fifo0 = 0;"
1655: echo " if (dst_fifo0_may_be_unaligned) {"
1656: echo ""
1657: echo " /* calculate the bit offset into the destination buffer of"
1658: echo " the destination pixel: */"
1659: echo " dst_off = (dst_y * dst_bypl * 8) + ((dst_skipx + dst_x) * dst_bipp);"
1660: echo ""
1661: echo " /* calculate the number of bits that will be in the primed FIFO: */"
1662: echo " dst_fifo0_bits = dst_off % 32;"
1663: echo ""
1664: echo " /* set dst_raw0: */"
1665: echo " dst_raw0 = (tme_uint32_t *)"
1666: echo " (dst->tme_fb_connection_buffer"
1667: echo " + ((dst_off - dst_fifo0_bits) / 8));"
1668: echo ""
1669: echo " /* prime the primary destination FIFO: */"
1670: echo " dst_fifo0_next = 0;"
1671: echo " if (dst_fifo0_bits) {"
1672: echo " dst_fifo0_next = (src_order == TME_ENDIAN_BIG"
1673: echo " ? (tme_betoh_u32(*dst_raw0) & (0xffffffffUL << (32 - dst_fifo0_bits)))"
1674: echo " : (tme_letoh_u32(*dst_raw0) & (0xffffffffUL >> (32 - dst_fifo0_bits))));"
1675: echo " }"
1676: echo " }"
1677: echo ""
1678: echo " /* otherwise the destination primary FIFO is aligned: */"
1679: echo " else {"
1680: echo " dst_off = (dst_y * dst_bypl) + (((dst_skipx + dst_x) * dst_bipp) / 8);"
1681: echo " dst_raw0 = (tme_uint32_t *) (dst->tme_fb_connection_buffer + dst_off);"
1682: echo " }"
1683:
1684: if test $scale = _d_; then
1685: echo ""
1686: echo " /* when doubling the image, we have a destination secondary bit "
1687: echo " FIFO, for pixel values at the same source x coordinate"
1688: echo " but on the \"other\" line. prime the destination secondary"
1689: echo " bit FIFO: */"
1690: echo " dst_fifo1 = 0;"
1691: echo " if (dst_fifo1_may_be_unaligned) {"
1692: echo ""
1693: echo " /* calculate the bit offset into the destination buffer of"
1694: echo " the destination pixel: */"
1695: echo " dst_off = ((dst_y + 1) * dst_bypl * 8) + ((dst_skipx + dst_x) * dst_bipp);"
1696: echo ""
1697: echo " /* calculate the number of bits that will be in the primed FIFO: */"
1698: echo " dst_fifo1_bits = dst_off % 32;"
1699: echo ""
1700: echo " /* set dst_raw1: */"
1701: echo " dst_raw1 = (tme_uint32_t *)"
1702: echo " (dst->tme_fb_connection_buffer"
1703: echo " + ((dst_off - dst_fifo1_bits) / 8));"
1704: echo ""
1705: echo " /* prime the primary destination FIFO: */"
1706: echo " dst_fifo1_next = 0;"
1707: echo " if (dst_fifo1_bits) {"
1708: echo " dst_fifo1_next = (src_order == TME_ENDIAN_BIG"
1709: echo " ? (tme_betoh_u32(*dst_raw1) & (0xffffffffUL << (32 - dst_fifo1_bits)))"
1710: echo " : (tme_letoh_u32(*dst_raw1) & (0xffffffffUL >> (32 - dst_fifo1_bits))));"
1711: echo " }"
1712: echo " }"
1713: echo ""
1714: echo " /* otherwise, the destination secondary FIFO is aligned: */"
1715: echo " else {"
1716: echo " dst_raw1 = (tme_uint32_t *)"
1717: echo " (((tme_uint8_t *) dst_raw0)"
1718: echo " + dst_bypl);"
1719: echo " }"
1720: fi
1721:
1722: # we want to unroll the pixel translation loop to read as many
1723: # source pixels as possible out of the source bit FIFOs and
1724: # write as many destination pixels as possible into the
1725: # destination bit FIFOs before shifting them.
1726: #
1727: # it is very common to want to unroll the translation loop a
1728: # different number of times on source and destination pixels,
1729: # so we always unroll the maximum possible, tracking within
1730: # each unrolled iteration the relative unrolled iteration for
1731: # the source and destination bit FIFOs.
1732: #
1733:
1734: # src_unroll and dst_unroll are the number of times we will
1735: # unroll the translation loop on source and destination
1736: # pixels, respectively. assume no unrolling:
1737: #
1738: src_unroll=1
1739: dst_unroll=1
1740:
1741: # src_iter_scale is the number of source pixels read out of a
1742: # source bit FIFO in one unrolled iteration of the translation
1743: # loop. if this function halves the source image, this is
1744: # two, otherwise this is one.
1745: #
1746: # dst_iter_scale is the number of destination pixels written
1747: # to a destination bit FIFO in one unrolled iteration of the
1748: # translation loop. if this function doubles the source
1749: # image, this is two, otherwise this is one.
1750: #
1751: # src_fifo_shift is the number of bits that the source bit
1752: # FIFO(s) must be shifted after all unrolled iterations on
1753: # source pixels. assume no unrolling, so if this function
1754: # halves the source image and src_bipp is less than 24, two
1755: # pixels' bits must be shifted, otherwise one pixel's bits
1756: # must be shifted.
1757: #
1758: # dst_fifo_shift is the number of bits that the destination bit
1759: # FIFO(s) must be shifted after all unrolled iterations on
1760: # destination pixels. we are assuming no unrolling, so if this
1761: # function doubles the source image and dst_bipp is less than
1762: # 24, two pixels' bits must be shifted, otherwise one pixel's
1763: # bits must be shifted:
1764: #
1765: if test $scale = _h_; then
1766: src_iter_scale=2
1767: src_fifo_shift="(src_bipp < 24 ? (src_bipp * 2) : src_bipp)"
1768: else
1769: src_iter_scale=1
1770: src_fifo_shift="src_bipp"
1771: fi
1772: if test $scale = _d_; then
1773: dst_iter_scale=2
1774: dst_fifo_shift="(dst_bipp < 24 ? (dst_bipp * 2) : dst_bipp)"
1775: else
1776: dst_iter_scale=1
1777: dst_fifo_shift="dst_bipp"
1778: fi
1779:
1780: # if src_bipp is known now, see how many times we can unroll the
1781: # translation loop on source pixels:
1782: #
1783: if test ${src_bipp} != 0; then
1784:
1785: # in general, we can unroll once for each pixel in the
1786: # visible part of a source bit FIFO:
1787: #
1788: src_unroll=`expr 32 / ${src_bipp}`
1789:
1790: # if this function halves the source image, we can unroll
1791: # half as many times:
1792: #
1793: src_unroll=`expr ${src_unroll} / ${src_iter_scale}`
1794:
1795: # if we think we can unroll zero times, this means that
1796: # src_bipp is greater than 16 and this function halves the
1797: # source image - the zero is telling us that two whole
1798: # pixels cannot fit in the visible part of a source bit
1799: # FIFO. so we unroll once on source pixels, and shift
1800: # only one pixel's bits after the unrolling (the halving
1801: # code will be shifting one pixel's worth of bits to get
1802: # to the next pixel it has to read):
1803: #
1804: if test ${src_unroll} = 0; then
1805: src_unroll=1
1806: src_fifo_shift=${src_bipp}
1807:
1808: # otherwise, we will be shifting the entire visible part
1809: # of the source bit FIFO(s) after all unrolled iterations:
1810: #
1811: else
1812: src_fifo_shift=32
1813: fi
1814:
1815: echo ""
1816: echo " /* since src_bipp is known at code-generation time, the"
1817: echo " pixel translation loop is unrolled to translate all"
1818: echo " source pixels in the 32-bit visible part of the source"
1819: echo " bit FIFO(s) before shifting."
1820: echo ""
1821: echo " in this case, src_bipp is known to be ${src_bipp}, so "`expr ${src_unroll} \* ${src_iter_scale}`" pixels will"
1822: echo " be read out of the source bit FIFO(s) before shifting, and"
1823: echo " when the source bit FIFO(s) are shifted, they are shifted"
1824: echo " ${src_fifo_shift} bits at a time: */"
1825: fi
1826:
1827: # if dst_bipp is known now, see how many times we can unroll the
1828: # translation loop on destination pixels:
1829: #
1830: if test ${dst_bipp} != 0; then
1831:
1832: # in general, we can unroll once for each pixel in the
1833: # visible part of a destination bit FIFO:
1834: #
1835: dst_unroll=`expr 32 / ${dst_bipp}`
1836:
1837: # if this function doubles the source image, we can unroll
1838: # half as many times:
1839: #
1840: dst_unroll=`expr ${dst_unroll} / ${dst_iter_scale}`
1841:
1842: # if we think we can unroll zero times, this means that
1843: # dst_bipp is greater than 16 and this function doubles the
1844: # source image - the zero is telling us that two whole
1845: # pixels cannot fit in the visible part of a destination bit
1846: # FIFO. so we unroll once on destination pixels, and shift
1847: # only one pixel's bits after the unrolling (the doubling
1848: # code will be shifting one pixel's worth of bits to get
1849: # out the first pixel it has to write):
1850: #
1851: if test ${dst_unroll} = 0; then
1852: dst_unroll=1
1853: dst_fifo_shift=${dst_bipp}
1854:
1855: # otherwise, we will be shifting the entire visible part
1856: # of the source bit FIFO(s) after all unrolled iterations:
1857: #
1858: else
1859: dst_fifo_shift=32
1860: fi
1861:
1862: echo ""
1863: echo " /* since dst_bipp is known at code-generation time, the pixel"
1864: echo " translation loop is unrolled to translate all destination"
1865: echo " pixels in the 32-bit visible part of the destination bit"
1866: echo " FIFO(s) before shifting."
1867: echo ""
1868: echo " in this case, dst_bipp is known to be ${dst_bipp}, so "`expr ${dst_unroll} \* ${dst_iter_scale}`" pixels will"
1869: echo " be written into the destination bit FIFO(s) before shifting,"
1870: echo " and when the destination bit FIFO(s) are shifted, they are"
1871: echo " shifted ${dst_fifo_shift} bits at a time: */"
1872: fi
1873:
1874: # unroll the translation loop the maximum number amount of times:
1875: #
1876: if test `expr ${src_unroll} \> ${dst_unroll}` = 1; then
1877: unroll=${src_unroll}
1878: else
1879: unroll=${dst_unroll}
1880: fi
1881:
1882: echo ""
1883: echo " /* src_unroll = ${src_unroll}, src_iter_scale = ${src_iter_scale}"
1884: echo " dst_unroll = ${dst_unroll}, dst_iter_scale = ${dst_iter_scale} */"
1885: echo " for (xlat_run = TME_FB_XLAT_RUN;"
1886: echo " xlat_run > 0; ) {"
1887: iter=0
1888:
1889: while test `expr ${iter} \< ${unroll}` = 1; do
1890: echo ""
1891: echo " /* iter #${iter} */"
1892: echo ""
1893: iter_next=`expr ${iter} + 1`
1894:
1895: # the number of bits to skip in a source FIFO to get to
1896: # this iteration's pixel:
1897: src_shift=`expr ${iter} % ${src_unroll}`
1898: src_shift='('`expr ${src_shift} \* ${src_iter_scale}`' * src_bipp)'
1899:
1900: echo " /* get a pixel from the source primary FIFO: */"
1901: echo " pixel ="
1902: echo " ((src_fifo0"
1903: echo " >> (src_order == TME_ENDIAN_BIG"
1904: echo " ? (32 - (src_bipp + ${src_shift}))"
1.1.1.2 ! root 1905: echo " : ${src_shift})));"
! 1906: indent0=X
1.1 root 1907:
1.1.1.2 ! root 1908: if test $scale != _h_; then
1.1 root 1909:
1.1.1.2 ! root 1910: if test "x${src_mask_g}" = x; then
! 1911: echo ""
! 1912: echo " /* since source pixels are known at compile time to"
! 1913: echo " not have subfields, map the source pixel into the"
! 1914: echo " destination pixel: */"
! 1915: echo " pixel = dst->tme_fb_connection_map_pixel[pixel & src_mask];"
! 1916: else
! 1917: echo ""
! 1918: echo " /* if the source depth is within the threshold for pixel"
! 1919: echo " mapping, or if source pixels don't have subfields,"
! 1920: echo " map the source pixel into the destination pixel: */"
! 1921: echo " if (src_mask <= TME_FB_XLAT_MAP_INDEX_MASK_MAX"
! 1922: echo " || src_mask_g == src_mask) {"
! 1923: echo " pixel = dst->tme_fb_connection_map_pixel[pixel & src_mask];"
! 1924: echo " }"
! 1925: echo ""
! 1926: echo " /* otherwise, we will decompose this source pixel"
! 1927: echo " and then compose the destination pixel: */"
! 1928: echo " else {"
! 1929: echo ""
! 1930: echo " /* map the pixel subfields into intensities: */"
! 1931: echo " value_g = TME_FB_XLAT_MAP(pixel, src_mask_g, src_mask_i, src_indexed, src->tme_fb_connection_map_g);"
! 1932: if test "x${src_class}" != xm; then
! 1933: echo " value_r = TME_FB_XLAT_MAP(pixel, src_mask_r, src_mask_i, src_indexed, src->tme_fb_connection_map_r);"
! 1934: echo " value_b = TME_FB_XLAT_MAP(pixel, src_mask_b, src_mask_i, src_indexed, src->tme_fb_connection_map_b);"
! 1935: fi
! 1936: indent0=" "
! 1937: src_mask_i=src_mask_i
! 1938: src_mask_i_max=TME_FB_XLAT_MAP_INDEX_MASK_MAX
! 1939: fi
! 1940:
! 1941: else
1.1 root 1942:
1943: echo ""
1.1.1.2 ! root 1944: echo " /* map the pixel subfields into intensities: */"
! 1945: echo " value_g = TME_FB_XLAT_MAP(pixel, src_mask_g, src_mask_i, src_indexed, src->tme_fb_connection_map_g);"
! 1946: if test "x${src_class}" != xm; then
! 1947: echo " value_r = TME_FB_XLAT_MAP(pixel, src_mask_r, src_mask_i, src_indexed, src->tme_fb_connection_map_r);"
! 1948: echo " value_b = TME_FB_XLAT_MAP(pixel, src_mask_b, src_mask_i, src_indexed, src->tme_fb_connection_map_b);"
1.1 root 1949: fi
1.1.1.2 ! root 1950:
! 1951: echo ""
! 1952: echo " /* get a second pixel, from the source secondary FIFO: */"
! 1953: echo " pixel ="
1.1 root 1954: echo " ((src_fifo1"
1955: echo " >> (src_order == TME_ENDIAN_BIG"
1956: echo " ? (32 - (src_bipp + ${src_shift}))"
1.1.1.2 ! root 1957: echo " : ${src_shift})));"
! 1958:
! 1959: echo ""
! 1960: echo " /* map the pixel subfields into intensities and accumulate them: */"
! 1961: echo " value_g += TME_FB_XLAT_MAP(pixel, src_mask_g, src_mask_i, src_indexed, src->tme_fb_connection_map_g);"
! 1962: if test "x${src_class}" != xm; then
! 1963: echo " value_r += TME_FB_XLAT_MAP(pixel, src_mask_r, src_mask_i, src_indexed, src->tme_fb_connection_map_r);"
! 1964: echo " value_b += TME_FB_XLAT_MAP(pixel, src_mask_b, src_mask_i, src_indexed, src->tme_fb_connection_map_b);"
! 1965: fi
1.1 root 1966:
1967: echo ""
1968: echo " /* get third and fourth pixels, from the source primary"
1969: echo " FIFO and source secondary FIFO, respectively. if"
1970: echo " src_bipp is 24 or greater, these pixels are not yet"
1971: echo " entirely in the first parts of the FIFOs, so we need"
1972: echo " to shift: */"
1973: echo " if (src_bipp >= 24) {"
1974: echo " TME_FB_XLAT_SHIFT_SRC(src_fifo0_may_be_unaligned,"
1975: echo " src_fifo0,"
1976: echo " src_fifo0_next,"
1977: echo " src_fifo0_bits,"
1978: echo " src_bipp,"
1979: echo " src_raw0,"
1980: echo " src_order);"
1981: echo " TME_FB_XLAT_SHIFT_SRC(src_fifo1_may_be_unaligned,"
1982: echo " src_fifo1,"
1983: echo " src_fifo1_next,"
1984: echo " src_fifo1_bits,"
1985: echo " src_bipp,"
1986: echo " src_raw1,"
1987: echo " src_order);"
1.1.1.2 ! root 1988: echo " pixel ="
1.1 root 1989: echo " ((src_fifo0"
1990: echo " >> (src_order == TME_ENDIAN_BIG"
1991: echo " ? (32 - (src_bipp + ${src_shift}))"
1.1.1.2 ! root 1992: echo " : ${src_shift})));"
! 1993:
! 1994: echo ""
! 1995: echo " /* map the pixel subfields into intensities and accumulate them: */"
! 1996: echo " value_g += TME_FB_XLAT_MAP(pixel, src_mask_g, src_mask_i, src_indexed, src->tme_fb_connection_map_g);"
! 1997: if test "x${src_class}" != xm; then
! 1998: echo " value_r += TME_FB_XLAT_MAP(pixel, src_mask_r, src_mask_i, src_indexed, src->tme_fb_connection_map_r);"
! 1999: echo " value_b += TME_FB_XLAT_MAP(pixel, src_mask_b, src_mask_i, src_indexed, src->tme_fb_connection_map_b);"
1.1 root 2000: fi
1.1.1.2 ! root 2001: echo ""
! 2002:
! 2003: echo " pixel ="
1.1 root 2004: echo " ((src_fifo1"
2005: echo " >> (src_order == TME_ENDIAN_BIG"
2006: echo " ? (32 - (src_bipp + ${src_shift}))"
1.1.1.2 ! root 2007: echo " : ${src_shift})));"
! 2008:
! 2009: echo ""
! 2010: echo " /* map the pixel subfields into intensities and accumulate them: */"
! 2011: echo " value_g += TME_FB_XLAT_MAP(pixel, src_mask_g, src_mask_i, src_indexed, src->tme_fb_connection_map_g);"
! 2012: if test "x${src_class}" != xm; then
! 2013: echo " value_r += TME_FB_XLAT_MAP(pixel, src_mask_r, src_mask_i, src_indexed, src->tme_fb_connection_map_r);"
! 2014: echo " value_b += TME_FB_XLAT_MAP(pixel, src_mask_b, src_mask_i, src_indexed, src->tme_fb_connection_map_b);"
! 2015: fi
1.1 root 2016: echo " }"
2017: echo ""
1.1.1.2 ! root 2018: echo " /* otherwise, the third and fourth pixels are already in the"
1.1 root 2019: echo " visible parts of the source bit FIFOs; we just have to"
2020: echo " reach over the pixels we already read to get at them: */"
2021: echo " else {"
1.1.1.2 ! root 2022: echo " pixel ="
1.1 root 2023: echo " ((src_fifo0"
2024: echo " >> (src_order == TME_ENDIAN_BIG"
2025: echo " ? (32 - (src_bipp + (${src_shift} + src_bipp)))"
1.1.1.2 ! root 2026: echo " : (${src_shift} + src_bipp))));"
! 2027: echo ""
! 2028: echo " /* map the pixel subfields into intensities and accumulate them: */"
! 2029: echo " value_g += TME_FB_XLAT_MAP(pixel, src_mask_g, src_mask_i, src_indexed, src->tme_fb_connection_map_g);"
! 2030: if test "x${src_class}" != xm; then
! 2031: echo " value_r += TME_FB_XLAT_MAP(pixel, src_mask_r, src_mask_i, src_indexed, src->tme_fb_connection_map_r);"
! 2032: echo " value_b += TME_FB_XLAT_MAP(pixel, src_mask_b, src_mask_i, src_indexed, src->tme_fb_connection_map_b);"
1.1 root 2033: fi
1.1.1.2 ! root 2034: echo ""
! 2035: echo " pixel ="
1.1 root 2036: echo " ((src_fifo1"
2037: echo " >> (src_order == TME_ENDIAN_BIG"
2038: echo " ? (32 - (src_bipp + (${src_shift} + src_bipp)))"
1.1.1.2 ! root 2039: echo " : (${src_shift} + src_bipp))));"
! 2040: echo ""
! 2041: echo " /* map the pixel subfields into intensities and accumulate them: */"
! 2042: echo " value_g += TME_FB_XLAT_MAP(pixel, src_mask_g, src_mask_i, src_indexed, src->tme_fb_connection_map_g);"
! 2043: if test "x${src_class}" != xm; then
! 2044: echo " value_r += TME_FB_XLAT_MAP(pixel, src_mask_r, src_mask_i, src_indexed, src->tme_fb_connection_map_r);"
! 2045: echo " value_b += TME_FB_XLAT_MAP(pixel, src_mask_b, src_mask_i, src_indexed, src->tme_fb_connection_map_b);"
! 2046: fi
1.1 root 2047: echo " }"
1.1.1.2 ! root 2048: indent0=
! 2049: src_mask_i='((src_mask_i * 4) + 3)'
! 2050: src_mask_i_max='(TME_FB_XLAT_MAP_INDEX_MASK_MAX / 4)'
! 2051: fi
1.1 root 2052:
1.1.1.2 ! root 2053: # if we may have intensities:
! 2054: #
! 2055: if test "X${indent0}" != XX; then
1.1 root 2056: echo ""
1.1.1.2 ! root 2057: indent1=X
! 2058: case "x${src_class}" in
! 2059: xm)
! 2060: echo "${indent0} /* since the source_class is known as monochrome at code-generation"
! 2061: echo "${indent0} time, we map the green intensity directly into a pixel. we may have"
! 2062: echo "${indent0} to scale the intensity to be in the lookup range: */"
! 2063: echo "${indent0} if (src_mask_i > ${src_mask_i_max}) {"
! 2064: echo "${indent0} value_g /= TME_FB_XLAT_MAP_LINEAR_SCALE(src_mask_i, ${src_mask_i_max});"
! 2065: echo "${indent0} }"
! 2066: echo "${indent0} pixel = dst->tme_fb_connection_map_pixel[value_g];"
! 2067: ;;
! 2068: x)
! 2069: echo "${indent0} /* if the source class is monochrome, we map the green intensity"
! 2070: echo "${indent0} directly into a pixel. we may have to scale the intensity"
! 2071: echo "${indent0} to be in the lookup range: */"
! 2072: echo "${indent0} if (src->tme_fb_connection_class == TME_FB_XLAT_CLASS_MONOCHROME) {"
! 2073: echo "${indent0} if (src_mask_i > ${src_mask_i_max}) {"
! 2074: echo "${indent0} value_g /= TME_FB_XLAT_MAP_LINEAR_SCALE(src_mask_i, ${src_mask_i_max});"
! 2075: echo "${indent0} }"
! 2076: echo "${indent0} pixel = dst->tme_fb_connection_map_pixel[value_g];"
! 2077: echo "${indent0} }"
1.1 root 2078: echo ""
1.1.1.2 ! root 2079: echo "${indent0} /* otherwise, we have to consider all three intensities: */"
! 2080: echo "${indent0} else {"
! 2081: indent1="${indent0} "
! 2082: ;;
! 2083: *)
! 2084: echo "${indent0} /* we have to consider all three intensities: */"
! 2085: indent1="${indent0}"
! 2086: esac
! 2087:
! 2088: if test "X${indent1}" != "XX"; then
! 2089: echo ""
! 2090: echo "${indent1} /* if destination intensities are indexed: */"
! 2091: echo "${indent1} if (dst_indexed) {"
! 2092: echo ""
! 2093: echo "${indent1} /* we may have to scale the intensities to be in the lookup range: */"
! 2094: echo "${indent1} if (src_mask_i > ${src_mask_i_max}) {"
! 2095: echo "${indent1} value_g /= TME_FB_XLAT_MAP_LINEAR_SCALE(src_mask_i, ${src_mask_i_max});"
! 2096: echo "${indent1} value_r /= TME_FB_XLAT_MAP_LINEAR_SCALE(src_mask_i, ${src_mask_i_max});"
! 2097: echo "${indent1} value_b /= TME_FB_XLAT_MAP_LINEAR_SCALE(src_mask_i, ${src_mask_i_max});"
! 2098: echo "${indent1} }"
! 2099: echo ""
! 2100: echo "${indent1} /* form the pixel: */"
! 2101: echo "${indent1} pixel = _TME_FB_XLAT_MAP_INDEX(value_g, dst_mask_g, dst->tme_fb_connection_map_g);"
! 2102: echo "${indent1} pixel |= _TME_FB_XLAT_MAP_INDEX(value_r, dst_mask_r, dst->tme_fb_connection_map_r);"
! 2103: echo "${indent1} pixel |= _TME_FB_XLAT_MAP_INDEX(value_b, dst_mask_b, dst->tme_fb_connection_map_b);"
! 2104: echo "${indent1} }"
! 2105: echo ""
! 2106: echo "${indent1} /* otherwise, destination intensities are linear: */"
! 2107: echo "${indent1} else {"
! 2108: echo ""
! 2109: echo "${indent1} /* form the pixel: */"
! 2110: echo "${indent1} pixel = _TME_FB_XLAT_MAP_LINEAR(value_g, ${src_mask_i}, dst_mask_g);"
! 2111: echo "${indent1} pixel |= _TME_FB_XLAT_MAP_LINEAR(value_r, ${src_mask_i}, dst_mask_r);"
! 2112: echo "${indent1} pixel |= _TME_FB_XLAT_MAP_LINEAR(value_b, ${src_mask_i}, dst_mask_b);"
! 2113: echo ""
! 2114: echo "${indent1} /* if destination pixels are indexed: */"
! 2115: echo "${indent1} if (dst_masks_default) {"
! 2116: echo "${indent1} pixel = dst->tme_fb_connection_map_pixel[pixel];"
! 2117: echo "${indent1} }"
! 2118: echo "${indent1} }"
! 2119:
! 2120: if test "X${indent1}" != "X${indent0}"; then
! 2121: echo "${indent0} }"
! 2122: fi
! 2123: if test "X${indent0}" != X; then
! 2124: echo "${indent0} }"
! 2125: fi
1.1 root 2126: fi
2127: fi
2128:
2129: echo ""
2130: if test $scale = _h_; then
2131:
2132: echo " /* if we just read the last pixels on these"
2133: echo " source scanlines: */"
2134: if test `expr ${iter_next} % ${src_unroll}` = 0; then
2135: echo " if ((src_x +="
2136: echo " (src_packed"
2137: echo " ? `expr ${src_unroll} \* 2`"
2138: echo " : 2))"
2139: echo " == src_width) {"
2140: else
2141: echo " if (!src_packed"
2142: echo " && (src_x += 2) == src_width) {"
2143: fi
2144: echo ""
2145: echo " /* we need to rapidly shift the source FIFOs"
2146: echo " to skip not only pad bits and undisplayed"
2147: echo " pixels on the next line, but actually the"
2148: echo " *entire* next line."
2149: echo ""
2150: echo " note that this sounds like when we're done,"
2151: echo " the bits at the fronts of the FIFOs will be"
2152: echo " the *first* pixels on the next scanlines."
2153: echo ""
2154: echo " but the bits at the fronts of the FIFOs now"
2155: echo " are the *last* pixels on the current scanlines -"
2156: echo " they haven't been shifted off yet. so when"
2157: echo " we're done, we want one pixel's worth of bits"
2158: echo " in the FIFOs before the first pixel on the"
2159: echo " next scanlines: */"
2160: echo ""
2161: echo " /* calculate the number of bits that we need"
2162: echo " to shift the source primary FIFO, after"
2163: echo " discarding any bits in it now: */"
2164: echo " src_off = ((src_bypl * 8) - (src_width * src_bipp)) + (src_bypl * 8);"
2165: echo " src_off -= (src_fifo0_may_be_unaligned"
2166: echo " ? src_fifo0_bits"
2167: echo " : 32);"
2168: echo ""
2169: echo " /* rapidly advance src_raw0 by the number of"
2170: echo " whole 32-bit words. this will leave it pointing"
2171: echo " to the 32-bit word that has the first bit that"
2172: echo " we want to end up as the first bit in the source"
2173: echo " primary FIFO: */"
2174: echo " src_raw0 += (src_off / 32);"
2175: echo ""
2176: echo " /* reprime the source primary FIFO: */"
2177: echo " src_fifo0 = *src_raw0;"
2178: echo " *TME_FB_XLAT_SRC_OLD(src_raw0) = src_fifo0;"
2179: echo " src_raw0++;"
2180: echo " src_fifo0 = ((src_order == TME_ENDIAN_BIG)"
2181: echo " ? tme_betoh_u32(src_fifo0)"
2182: echo " : tme_letoh_u32(src_fifo0));"
2183: echo ""
2184: echo " /* if the source primary FIFO may be unaligned: */"
2185: echo " if (src_fifo0_may_be_unaligned) {"
2186: echo ""
2187: echo " /* reprime the top half of the FIFO, leaving a"
2188: echo " total of 64 bits in it: */"
2189: echo " src_fifo0_next = *src_raw0;"
2190: echo " *TME_FB_XLAT_SRC_OLD(src_raw0) = src_fifo0_next;"
2191: echo " src_raw0++;"
2192: echo " src_fifo0_next = ((src_order == TME_ENDIAN_BIG)"
2193: echo " ? tme_betoh_u32(src_fifo0_next)"
2194: echo " : tme_letoh_u32(src_fifo0_next));"
2195: echo " src_fifo0_bits = 64;"
2196: echo ""
2197: echo " /* if we have to shift off bits left over"
2198: echo " from rapidly advancing whole 32-bit words: */"
2199: echo " src_off %= 32;"
2200: echo " if (src_off > 0) {"
1.1.1.2 ! root 2201: echo " TME_FB_XLAT_SHIFT_SRC(TRUE,"
1.1 root 2202: echo " src_fifo0,"
2203: echo " src_fifo0_next,"
2204: echo " src_fifo0_bits,"
2205: echo " src_off,"
2206: echo " src_raw0,"
2207: echo " src_order);"
2208: echo " }"
2209: echo " }"
2210: echo ""
2211: echo " /* otherwise, the source primary FIFO is always aligned: */"
2212: echo " else {"
2213: echo " assert ((src_off % 32) == 0);"
2214: echo " }"
2215: echo ""
2216: echo " /* calculate the number of bits that we need"
2217: echo " to shift the source secondary FIFO, after"
2218: echo " discarding any bits in it now: */"
2219: echo " src_off = ((src_bypl * 8) - (src_width * src_bipp)) + (src_bypl * 8);"
2220: echo " src_off -= (src_fifo1_may_be_unaligned"
2221: echo " ? src_fifo1_bits"
2222: echo " : 32);"
2223: echo ""
2224: echo " /* rapidly advance src_raw1 by the number of"
2225: echo " whole 32-bit words. this will leave it pointing"
2226: echo " to the 32-bit word that has the first bit that"
2227: echo " we want to end up as the first bit in the source"
2228: echo " secondary FIFO: */"
2229: echo " src_raw1 += (src_off / 32);"
2230: echo ""
2231: echo " /* reprime the source secondary FIFO: */"
2232: echo " src_fifo1 = *src_raw1;"
2233: echo " *TME_FB_XLAT_SRC_OLD(src_raw1) = src_fifo1;"
2234: echo " src_raw1++;"
2235: echo " src_fifo1 = ((src_order == TME_ENDIAN_BIG)"
2236: echo " ? tme_betoh_u32(src_fifo1)"
2237: echo " : tme_letoh_u32(src_fifo1));"
2238: echo ""
2239: echo " /* if the source secondary FIFO may be unaligned: */"
2240: echo " if (src_fifo1_may_be_unaligned) {"
2241: echo ""
2242: echo " /* reprime the top half of the FIFO, leaving a"
2243: echo " total of 64 bits in it: */"
2244: echo " src_fifo1_next = *src_raw1;"
2245: echo " *TME_FB_XLAT_SRC_OLD(src_raw1) = src_fifo1_next;"
2246: echo " src_raw1++;"
2247: echo " src_fifo1_next = ((src_order == TME_ENDIAN_BIG)"
2248: echo " ? tme_betoh_u32(src_fifo1_next)"
2249: echo " : tme_letoh_u32(src_fifo1_next));"
2250: echo " src_fifo1_bits = 64;"
2251: echo ""
2252: echo " /* if we have to shift off bits left over"
2253: echo " from rapidly advancing whole 32-bit words: */"
2254: echo " src_off %= 32;"
2255: echo " if (src_off > 0) {"
1.1.1.2 ! root 2256: echo " TME_FB_XLAT_SHIFT_SRC(TRUE,"
1.1 root 2257: echo " src_fifo1,"
2258: echo " src_fifo1_next,"
2259: echo " src_fifo1_bits,"
2260: echo " src_off,"
2261: echo " src_raw1,"
2262: echo " src_order);"
2263: echo " }"
2264: echo " }"
2265: echo ""
2266: echo " /* otherwise, the source secondary FIFO is always aligned: */"
2267: echo " else {"
2268: echo " assert ((src_off % 32) == 0);"
2269: echo " }"
2270: echo ""
2271: echo " /* we are now on the first pixel of the next scanline: */"
2272: echo " src_x = 0;"
2273: echo " }"
2274: else
2275: echo " /* if the source buffer is not packed, and we just"
2276: echo " read the last pixel on this source scanline: */"
2277: echo " if (!src_packed"
2278: echo " && ++src_x == src_width) {"
2279: echo ""
2280: echo " /* calculate the number of bits between the"
2281: echo " last bit of the last pixel and the first bit"
2282: echo " of the first displayed pixel on the next"
2283: echo " scanline. this is equal to the number of"
2284: echo " pad bits plus bits for undisplayed pixels: */"
2285: echo " src_off = ((src_bypl * 8) - (src_width * src_bipp));"
2286: echo ""
2287: echo " /* while there are bits to shift: */"
2288: echo " for (; src_off > 0; src_off -= TME_MIN(src_off, 32)) {"
2289: echo ""
2290: echo " /* shift the source primary FIFO: */"
2291: echo " TME_FB_XLAT_SHIFT_SRC(src_fifo0_may_be_unaligned,"
2292: echo " src_fifo0,"
2293: echo " src_fifo0_next,"
2294: echo " src_fifo0_bits,"
2295: echo " TME_MIN(src_off, 32),"
2296: echo " src_raw0,"
2297: echo " src_order);"
2298: echo " }"
2299: echo ""
2300: echo " /* we are now on the first pixel of the next scanline: */"
2301: echo " src_x = 0;"
2302: echo " }"
2303: fi
2304:
2305: if test `expr ${iter_next} % ${src_unroll}` = 0; then
1.1.1.2 ! root 2306:
! 2307: echo ""
! 2308: if test "${src_fifo_shift}" = 32; then
! 2309: echo " /* we've just translated another 32-bit word of the"
! 2310: echo " source image, so decrement xlat_run: */"
! 2311: echo " xlat_run--;"
! 2312: else
! 2313: echo " /* if we've just finished translating another 32-bit"
! 2314: echo " word of the source image, decrement xlat_run: */"
! 2315: echo " if (src_fifo0_bits <= 32 + ${src_fifo_shift}) {"
! 2316: echo " xlat_run--;"
! 2317: echo " }"
! 2318: fi
1.1 root 2319: echo ""
2320: echo " /* shift the source primary FIFO: */"
2321: echo " TME_FB_XLAT_SHIFT_SRC(src_fifo0_may_be_unaligned,"
2322: echo " src_fifo0,"
2323: echo " src_fifo0_next,"
2324: echo " src_fifo0_bits,"
2325: echo " ${src_fifo_shift},"
2326: echo " src_raw0,"
2327: echo " src_order);"
2328: if test $scale = _h_; then
2329: echo ""
2330: echo " /* shift the source secondary FIFO: */"
2331: echo " TME_FB_XLAT_SHIFT_SRC(src_fifo1_may_be_unaligned,"
2332: echo " src_fifo1,"
2333: echo " src_fifo1_next,"
2334: echo " src_fifo1_bits,"
2335: echo " ${src_fifo_shift},"
2336: echo " src_raw1,"
2337: echo " src_order);"
2338: fi
2339: fi
2340:
2341: # the number of bits to skip in a destination FIFO to get to
2342: # this iteration's pixel:
2343: dst_shift=`expr ${iter} % ${dst_unroll}`
2344: dst_shift='('`expr ${dst_shift} \* ${dst_iter_scale}`' * dst_bipp)'
2345:
2346: echo ""
2347: echo " /* put the pixel into the destination primary FIFO: */"
2348: echo " dst_fifo0 |="
2349: echo " (pixel"
2350: echo " << (dst_order == TME_ENDIAN_BIG"
2351: echo " ? ((32 - dst_bipp) - ${dst_shift})"
2352: echo " : ${dst_shift}));"
2353:
2354: if test $scale = _d_; then
2355:
2356: echo ""
2357: echo " /* put the pixel into the destination secondary FIFO: */"
2358: echo " dst_fifo1 |="
2359: echo " (pixel"
2360: echo " << (dst_order == TME_ENDIAN_BIG"
2361: echo " ? ((32 - dst_bipp) - ${dst_shift})"
2362: echo " : ${dst_shift}));"
2363:
2364: echo ""
1.1.1.2 ! root 2365: if test `expr ${dst_bipp} \>= 24` = 1; then
! 2366: echo " /* put the pixel into both FIFOs again. in"
! 2367: echo " this case, dst_bipp is known to be ${dst_bipp},"
! 2368: echo " meaning the FIFOs cannot entirely take these"
! 2369: echo " further pixels, so we need to shift the FIFOs: */"
! 2370: indent0=""
! 2371: indent1=X
! 2372: elif test ${dst_bipp} = 0; then
! 2373: echo " /* put the pixel into both FIFOs again. if"
! 2374: echo " dst_bipp is 24 or greater, the FIFOs can"
! 2375: echo " not entirely take these further pixels,"
! 2376: echo " so we need to shift the FIFOs: */"
! 2377: echo " if (dst_bipp >= 24) {"
! 2378: indent0=" "
! 2379: indent1=" "
! 2380: else
! 2381: echo " /* put the pixel into both FIFOs again. in"
! 2382: echo " this case, dst_bipp is known to be ${dst_bipp},"
! 2383: echo " meaning the FIFOs can take these further pixels"
! 2384: echo " without shifting the FIFOs, as long as we shift"
! 2385: echo " the pixels one pixel further: */"
! 2386: indent0=X
! 2387: indent1=""
! 2388: fi
! 2389: if test "X${indent0}" != "XX"; then
! 2390: echo "${indent0} TME_FB_XLAT_SHIFT_DST(dst_fifo0_may_be_unaligned,"
! 2391: echo "${indent0} dst_fifo0,"
! 2392: echo "${indent0} dst_fifo0_next,"
! 2393: echo "${indent0} dst_fifo0_bits,"
! 2394: echo "${indent0} dst_bipp,"
! 2395: echo "${indent0} dst_raw0,"
! 2396: echo "${indent0} dst_order);"
! 2397: echo "${indent0} TME_FB_XLAT_SHIFT_DST(dst_fifo1_may_be_unaligned,"
! 2398: echo "${indent0} dst_fifo1,"
! 2399: echo "${indent0} dst_fifo1_next,"
! 2400: echo "${indent0} dst_fifo1_bits,"
! 2401: echo "${indent0} dst_bipp,"
! 2402: echo "${indent0} dst_raw1,"
! 2403: echo "${indent0} dst_order);"
! 2404: echo ""
! 2405: echo "${indent0} /* now that we've shifted by dst_bipp, we can"
! 2406: echo "${indent0} put the further pixels exactly where the"
! 2407: echo "${indent0} first pixels went in the FIFOs: */"
! 2408: echo "${indent0} dst_fifo0 |="
! 2409: echo "${indent0} (pixel"
! 2410: echo "${indent0} << (dst_order == TME_ENDIAN_BIG"
! 2411: echo "${indent0} ? ((32 - dst_bipp) - ${dst_shift})"
! 2412: echo "${indent0} : ${dst_shift}));"
! 2413: echo "${indent0} dst_fifo1 |="
! 2414: echo "${indent0} (pixel"
! 2415: echo "${indent0} << (dst_order == TME_ENDIAN_BIG"
! 2416: echo "${indent0} ? ((32 - dst_bipp) - ${dst_shift})"
! 2417: echo "${indent0} : ${dst_shift}));"
! 2418: fi
! 2419: if test ${dst_bipp} = 0; then
! 2420: echo " }"
! 2421: echo ""
! 2422: echo " /* otherwise, the FIFOs can take these further pixels,"
! 2423: echo " as long as we shift the pixels one pixel further: */"
! 2424: echo " else {"
! 2425: fi
! 2426: if test "X${indent1}" != "XX"; then
! 2427: echo "${indent1} dst_fifo0 |="
! 2428: echo "${indent1} (pixel"
! 2429: echo "${indent1} << (dst_order == TME_ENDIAN_BIG"
! 2430: echo "${indent1} ? ((32 - dst_bipp) - (${dst_shift} + dst_bipp))"
! 2431: echo "${indent1} : (${dst_shift} + dst_bipp)));"
! 2432: echo "${indent1} dst_fifo1 |="
! 2433: echo "${indent1} (pixel"
! 2434: echo "${indent1} << (dst_order == TME_ENDIAN_BIG"
! 2435: echo "${indent1} ? ((32 - dst_bipp) - (${dst_shift} + dst_bipp))"
! 2436: echo "${indent1} : (${dst_shift} + dst_bipp)));"
! 2437: fi
! 2438: if test ${dst_bipp} = 0; then
! 2439: echo " }"
! 2440: fi
1.1 root 2441: fi
2442:
2443: echo ""
2444: echo " /* if the destination buffer is not packed, and we just"
2445: echo " wrote the last pixel on this destination scanline: */"
2446: if test $scale = _d_; then value=2; else value=1; fi
2447: echo " if (!dst_packed"
2448: echo " && (dst_x += ${value}) == dst_width) {"
2449: echo ""
2450: echo " /* calculate the number of bits between the"
2451: echo " last bit of the last pixel and the first bit"
2452: echo " of the first displayed pixel on the next"
2453: echo " scanline. this is equal to the number of"
2454: echo " pad bits plus bits for undisplayed pixels: */"
2455: echo " dst_off = ((dst_bypl * 8) - (dst_width * dst_bipp));"
2456: echo ""
2457: echo " /* while there are bits to shift: */"
2458: echo " for (; dst_off > 0; dst_off -= TME_MIN(dst_off, 32)) {"
2459: echo ""
2460: echo " /* shift the destination primary FIFO: */"
2461: echo " TME_FB_XLAT_SHIFT_DST(dst_fifo0_may_be_unaligned,"
2462: echo " dst_fifo0,"
2463: echo " dst_fifo0_next,"
2464: echo " dst_fifo0_bits,"
2465: echo " TME_MIN(dst_off, 32),"
2466: echo " dst_raw0,"
2467: echo " dst_order);"
2468: if test $scale = _d_; then
2469: echo ""
2470: echo " /* shift the destination secondary FIFO: */"
2471: echo " TME_FB_XLAT_SHIFT_DST(dst_fifo1_may_be_unaligned,"
2472: echo " dst_fifo1,"
2473: echo " dst_fifo1_next,"
2474: echo " dst_fifo1_bits,"
2475: echo " TME_MIN(dst_off, 32),"
2476: echo " dst_raw1,"
2477: echo " dst_order);"
2478: fi
2479: echo " }"
2480: echo ""
2481: echo " /* we are now on the first pixel of the next scanline: */"
2482: echo " dst_x = 0;"
2483: echo " }"
2484:
2485: if test `expr ${iter_next} % ${dst_unroll}` = 0; then
2486: echo ""
2487: echo " /* shift the destination primary FIFO: */"
2488: echo " TME_FB_XLAT_SHIFT_DST(dst_fifo0_may_be_unaligned,"
2489: echo " dst_fifo0,"
2490: echo " dst_fifo0_next,"
2491: echo " dst_fifo0_bits,"
2492: echo " ${dst_fifo_shift},"
2493: echo " dst_raw0,"
2494: echo " dst_order);"
2495: if test $scale = _d_; then
2496: echo ""
2497: echo " /* shift the destination secondary FIFO: */"
2498: echo " TME_FB_XLAT_SHIFT_DST(dst_fifo1_may_be_unaligned,"
2499: echo " dst_fifo1,"
2500: echo " dst_fifo1_next,"
2501: echo " dst_fifo1_bits,"
2502: echo " ${dst_fifo_shift},"
2503: echo " dst_raw1,"
2504: echo " dst_order);"
2505: fi
2506: fi
2507:
2508: iter=${iter_next}
2509: done
2510: echo ""
2511: echo " }"
2512:
2513: if test `expr ${iter} % ${dst_unroll}` != 0; then
2514: echo "$PROG internal error - the last iter did not shift the destination FIFOs ($iter and $dst_unroll)" 1>&2
2515: exit 1
2516: fi
2517:
2518: echo ""
2519: echo " /* if the destination FIFOs may be unaligned, there"
2520: echo " may be bits left in the FIFO that we need to flush: */"
2521: echo " if (dst_fifo0_may_be_unaligned"
2522: echo " && dst_fifo0_bits > 0) {"
2523: echo " dst_fifo0 = *dst_raw0;"
2524: echo " if (dst_order == TME_ENDIAN_BIG) {"
2525: echo " dst_fifo0_next |= (tme_betoh_u32(dst_fifo0) & (0xffffffff >> dst_fifo0_bits));"
2526: echo " dst_fifo0_next = tme_htobe_u32(dst_fifo0_next);"
2527: echo " }"
2528: echo " else {"
2529: echo " dst_fifo0_next |= (tme_letoh_u32(dst_fifo0) & (0xffffffff << dst_fifo0_bits));"
2530: echo " dst_fifo0_next = tme_htole_u32(dst_fifo0_next);"
2531: echo " }"
2532: echo " *dst_raw0 = dst_fifo0;"
2533: echo " }"
2534: if test $scale = _d_; then
2535: echo " if (dst_fifo1_may_be_unaligned"
2536: echo " && dst_fifo1_bits > 0) {"
2537: echo " dst_fifo1 = *dst_raw1;"
2538: echo " if (dst_order == TME_ENDIAN_BIG) {"
2539: echo " dst_fifo1_next |= (tme_betoh_u32(dst_fifo1) & (0xffffffff >> dst_fifo1_bits));"
2540: echo " dst_fifo1_next = tme_htobe_u32(dst_fifo1_next);"
2541: echo " }"
2542: echo " else {"
2543: echo " dst_fifo1_next |= (tme_letoh_u32(dst_fifo1) & (0xffffffff << dst_fifo1_bits));"
2544: echo " dst_fifo1_next = tme_htole_u32(dst_fifo1_next);"
2545: echo " }"
2546: echo " *dst_raw1 = dst_fifo1;"
2547: echo " }"
2548: fi
2549:
2550: echo ""
2551: echo " /* loop back to compare more 32-bit words: */"
2552: echo " src_raw0--;"
2553: echo " }"
2554:
2555: echo ""
2556: echo " /* return nonzero iff we did some translating: */"
2557: echo " return (xlat_run >= 0);"
2558:
2559: echo ""
2560: for macro in ${undef_macros}; do
2561: echo "#undef ${macro}"
2562: done
2563: echo "}"
2564:
2565: done
2566: done
2567:
2568: echo ""
2569: echo "/* the xlat function array: */"
2570: echo "static const struct tme_fb_xlat tme_fb_xlats[] = {$xlat_array
2571: };"
2572:
2573: # done:
2574: exit 0
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.