PageRenderTime 42ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/Pristine/V/BLUE.C

http://github.com/AnimatorPro/Animator-Pro
C | 332 lines | 255 code | 55 blank | 22 comment | 32 complexity | ba87aeb0de28be8e06c2c2ead82d9eab MD5 | raw file
Possible License(s): BSD-3-Clause
  1. /* blue.c - Stuff to implement much of the trace drop down */
  2. #include "jimk.h"
  3. #include "fli.h"
  4. /* map everything but clearc to destc */
  5. static
  6. set_one_val(pic, clearc, destc)
  7. Vscreen *pic;
  8. UBYTE clearc, destc;
  9. {
  10. UBYTE table[COLORS];
  11. stuff_words((destc<<8)+destc, table, COLORS/sizeof(WORD));
  12. table[clearc] = clearc;
  13. xlat(table, pic->p, 64000);
  14. }
  15. /* blue pic stuff */
  16. static
  17. blue1()
  18. {
  19. set_one_val(render_form, vs.inks[0], vs.inks[1]);
  20. return(1);
  21. }
  22. qblue_pic()
  23. {
  24. uzauto(blue1);
  25. }
  26. /* unblue pic stuff */
  27. static
  28. unblue1()
  29. {
  30. UBYTE table[COLORS];
  31. int i;
  32. for (i=0; i<COLORS; i++)
  33. table[i] = i;
  34. table[vs.inks[1]] = vs.inks[0];
  35. xlat(table, render_form->p, 64000);
  36. return(1);
  37. }
  38. qunblue_pic()
  39. {
  40. uzauto(unblue1);
  41. }
  42. /* Stuff for insert tween. */
  43. static
  44. bluesome(s,d,count,ink)
  45. PLANEPTR s,d;
  46. unsigned count;
  47. unsigned char ink;
  48. {
  49. unsigned i;
  50. for (i = 0; i<count; i++)
  51. {
  52. if (*s == ink)
  53. *d = ink;
  54. s++;
  55. d++;
  56. }
  57. }
  58. insert_tween()
  59. {
  60. Vscreen *nf;
  61. int oix;
  62. unzoom();
  63. scrub_cur_frame();
  64. /* Make undo buffer hold current frame, vga screen hold next screen */
  65. oix = vs.frame_ix;
  66. advance_frame_ix();
  67. copy_form(render_form, &uf);
  68. unfli(render_form, vs.frame_ix, 1);
  69. /* set next screen to color 2 (a dark red) */
  70. set_one_val(render_form, vs.inks[0], vs.inks[2]);
  71. /* set this screen to color 1 */
  72. set_one_val(&uf, vs.inks[0], vs.inks[1]);
  73. /* superimpose future on present */
  74. bluesome(render_form->p, uf.p, (unsigned)64000, vs.inks[2]);
  75. /* make combination current screen */
  76. copy_form(&uf, render_form);
  77. see_cmap();
  78. /* and insert frame into FLI */
  79. insert_frames(1, oix);
  80. /* leave frame position one past original */
  81. vs.frame_ix =oix;
  82. advance_frame_ix();
  83. /* Make sure we update FLI when leave this frame */
  84. dirties();
  85. rezoom();
  86. }
  87. /* stuff for remove guides */
  88. static
  89. clean_t1()
  90. {
  91. UBYTE table[COLORS];
  92. int i;
  93. for (i=0; i<COLORS; i++)
  94. table[i] = i;
  95. table[vs.inks[1]] = vs.inks[0];
  96. table[vs.inks[2]] = vs.inks[0];
  97. xlat(table, render_form->p, 64000);
  98. return(1);
  99. }
  100. clean_tween()
  101. {
  102. uzauto(clean_t1);
  103. }
  104. #define MSZ (Mask_block(XMAX,YMAX))
  105. #define PSZ ((unsigned)64000)
  106. /* routine that helps get changes, repeat changes, and next blue */
  107. static
  108. build_change_mask(p1, p2, mask)
  109. UBYTE *p1, *p2, *mask;
  110. {
  111. UBYTE mod, mword;
  112. unsigned count;
  113. zero_structure(mask, MSZ);
  114. count = PSZ+1;
  115. mod = 0x80;
  116. mword = 0;
  117. while (--count != 0)
  118. {
  119. if (*p1++ != *p2++)
  120. {
  121. mword |= mod;
  122. }
  123. if ((mod >>= 1) == 0)
  124. {
  125. mod = 0x80;
  126. *mask++ = mword;
  127. mword = 0;
  128. }
  129. }
  130. }
  131. /* stuff for repeat changes */
  132. static
  133. update_changes(new, old, dest, mask)
  134. UBYTE *new, *old, *dest, *mask;
  135. {
  136. UBYTE mod, mword;
  137. unsigned count;
  138. count = PSZ+1;
  139. mod = 0;
  140. while (--count != 0)
  141. {
  142. if ((mod >>= 1) == 0)
  143. {
  144. mword = *mask++;
  145. mod = 0x80;
  146. }
  147. if (mword&mod)
  148. {
  149. *dest++ = *new++;
  150. old++;
  151. }
  152. else
  153. {
  154. *dest++ = *old++;
  155. new++;
  156. }
  157. }
  158. }
  159. /* make one line of changes */
  160. static
  161. mc1line(s1,s2,d,w,tcolor)
  162. PLANEPTR s1,s2,d;
  163. int w,tcolor;
  164. {
  165. UBYTE c;
  166. while (--w >= 0)
  167. {
  168. c = *s2++;
  169. if (c != *s1++)
  170. *d++ = c;
  171. else
  172. *d++ = tcolor;
  173. }
  174. }
  175. qget_changes()
  176. {
  177. int w, h;
  178. PLANEPTR s1,s2,d;
  179. if (!push_screen())
  180. return;
  181. fli_abs_tseek(&uf,vs.frame_ix); /* put the unchanged screen into uf */
  182. /* xor with changed screen and find dimensions of changed result */
  183. xor_form(&uf, render_form);
  184. find_clip(render_form,0);
  185. w = x_1 - x_0 + 1;
  186. h = y_1 - y_0 + 1;
  187. pop_screen(); /* back to original screen */
  188. free_cel(cel);
  189. if ((cel = alloc_cel(w,h,x_0,y_0)) != NULL)
  190. {
  191. d = cel->p;
  192. s1 = uf.p + y_0*BPR + x_0;
  193. s2 = render_form->p + y_0*BPR + x_0;
  194. while (--h >= 0)
  195. {
  196. mc1line(s1,s2,d,w,vs.inks[0]);
  197. s1 += BPR;
  198. s2 += BPR;
  199. d += cel->bpr;
  200. }
  201. copy_cmap(render_form->cmap, cel->cmap);
  202. show_cel_a_sec();
  203. }
  204. }
  205. /* Stuff for repeat changes and next blue */
  206. /* selective copy of s to d. Where d is 'blue' replace it with s. Used
  207. by next blue. */
  208. static
  209. restore_blue(s,d,count,ink)
  210. PLANEPTR s, d;
  211. unsigned count;
  212. unsigned char ink;
  213. {
  214. int i;
  215. for (i = 0; i<count; i++)
  216. {
  217. if (*d == ink)
  218. *d = *s;
  219. s++;
  220. d++;
  221. }
  222. }
  223. /* Either do repeat changes or next blue */
  224. static
  225. next_bc(blue)
  226. int blue; /* blue it or copy changes */
  227. {
  228. PLANEPTR mask;
  229. int ok, oix;
  230. oix = vs.frame_ix;
  231. unzoom();
  232. maybe_push_most();
  233. fli_abs_tseek(&uf,vs.frame_ix);
  234. if (blue)
  235. restore_blue(uf.p, render_form->p, (unsigned)64000,vs.inks[1]);
  236. if ((mask = begmem(MSZ)) != NULL)
  237. {
  238. build_change_mask(uf.p, render_form->p, mask);
  239. if (push_screen())
  240. {
  241. scrub_cur_frame();
  242. advance_frame_ix();
  243. copy_form(render_form, &uf);
  244. ok = unfli(&uf,vs.frame_ix,1);
  245. pop_screen();
  246. if (ok)
  247. {
  248. if (blue)
  249. {
  250. copy_form(&uf, render_form);
  251. a1blit(XMAX,YMAX,0,0,mask,Mask_line(XMAX),
  252. 0,0,render_form->p, BPR,vs.inks[1]);
  253. }
  254. else
  255. {
  256. update_changes(render_form->p, uf.p, render_form->p, mask);
  257. copy_cmap(uf.cmap, render_form->cmap);
  258. }
  259. dirties();
  260. }
  261. else
  262. vs.frame_ix = oix;
  263. }
  264. freemem(mask);
  265. }
  266. maybe_pop_most();
  267. see_cmap();
  268. rezoom();
  269. }
  270. qnext_changes()
  271. {
  272. next_bc(0);
  273. }
  274. qnext_blue()
  275. {
  276. next_bc(1);
  277. }