File: ldconvert.c

package info (click to toggle)
wily 0.13.33-3
  • links: PTS
  • area: main
  • in suites: slink
  • size: 1,500 kB
  • ctags: 1,720
  • sloc: ansic: 12,830; sh: 245; makefile: 188
file content (54 lines) | stat: -rw-r--r-- 1,143 bytes parent folder | download | duplicates (18)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/* Copyright (c) 1992 AT&T - All rights reserved. */
#include <libc.h>
#include <libg.h>
#include "libgint.h"

void
_ldconvert(char *in, int inld, char *out, int outld, int w, int h)
{
	int	a, b, i, j, i1, j1, j2, mask;
	int	ind, inl, outd, outl;
	int	hh, ww;
	char	*p, *q;

	i1 = 8 >> inld;
	j1 = 8 >> outld;
	ind = 1 << inld;
	outd = 1 << outld;
	inl = ((w << inld) + 7)/8;
	outl = ((w << outld) + 7)/8;
	b = 0;

	if (ind > outd) {
		mask = 256 - (256 >> outd);
		for (hh = 0; hh < h; hh++, in += inl, out += outl)
			for (p = in, q = out, ww = 0; ww < w; ww++) {
				for (j = j1; j > 0; ) {
					a = *p++;
					for (i = i1; i > 0; i--, j--) {
						b |= a & mask;
						a <<= ind;
						b <<= outd;
					}
				}
				*q++ = (b >> 8);
			}
	} else {
		j2 = 1 << (outld - inld);
		mask = 256 - (256 >> ind);
		for (hh = 0; hh < h; hh++, in += inl, out += outl)
			for (p = in, q = out, ww = 0; ww < w; ww++) {
				a = *p++;
				for (i = i1; i > 0; ) {
					for (j = j1; j > 0; j--, i--) {
						b |= a & mask;
						a <<= ind;
						b <<= outd;
					}
					for (j = j2; j > 0; j--)
						b |= (b << ind);
					*q++ = (b >> 8);
				}
			}
	}
}