ldconvert.c - sam - An updated version of the sam text editor.
 (HTM) git clone git://vernunftzentrum.de/sam.git
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) LICENSE
       ---
       ldconvert.c (1569B)
       ---
            1 /* Copyright (c) 1998 Lucent Technologies - All rights reserved. */
            2 #include <u.h>
            3 #include <libg.h>
            4 #include "libgint.h"
            5 
            6 void
            7 _ldconvert(char *in, int inld, char *out, int outld, int w, int h)
            8 {
            9     int a, b, i, j, i1, j1, j2, mask;
           10     int ind, inl, outd, outl;
           11     int hh, ww;
           12     char    *p, *q;
           13 
           14     i1 = 8 >> inld;
           15     j1 = 8 >> outld;
           16     ind = 1 << inld;
           17     outd = 1 << outld;
           18     inl = ((w << inld) + 7)/8;
           19     outl = ((w << outld) + 7)/8;
           20     b = 0;
           21 
           22     if (ind > outd) {
           23         mask = 256 - (256 >> outd);
           24         for (hh = 0; hh < h; hh++, in += inl, out += outl)
           25             for (p = in, q = out, ww = 0; ww < w; ww++) {
           26                 for (j = j1; j > 0; ) {
           27                     a = *p++;
           28                     for (i = i1; i > 0; i--, j--) {
           29                         b |= a & mask;
           30                         a <<= ind;
           31                         b <<= outd;
           32                     }
           33                 }
           34                 *q++ = (b >> 8);
           35             }
           36     } else {
           37         j2 = 1 << (outld - inld);
           38         mask = 256 - (256 >> ind);
           39         for (hh = 0; hh < h; hh++, in += inl, out += outl)
           40             for (p = in, q = out, ww = 0; ww < w; ww++) {
           41                 a = *p++;
           42                 for (i = i1; i > 0; ) {
           43                     for (j = j1; j > 0; j--, i--) {
           44                         b |= a & mask;
           45                         a <<= ind;
           46                         b <<= outd;
           47                     }
           48                     for (j = j2; j > 0; j--)
           49                         b |= (b << ind);
           50                     *q++ = (b >> 8);
           51                 }
           52             }
           53     }
           54 }