cc68a136 |
1 | // This is part of Pico Library\r |
2 | \r |
3 | // (c) Copyright 2004 Dave, All rights reserved.\r |
4 | // (c) Copyright 2006 notaz, All rights reserved.\r |
5 | // Free for non-commercial use.\r |
6 | \r |
7 | // For commercial use, separate licencing terms must be obtained.\r |
8 | \r |
9 | \r |
10 | #include "PicoInt.h"\r |
11 | \r |
12 | int PicuAnd=0xf7de;\r |
13 | \r |
14 | // Quick low-quality conversion of 320 to 176:\r |
15 | int PicuQuick(unsigned short *dest,unsigned short *src)\r |
16 | {\r |
17 | unsigned short *end=NULL;\r |
18 | \r |
19 | src+=13; end=src+290;\r |
20 | dest++;\r |
21 | \r |
22 | do\r |
23 | {\r |
24 | *dest++=*src++;\r |
25 | *dest++=*src; src+=2;\r |
26 | *dest++=*src; src+=2;\r |
27 | *dest++=*src++;\r |
28 | *dest++=*src; src+=2;\r |
29 | *dest++=*src; src+=2;\r |
30 | }\r |
31 | while (src<end);\r |
32 | \r |
33 | return 0;\r |
34 | }\r |
35 | \r |
36 | // Shrink the pixels in src/srcLen, to the screen line pointed to by dest/destLen\r |
37 | int PicuShrink(unsigned short *dest,int destLen,unsigned short *src,int srcLen)\r |
38 | {\r |
39 | unsigned short *end=NULL;\r |
40 | int bias=0,pa=0,sub=0;\r |
41 | \r |
42 | end=dest+destLen;\r |
43 | sub=srcLen-destLen;\r |
44 | \r |
45 | do\r |
46 | {\r |
47 | pa=*src++; bias-=sub;\r |
48 | if (bias<0) { pa+=*src++; pa>>=1; bias+=destLen; }\r |
49 | *dest++=(unsigned short)pa;\r |
50 | \r |
51 | pa=*src++; bias-=sub;\r |
52 | if (bias<0) { pa+=*src++; pa>>=1; bias+=destLen; }\r |
53 | *dest++=(unsigned short)pa;\r |
54 | }\r |
55 | while (dest<end);\r |
56 | \r |
57 | return 0;\r |
58 | }\r |
59 | \r |
60 | // same thing, only reversed (dest is in pre-decremental mode)\r |
61 | int PicuShrinkReverse(unsigned short *dest,int destLen,unsigned short *src,int srcLen)\r |
62 | {\r |
63 | unsigned short *end=NULL;\r |
64 | int bias=0,pa=0,sub=0;\r |
65 | \r |
66 | end=dest-destLen;\r |
67 | sub=srcLen-destLen;\r |
68 | \r |
69 | do\r |
70 | {\r |
71 | pa=*src++; bias-=sub;\r |
72 | if (bias<0) { pa+=*src++; pa>>=1; bias+=destLen; }\r |
73 | *(--dest)=(unsigned short)pa;\r |
74 | \r |
75 | pa=*src++; bias-=sub;\r |
76 | if (bias<0) { pa+=*src++; pa>>=1; bias+=destLen; }\r |
77 | *(--dest)=(unsigned short)pa;\r |
78 | }\r |
79 | while (dest>end);\r |
80 | \r |
81 | return 0;\r |
82 | }\r |
83 | \r |
84 | int PicuMerge(unsigned short *dest,int destLen,unsigned short *src,int srcLen)\r |
85 | {\r |
86 | unsigned short *end=NULL;\r |
87 | int bias=0,pa=0,mask=PicuAnd,sub=0;\r |
88 | \r |
89 | end=dest+destLen;\r |
90 | sub=srcLen-destLen;\r |
91 | \r |
92 | do\r |
93 | {\r |
94 | pa=*src++; bias-=sub;\r |
95 | if (bias<0) { pa+=*src++; pa>>=1; bias+=destLen; }\r |
96 | pa&=mask; pa+=(*dest)&mask; pa>>=1;\r |
97 | *dest++=(unsigned short)pa;\r |
98 | \r |
99 | pa=*src++; bias-=sub;\r |
100 | if (bias<0) { pa+=*src++; pa>>=1; bias+=destLen; }\r |
101 | pa&=mask; pa+=(*dest)&mask; pa>>=1;\r |
102 | *dest++=(unsigned short)pa;\r |
103 | }\r |
104 | while (dest<end);\r |
105 | \r |
106 | return 0;\r |
107 | }\r |
108 | \r |