Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate
Sign In | Create Account

smooth_scaling_core.patch
Wednesday, February 6th, 2008 at 9:34:47pm UTC 

  1. commit cfe31d97ff1c4edf6f4c000ecd334de5625d81a3
  2. Author: Nicolas Pennequin <nicolas@nicolas-laptop.(none)>
  3. Date:   Wed Feb 6 22:25:36 2008 +0100
  4.  
  5.     Smooth scaling in the core
  6.  
  7. diff --git a/apps/SOURCES b/apps/SOURCES
  8. index c93c5bc..1f53a0d 100644
  9. --- a/apps/SOURCES
  10. +++ b/apps/SOURCES
  11. @@ -73,6 +73,7 @@ player/keyboard.c
  12.  #endif
  13.  #ifdef HAVE_LCD_BITMAP
  14.  recorder/bmp.c
  15. +recorder/bmp_smooth_scale.c
  16.  recorder/icons.c
  17.  recorder/keyboard.c
  18.  recorder/peakmeter.c
  19. diff --git a/apps/plugin.c b/apps/plugin.c
  20. index 6862ddb..2012b54 100644
  21. --- a/apps/plugin.c
  22. +++ b/apps/plugin.c
  23. @@ -592,6 +592,10 @@ static const struct plugin_api rockbox_api = {
  24.      dsp_configure,
  25.      dsp_process,
  26.  #endif /* CONFIG_CODEC == SWCODEC */
  27. +
  28. +#ifdef HAVE_LCD_BITMAP
  29. +    smooth_resize_bitmap,
  30. +#endif
  31.  };
  32.  
  33.  int plugin_load(const char* plugin, void* parameter)
  34. diff --git a/apps/plugin.h b/apps/plugin.h
  35. index 164a2c9..afba1b1 100644
  36. --- a/apps/plugin.h
  37. +++ b/apps/plugin.h
  38. @@ -731,6 +731,10 @@ struct plugin_api {
  39.      int (*dsp_process)(struct dsp_config *dsp, char *dest,
  40.                         const char *src[], int count);
  41.  #endif /* CONFIG_CODEC == SWCODEC */
  42. +
  43. +#ifdef HAVE_LCD_BITMAP
  44. +    void (*smooth_resize_bitmap)(struct bitmap *src,  struct bitmap *dst);
  45. +#endif
  46.  };
  47.  
  48.  /* plugin header */
  49. diff --git a/apps/plugins/CATEGORIES b/apps/plugins/CATEGORIES
  50. index 4b267c1..fc81614 100644
  51. --- a/apps/plugins/CATEGORIES
  52. +++ b/apps/plugins/CATEGORIES
  53. @@ -82,6 +82,7 @@ test_disk,apps
  54.  test_fps,apps
  55.  test_sampr,apps
  56.  test_scanrate,apps
  57. +test_resize,apps
  58.  test_viewports,apps
  59.  text_editor,apps
  60.  vbrfix,viewers
  61. diff --git a/apps/plugins/SOURCES b/apps/plugins/SOURCES
  62. index 8ad7c3f..c8f269e 100644
  63. --- a/apps/plugins/SOURCES
  64. +++ b/apps/plugins/SOURCES
  65. @@ -22,6 +22,8 @@ stopwatch.c
  66.  vbrfix.c
  67.  viewer.c
  68.  
  69. +test_resize.c
  70. +
  71.  #ifdef OLYMPUS_MROBE_500
  72.  /* remove these once the plugins before it are compileable */
  73.  jpeg.c
  74. diff --git a/apps/plugins/sliding_puzzle.c b/apps/plugins/sliding_puzzle.c
  75. index f9a723c..03dc3e1 100644
  76. --- a/apps/plugins/sliding_puzzle.c
  77. +++ b/apps/plugins/sliding_puzzle.c
  78. @@ -239,7 +239,7 @@ static bool load_resize_bitmap(void)
  79.                                  FORMAT_NATIVE );
  80.          if( rc > 0 )
  81.          {
  82. -            simple_resize_bitmap( &temp_bitmap, &main_bitmap );
  83. +            rb->smooth_resize_bitmap( &temp_bitmap, &main_bitmap );
  84.              puzzle_bmp_ptr = (const fb_data *)img_buf;
  85.              rb->strcpy( img_buf_path, filename );
  86.              return true;
  87. diff --git a/apps/plugins/test_resize.c b/apps/plugins/test_resize.c
  88. index 8583613..109b608 100644
  89. --- a/apps/plugins/test_resize.c
  90. +++ b/apps/plugins/test_resize.c
  91. @@ -36,31 +36,28 @@ const struct button_mapping *plugin_contexts[]
  92.  #define NB_ACTION_CONTEXTS sizeof(plugin_contexts)/sizeof(plugin_contexts[0])
  93.  
  94.  /* Key assignement */
  95. -#if (CONFIG_KEYPAD == IPOD_1G2G_PAD) \
  96. - || (CONFIG_KEYPAD == IPOD_3G_PAD) \
  97. - || (CONFIG_KEYPAD == IPOD_4G_PAD) \
  98. - || (CONFIG_KEYPAD == SANSA_E200_PAD)
  99.  #define SIZE_INCREASE           PLA_UP
  100.  #define SIZE_INCREASE_REPEAT    PLA_UP_REPEAT
  101.  #define SIZE_DECREASE           PLA_DOWN
  102.  #define SIZE_DECREASE_REPEAT    PLA_DOWN_REPEAT
  103. -#else
  104. -#define SIZE_INCREASE           PLA_RIGHT
  105. -#define SIZE_INCREASE_REPEAT    PLA_RIGHT_REPEAT
  106. -#define SIZE_DECREASE           PLA_LEFT
  107. -#define SIZE_DECREASE_REPEAT    PLA_LEFT_REPEAT
  108. -#endif
  109. +
  110. +#define WIDTH_INCREASE           PLA_RIGHT
  111. +#define WIDTH_INCREASE_REPEAT    PLA_RIGHT_REPEAT
  112. +#define WIDTH_DECREASE           PLA_LEFT
  113. +#define WIDTH_DECREASE_REPEAT    PLA_LEFT_REPEAT
  114. +
  115.  #define BUTTON_QUIT             PLA_QUIT
  116. +#define CHANGE_MODE             PLA_MENU
  117.  
  118. -#define MAX_OUTPUT_WIDTH    200
  119. -#define MAX_OUTPUT_HEIGHT   200
  120. +#define MAX_OUTPUT_WIDTH    LCD_WIDTH
  121. +#define MAX_OUTPUT_HEIGHT   LCD_HEIGHT
  122.  
  123.  static fb_data *b;
  124.  
  125.  static struct bitmap input_bmp;
  126.  static struct bitmap output_bmp;
  127.  
  128. -static fb_data input_bmp_data[100*100];
  129. +static fb_data input_bmp_data[200*200];
  130.  static fb_data output_bmp_data[MAX_OUTPUT_WIDTH*MAX_OUTPUT_HEIGHT];
  131.  
  132.  
  133. @@ -93,11 +90,22 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
  134.      DEBUGF("input_bmp_data starts at %p\n", input_bmp_data);
  135.      DEBUGF("output_bmp_data starts at %p\n", output_bmp_data);
  136.  
  137. +    int scale_algorithm = 0;
  138. +
  139.      while(1) {
  140.          rb->lcd_clear_display();
  141.          rb->lcd_bitmap(input_bmp_data, 0, 0, input_bmp.width, input_bmp.height);
  142.  
  143. -        simple_resize_bitmap(&input_bmp, &output_bmp);
  144. +        switch ( scale_algorithm ) {
  145. +            case 0:
  146. +                rb->smooth_resize_bitmap(&input_bmp, &output_bmp);
  147. +                rb->lcd_putsxy(0,0,"smooth_resize_bitmap");
  148. +                break;
  149. +            case 1:
  150. +                simple_resize_bitmap(&input_bmp, &output_bmp);
  151. +                rb->lcd_putsxy(0,0,"simple_resize_bitmap");
  152. +                break;
  153. +        }
  154.  
  155.          rb->lcd_bitmap(output_bmp_data, 0, 100, output_bmp.width,
  156.                         output_bmp.height);
  157. @@ -118,8 +126,23 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
  158.  
  159.              case SIZE_DECREASE:
  160.              case SIZE_DECREASE_REPEAT:
  161. -                if (output_bmp.width >= 2) output_bmp.width -= 2;
  162. -                if (output_bmp.height >= 2) output_bmp.height -= 2;
  163. +                if (output_bmp.width > 2) output_bmp.width -= 2;
  164. +                if (output_bmp.height > 2) output_bmp.height -= 2;
  165. +                break;
  166. +
  167. +            case WIDTH_INCREASE:
  168. +            case WIDTH_INCREASE_REPEAT:
  169. +                if (output_bmp.width < MAX_OUTPUT_WIDTH - 2)
  170. +                    output_bmp.width += 2;
  171. +                break;
  172. +
  173. +            case WIDTH_DECREASE:
  174. +            case WIDTH_DECREASE_REPEAT:
  175. +                if (output_bmp.width > 2) output_bmp.width -= 2;
  176. +                break;
  177. +
  178. +            case CHANGE_MODE:
  179. +                scale_algorithm = (scale_algorithm+1)%2;
  180.                  break;
  181.          }
  182.      }
  183. diff --git a/apps/recorder/bmp.h b/apps/recorder/bmp.h
  184. index 3d33a8c..53c4f19 100644
  185. --- a/apps/recorder/bmp.h
  186. +++ b/apps/recorder/bmp.h
  187. @@ -39,4 +39,11 @@ int read_bmp_fd(int fd,
  188.                  struct bitmap *bm,
  189.                  int maxsize,
  190.                  int format);
  191. +
  192. +/**
  193. +   Advanced image scale from src to dst (bilinear) based on imlib2.
  194. +   Source and destination dimensions are read from the struct bitmap.
  195. + */
  196. +void smooth_resize_bitmap(struct bitmap *src,  struct bitmap *dst);
  197. +
  198.  #endif
  199. diff --git a/apps/recorder/bmp_smooth_scale.c b/apps/recorder/bmp_smooth_scale.c
  200. new file mode 100644
  201. index 0000000..a500bfa
  202. --- /dev/null
  203. +++ b/apps/recorder/bmp_smooth_scale.c
  204. @@ -0,0 +1,444 @@
  205. +/***************************************************************************
  206. + *             __________               __   ___.
  207. + *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
  208. + *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
  209. + *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
  210. + *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
  211. + *                     \/            \/     \/    \/            \/
  212. + * $Id$
  213. + *
  214. + * Code for the scaling algorithm:
  215. + * Imlib2 is (C) Carsten Haitzler and various contributors. The MMX code
  216. + * is by Willem Monsuwe <[email protected]>. Additional modifications are by
  217. + * (C) Daniel M. Duley.
  218. + *
  219. + * Port to Rockbox
  220. + * Copyright (C) 2007 Jonas Hurrelmann ([email protected])
  221. + *
  222. + * All files in this archive are subject to the GNU General Public License.
  223. + * See the file COPYING in the source tree root for full license agreement.
  224. + *
  225. + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  226. + * KIND, either express or implied.
  227. + *
  228. + ****************************************************************************/
  229. +
  230. +/*
  231. + * Copyright (C) 2004, 2005 Daniel M. Duley
  232. + *
  233. + * Redistribution and use in source and binary forms, with or without
  234. + * modification, are permitted provided that the following conditions
  235. + * are met:
  236. + *
  237. + * 1. Redistributions of source code must retain the above copyright
  238. + *    notice, this list of conditions and the following disclaimer.
  239. + * 2. Redistributions in binary form must reproduce the above copyright
  240. + *    notice, this list of conditions and the following disclaimer in the
  241. + *    documentation and/or other materials provided with the distribution.
  242. + *
  243. + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  244. + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  245. + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  246. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  247. + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  248. + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  249. + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  250. + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  251. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  252. + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  253. + *
  254. + */
  255. +
  256. +/* OTHER CREDITS:
  257. + *
  258. + * This is the normal smoothscale method, based on Imlib2's smoothscale.
  259. + *
  260. + * Originally I took the algorithm used in NetPBM and Qt and added MMX/3dnow
  261. + * optimizations. It ran in about 1/2 the time as Qt. Then I ported Imlib's
  262. + * C algorithm and it ran at about the same speed as my MMX optimized one...
  263. + * Finally I ported Imlib's MMX version and it ran in less than half the
  264. + * time as my MMX algorithm, (taking only a quarter of the time Qt does).
  265. + * After further optimization it seems to run at around 1/6th.
  266. + *
  267. + * Changes include formatting, namespaces and other C++'ings, removal of old
  268. + * #ifdef'ed code, and removal of unneeded border calculation code.
  269. + *
  270. + * Imlib2 is (C) Carsten Haitzler and various contributors. The MMX code
  271. + * is by Willem Monsuwe <[email protected]>. All other modifications are
  272. + * (C) Daniel M. Duley.
  273. + */
  274. +
  275. +#include "bmp.h"
  276. +#include "lcd.h"
  277. +
  278. +void smooth_resize_bitmap(struct bitmap *src_bmp,  struct bitmap *dest_bmp)
  279. +{
  280. +    fb_data *sptr, *dptr;
  281. +    int x, y, end;
  282. +    int val_y = 0, val_x;
  283. +    const int sw = src_bmp->width;
  284. +    const int sh = src_bmp->height;
  285. +    const int dw = dest_bmp->width;
  286. +    const int dh = dest_bmp->height;
  287. +    const int inc_x = (sw << 16) / dw;
  288. +    const int inc_y = (sh << 16) / dh;
  289. +    const int Cp_x = ((dw << 14) / sw) + 1;
  290. +    const int Cp_y = ((dh << 14) / sh) + 1;
  291. +    const int xup_yup = (dw >= sw) + ((dh >= sh) << 1);
  292. +    const int dow = dw;
  293. +    const int sow = sw;
  294. +    fb_data *src = (fb_data*)src_bmp->data;
  295. +    fb_data *dest = (fb_data*)dest_bmp->data;
  296. +    int XAP, YAP, INV_YAP, INV_XAP;
  297. +    int xpoint;
  298. +    fb_data *ypoint;
  299. +
  300. +    end = dw;
  301. +    /* scaling up both ways */
  302. +    if (xup_yup == 3) {
  303. +        /* go through every scanline in the output buffer */
  304. +        for (y = 0; y < dh; y++) {
  305. +            /* calculate the source line we'll scan from */
  306. +            ypoint = src + ((val_y >> 16) * sw);
  307. +            YAP = ((val_y >> 16) >= (sh - 1)) ? 0 : (val_y >> 8) - ((val_y >> 8) & 0xffffff00);
  308. +            INV_YAP = 256 - YAP;
  309. +
  310. +            val_y += inc_y;
  311. +            val_x = 0;
  312. +
  313. +            dptr = dest + (y * dow);
  314. +            sptr = ypoint;
  315. +            if (YAP > 0) {
  316. +                for (x = 0; x < end; x++) {
  317. +                    int r = 0, g = 0, b = 0;
  318. +                    int rr = 0, gg = 0, bb = 0;
  319. +                    fb_data *pix;
  320. +
  321. +                    xpoint = (val_x >> 16);
  322. +                    XAP = ((val_x >> 16) >= (sw - 1)) ? 0 : (val_x >> 8) - ((val_x >> 8) & 0xffffff00);
  323. +                    INV_XAP = 256 - XAP;
  324. +                    val_x += inc_x;
  325. +
  326. +                    if (XAP > 0) {
  327. +                        pix = ypoint + xpoint;
  328. +                        r = RGB_UNPACK_RED(*pix) * INV_XAP;
  329. +                        g = RGB_UNPACK_GREEN(*pix) * INV_XAP;
  330. +                        b = RGB_UNPACK_BLUE(*pix) * INV_XAP;
  331. +                        pix++;
  332. +                        r += RGB_UNPACK_RED(*pix) * XAP;
  333. +                        g += RGB_UNPACK_GREEN(*pix) * XAP;
  334. +                        b += RGB_UNPACK_BLUE(*pix) * XAP;
  335. +                        pix += sow;
  336. +                        rr = RGB_UNPACK_RED(*pix) * XAP;
  337. +                        gg = RGB_UNPACK_GREEN(*pix) * XAP;
  338. +                        bb = RGB_UNPACK_BLUE(*pix) * XAP;
  339. +                        pix--;
  340. +                        rr += RGB_UNPACK_RED(*pix) * INV_XAP;
  341. +                        gg += RGB_UNPACK_GREEN(*pix) * INV_XAP;
  342. +                        bb += RGB_UNPACK_BLUE(*pix) * INV_XAP;
  343. +                        r = ((rr * YAP) + (r * INV_YAP)) >> 16;
  344. +                        g = ((gg * YAP) + (g * INV_YAP)) >> 16;
  345. +                        b = ((bb * YAP) + (b * INV_YAP)) >> 16;
  346. +                        *dptr++ = LCD_RGBPACK(r, g, b);
  347. +                    } else {
  348. +                        pix = ypoint + xpoint;
  349. +                        r = RGB_UNPACK_RED(*pix) * INV_YAP;
  350. +                        g = RGB_UNPACK_GREEN(*pix) * INV_YAP;
  351. +                        b = RGB_UNPACK_BLUE(*pix) * INV_YAP;
  352. +                        pix += sow;
  353. +                        r += RGB_UNPACK_RED(*pix) * YAP;
  354. +                        g += RGB_UNPACK_GREEN(*pix) * YAP;
  355. +                        b += RGB_UNPACK_BLUE(*pix) * YAP;
  356. +                        r >>= 8;
  357. +                        g >>= 8;
  358. +                        b >>= 8;
  359. +                        *dptr++ = LCD_RGBPACK(r, g, b);
  360. +                    }
  361. +                }
  362. +            } else {
  363. +                for (x = 0; x < end; x++) {
  364. +                    int r = 0, g = 0, b = 0;
  365. +                    fb_data *pix;
  366. +
  367. +                    xpoint = (val_x >> 16);
  368. +                    XAP = ((val_x >> 16) >= (sw - 1)) ? 0 : (val_x >> 8) - ((val_x >> 8) & 0xffffff00);
  369. +                    INV_XAP = 256 - XAP;
  370. +                    val_x += inc_x;
  371. +
  372. +                    if (XAP > 0) {
  373. +                        pix = ypoint + xpoint;
  374. +                        r = RGB_UNPACK_RED(*pix) * INV_XAP;
  375. +                        g = RGB_UNPACK_GREEN(*pix) * INV_XAP;
  376. +                        b = RGB_UNPACK_BLUE(*pix) * INV_XAP;
  377. +                        pix++;
  378. +                        r += RGB_UNPACK_RED(*pix) * XAP;
  379. +                        g += RGB_UNPACK_GREEN(*pix) * XAP;
  380. +                        b += RGB_UNPACK_BLUE(*pix) * XAP;
  381. +                        r >>= 8;
  382. +                        g >>= 8;
  383. +                        b >>= 8;
  384. +                        *dptr++ = LCD_RGBPACK(r, g, b);
  385. +                    } else
  386. +                        *dptr++ = sptr[xpoint];
  387. +                }
  388. +            }
  389. +        }
  390. +    }
  391. +    /* if we're scaling down vertically */
  392. +    else if (xup_yup == 1) {
  393. +        /*\ 'Correct' version, with math units prepared for MMXification \ */
  394. +        int Cy, j;
  395. +        fb_data *pix;
  396. +        int r, g, b, rr, gg, bb;
  397. +        int yap;
  398. +
  399. +        /* go through every scanline in the output buffer */
  400. +        for (y = 0; y < dh; y++) {
  401. +            ypoint = src + ((val_y >> 16) * sw);
  402. +            YAP = (((0x100 - ((val_y >> 8) & 0xff)) * Cp_y) >> 8) | (Cp_y << 16);
  403. +            INV_YAP = 256 - YAP;
  404. +            val_y += inc_y;
  405. +            val_x = 0;
  406. +
  407. +            Cy = YAP >> 16;
  408. +            yap = YAP & 0xffff;
  409. +
  410. +
  411. +            dptr = dest + (y * dow);
  412. +            for (x = 0; x < end; x++) {
  413. +                xpoint = (val_x >> 16);
  414. +                XAP = ((val_x >> 16) >= (sw - 1)) ? 0 : (val_x >> 8) - ((val_x >> 8) & 0xffffff00);
  415. +                INV_XAP = 256 - XAP;
  416. +                val_x += inc_x;
  417. +
  418. +                pix = ypoint + xpoint;
  419. +                r = (RGB_UNPACK_RED(*pix) * yap) >> 10;
  420. +                g = (RGB_UNPACK_GREEN(*pix) * yap) >> 10;
  421. +                b = (RGB_UNPACK_BLUE(*pix) * yap) >> 10;
  422. +                pix += sow;
  423. +                for (j = (1 << 14) - yap; j > Cy; j -= Cy) {
  424. +                    r += (RGB_UNPACK_RED(*pix) * Cy) >> 10;
  425. +                    g += (RGB_UNPACK_GREEN(*pix) * Cy) >> 10;
  426. +                    b += (RGB_UNPACK_BLUE(*pix) * Cy) >> 10;
  427. +                    pix += sow;
  428. +                }
  429. +                if (j > 0) {
  430. +                    r += (RGB_UNPACK_RED(*pix) * j) >> 10;
  431. +                    g += (RGB_UNPACK_GREEN(*pix) * j) >> 10;
  432. +                    b += (RGB_UNPACK_BLUE(*pix) * j) >> 10;
  433. +                }
  434. +                if (XAP > 0) {
  435. +                    pix = ypoint + xpoint + 1;
  436. +                    rr = (RGB_UNPACK_RED(*pix) * yap) >> 10;
  437. +                    gg = (RGB_UNPACK_GREEN(*pix) * yap) >> 10;
  438. +                    bb = (RGB_UNPACK_BLUE(*pix) * yap) >> 10;
  439. +                    pix += sow;
  440. +                    for (j = (1 << 14) - yap; j > Cy; j -= Cy) {
  441. +                        rr += (RGB_UNPACK_RED(*pix) * Cy) >> 10;
  442. +                        gg += (RGB_UNPACK_GREEN(*pix) * Cy) >> 10;
  443. +                        bb += (RGB_UNPACK_BLUE(*pix) * Cy) >> 10;
  444. +                        pix += sow;
  445. +                    }
  446. +                    if (j > 0) {
  447. +                        rr += (RGB_UNPACK_RED(*pix) * j) >> 10;
  448. +                        gg += (RGB_UNPACK_GREEN(*pix) * j) >> 10;
  449. +                        bb += (RGB_UNPACK_BLUE(*pix) * j) >> 10;
  450. +                    }
  451. +                    r = r * INV_XAP;
  452. +                    g = g * INV_XAP;
  453. +                    b = b * INV_XAP;
  454. +                    r = (r + ((rr * XAP))) >> 12;
  455. +                    g = (g + ((gg * XAP))) >> 12;
  456. +                    b = (b + ((bb * XAP))) >> 12;
  457. +                } else {
  458. +                    r >>= 4;
  459. +                    g >>= 4;
  460. +                    b >>= 4;
  461. +                }
  462. +                *dptr = LCD_RGBPACK(r, g, b);
  463. +                dptr++;
  464. +            }
  465. +        }
  466. +    }
  467. +    /* if we're scaling down horizontally */
  468. +    else if (xup_yup == 2) {
  469. +        /*\ 'Correct' version, with math units prepared for MMXification \ */
  470. +        int Cx, j;
  471. +        fb_data *pix;
  472. +        int r, g, b, rr, gg, bb;
  473. +        int xap;
  474. +
  475. +        /* go through every scanline in the output buffer */
  476. +        for (y = 0; y < dh; y++) {
  477. +            ypoint = src + ((val_y >> 16) * sw);
  478. +            YAP = ((val_y >> 16) >= (sh - 1)) ? 0 : (val_y >> 8) - ((val_y >> 8) & 0xffffff00);
  479. +            INV_YAP = 256 - YAP;
  480. +            val_y += inc_y;
  481. +            val_x = 0;
  482. +
  483. +            dptr = dest + (y * dow);
  484. +            for (x = 0; x < end; x++) {
  485. +                xpoint = (val_x >> 16);
  486. +                XAP = (((0x100 - ((val_x >> 8) & 0xff)) * Cp_x) >> 8) | (Cp_x << 16);
  487. +                INV_XAP = 256 - XAP;
  488. +
  489. +                val_x += inc_x;
  490. +
  491. +                Cx = XAP >> 16;
  492. +                xap = XAP & 0xffff;
  493. +
  494. +                pix = ypoint + xpoint;
  495. +                r = (RGB_UNPACK_RED(*pix) * xap) >> 10;
  496. +                g = (RGB_UNPACK_GREEN(*pix) * xap) >> 10;
  497. +                b = (RGB_UNPACK_BLUE(*pix) * xap) >> 10;
  498. +                pix++;
  499. +                for (j = (1 << 14) - xap; j > Cx; j -= Cx) {
  500. +                    r += (RGB_UNPACK_RED(*pix) * Cx) >> 10;
  501. +                    g += (RGB_UNPACK_GREEN(*pix) * Cx) >> 10;
  502. +                    b += (RGB_UNPACK_BLUE(*pix) * Cx) >> 10;
  503. +                    pix++;
  504. +                }
  505. +                if (j > 0) {
  506. +                    r += (RGB_UNPACK_RED(*pix) * j) >> 10;
  507. +                    g += (RGB_UNPACK_GREEN(*pix) * j) >> 10;
  508. +                    b += (RGB_UNPACK_BLUE(*pix) * j) >> 10;
  509. +                }
  510. +                if (YAP > 0) {
  511. +                    pix = ypoint + xpoint + sow;
  512. +                    rr = (RGB_UNPACK_RED(*pix) * xap) >> 10;
  513. +                    gg = (RGB_UNPACK_GREEN(*pix) * xap) >> 10;
  514. +                    bb = (RGB_UNPACK_BLUE(*pix) * xap) >> 10;
  515. +                    pix++;
  516. +                    for (j = (1 << 14) - xap; j > Cx; j -= Cx) {
  517. +                        rr += (RGB_UNPACK_RED(*pix) * Cx) >> 10;
  518. +                        gg += (RGB_UNPACK_GREEN(*pix) * Cx) >> 10;
  519. +                        bb += (RGB_UNPACK_BLUE(*pix) * Cx) >> 10;
  520. +                        pix++;
  521. +                    }
  522. +                    if (j > 0) {
  523. +                        rr += (RGB_UNPACK_RED(*pix) * j) >> 10;
  524. +                        gg += (RGB_UNPACK_GREEN(*pix) * j) >> 10;
  525. +                        bb += (RGB_UNPACK_BLUE(*pix) * j) >> 10;
  526. +                    }
  527. +                    r = r * INV_YAP;
  528. +                    g = g * INV_YAP;
  529. +                    b = b * INV_YAP;
  530. +                    r = (r + ((rr * YAP))) >> 12;
  531. +                    g = (g + ((gg * YAP))) >> 12;
  532. +                    b = (b + ((bb * YAP))) >> 12;
  533. +                } else {
  534. +                    r >>= 4;
  535. +                    g >>= 4;
  536. +                    b >>= 4;
  537. +                }
  538. +                *dptr = LCD_RGBPACK(r, g, b);
  539. +                dptr++;
  540. +            }
  541. +        }
  542. +    }
  543. +    /* fully optimized (i think) - only change of algorithm can help */
  544. +    /* if we're scaling down horizontally & vertically */
  545. +    else {
  546. +        /*\ 'Correct' version, with math units prepared for MMXification \ */
  547. +        int Cx, Cy, i, j;
  548. +        fb_data *pix;
  549. +        int r, g, b, rx, gx, bx;
  550. +        int xap, yap;
  551. +
  552. +        for (y = 0; y < dh; y++) {
  553. +            ypoint = src + ((val_y >> 16) * sw);
  554. +            YAP = (((0x100 - ((val_y >> 8) & 0xff)) * Cp_y) >> 8) | (Cp_y << 16);
  555. +            INV_YAP = 256 - YAP;
  556. +            val_y += inc_y;
  557. +            val_x = 0;
  558. +
  559. +            Cy = YAP >> 16;
  560. +            yap = YAP & 0xffff;
  561. +
  562. +            dptr = dest + (y * dow);
  563. +            for (x = 0; x < end; x++) {
  564. +                xpoint = (val_x >> 16);
  565. +                XAP = (((0x100 - ((val_x >> 8) & 0xff)) * Cp_x) >> 8) | (Cp_x << 16);
  566. +                INV_XAP = 256 - XAP;
  567. +                val_x += inc_x;
  568. +
  569. +                Cx = XAP >> 16;
  570. +                xap = XAP & 0xffff;
  571. +
  572. +                sptr = ypoint + xpoint;
  573. +
  574. +                pix = sptr;
  575. +                sptr += sow;
  576. +                rx = (RGB_UNPACK_RED(*pix) * xap) >> 9;
  577. +                gx = (RGB_UNPACK_GREEN(*pix) * xap) >> 9;
  578. +                bx = (RGB_UNPACK_BLUE(*pix) * xap) >> 9;
  579. +                pix++;
  580. +                for (i = (1 << 14) - xap; i > Cx; i -= Cx) {
  581. +                    rx += (RGB_UNPACK_RED(*pix) * Cx) >> 9;
  582. +                    gx += (RGB_UNPACK_GREEN(*pix) * Cx) >> 9;
  583. +                    bx += (RGB_UNPACK_BLUE(*pix) * Cx) >> 9;
  584. +                    pix++;
  585. +                }
  586. +                if (i > 0) {
  587. +                    rx += (RGB_UNPACK_RED(*pix) * i) >> 9;
  588. +                    gx += (RGB_UNPACK_GREEN(*pix) * i) >> 9;
  589. +                    bx += (RGB_UNPACK_BLUE(*pix) * i) >> 9;
  590. +                }
  591. +
  592. +                r = (rx * yap) >> 14;
  593. +                g = (gx * yap) >> 14;
  594. +                b = (bx * yap) >> 14;
  595. +
  596. +                for (j = (1 << 14) - yap; j > Cy; j -= Cy) {
  597. +                    pix = sptr;
  598. +                    sptr += sow;
  599. +                    rx = (RGB_UNPACK_RED(*pix) * xap) >> 9;
  600. +                    gx = (RGB_UNPACK_GREEN(*pix) * xap) >> 9;
  601. +                    bx = (RGB_UNPACK_BLUE(*pix) * xap) >> 9;
  602. +                    pix++;
  603. +                    for (i = (1 << 14) - xap; i > Cx; i -= Cx) {
  604. +                        rx += (RGB_UNPACK_RED(*pix) * Cx) >> 9;
  605. +                        gx += (RGB_UNPACK_GREEN(*pix) * Cx) >> 9;
  606. +                        bx += (RGB_UNPACK_BLUE(*pix) * Cx) >> 9;
  607. +                        pix++;
  608. +                    }
  609. +                    if (i > 0) {
  610. +                        rx += (RGB_UNPACK_RED(*pix) * i) >> 9;
  611. +                        gx += (RGB_UNPACK_GREEN(*pix) * i) >> 9;
  612. +                        bx += (RGB_UNPACK_BLUE(*pix) * i) >> 9;
  613. +                    }
  614. +
  615. +                    r += (rx * Cy) >> 14;
  616. +                    g += (gx * Cy) >> 14;
  617. +                    b += (bx * Cy) >> 14;
  618. +                }
  619. +                if (j > 0) {
  620. +                    pix = sptr;
  621. +                    sptr += sow;
  622. +                    rx = (RGB_UNPACK_RED(*pix) * xap) >> 9;
  623. +                    gx = (RGB_UNPACK_GREEN(*pix) * xap) >> 9;
  624. +                    bx = (RGB_UNPACK_BLUE(*pix) * xap) >> 9;
  625. +                    pix++;
  626. +                    for (i = (1 << 14) - xap; i > Cx; i -= Cx) {
  627. +                        rx += (RGB_UNPACK_RED(*pix) * Cx) >> 9;
  628. +                        gx += (RGB_UNPACK_GREEN(*pix) * Cx) >> 9;
  629. +                        bx += (RGB_UNPACK_BLUE(*pix) * Cx) >> 9;
  630. +                        pix++;
  631. +                    }
  632. +                    if (i > 0) {
  633. +                        rx += (RGB_UNPACK_RED(*pix) * i) >> 9;
  634. +                        gx += (RGB_UNPACK_GREEN(*pix) * i) >> 9;
  635. +                        bx += (RGB_UNPACK_BLUE(*pix) * i) >> 9;
  636. +                    }
  637. +
  638. +                    r += (rx * j) >> 14;
  639. +                    g += (gx * j) >> 14;
  640. +                    b += (bx * j) >> 14;
  641. +                }
  642. +
  643. +                *dptr = LCD_RGBPACK(r >> 5, g >> 5, b >> 5);
  644. +                dptr++;
  645. +            }
  646. +        }
  647. +    }
  648. +}

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

comments powered by Disqus
worth-right
worth-right
worth-right