original 1.0.1 release
[xwelltris.git] / src / image / accel.c
blob77b02243bca320873958effef28a6fc2be25d5cb
1 /****************************************************************************
2 * Copyright (C) 1996 by Leo Khramov
3 * email: old@sunct2.jinr.dubna.su
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 ****************************************************************************/
15 #include "accel.h"
16 #include <X11/Xlib.h>
18 char *imd;
19 void (*im_coding)(unsigned int,unsigned int,unsigned int,char**);
20 void im_truetruecoding(unsigned int ir,unsigned int ig,unsigned int ib,char **imdata)
22 int j;
23 imd=*imdata;
24 ir>>=red_rsh;
25 ir<<=red_lsh;
26 ig>>=green_rsh;
27 ig<<=green_lsh;
28 ib>>=blue_rsh;
29 ib<<=blue_lsh;
30 ir=ir | ig | ib;
31 imd+=bdep;
32 for(j=0;j<bdep;j++)
34 *(--imd)=(char)(ir & 0xff);
35 ir>>=8;
38 (*imdata)+=bdep;
41 void im_truenocoding(unsigned int ir,unsigned int ig,unsigned int ib,char **imdata)
43 *((*imdata)++)=ir&0xff;
44 *((*imdata)++)=ig&0xff;
45 *((*imdata)++)=ib&0xff;
48 char *im_alloc_true(int l,int h)
50 if (bdep == 1) {
51 l *= 3;
52 } else {
53 l *= bdep;
54 if (l % b_pad)
55 l += b_pad - l % b_pad;
57 return (char*) malloc(l*h);
60 void im_setzero(char* s,int len)
62 for ( ; len>0; len--)
63 *s++ = 0;
66 void im_memcopy(char *src, char* dest, int len)
69 if (src==dest || len<=0)
70 return; /* nothin' to do */
72 if (src<dest && src+len>dest)
73 { /* do backward copy */
74 src = src + len - 1;
75 dest = dest + len - 1;
76 for ( ; len>0; len--, src--, dest--)
77 *dest = *src;
80 else
82 for ( ; len>0; len--, src++, dest++)
83 *dest = *src;
88 extern int vclass;
90 unsigned int im_get_linew_true(unsigned int w)
92 unsigned line_w;
93 if(vclass==TrueColor)
95 line_w = w * bdep;
96 if (line_w % b_pad)
97 line_w += b_pad - line_w % b_pad;
98 } else
99 line_w=w*3; //24 bit non-converted images in PseudoColor before convertion.
100 return line_w;