Guest User

Untitled

a guest
Jun 18th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 28.21 KB | None | 0 0
  1. diff --git a/apps/plugins/SOURCES b/apps/plugins/SOURCES
  2. index a695478..ad88bde 100644
  3. --- a/apps/plugins/SOURCES
  4. +++ b/apps/plugins/SOURCES
  5. @@ -47,6 +47,7 @@ disktidy.c
  6. flipit.c
  7.  
  8. #ifdef HAVE_LCD_BITMAP /* Not for the Player */
  9. +bench_scaler.c
  10. rockblox1d.c
  11. brickmania.c
  12. maze.c
  13. diff --git a/apps/plugins/bench_scaler.c b/apps/plugins/bench_scaler.c
  14. index c24807d..7bdd4b9 100644
  15. --- a/apps/plugins/bench_scaler.c
  16. +++ b/apps/plugins/bench_scaler.c
  17. @@ -49,8 +49,8 @@ static void output_row_null(uint32_t row, void * row_in,
  18. #else
  19. uint32_t *lim = in + ctx->bm->width;
  20. #endif
  21. - for (; in < lim; in++)
  22. - output = SC_MUL(*in + ctx->round, ctx->divisor);
  23. + while (in < lim)
  24. + output = SC_OUT(*in++);
  25. return;
  26. }
  27.  
  28. @@ -86,6 +86,9 @@ do { \
  29. /* this is the plugin entry point */
  30. enum plugin_status plugin_start(const void* parameter)
  31. {
  32. + int fd;
  33. + char logfilename[MAX_PATH];
  34. + char *ext;
  35. size_t plugin_buf_len;
  36. plugin_buf = (unsigned char *)rb->plugin_get_buffer(&plugin_buf_len);
  37. struct bitmap bm;
  38. @@ -96,13 +99,24 @@ enum plugin_status plugin_start(const void* parameter)
  39. };
  40. (void)parameter;
  41.  
  42. + rb->strcpy(logfilename, rb->plugin_get_current_filename());
  43. + ext = logfilename + rb->strlen(logfilename) - 5;
  44. + if (rb->strcasecmp(ext, ".rock"))
  45. + ext += 5;
  46. + DEBUGF("ext: %s\n", ext);
  47. + rb->strncpy(ext, ".log", MAX_PATH - (ext - logfilename));
  48. + logfilename[MAX_PATH - 1] = 0;
  49. + DEBUGF("logfilename: %s\n", logfilename);
  50. + fd = rb->open(logfilename, O_APPEND|O_WRONLY|O_CREAT);
  51. + if (fd < 0)
  52. + return PLUGIN_ERROR;
  53. rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
  54. rb->lcd_fillrect(0, 0, LCD_WIDTH, LCD_HEIGHT);
  55. rb->lcd_set_drawmode(DRMODE_SOLID);
  56. rb->lcd_getstringsize("A", NULL, &font_h);
  57. bm.data = plugin_buf;
  58. int in, out;
  59. - for (in = 64; in < 1025; in <<= 2)
  60. + for (in = 64; in < 257; in <<= 2)
  61. {
  62. for (out = 64; out < 257; out <<= 1)
  63. {
  64. @@ -128,11 +142,12 @@ enum plugin_status plugin_start(const void* parameter)
  65. t1 = t2 / 1000;
  66. t2 -= t1 * 1000;
  67. lcd_printf("%01d.%03d secs/scale", (int)t1, (int)t2);
  68. + rb->fdprintf(fd,"%dx%d->%dx%d took %d.%03d secs/scale\n", in, in, out, out, (int)t1, (int)t2);
  69. if (!(bm.width && bm.height))
  70. break;
  71. }
  72. }
  73. -
  74. + rb->close(fd);
  75. while (rb->get_action(CONTEXT_STD,1) != ACTION_STD_OK) rb->yield();
  76. return PLUGIN_OK;
  77. }
  78. diff --git a/apps/plugins/lib/grey_draw.c b/apps/plugins/lib/grey_draw.c
  79. index 6315ad9..521643c 100644
  80. --- a/apps/plugins/lib/grey_draw.c
  81. +++ b/apps/plugins/lib/grey_draw.c
  82. @@ -733,7 +733,7 @@ static void output_row_grey_32(uint32_t row, void * row_in,
  83. uint32_t *qp = (uint32_t*)row_in;
  84. uint8_t *dest = (uint8_t*)ctx->bm->data + ctx->bm->width * row;
  85. for (col = 0; col < ctx->bm->width; col++)
  86. - *dest++ = SC_MUL((*qp++) + ctx->round,ctx->divisor);
  87. + *dest++ = SC_OUT(*qp++);
  88. }
  89.  
  90. static unsigned int get_size_grey(struct bitmap *bm)
  91. diff --git a/apps/plugins/pictureflow/pictureflow.c b/apps/plugins/pictureflow/pictureflow.c
  92. index c678254..2ad74df 100644
  93. --- a/apps/plugins/pictureflow/pictureflow.c
  94. +++ b/apps/plugins/pictureflow/pictureflow.c
  95. @@ -634,20 +634,19 @@ static void output_row_32_transposed(uint32_t row, void * row_in,
  96. #ifdef USEGSLIB
  97. uint32_t *qp = (uint32_t*)row_in;
  98. for (; dest < end; dest += ctx->bm->height)
  99. - *dest = SC_MUL((*qp++) + ctx->round, ctx->divisor);
  100. + *dest = SC_OUT(*qp++);
  101. #else
  102. struct uint32_rgb *qp = (struct uint32_rgb*)row_in;
  103. - uint32_t rb_mul = SCALE_VAL(ctx->divisor, 31),
  104. - rb_rnd = SCALE_VAL(ctx->round, 31),
  105. - g_mul = SCALE_VAL(ctx->divisor, 63),
  106. - g_rnd = SCALE_VAL(ctx->round, 63);
  107. int r, g, b;
  108. for (; dest < end; dest += ctx->bm->height)
  109. {
  110. - r = SC_MUL(qp->r + rb_rnd, rb_mul);
  111. - g = SC_MUL(qp->g + g_rnd, g_mul);
  112. - b = SC_MUL(qp->b + rb_rnd, rb_mul);
  113. + r = SC_OUT(qp->r);
  114. + g = SC_OUT(qp->g);
  115. + b = SC_OUT(qp->b);
  116. qp++;
  117. + r = SCALE_VAL(r, 31);
  118. + g = SCALE_VAL(g, 63);
  119. + b = SCALE_VAL(b, 31);
  120. *dest = LCD_RGBPACK_LCD(r,g,b);
  121. }
  122. #endif
  123. @@ -663,9 +662,9 @@ static void output_row_32_transposed_fromyuv(uint32_t row, void * row_in,
  124. for (; dest < end; dest += ctx->bm->height)
  125. {
  126. unsigned r, g, b, y, u, v;
  127. - y = SC_MUL(qp->b + ctx->round, ctx->divisor);
  128. - u = SC_MUL(qp->g + ctx->round, ctx->divisor);
  129. - v = SC_MUL(qp->r + ctx->round, ctx->divisor);
  130. + y = SC_OUT(qp->b);
  131. + u = SC_OUT(qp->g);
  132. + v = SC_OUT(qp->r);
  133. qp++;
  134. yuv_to_rgb(y, u, v, &r, &g, &b);
  135. r = (31 * r + (r >> 3) + 127) >> 8;
  136. diff --git a/apps/recorder/resize.c b/apps/recorder/resize.c
  137. index 1e9210e..e6abbe9 100644
  138. --- a/apps/recorder/resize.c
  139. +++ b/apps/recorder/resize.c
  140. @@ -131,14 +131,6 @@ int recalc_dimension(struct dim *dst, struct dim *src)
  141. return false; \
  142. }
  143.  
  144. -/* Set up rounding and scale factors for horizontal area scaler */
  145. -static inline void scale_h_area_setup(struct scaler_context *ctx)
  146. -{
  147. -/* sum is output value * src->width */
  148. - SDEBUGF("scale_h_area_setup\n");
  149. - ctx->divisor = ctx->src->width;
  150. -}
  151. -
  152. /* horizontal area average scaler */
  153. static bool scale_h_area(void *out_line_ptr,
  154. struct scaler_context *ctx, bool accum)
  155. @@ -159,33 +151,86 @@ static bool scale_h_area(void *out_line_ptr,
  156. mul = 0;
  157. /* give other tasks a chance to run */
  158. yield();
  159. +#ifdef CPU_COLDFIRE
  160. + asm volatile (
  161. + "move.l #0, %acc0\n\t"
  162. +#ifdef HAVE_LCD_COLOR
  163. + "move.l #0, %acc1\n\t"
  164. + "move.l #0, %acc2\n\t"
  165. +#endif
  166. + );
  167. +#endif
  168. for (ix = 0; ix < (unsigned int)ctx->src->width; ix++)
  169. {
  170. - oxe += ctx->bm->width;
  171. + oxe += ctx->h_o_val;
  172. /* end of current area has been reached */
  173. /* fill buffer if needed */
  174. FILL_BUF(part,ctx->store_part,ctx->args);
  175. #ifdef HAVE_LCD_COLOR
  176. - if (oxe >= (unsigned int)ctx->src->width)
  177. + if (oxe >= ctx->h_i_val)
  178. {
  179. /* "reset" error, which now represents partial coverage of next
  180. pixel by the next area
  181. */
  182. - oxe -= ctx->src->width;
  183. + oxe -= ctx->h_i_val;
  184.  
  185. +#ifdef CPU_COLDFIRE
  186. /* add saved partial pixel from start of area */
  187. - rgbvalacc.r = rgbvalacc.r * ctx->bm->width + rgbvaltmp.r * mul;
  188. - rgbvalacc.g = rgbvalacc.g * ctx->bm->width + rgbvaltmp.g * mul;
  189. - rgbvalacc.b = rgbvalacc.b * ctx->bm->width + rgbvaltmp.b * mul;
  190. + asm volatile (
  191. + "mac.l %[racc], %[h_o], %%acc0\n\t"
  192. + "mac.l %[gacc], %[h_o], %%acc1\n\t"
  193. + "mac.l %[bacc], %[h_o], %%acc2\n\t"
  194. + "mac.l %[rtmp], %[mul], %%acc0\n\t"
  195. + "mac.l %[gtmp], %[mul], %%acc1\n\t"
  196. + "mac.l %[btmp], %[mul], %%acc2\n\t"
  197. + :
  198. + : [racc] "r" (rgbvalacc.r),
  199. + [gacc] "r" (rgbvalacc.g),
  200. + [bacc] "r" (rgbvalacc.b),
  201. + [rtmp] "r" (rgbvaltmp.r),
  202. + [gtmp] "r" (rgbvaltmp.g),
  203. + [btmp] "r" (rgbvaltmp.b),
  204. + [h_o] "r" (ctx->h_o_val),
  205. + [mul] "r" (mul)
  206. + );
  207. + /* get new pixel , then add its partial coverage to this area */
  208. + rgbvaltmp.r = part->buf->red;
  209. + rgbvaltmp.g = part->buf->green;
  210. + rgbvaltmp.b = part->buf->blue;
  211. + mul = ctx->h_o_val - oxe;
  212. + asm volatile (
  213. + "mac.l %[rtmp], %[mul], %%acc0\n\t"
  214. + "mac.l %[gtmp], %[mul], %%acc1\n\t"
  215. + "mac.l %[btmp], %[mul], %%acc2\n\t"
  216. + "movclr.l %%acc0, %[racc]\n\t"
  217. + "movclr.l %%acc1, %[gacc]\n\t"
  218. + "movclr.l %%acc2, %[bacc]\n\t"
  219. + : [racc] "=r" (rgbvalacc.r),
  220. + [gacc] "=r" (rgbvalacc.g),
  221. + [bacc] "=r" (rgbvalacc.b)
  222. + : [rtmp] "r" (rgbvaltmp.r),
  223. + [gtmp] "r" (rgbvaltmp.g),
  224. + [btmp] "r" (rgbvaltmp.b),
  225. + [mul] "r" (mul)
  226. + );
  227. +#else
  228. + /* add saved partial pixel from start of area */
  229. + rgbvalacc.r = rgbvalacc.r * ctx->h_o_val + rgbvaltmp.r * mul;
  230. + rgbvalacc.g = rgbvalacc.g * ctx->h_o_val + rgbvaltmp.g * mul;
  231. + rgbvalacc.b = rgbvalacc.b * ctx->h_o_val + rgbvaltmp.b * mul;
  232.  
  233. /* get new pixel , then add its partial coverage to this area */
  234. rgbvaltmp.r = part->buf->red;
  235. rgbvaltmp.g = part->buf->green;
  236. rgbvaltmp.b = part->buf->blue;
  237. - mul = ctx->bm->width - oxe;
  238. + mul = ctx->h_o_val - oxe;
  239. rgbvalacc.r += rgbvaltmp.r * mul;
  240. rgbvalacc.g += rgbvaltmp.g * mul;
  241. rgbvalacc.b += rgbvaltmp.b * mul;
  242. +#endif
  243. + rgbvalacc.r = (rgbvalacc.r + (1 << 21)) >> 22;
  244. + rgbvalacc.g = (rgbvalacc.g + (1 << 21)) >> 22;
  245. + rgbvalacc.b = (rgbvalacc.b + (1 << 21)) >> 22;
  246. /* store or accumulate to output row */
  247. if (accum)
  248. {
  249. @@ -200,7 +245,7 @@ static bool scale_h_area(void *out_line_ptr,
  250. rgbvalacc.r = 0;
  251. rgbvalacc.g = 0;
  252. rgbvalacc.b = 0;
  253. - mul = ctx->bm->width - mul;
  254. + mul = ctx->h_o_val - mul;
  255. ox += 1;
  256. /* inside an area */
  257. } else {
  258. @@ -210,21 +255,45 @@ static bool scale_h_area(void *out_line_ptr,
  259. rgbvalacc.b += part->buf->blue;
  260. }
  261. #else
  262. - if (oxe >= (unsigned int)ctx->src->width)
  263. + if (oxe >= ctx->h_i_val)
  264. {
  265. /* "reset" error, which now represents partial coverage of next
  266. pixel by the next area
  267. */
  268. - oxe -= ctx->src->width;
  269. + oxe -= ctx->h_i_val;
  270.  
  271. +#ifdef CPU_COLDFIRE
  272. + /* add saved partial pixel from start of area */
  273. + asm volatile (
  274. + "mac.l %[acc], %[h_o], %%acc0\n\t"
  275. + "mac.l %[tmp], %[mul], %%acc0\n\t"
  276. + :
  277. + : [acc] "r" (acc),
  278. + [tmp] "r" (tmp),
  279. + [h_o] "r" (ctx->h_o_val),
  280. + [mul] "r" (mul)
  281. + );
  282. + /* get new pixel , then add its partial coverage to this area */
  283. + tmp = *(part->buf);
  284. + mul = ctx->h_o_val - oxe;
  285. + asm volatile (
  286. + "mac.l %[tmp], %[mul], %%acc0\n\t"
  287. + "movclr.l %%acc0, %[acc]\n\t"
  288. + : [acc] "=r" (acc)
  289. + : [tmp] "r" (tmp),
  290. + [mul] "r" (mul)
  291. + );
  292. +#else
  293. /* add saved partial pixel from start of area */
  294. - acc = MULUQ(acc, ctx->bm->width) + MULUQ(tmp, mul);
  295. + acc = (acc * ctx->h_o_val) + (tmp * mul);
  296.  
  297. /* get new pixel , then add its partial coverage to this area */
  298. tmp = *(part->buf);
  299. - mul = ctx->bm->width - oxe;
  300. - acc += MULUQ(tmp, mul);
  301. + mul = ctx->h_o_val - oxe;
  302. + acc += tmp * mul;
  303. +#endif
  304. /* round, divide, and either store or accumulate to output row */
  305. + acc = (acc + (1 << 21)) >> 22;
  306. if (accum)
  307. {
  308. acc += out_line[ox];
  309. @@ -232,7 +301,7 @@ static bool scale_h_area(void *out_line_ptr,
  310. out_line[ox] = acc;
  311. /* reset accumulator */
  312. acc = 0;
  313. - mul = ctx->bm->width - mul;
  314. + mul = ctx->h_o_val - mul;
  315. ox += 1;
  316. /* inside an area */
  317. } else {
  318. @@ -252,9 +321,6 @@ static inline bool scale_v_area(struct rowset *rset, struct scaler_context *ctx)
  319. uint32_t mul, x, oy, iy, oye;
  320.  
  321. /* Set up rounding and scale factors */
  322. - ctx->divisor *= ctx->src->height;
  323. - ctx->round = ctx->divisor >> 1;
  324. - ctx->divisor = 1 + (-((ctx->divisor + 1) >> 1)) / ctx->divisor;
  325. mul = 0;
  326. oy = rset->rowstart;
  327. oye = 0;
  328. @@ -271,28 +337,28 @@ static inline bool scale_v_area(struct rowset *rset, struct scaler_context *ctx)
  329. /* zero the accumulator and temp rows */
  330. for (iy = 0; iy < (unsigned int)ctx->src->height; iy++)
  331. {
  332. - oye += ctx->bm->height;
  333. + oye += ctx->v_o_val;
  334. /* end of current area has been reached */
  335. - if (oye >= (unsigned int)ctx->src->height)
  336. + if (oye >= (unsigned int)ctx->v_i_val)
  337. {
  338. /* "reset" error, which now represents partial coverage of the next
  339. row by the next area
  340. */
  341. - oye -= ctx->src->height;
  342. + oye -= ctx->v_i_val;
  343. /* add stored partial row to accumulator */
  344. #ifdef HAVE_LCD_COLOR
  345. for (x = 0; x < 3 * (unsigned int)ctx->bm->width; x++)
  346. #else
  347. for (x = 0; x < (unsigned int)ctx->bm->width; x++)
  348. #endif
  349. - rowacc[x] = rowacc[x] * ctx->bm->height + mul * rowtmp[x];
  350. + rowacc[x] = rowacc[x] * ctx->v_o_val + mul * rowtmp[x];
  351. /* store new scaled row in temp row */
  352. if(!ctx->h_scaler(rowtmp, ctx, false))
  353. return false;
  354. /* add partial coverage by new row to this area, then round and
  355. scale to final value
  356. */
  357. - mul = ctx->bm->height - oye;
  358. + mul = ctx->v_o_val - oye;
  359. #ifdef HAVE_LCD_COLOR
  360. for (x = 0; x < 3 * (unsigned int)ctx->bm->width; x++)
  361. #else
  362. @@ -319,15 +385,6 @@ static inline bool scale_v_area(struct rowset *rset, struct scaler_context *ctx)
  363. }
  364.  
  365. #ifdef HAVE_UPSCALER
  366. -/* Set up rounding and scale factors for the horizontal scaler. The divisor
  367. - is bm->width - 1, so that the first and last pixels in the row align
  368. - exactly between input and output
  369. -*/
  370. -static inline void scale_h_linear_setup(struct scaler_context *ctx)
  371. -{
  372. - ctx->divisor = ctx->bm->width - 1;
  373. -}
  374. -
  375. /* horizontal linear scaler */
  376. static bool scale_h_linear(void *out_line_ptr, struct scaler_context *ctx,
  377. bool accum)
  378. @@ -348,24 +405,24 @@ static bool scale_h_linear(void *out_line_ptr, struct scaler_context *ctx,
  379. FILL_BUF_INIT(part,ctx->store_part,ctx->args);
  380. ix = 0;
  381. /* The error is set so that values are initialized on the first pass. */
  382. - ixe = ctx->bm->width - 1;
  383. + ixe = ctx->h_o_val;
  384. /* give other tasks a chance to run */
  385. yield();
  386. for (ox = 0; ox < (uint32_t)ctx->bm->width; ox++)
  387. {
  388. #ifdef HAVE_LCD_COLOR
  389. - if (ixe >= ((uint32_t)ctx->bm->width - 1))
  390. + if (ixe >= ctx->h_o_val)
  391. {
  392. /* Store the new "current" pixel value in rgbval, and the color
  393. step value in rgbinc.
  394. */
  395. - ixe -= (ctx->bm->width - 1);
  396. + ixe -= ctx->h_o_val;
  397. rgbinc.r = -(part->buf->red);
  398. rgbinc.g = -(part->buf->green);
  399. rgbinc.b = -(part->buf->blue);
  400. - rgbval.r = (part->buf->red) * (ctx->bm->width - 1);
  401. - rgbval.g = (part->buf->green) * (ctx->bm->width - 1);
  402. - rgbval.b = (part->buf->blue) * (ctx->bm->width - 1);
  403. + rgbval.r = (part->buf->red) * ctx->h_o_val;
  404. + rgbval.g = (part->buf->green) * ctx->h_o_val;
  405. + rgbval.b = (part->buf->blue) * ctx->h_o_val;
  406. ix += 1;
  407. /* If this wasn't the last pixel, add the next one to rgbinc. */
  408. if (ix < (uint32_t)ctx->src->width) {
  409. @@ -383,10 +440,10 @@ static bool scale_h_linear(void *out_line_ptr, struct scaler_context *ctx,
  410. rgbval.g += rgbinc.g * ixe;
  411. rgbval.b += rgbinc.b * ixe;
  412. }
  413. - /* Now multiple the color increment to its proper value */
  414. - rgbinc.r *= ctx->src->width - 1;
  415. - rgbinc.g *= ctx->src->width - 1;
  416. - rgbinc.b *= ctx->src->width - 1;
  417. + /* Now multiply the color increment to its proper value */
  418. + rgbinc.r *= ctx->h_i_val;
  419. + rgbinc.g *= ctx->h_i_val;
  420. + rgbinc.b *= ctx->h_i_val;
  421. } else {
  422. rgbval.r += rgbinc.r;
  423. rgbval.g += rgbinc.g;
  424. @@ -395,24 +452,24 @@ static bool scale_h_linear(void *out_line_ptr, struct scaler_context *ctx,
  425. /* round and scale values, and accumulate or store to output */
  426. if (accum)
  427. {
  428. - out_line[ox].r += rgbval.r;
  429. - out_line[ox].g += rgbval.g;
  430. - out_line[ox].b += rgbval.b;
  431. + out_line[ox].r += (rgbval.r + (1 << 21)) >> 22;
  432. + out_line[ox].g += (rgbval.g + (1 << 21)) >> 22;
  433. + out_line[ox].b += (rgbval.b + (1 << 21)) >> 22;
  434. } else {
  435. - out_line[ox].r = rgbval.r;
  436. - out_line[ox].g = rgbval.g;
  437. - out_line[ox].b = rgbval.b;
  438. + out_line[ox].r = (rgbval.r + (1 << 21)) >> 22;
  439. + out_line[ox].g = (rgbval.g + (1 << 21)) >> 22;
  440. + out_line[ox].b = (rgbval.b + (1 << 21)) >> 22;
  441. }
  442. #else
  443. - if (ixe >= ((uint32_t)ctx->bm->width - 1))
  444. + if (ixe >= ctx->h_o_val)
  445. {
  446. /* Store the new "current" pixel value in rgbval, and the color
  447. step value in rgbinc.
  448. */
  449. - ixe -= (ctx->bm->width - 1);
  450. + ixe -= ctx->h_o_val;
  451. val = *(part->buf);
  452. inc = -val;
  453. - val = MULUQ(val, ctx->bm->width - 1);
  454. + val = val * ctx->h_o_val;
  455. ix += 1;
  456. /* If this wasn't the last pixel, add the next one to rgbinc. */
  457. if (ix < (uint32_t)ctx->src->width) {
  458. @@ -424,21 +481,21 @@ static bool scale_h_linear(void *out_line_ptr, struct scaler_context *ctx,
  459. /* Add a partial step to rgbval, in this pixel isn't precisely
  460. aligned with the new source pixel
  461. */
  462. - val += MULQ(inc, ixe);
  463. + val += inc * ixe;
  464. }
  465. /* Now multiply the color increment to its proper value */
  466. - inc = MULQ(inc, ctx->src->width - 1);
  467. + inc = inc * ctx->h_i_val;
  468. } else
  469. val += inc;
  470. /* round and scale values, and accumulate or store to output */
  471. if (accum)
  472. {
  473. - out_line[ox] += val;
  474. + out_line[ox] += (val + (1 << 21)) >> 22;
  475. } else {
  476. - out_line[ox] = val;
  477. + out_line[ox] = (val + (1 << 21)) >> 22;
  478. }
  479. #endif
  480. - ixe += ctx->src->width - 1;
  481. + ixe += ctx->h_i_val;
  482. }
  483. return true;
  484. }
  485. @@ -449,12 +506,8 @@ static inline bool scale_v_linear(struct rowset *rset,
  486. {
  487. uint32_t mul, x, iy, iye;
  488. int32_t oy;
  489. - /* Set up scale and rounding factors, the divisor is bm->height - 1 */
  490. - ctx->divisor *= (ctx->bm->height - 1);
  491. - ctx->round = ctx->divisor >> 1;
  492. - ctx->divisor = 1 + (-((ctx->divisor + 1) >> 1)) / ctx->divisor;
  493. - /* Set up our two temp buffers. The names are generic because they'll be
  494. - swapped each time a new input row is read
  495. + /* Set up our buffers, to store the increment and current value for each
  496. + column, and one temp buffer used to read in new rows.
  497. */
  498. #ifdef HAVE_LCD_COLOR
  499. uint32_t *rowinc = (uint32_t *)(ctx->buf),
  500. @@ -469,15 +522,15 @@ static inline bool scale_v_linear(struct rowset *rset,
  501. SDEBUGF("scale_v_linear\n");
  502. mul = 0;
  503. iy = 0;
  504. - iye = ctx->bm->height - 1;
  505. + iye = ctx->v_o_val;
  506. /* get first scaled row in rowtmp */
  507. if(!ctx->h_scaler((void*)rowtmp, ctx, false))
  508. return false;
  509. for (oy = rset->rowstart; oy != rset->rowstop; oy += rset->rowstep)
  510. {
  511. - if (iye >= (uint32_t)ctx->bm->height - 1)
  512. + if (iye >= ctx->v_o_val)
  513. {
  514. - iye -= ctx->bm->height - 1;
  515. + iye -= ctx->v_o_val;
  516. iy += 1;
  517. #ifdef HAVE_LCD_COLOR
  518. for (x = 0; x < 3 * (uint32_t)ctx->bm->width; x++)
  519. @@ -486,7 +539,7 @@ static inline bool scale_v_linear(struct rowset *rset,
  520. #endif
  521. {
  522. rowinc[x] = -rowtmp[x];
  523. - rowval[x] = rowtmp[x] * (ctx->bm->height - 1);
  524. + rowval[x] = rowtmp[x] * ctx->v_o_val;
  525. }
  526. if (iy < (uint32_t)ctx->src->height)
  527. {
  528. @@ -500,7 +553,7 @@ static inline bool scale_v_linear(struct rowset *rset,
  529. {
  530. rowinc[x] += rowtmp[x];
  531. rowval[x] += rowinc[x] * iye;
  532. - rowinc[x] *= ctx->src->height - 1;
  533. + rowinc[x] *= ctx->v_i_val;
  534. }
  535. }
  536. } else
  537. @@ -511,7 +564,7 @@ static inline bool scale_v_linear(struct rowset *rset,
  538. #endif
  539. rowval[x] += rowinc[x];
  540. ctx->output_row(oy, (void*)rowval, ctx);
  541. - iye += ctx->src->height - 1;
  542. + iye += ctx->v_i_val;
  543. }
  544. return true;
  545. }
  546. @@ -533,9 +586,9 @@ static void output_row_32_native_fromyuv(uint32_t row, void * row_in,
  547. for (col = 0; col < ctx->bm->width; col++) {
  548. if (ctx->dither)
  549. delta = DITHERXDY(col,dy);
  550. - y = SC_MUL(qp->b + ctx->round, ctx->divisor);
  551. - u = SC_MUL(qp->g + ctx->round, ctx->divisor);
  552. - v = SC_MUL(qp->r + ctx->round, ctx->divisor);
  553. + y = SC_OUT(qp->b);
  554. + u = SC_OUT(qp->g);
  555. + v = SC_OUT(qp->r);
  556. qp++;
  557. yuv_to_rgb(y, u, v, &r, &g, &b);
  558. r = (31 * r + (r >> 3) + delta) >> 8;
  559. @@ -571,7 +624,7 @@ static void output_row_32_native(uint32_t row, void * row_in,
  560. for (col = 0; col < ctx->bm->width; col++) {
  561. if (ctx->dither)
  562. delta = DITHERXDY(col,dy);
  563. - bright = SC_MUL((*qp++) + ctx->round,ctx->divisor);
  564. + bright = SC_OUT(*qp++);
  565. bright = (3 * bright + (bright >> 6) + delta) >> 8;
  566. data |= (~bright & 3) << shift;
  567. shift -= 2;
  568. @@ -594,7 +647,7 @@ static void output_row_32_native(uint32_t row, void * row_in,
  569. for (col = 0; col < ctx->bm->width; col++) {
  570. if (ctx->dither)
  571. delta = DITHERXDY(col,dy);
  572. - bright = SC_MUL((*qp++) + ctx->round, ctx->divisor);
  573. + bright = SC_OUT(*qp++);
  574. bright = (3 * bright + (bright >> 6) + delta) >> 8;
  575. *dest++ |= (~bright & 3) << shift;
  576. }
  577. @@ -609,7 +662,7 @@ static void output_row_32_native(uint32_t row, void * row_in,
  578. for (col = 0; col < ctx->bm->width; col++) {
  579. if (ctx->dither)
  580. delta = DITHERXDY(col,dy);
  581. - bright = SC_MUL((*qp++) + ctx->round, ctx->divisor);
  582. + bright = SC_OUT(*qp++);
  583. bright = (3 * bright + (bright >> 6) + delta) >> 8;
  584. *dest++ |= vi_pattern[bright] << shift;
  585. }
  586. @@ -625,9 +678,9 @@ static void output_row_32_native(uint32_t row, void * row_in,
  587. if (ctx->dither)
  588. delta = DITHERXDY(col,dy);
  589. q0 = *qp++;
  590. - r = SC_MUL(q0.r + ctx->round, ctx->divisor);
  591. - g = SC_MUL(q0.g + ctx->round, ctx->divisor);
  592. - b = SC_MUL(q0.b + ctx->round, ctx->divisor);
  593. + r = SC_OUT(q0.r);
  594. + g = SC_OUT(q0.g);
  595. + b = SC_OUT(q0.b);
  596. r = (31 * r + (r >> 3) + delta) >> 8;
  597. g = (63 * g + (g >> 2) + delta) >> 8;
  598. b = (31 * b + (b >> 3) + delta) >> 8;
  599. @@ -664,13 +717,10 @@ int resize_on_load(struct bitmap *bm, bool dither, struct dim *src,
  600. struct img_part* (*store_part)(void *args),
  601. void *args)
  602. {
  603. -
  604. -#ifdef HAVE_UPSCALER
  605. const int sw = src->width;
  606. const int sh = src->height;
  607. const int dw = bm->width;
  608. const int dh = bm->height;
  609. -#endif
  610. int ret;
  611. #ifdef HAVE_LCD_COLOR
  612. unsigned int needed = sizeof(struct uint32_rgb) * 3 * bm->width;
  613. @@ -740,23 +790,35 @@ int resize_on_load(struct bitmap *bm, bool dither, struct dim *src,
  614. {
  615. #endif
  616. ctx.h_scaler = scale_h_area;
  617. - scale_h_area_setup(&ctx);
  618. + uint32_t h_div = (1U << 24) / sw;
  619. + ctx.h_i_val = sw * h_div;
  620. + ctx.h_o_val = dw * h_div;
  621. #ifdef HAVE_UPSCALER
  622. } else {
  623. ctx.h_scaler = scale_h_linear;
  624. - scale_h_linear_setup(&ctx);
  625. + uint32_t h_div = (1U << 24) / (dw - 1);
  626. + ctx.h_i_val = (sw - 1) * h_div;
  627. + ctx.h_o_val = (dw - 1) * h_div;
  628. }
  629. #endif
  630. - SC_MUL_INIT;
  631. #ifdef HAVE_UPSCALER
  632. if (sh > dh)
  633. #endif
  634. + {
  635. + uint32_t v_div = (1U << 22) / sh;
  636. + ctx.v_i_val = sh * v_div;
  637. + ctx.v_o_val = dh * v_div;
  638. ret = scale_v_area(rset, &ctx);
  639. + }
  640. #ifdef HAVE_UPSCALER
  641. else
  642. + {
  643. + uint32_t v_div = (1U << 22) / dh;
  644. + ctx.v_i_val = (sh - 1) * v_div;
  645. + ctx.v_o_val = (dh - 1) * v_div;
  646. ret = scale_v_linear(rset, &ctx);
  647. + }
  648. #endif
  649. - SC_MUL_END;
  650. #ifdef HAVE_ADJUSTABLE_CPU_FREQ
  651. cpu_boost(false);
  652. #endif
  653. diff --git a/apps/recorder/resize.h b/apps/recorder/resize.h
  654. index 2964fcd..b861e43 100644
  655. --- a/apps/recorder/resize.h
  656. +++ b/apps/recorder/resize.h
  657. @@ -43,68 +43,7 @@
  658. #define MAX_SC_STACK_ALLOC 0
  659. #define HAVE_UPSCALER 1
  660.  
  661. -#if defined(CPU_COLDFIRE)
  662. -#define SC_MUL_INIT \
  663. - unsigned long macsr_st = coldfire_get_macsr(); \
  664. - coldfire_set_macsr(EMAC_UNSIGNED);
  665. -#define SC_MUL_END coldfire_set_macsr(macsr_st);
  666. -#define SC_MUL(x, y) \
  667. -({ \
  668. - unsigned long t; \
  669. - asm ("mac.l %[a], %[b], %%acc0\n\t" \
  670. - "move.l %%accext01, %[t]\n\t" \
  671. - "move.l #0, %%acc0\n\t" \
  672. - : [t] "=r" (t) : [a] "r" (x), [b] "r" (y)); \
  673. - t; \
  674. -})
  675. -#elif (CONFIG_CPU == SH7034)
  676. -/* multiply two unsigned 32 bit values and return the top 32 bit
  677. - * of the 64 bit result */
  678. -static inline unsigned sc_mul32(unsigned a, unsigned b)
  679. -{
  680. - unsigned r, t1, t2, t3;
  681. -
  682. - asm (
  683. - "swap.w %[a], %[t1] \n" /* t1 = ba */
  684. - "mulu %[t1], %[b] \n" /* a * d */
  685. - "swap.w %[b], %[t3] \n" /* t3 = dc */
  686. - "sts macl, %[t2] \n" /* t2 = a * d */
  687. - "mulu %[t1], %[t3] \n" /* a * c */
  688. - "sts macl, %[r] \n" /* hi = a * c */
  689. - "mulu %[a], %[t3] \n" /* b * c */
  690. - "clrt \n"
  691. - "sts macl, %[t3] \n" /* t3 = b * c */
  692. - "addc %[t2], %[t3] \n" /* t3 += t2, carry -> t2 */
  693. - "movt %[t2] \n"
  694. - "mulu %[a], %[b] \n" /* b * d */
  695. - "mov %[t3], %[t1] \n" /* t1t3 = t2t3 << 16 */
  696. - "xtrct %[t2], %[t1] \n"
  697. - "shll16 %[t3] \n"
  698. - "sts macl, %[t2] \n" /* lo = b * d */
  699. - "clrt \n" /* hi.lo += t1t3 */
  700. - "addc %[t3], %[t2] \n"
  701. - "addc %[t1], %[r] \n"
  702. - : /* outputs */
  703. - [r] "=&r"(r),
  704. - [t1]"=&r"(t1),
  705. - [t2]"=&r"(t2),
  706. - [t3]"=&r"(t3)
  707. - : /* inputs */
  708. - [a] "r" (a),
  709. - [b] "r" (b)
  710. - );
  711. - return r;
  712. -}
  713. -#define SC_MUL(x, y) sc_mul32(x, y)
  714. -#define SC_MUL_INIT
  715. -#define SC_MUL_END
  716. -#endif
  717. -
  718. -#ifndef SC_MUL
  719. -#define SC_MUL(x, y) ((x) * (uint64_t)(y) >> 32)
  720. -#define SC_MUL_INIT
  721. -#define SC_MUL_END
  722. -#endif
  723. +#define SC_OUT(n) (((n) + (1 << 23)) >> 24);
  724.  
  725. struct img_part {
  726. int len;
  727. @@ -130,8 +69,12 @@ struct uint32_rgb {
  728. horizontal scaler, and row output
  729. */
  730. struct scaler_context {
  731. - uint32_t divisor;
  732. - uint32_t round;
  733. + uint32_t h_div;
  734. + uint32_t h_i_val;
  735. + uint32_t h_o_val;
  736. + uint32_t v_div;
  737. + uint32_t v_i_val;
  738. + uint32_t v_o_val;
  739. struct bitmap *bm;
  740. struct dim *src;
  741. unsigned char *buf;
Add Comment
Please, Sign In to add comment