Guest User

Untitled

a guest
Jun 18th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.41 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..3741bae 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. @@ -161,31 +153,34 @@ static bool scale_h_area(void *out_line_ptr,
  156. yield();
  157. for (ix = 0; ix < (unsigned int)ctx->src->width; ix++)
  158. {
  159. - oxe += ctx->bm->width;
  160. + oxe += ctx->h_o_val;
  161. /* end of current area has been reached */
  162. /* fill buffer if needed */
  163. FILL_BUF(part,ctx->store_part,ctx->args);
  164. #ifdef HAVE_LCD_COLOR
  165. - if (oxe >= (unsigned int)ctx->src->width)
  166. + if (oxe >= ctx->h_i_val)
  167. {
  168. /* "reset" error, which now represents partial coverage of next
  169. pixel by the next area
  170. */
  171. - oxe -= ctx->src->width;
  172. + oxe -= ctx->h_i_val;
  173.  
  174. /* add saved partial pixel from start of area */
  175. - rgbvalacc.r = rgbvalacc.r * ctx->bm->width + rgbvaltmp.r * mul;
  176. - rgbvalacc.g = rgbvalacc.g * ctx->bm->width + rgbvaltmp.g * mul;
  177. - rgbvalacc.b = rgbvalacc.b * ctx->bm->width + rgbvaltmp.b * mul;
  178. + rgbvalacc.r = rgbvalacc.r * ctx->h_o_val + rgbvaltmp.r * mul;
  179. + rgbvalacc.g = rgbvalacc.g * ctx->h_o_val + rgbvaltmp.g * mul;
  180. + rgbvalacc.b = rgbvalacc.b * ctx->h_o_val + rgbvaltmp.b * mul;
  181.  
  182. /* get new pixel , then add its partial coverage to this area */
  183. rgbvaltmp.r = part->buf->red;
  184. rgbvaltmp.g = part->buf->green;
  185. rgbvaltmp.b = part->buf->blue;
  186. - mul = ctx->bm->width - oxe;
  187. + mul = ctx->h_o_val - oxe;
  188. rgbvalacc.r += rgbvaltmp.r * mul;
  189. rgbvalacc.g += rgbvaltmp.g * mul;
  190. rgbvalacc.b += rgbvaltmp.b * mul;
  191. + rgbvalacc.r = (rgbvalacc.r + (1 << 21)) >> 22;
  192. + rgbvalacc.g = (rgbvalacc.g + (1 << 21)) >> 22;
  193. + rgbvalacc.b = (rgbvalacc.b + (1 << 21)) >> 22;
  194. /* store or accumulate to output row */
  195. if (accum)
  196. {
  197. @@ -200,7 +195,7 @@ static bool scale_h_area(void *out_line_ptr,
  198. rgbvalacc.r = 0;
  199. rgbvalacc.g = 0;
  200. rgbvalacc.b = 0;
  201. - mul = ctx->bm->width - mul;
  202. + mul = ctx->h_o_val - mul;
  203. ox += 1;
  204. /* inside an area */
  205. } else {
  206. @@ -210,21 +205,22 @@ static bool scale_h_area(void *out_line_ptr,
  207. rgbvalacc.b += part->buf->blue;
  208. }
  209. #else
  210. - if (oxe >= (unsigned int)ctx->src->width)
  211. + if (oxe >= ctx->h_i_val)
  212. {
  213. /* "reset" error, which now represents partial coverage of next
  214. pixel by the next area
  215. */
  216. - oxe -= ctx->src->width;
  217. + oxe -= ctx->h_i_val;
  218.  
  219. /* add saved partial pixel from start of area */
  220. - acc = MULUQ(acc, ctx->bm->width) + MULUQ(tmp, mul);
  221. + acc = (acc * ctx->h_o_val) + (tmp * mul);
  222.  
  223. /* get new pixel , then add its partial coverage to this area */
  224. tmp = *(part->buf);
  225. - mul = ctx->bm->width - oxe;
  226. - acc += MULUQ(tmp, mul);
  227. + mul = ctx->h_o_val - oxe;
  228. + acc += tmp * mul;
  229. /* round, divide, and either store or accumulate to output row */
  230. + acc = (acc + (1 << 21)) >> 22;
  231. if (accum)
  232. {
  233. acc += out_line[ox];
  234. @@ -232,7 +228,7 @@ static bool scale_h_area(void *out_line_ptr,
  235. out_line[ox] = acc;
  236. /* reset accumulator */
  237. acc = 0;
  238. - mul = ctx->bm->width - mul;
  239. + mul = ctx->h_o_val - mul;
  240. ox += 1;
  241. /* inside an area */
  242. } else {
  243. @@ -252,9 +248,6 @@ static inline bool scale_v_area(struct rowset *rset, struct scaler_context *ctx)
  244. uint32_t mul, x, oy, iy, oye;
  245.  
  246. /* Set up rounding and scale factors */
  247. - ctx->divisor *= ctx->src->height;
  248. - ctx->round = ctx->divisor >> 1;
  249. - ctx->divisor = 1 + (-((ctx->divisor + 1) >> 1)) / ctx->divisor;
  250. mul = 0;
  251. oy = rset->rowstart;
  252. oye = 0;
  253. @@ -271,28 +264,28 @@ static inline bool scale_v_area(struct rowset *rset, struct scaler_context *ctx)
  254. /* zero the accumulator and temp rows */
  255. for (iy = 0; iy < (unsigned int)ctx->src->height; iy++)
  256. {
  257. - oye += ctx->bm->height;
  258. + oye += ctx->v_o_val;
  259. /* end of current area has been reached */
  260. - if (oye >= (unsigned int)ctx->src->height)
  261. + if (oye >= (unsigned int)ctx->v_i_val)
  262. {
  263. /* "reset" error, which now represents partial coverage of the next
  264. row by the next area
  265. */
  266. - oye -= ctx->src->height;
  267. + oye -= ctx->v_i_val;
  268. /* add stored partial row to accumulator */
  269. #ifdef HAVE_LCD_COLOR
  270. for (x = 0; x < 3 * (unsigned int)ctx->bm->width; x++)
  271. #else
  272. for (x = 0; x < (unsigned int)ctx->bm->width; x++)
  273. #endif
  274. - rowacc[x] = rowacc[x] * ctx->bm->height + mul * rowtmp[x];
  275. + rowacc[x] = rowacc[x] * ctx->v_o_val + mul * rowtmp[x];
  276. /* store new scaled row in temp row */
  277. if(!ctx->h_scaler(rowtmp, ctx, false))
  278. return false;
  279. /* add partial coverage by new row to this area, then round and
  280. scale to final value
  281. */
  282. - mul = ctx->bm->height - oye;
  283. + mul = ctx->v_o_val - oye;
  284. #ifdef HAVE_LCD_COLOR
  285. for (x = 0; x < 3 * (unsigned int)ctx->bm->width; x++)
  286. #else
  287. @@ -319,15 +312,6 @@ static inline bool scale_v_area(struct rowset *rset, struct scaler_context *ctx)
  288. }
  289.  
  290. #ifdef HAVE_UPSCALER
  291. -/* Set up rounding and scale factors for the horizontal scaler. The divisor
  292. - is bm->width - 1, so that the first and last pixels in the row align
  293. - exactly between input and output
  294. -*/
  295. -static inline void scale_h_linear_setup(struct scaler_context *ctx)
  296. -{
  297. - ctx->divisor = ctx->bm->width - 1;
  298. -}
  299. -
  300. /* horizontal linear scaler */
  301. static bool scale_h_linear(void *out_line_ptr, struct scaler_context *ctx,
  302. bool accum)
  303. @@ -348,24 +332,24 @@ static bool scale_h_linear(void *out_line_ptr, struct scaler_context *ctx,
  304. FILL_BUF_INIT(part,ctx->store_part,ctx->args);
  305. ix = 0;
  306. /* The error is set so that values are initialized on the first pass. */
  307. - ixe = ctx->bm->width - 1;
  308. + ixe = ctx->h_o_val;
  309. /* give other tasks a chance to run */
  310. yield();
  311. for (ox = 0; ox < (uint32_t)ctx->bm->width; ox++)
  312. {
  313. #ifdef HAVE_LCD_COLOR
  314. - if (ixe >= ((uint32_t)ctx->bm->width - 1))
  315. + if (ixe >= ctx->h_o_val)
  316. {
  317. /* Store the new "current" pixel value in rgbval, and the color
  318. step value in rgbinc.
  319. */
  320. - ixe -= (ctx->bm->width - 1);
  321. + ixe -= ctx->h_o_val;
  322. rgbinc.r = -(part->buf->red);
  323. rgbinc.g = -(part->buf->green);
  324. rgbinc.b = -(part->buf->blue);
  325. - rgbval.r = (part->buf->red) * (ctx->bm->width - 1);
  326. - rgbval.g = (part->buf->green) * (ctx->bm->width - 1);
  327. - rgbval.b = (part->buf->blue) * (ctx->bm->width - 1);
  328. + rgbval.r = (part->buf->red) * ctx->h_o_val;
  329. + rgbval.g = (part->buf->green) * ctx->h_o_val;
  330. + rgbval.b = (part->buf->blue) * ctx->h_o_val;
  331. ix += 1;
  332. /* If this wasn't the last pixel, add the next one to rgbinc. */
  333. if (ix < (uint32_t)ctx->src->width) {
  334. @@ -383,10 +367,10 @@ static bool scale_h_linear(void *out_line_ptr, struct scaler_context *ctx,
  335. rgbval.g += rgbinc.g * ixe;
  336. rgbval.b += rgbinc.b * ixe;
  337. }
  338. - /* Now multiple the color increment to its proper value */
  339. - rgbinc.r *= ctx->src->width - 1;
  340. - rgbinc.g *= ctx->src->width - 1;
  341. - rgbinc.b *= ctx->src->width - 1;
  342. + /* Now multiply the color increment to its proper value */
  343. + rgbinc.r *= ctx->h_i_val;
  344. + rgbinc.g *= ctx->h_i_val;
  345. + rgbinc.b *= ctx->h_i_val;
  346. } else {
  347. rgbval.r += rgbinc.r;
  348. rgbval.g += rgbinc.g;
  349. @@ -395,24 +379,24 @@ static bool scale_h_linear(void *out_line_ptr, struct scaler_context *ctx,
  350. /* round and scale values, and accumulate or store to output */
  351. if (accum)
  352. {
  353. - out_line[ox].r += rgbval.r;
  354. - out_line[ox].g += rgbval.g;
  355. - out_line[ox].b += rgbval.b;
  356. + out_line[ox].r += (rgbval.r + (1 << 21)) >> 22;
  357. + out_line[ox].g += (rgbval.g + (1 << 21)) >> 22;
  358. + out_line[ox].b += (rgbval.b + (1 << 21)) >> 22;
  359. } else {
  360. - out_line[ox].r = rgbval.r;
  361. - out_line[ox].g = rgbval.g;
  362. - out_line[ox].b = rgbval.b;
  363. + out_line[ox].r = (rgbval.r + (1 << 21)) >> 22;
  364. + out_line[ox].g = (rgbval.g + (1 << 21)) >> 22;
  365. + out_line[ox].b = (rgbval.b + (1 << 21)) >> 22;
  366. }
  367. #else
  368. - if (ixe >= ((uint32_t)ctx->bm->width - 1))
  369. + if (ixe >= ctx->h_o_val)
  370. {
  371. /* Store the new "current" pixel value in rgbval, and the color
  372. step value in rgbinc.
  373. */
  374. - ixe -= (ctx->bm->width - 1);
  375. + ixe -= ctx->h_o_val;
  376. val = *(part->buf);
  377. inc = -val;
  378. - val = MULUQ(val, ctx->bm->width - 1);
  379. + val = val * ctx->h_o_val;
  380. ix += 1;
  381. /* If this wasn't the last pixel, add the next one to rgbinc. */
  382. if (ix < (uint32_t)ctx->src->width) {
  383. @@ -424,21 +408,21 @@ static bool scale_h_linear(void *out_line_ptr, struct scaler_context *ctx,
  384. /* Add a partial step to rgbval, in this pixel isn't precisely
  385. aligned with the new source pixel
  386. */
  387. - val += MULQ(inc, ixe);
  388. + val += inc * ixe;
  389. }
  390. /* Now multiply the color increment to its proper value */
  391. - inc = MULQ(inc, ctx->src->width - 1);
  392. + inc = inc * ctx->h_i_val;
  393. } else
  394. val += inc;
  395. /* round and scale values, and accumulate or store to output */
  396. if (accum)
  397. {
  398. - out_line[ox] += val;
  399. + out_line[ox] += (val + (1 << 21)) >> 22;
  400. } else {
  401. - out_line[ox] = val;
  402. + out_line[ox] = (val + (1 << 21)) >> 22;
  403. }
  404. #endif
  405. - ixe += ctx->src->width - 1;
  406. + ixe += ctx->h_i_val;
  407. }
  408. return true;
  409. }
  410. @@ -449,12 +433,8 @@ static inline bool scale_v_linear(struct rowset *rset,
  411. {
  412. uint32_t mul, x, iy, iye;
  413. int32_t oy;
  414. - /* Set up scale and rounding factors, the divisor is bm->height - 1 */
  415. - ctx->divisor *= (ctx->bm->height - 1);
  416. - ctx->round = ctx->divisor >> 1;
  417. - ctx->divisor = 1 + (-((ctx->divisor + 1) >> 1)) / ctx->divisor;
  418. - /* Set up our two temp buffers. The names are generic because they'll be
  419. - swapped each time a new input row is read
  420. + /* Set up our buffers, to store the increment and current value for each
  421. + column, and one temp buffer used to read in new rows.
  422. */
  423. #ifdef HAVE_LCD_COLOR
  424. uint32_t *rowinc = (uint32_t *)(ctx->buf),
  425. @@ -469,15 +449,15 @@ static inline bool scale_v_linear(struct rowset *rset,
  426. SDEBUGF("scale_v_linear\n");
  427. mul = 0;
  428. iy = 0;
  429. - iye = ctx->bm->height - 1;
  430. + iye = ctx->v_o_val;
  431. /* get first scaled row in rowtmp */
  432. if(!ctx->h_scaler((void*)rowtmp, ctx, false))
  433. return false;
  434. for (oy = rset->rowstart; oy != rset->rowstop; oy += rset->rowstep)
  435. {
  436. - if (iye >= (uint32_t)ctx->bm->height - 1)
  437. + if (iye >= ctx->v_o_val)
  438. {
  439. - iye -= ctx->bm->height - 1;
  440. + iye -= ctx->v_o_val;
  441. iy += 1;
  442. #ifdef HAVE_LCD_COLOR
  443. for (x = 0; x < 3 * (uint32_t)ctx->bm->width; x++)
  444. @@ -486,7 +466,7 @@ static inline bool scale_v_linear(struct rowset *rset,
  445. #endif
  446. {
  447. rowinc[x] = -rowtmp[x];
  448. - rowval[x] = rowtmp[x] * (ctx->bm->height - 1);
  449. + rowval[x] = rowtmp[x] * ctx->v_o_val;
  450. }
  451. if (iy < (uint32_t)ctx->src->height)
  452. {
  453. @@ -500,7 +480,7 @@ static inline bool scale_v_linear(struct rowset *rset,
  454. {
  455. rowinc[x] += rowtmp[x];
  456. rowval[x] += rowinc[x] * iye;
  457. - rowinc[x] *= ctx->src->height - 1;
  458. + rowinc[x] *= ctx->v_i_val;
  459. }
  460. }
  461. } else
  462. @@ -511,7 +491,7 @@ static inline bool scale_v_linear(struct rowset *rset,
  463. #endif
  464. rowval[x] += rowinc[x];
  465. ctx->output_row(oy, (void*)rowval, ctx);
  466. - iye += ctx->src->height - 1;
  467. + iye += ctx->v_i_val;
  468. }
  469. return true;
  470. }
  471. @@ -533,9 +513,9 @@ static void output_row_32_native_fromyuv(uint32_t row, void * row_in,
  472. for (col = 0; col < ctx->bm->width; col++) {
  473. if (ctx->dither)
  474. delta = DITHERXDY(col,dy);
  475. - y = SC_MUL(qp->b + ctx->round, ctx->divisor);
  476. - u = SC_MUL(qp->g + ctx->round, ctx->divisor);
  477. - v = SC_MUL(qp->r + ctx->round, ctx->divisor);
  478. + y = SC_OUT(qp->b);
  479. + u = SC_OUT(qp->g);
  480. + v = SC_OUT(qp->r);
  481. qp++;
  482. yuv_to_rgb(y, u, v, &r, &g, &b);
  483. r = (31 * r + (r >> 3) + delta) >> 8;
  484. @@ -571,7 +551,7 @@ static void output_row_32_native(uint32_t row, void * row_in,
  485. for (col = 0; col < ctx->bm->width; col++) {
  486. if (ctx->dither)
  487. delta = DITHERXDY(col,dy);
  488. - bright = SC_MUL((*qp++) + ctx->round,ctx->divisor);
  489. + bright = SC_OUT(*qp++);
  490. bright = (3 * bright + (bright >> 6) + delta) >> 8;
  491. data |= (~bright & 3) << shift;
  492. shift -= 2;
  493. @@ -594,7 +574,7 @@ static void output_row_32_native(uint32_t row, void * row_in,
  494. for (col = 0; col < ctx->bm->width; col++) {
  495. if (ctx->dither)
  496. delta = DITHERXDY(col,dy);
  497. - bright = SC_MUL((*qp++) + ctx->round, ctx->divisor);
  498. + bright = SC_OUT(*qp++);
  499. bright = (3 * bright + (bright >> 6) + delta) >> 8;
  500. *dest++ |= (~bright & 3) << shift;
  501. }
  502. @@ -609,7 +589,7 @@ static void output_row_32_native(uint32_t row, void * row_in,
  503. for (col = 0; col < ctx->bm->width; col++) {
  504. if (ctx->dither)
  505. delta = DITHERXDY(col,dy);
  506. - bright = SC_MUL((*qp++) + ctx->round, ctx->divisor);
  507. + bright = SC_OUT(*qp++);
  508. bright = (3 * bright + (bright >> 6) + delta) >> 8;
  509. *dest++ |= vi_pattern[bright] << shift;
  510. }
  511. @@ -625,9 +605,9 @@ static void output_row_32_native(uint32_t row, void * row_in,
  512. if (ctx->dither)
  513. delta = DITHERXDY(col,dy);
  514. q0 = *qp++;
  515. - r = SC_MUL(q0.r + ctx->round, ctx->divisor);
  516. - g = SC_MUL(q0.g + ctx->round, ctx->divisor);
  517. - b = SC_MUL(q0.b + ctx->round, ctx->divisor);
  518. + r = SC_OUT(q0.r);
  519. + g = SC_OUT(q0.g);
  520. + b = SC_OUT(q0.b);
  521. r = (31 * r + (r >> 3) + delta) >> 8;
  522. g = (63 * g + (g >> 2) + delta) >> 8;
  523. b = (31 * b + (b >> 3) + delta) >> 8;
  524. @@ -664,13 +644,10 @@ int resize_on_load(struct bitmap *bm, bool dither, struct dim *src,
  525. struct img_part* (*store_part)(void *args),
  526. void *args)
  527. {
  528. -
  529. -#ifdef HAVE_UPSCALER
  530. const int sw = src->width;
  531. const int sh = src->height;
  532. const int dw = bm->width;
  533. const int dh = bm->height;
  534. -#endif
  535. int ret;
  536. #ifdef HAVE_LCD_COLOR
  537. unsigned int needed = sizeof(struct uint32_rgb) * 3 * bm->width;
  538. @@ -740,23 +717,35 @@ int resize_on_load(struct bitmap *bm, bool dither, struct dim *src,
  539. {
  540. #endif
  541. ctx.h_scaler = scale_h_area;
  542. - scale_h_area_setup(&ctx);
  543. + uint32_t h_div = (1U << 24) / sw;
  544. + ctx.h_i_val = sw * h_div;
  545. + ctx.h_o_val = dw * h_div;
  546. #ifdef HAVE_UPSCALER
  547. } else {
  548. ctx.h_scaler = scale_h_linear;
  549. - scale_h_linear_setup(&ctx);
  550. + uint32_t h_div = (1U << 24) / (dw - 1);
  551. + ctx.h_i_val = (sw - 1) * h_div;
  552. + ctx.h_o_val = (dw - 1) * h_div;
  553. }
  554. #endif
  555. - SC_MUL_INIT;
  556. #ifdef HAVE_UPSCALER
  557. if (sh > dh)
  558. #endif
  559. + {
  560. + uint32_t v_div = (1U << 22) / sh;
  561. + ctx.v_i_val = sh * v_div;
  562. + ctx.v_o_val = dh * v_div;
  563. ret = scale_v_area(rset, &ctx);
  564. + }
  565. #ifdef HAVE_UPSCALER
  566. else
  567. + {
  568. + uint32_t v_div = (1U << 22) / dh;
  569. + ctx.v_i_val = (sh - 1) * v_div;
  570. + ctx.v_o_val = (dh - 1) * v_div;
  571. ret = scale_v_linear(rset, &ctx);
  572. + }
  573. #endif
  574. - SC_MUL_END;
  575. #ifdef HAVE_ADJUSTABLE_CPU_FREQ
  576. cpu_boost(false);
  577. #endif
  578. diff --git a/apps/recorder/resize.h b/apps/recorder/resize.h
  579. index 2964fcd..b861e43 100644
  580. --- a/apps/recorder/resize.h
  581. +++ b/apps/recorder/resize.h
  582. @@ -43,68 +43,7 @@
  583. #define MAX_SC_STACK_ALLOC 0
  584. #define HAVE_UPSCALER 1
  585.  
  586. -#if defined(CPU_COLDFIRE)
  587. -#define SC_MUL_INIT \
  588. - unsigned long macsr_st = coldfire_get_macsr(); \
  589. - coldfire_set_macsr(EMAC_UNSIGNED);
  590. -#define SC_MUL_END coldfire_set_macsr(macsr_st);
  591. -#define SC_MUL(x, y) \
  592. -({ \
  593. - unsigned long t; \
  594. - asm ("mac.l %[a], %[b], %%acc0\n\t" \
  595. - "move.l %%accext01, %[t]\n\t" \
  596. - "move.l #0, %%acc0\n\t" \
  597. - : [t] "=r" (t) : [a] "r" (x), [b] "r" (y)); \
  598. - t; \
  599. -})
  600. -#elif (CONFIG_CPU == SH7034)
  601. -/* multiply two unsigned 32 bit values and return the top 32 bit
  602. - * of the 64 bit result */
  603. -static inline unsigned sc_mul32(unsigned a, unsigned b)
  604. -{
  605. - unsigned r, t1, t2, t3;
  606. -
  607. - asm (
  608. - "swap.w %[a], %[t1] \n" /* t1 = ba */
  609. - "mulu %[t1], %[b] \n" /* a * d */
  610. - "swap.w %[b], %[t3] \n" /* t3 = dc */
  611. - "sts macl, %[t2] \n" /* t2 = a * d */
  612. - "mulu %[t1], %[t3] \n" /* a * c */
  613. - "sts macl, %[r] \n" /* hi = a * c */
  614. - "mulu %[a], %[t3] \n" /* b * c */
  615. - "clrt \n"
  616. - "sts macl, %[t3] \n" /* t3 = b * c */
  617. - "addc %[t2], %[t3] \n" /* t3 += t2, carry -> t2 */
  618. - "movt %[t2] \n"
  619. - "mulu %[a], %[b] \n" /* b * d */
  620. - "mov %[t3], %[t1] \n" /* t1t3 = t2t3 << 16 */
  621. - "xtrct %[t2], %[t1] \n"
  622. - "shll16 %[t3] \n"
  623. - "sts macl, %[t2] \n" /* lo = b * d */
  624. - "clrt \n" /* hi.lo += t1t3 */
  625. - "addc %[t3], %[t2] \n"
  626. - "addc %[t1], %[r] \n"
  627. - : /* outputs */
  628. - [r] "=&r"(r),
  629. - [t1]"=&r"(t1),
  630. - [t2]"=&r"(t2),
  631. - [t3]"=&r"(t3)
  632. - : /* inputs */
  633. - [a] "r" (a),
  634. - [b] "r" (b)
  635. - );
  636. - return r;
  637. -}
  638. -#define SC_MUL(x, y) sc_mul32(x, y)
  639. -#define SC_MUL_INIT
  640. -#define SC_MUL_END
  641. -#endif
  642. -
  643. -#ifndef SC_MUL
  644. -#define SC_MUL(x, y) ((x) * (uint64_t)(y) >> 32)
  645. -#define SC_MUL_INIT
  646. -#define SC_MUL_END
  647. -#endif
  648. +#define SC_OUT(n) (((n) + (1 << 23)) >> 24);
  649.  
  650. struct img_part {
  651. int len;
  652. @@ -130,8 +69,12 @@ struct uint32_rgb {
  653. horizontal scaler, and row output
  654. */
  655. struct scaler_context {
  656. - uint32_t divisor;
  657. - uint32_t round;
  658. + uint32_t h_div;
  659. + uint32_t h_i_val;
  660. + uint32_t h_o_val;
  661. + uint32_t v_div;
  662. + uint32_t v_i_val;
  663. + uint32_t v_o_val;
  664. struct bitmap *bm;
  665. struct dim *src;
  666. unsigned char *buf;
Add Comment
Please, Sign In to add comment