PageRenderTime 46ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/Pristine/CROP/SEQ.C

http://github.com/AnimatorPro/Animator-Pro
C | 351 lines | 312 code | 25 blank | 14 comment | 56 complexity | 2cd547b91757d6ae153d29a62e40f024 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. /* seq.c - handles Atari ST/Cyber Paint .SEQ files. These are compressed
  2. frame files much like FLI's on the PC. */
  3. #include "jimk.h"
  4. #include "seq.h"
  5. #include "seq.str"
  6. static UBYTE *stscreen;
  7. static int seq_err = -1;
  8. static seq_fd;
  9. static char *seq_name;
  10. struct seq_header seq_h;
  11. struct neo_head neo_h;
  12. word_uncompress(s, d, length)
  13. WORD *s, *d;
  14. int length; /* in WORDS! */
  15. {
  16. WORD run_length;
  17. WORD run_data;
  18. for (;;)
  19. {
  20. if (length <= 0) /* check to see if out of data yet */
  21. break;
  22. run_length = *s++;
  23. length -= 1; /* used up 1 WORD of source */
  24. if (run_length & 0x8000) /* see if it's a compressed run or a literal */
  25. {
  26. run_length &= 0x7fff; /* knock of the hi bit */
  27. length -= run_length; /* used up lots more of source */
  28. while (--run_length >= 0) /* go through loop run_length times */
  29. *d++ = *s++;
  30. }
  31. else /* yeah, it's compressed a little */
  32. {
  33. run_data = *s++;
  34. length -= 1; /* used another WORD of source */
  35. while (--run_length >= 0)
  36. *d++ = run_data;
  37. }
  38. }
  39. }
  40. open_verify_seq(name, shead)
  41. char *name;
  42. struct seq_header *shead;
  43. {
  44. int file;
  45. if ((file = jopen(name, 0)) == 0)
  46. {
  47. cant_find(name);
  48. return(0);
  49. }
  50. if (jread(file, shead, sizeof(*shead)) < sizeof(*shead) )
  51. {
  52. truncated(name);
  53. goto BADEXIT;
  54. }
  55. intel_swap(&shead->magic);
  56. intel_swap(&shead->version);
  57. intel_swap(&shead->speed);
  58. long_intel_swap(&shead->cel_count);
  59. if (shead->magic != 0xfedc && shead->magic != 0xfedb)
  60. {
  61. continu_line(seq_100 /* "Not a Cyber SEQ file" */);
  62. goto BADEXIT;
  63. }
  64. return(file);
  65. BADEXIT:
  66. jclose(file);
  67. return(0);
  68. }
  69. open_seq(name)
  70. char *name;
  71. {
  72. if (seq_err != -1)
  73. {
  74. continu_line(seq_101 /* "Seq already open" */);
  75. return(0);
  76. }
  77. if ((seq_fd = open_verify_seq(name, &seq_h)) == 0)
  78. return(0);
  79. /* actually the stscreen will be viewed more like an amiga screen 'cause
  80. the ST word-interleaved blits are such a hassle to cope with.
  81. Also then can reuse routine to convert Amiga Bit-planes to VGA
  82. byte-a-pixel style. */
  83. if ((stscreen = lbegmem(40000L)) == NULL)
  84. {
  85. close_seq();
  86. return(0);
  87. }
  88. zero_lots(stscreen,40000L);
  89. seq_err = 0;
  90. seq_name = name;
  91. return(1);
  92. }
  93. close_seq()
  94. {
  95. if (seq_fd != 0)
  96. {
  97. jclose(seq_fd);
  98. seq_fd = 0;
  99. }
  100. gentle_freemem(stscreen);
  101. stscreen = NULL;
  102. seq_err = -1;
  103. }
  104. columns_to_bitplanes(s,d,wpl,height)
  105. WORD *s, *d;
  106. int wpl; /* words in a line */
  107. int height; /* # of lines */
  108. {
  109. int i, j, k;
  110. WORD *sp, *dp;
  111. WORD *sl, *dl;
  112. unsigned plane_size;
  113. plane_size = wpl*height;
  114. /* step through planes */
  115. for (i = 0; i< 4; i++)
  116. {
  117. sp = s;
  118. dp = d;
  119. /* step through lines */
  120. for (j=0; j<height; j++)
  121. {
  122. sl = sp;
  123. dl = dp;
  124. /* step through words */
  125. for (k=0; k<wpl; k++)
  126. {
  127. *dl = *sl;
  128. dl += 1;
  129. sl += height;
  130. }
  131. sp += 1;
  132. dp += wpl;
  133. }
  134. d += plane_size;
  135. s += plane_size;
  136. }
  137. }
  138. de_interleave(s,d,wpl,height)
  139. WORD *s, *d;
  140. int wpl; /* words in a line */
  141. int height; /* # of lines */
  142. {
  143. int i, j, k;
  144. WORD *sp, *dp;
  145. WORD *sl, *dl;
  146. unsigned plane_size;
  147. plane_size = wpl*height;
  148. /* step through planes */
  149. for (i = 0; i< 4; i++)
  150. {
  151. sp = s;
  152. dp = d;
  153. /* step through lines */
  154. for (j=0; j<height; j++)
  155. {
  156. sl = sp;
  157. dl = dp;
  158. /* step through words */
  159. for (k=0; k<wpl; k++)
  160. {
  161. *dl = *sl;
  162. sl += 4;
  163. dl += 1;
  164. }
  165. sp += 4*wpl;
  166. dp += wpl;
  167. }
  168. s += 1;
  169. d += plane_size;
  170. }
  171. }
  172. #ifdef SLUFFED
  173. make_lines(plane,bpr,height)
  174. UBYTE *plane;
  175. int bpr, height;
  176. {
  177. int i,j;
  178. UBYTE data;
  179. for (i=0; i<height; i++)
  180. {
  181. if (i&1)
  182. data = 0x55;
  183. else
  184. data = 0xaa;
  185. for (j=0; j<bpr; j++)
  186. *plane++ = data;
  187. }
  188. }
  189. #endif /* SLUFFED */
  190. next_seq()
  191. {
  192. int i;
  193. WORD *buf1, *buf2;
  194. int ok;
  195. int got_data;
  196. unsigned buf_size;
  197. unsigned plane_size;
  198. unsigned sbpr;
  199. unsigned bsize;
  200. UBYTE *planes;
  201. ok = 0;
  202. if (jread(seq_fd, &neo_h, (long)sizeof(neo_h)) < sizeof(neo_h) )
  203. {
  204. truncated(seq_name);
  205. return(0);
  206. }
  207. intel_swap(&neo_h.type);
  208. intel_swap(&neo_h.resolution);
  209. intel_swaps(neo_h.colormap, 16);
  210. intel_swap(&neo_h.xoff);
  211. intel_swap(&neo_h.yoff);
  212. intel_swap(&neo_h.width);
  213. intel_swap(&neo_h.height);
  214. long_intel_swap(&neo_h.data_size);
  215. sbpr = seq_Mask_line(neo_h.width);
  216. plane_size = sbpr*neo_h.height;
  217. buf_size = plane_size*4; /* 4 bitplanes in ST display */
  218. if (neo_h.compress == NEO_UNCOMPRESSED)
  219. {
  220. neo_h.data_size = seq_LRaster_block(neo_h.width, (long)neo_h.height);
  221. }
  222. if (neo_h.type != -1)
  223. {
  224. continu_line(seq_102 /* "Bad Cel Magic! File Damaged!" */);
  225. return(0);
  226. }
  227. got_data = (neo_h.data_size != 0);
  228. if (got_data)
  229. {
  230. buf1 = buf2 = NULL;
  231. if ((buf1 = begmem(buf_size)) == NULL)
  232. goto ENDDATA;
  233. if ((buf2 = begmem(buf_size)) == NULL)
  234. goto ENDDATA;
  235. if (jread(seq_fd, buf1, neo_h.data_size) != neo_h.data_size)
  236. {
  237. truncated(seq_name);
  238. goto ENDDATA;
  239. }
  240. if (neo_h.compress == NEO_CCOLUMNS)
  241. {
  242. bsize = neo_h.data_size>>1;
  243. intel_swaps(buf1,bsize); /* swap so counts are right */
  244. word_uncompress(buf1, buf2, bsize);
  245. intel_swaps(buf2,plane_size*2); /* swap back so image right */
  246. columns_to_bitplanes(buf2,buf1,sbpr>>1,neo_h.height);
  247. planes = (UBYTE *)buf1;
  248. }
  249. else
  250. {
  251. de_interleave(buf1,buf2,sbpr>>1,neo_h.height);
  252. planes = (UBYTE *)buf2;
  253. }
  254. if (neo_h.op == NEO_XOR)
  255. {
  256. for (i=0; i<4; i++)
  257. {
  258. xor_blit_box(neo_h.width, neo_h.height, 0, 0, planes, sbpr,
  259. neo_h.xoff, neo_h.yoff, stscreen+8000*i, 40);
  260. planes += plane_size;
  261. }
  262. }
  263. else
  264. {
  265. zero_structure(stscreen, 32000);
  266. for (i=0; i<4; i++)
  267. {
  268. blit_box(neo_h.width, neo_h.height, 0, 0, planes, sbpr,
  269. neo_h.xoff, neo_h.yoff, stscreen+8000*i, 40);
  270. planes += plane_size;
  271. }
  272. }
  273. ok = 1;
  274. ENDDATA:
  275. gentle_freemem(buf1);
  276. gentle_freemem(buf2);
  277. }
  278. else /* zero data length */
  279. {
  280. /* if it's an xor don't have to do anything at all, cool breeze! */
  281. if (neo_h.op != NEO_XOR)
  282. zero_structure(stscreen, 32000);
  283. ok = 1;
  284. }
  285. put_st_cmap(neo_h.colormap);
  286. conv_screen(stscreen);
  287. return(ok);
  288. }
  289. start_seq()
  290. {
  291. if (seq_err)
  292. return(0);
  293. /* skip past the offset lists */
  294. jseek(seq_fd, seq_h.cel_count * sizeof(long) + sizeof(seq_h), 0);
  295. return(next_seq());
  296. }
  297. count_seq()
  298. {
  299. if (seq_err)
  300. return(0);
  301. return(seq_h.cel_count);
  302. }
  303. speed_seq()
  304. {
  305. if (seq_err)
  306. return(0);
  307. return(seq_h.speed/100);
  308. }
  309. #ifdef SLUFFED
  310. do_test_blit(mask)
  311. UBYTE *mask;
  312. {
  313. UBYTE *scr;
  314. int i;
  315. if ((scr = lbegmem(40000L)) != NULL)
  316. {
  317. for (i=0; i<90; i+=3)
  318. {
  319. zero_lots(scr, 40000L);
  320. blit_box(100,100,0,0,mask,40,i, 0, scr, 40);
  321. conv_screen(scr);
  322. }
  323. freemem(scr);
  324. }
  325. }
  326. #endif /* SLUFFED */