base_trans.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. #include "fitz-internal.h"
  2. static int
  3. fade(fz_pixmap *tpix, fz_pixmap *opix, fz_pixmap *npix, int time)
  4. {
  5. unsigned char *t, *o, *n;
  6. int size;
  7. if (!tpix || !opix || !npix || tpix->w != opix->w || opix->w != npix->w || tpix->h != opix->h || opix->h != npix->h || tpix->n != opix->n || opix->n != npix->n)
  8. return 0;
  9. size = tpix->w * tpix->h * tpix->n;
  10. t = tpix->samples;
  11. o = opix->samples;
  12. n = npix->samples;
  13. while (size-- > 0)
  14. {
  15. int op = *o++;
  16. int np = *n++;
  17. *t++ = ((op<<8) + ((np-op) * time) + 0x80)>>8;
  18. }
  19. return 1;
  20. }
  21. static int
  22. blind_horiz(fz_pixmap *tpix, fz_pixmap *opix, fz_pixmap *npix, int time)
  23. {
  24. unsigned char *t, *o, *n;
  25. int blind_height, size, span, position, y;
  26. if (!tpix || !opix || !npix || tpix->w != opix->w || opix->w != npix->w || tpix->h != opix->h || opix->h != npix->h || tpix->n != opix->n || opix->n != npix->n)
  27. return 0;
  28. span = tpix->w * tpix->n;
  29. size = tpix->h * span;
  30. blind_height = (tpix->h+7) / 8;
  31. position = blind_height * time / 256;
  32. t = tpix->samples;
  33. o = opix->samples;
  34. n = npix->samples;
  35. for (y = 0; y < tpix->h; y++)
  36. {
  37. memcpy(t, ((y % blind_height) <= position ? n : o), span);
  38. t += span;
  39. o += span;
  40. n += span;
  41. }
  42. return 1;
  43. }
  44. static int
  45. blind_vertical(fz_pixmap *tpix, fz_pixmap *opix, fz_pixmap *npix, int time)
  46. {
  47. unsigned char *t, *o, *n;
  48. int blind_width, size, span, position, y;
  49. if (!tpix || !opix || !npix || tpix->w != opix->w || opix->w != npix->w || tpix->h != opix->h || opix->h != npix->h || tpix->n != opix->n || opix->n != npix->n)
  50. return 0;
  51. span = tpix->w * tpix->n;
  52. size = tpix->h * span;
  53. blind_width = (tpix->w+7) / 8;
  54. position = blind_width * time / 256;
  55. blind_width *= tpix->n;
  56. position *= tpix->n;
  57. t = tpix->samples;
  58. o = opix->samples;
  59. n = npix->samples;
  60. for (y = 0; y < tpix->h; y++)
  61. {
  62. int w, x;
  63. x = 0;
  64. while ((w = span - x) > 0)
  65. {
  66. int p;
  67. if (w > blind_width)
  68. w = blind_width;
  69. p = position;
  70. if (p > w)
  71. p = w;
  72. memcpy(t, n, p);
  73. memcpy(t+position, o+position, w - p);
  74. x += blind_width;
  75. t += w;
  76. o += w;
  77. n += w;
  78. }
  79. }
  80. return 1;
  81. }
  82. static int
  83. wipe_tb(fz_pixmap *tpix, fz_pixmap *opix, fz_pixmap *npix, int time)
  84. {
  85. unsigned char *t, *o, *n;
  86. int span, position, y;
  87. if (!tpix || !opix || !npix || tpix->w != opix->w || opix->w != npix->w || tpix->h != opix->h || opix->h != npix->h || tpix->n != opix->n || opix->n != npix->n)
  88. return 0;
  89. span = tpix->w * tpix->n;
  90. position = tpix->h * time / 256;
  91. t = tpix->samples;
  92. o = opix->samples;
  93. n = npix->samples;
  94. for (y = 0; y < position; y++)
  95. {
  96. memcpy(t, n, span);
  97. t += span;
  98. o += span;
  99. n += span;
  100. }
  101. for (; y < tpix->h; y++)
  102. {
  103. memcpy(t, o, span);
  104. t += span;
  105. o += span;
  106. n += span;
  107. }
  108. return 1;
  109. }
  110. static int
  111. wipe_lr(fz_pixmap *tpix, fz_pixmap *opix, fz_pixmap *npix, int time)
  112. {
  113. unsigned char *t, *o, *n;
  114. int span, position, y;
  115. if (!tpix || !opix || !npix || tpix->w != opix->w || opix->w != npix->w || tpix->h != opix->h || opix->h != npix->h || tpix->n != opix->n || opix->n != npix->n)
  116. return 0;
  117. span = tpix->w * tpix->n;
  118. position = tpix->w * time / 256;
  119. position *= tpix->n;
  120. t = tpix->samples;
  121. o = opix->samples + position;
  122. n = npix->samples;
  123. for (y = 0; y < tpix->h; y++)
  124. {
  125. memcpy(t, n, position);
  126. memcpy(t+position, o, span-position);
  127. t += span;
  128. o += span;
  129. n += span;
  130. }
  131. return 1;
  132. }
  133. int fz_generate_transition(fz_pixmap *tpix, fz_pixmap *opix, fz_pixmap *npix, int time, fz_transition *trans)
  134. {
  135. switch (trans->type)
  136. {
  137. default:
  138. case FZ_TRANSITION_FADE:
  139. return fade(tpix, opix, npix, time);
  140. case FZ_TRANSITION_BLINDS:
  141. if (trans->vertical)
  142. return blind_vertical(tpix, opix, npix, time);
  143. else
  144. return blind_horiz(tpix, opix, npix, time);
  145. case FZ_TRANSITION_WIPE:
  146. switch (((trans->direction + 45 + 360) % 360) / 90)
  147. {
  148. default:
  149. case 0: return wipe_lr(tpix, opix, npix, time);
  150. case 1: return wipe_tb(tpix, npix, opix, 256-time);
  151. case 2: return wipe_lr(tpix, npix, opix, 256-time);
  152. case 3: return wipe_tb(tpix, opix, npix, time);
  153. }
  154. }
  155. return 0;
  156. }