EFFECTS.C 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
  3. SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
  4. END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
  5. ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
  6. IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
  7. SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
  8. FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
  9. CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
  10. AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
  11. COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
  12. */
  13. #pragma off (unreferenced)
  14. static char rcsid[] = "$Id: effects.c 1.5 1994/11/18 22:51:04 john Exp $";
  15. #pragma on (unreferenced)
  16. #include <stdlib.h>
  17. #include <stdio.h>
  18. #include "mem.h"
  19. #include "gr.h"
  20. #include "grdef.h"
  21. #include "effect2d.h"
  22. int bitwidth(unsigned int n)
  23. {
  24. int width = 0;
  25. while ( n!=0 ) {
  26. n >>= 1;
  27. width++;
  28. }
  29. return width;
  30. }
  31. long randmasks[] = { 0,0,0x03,0x06,0x0c,0x14,0x30,0x60,0xb8,\
  32. 0x110,0x240,0x500,0xca0,0x1b00,0x3500,0x6000,0xb400,\
  33. 0x12000,0x204000,0x720000,0x90000,0x140000,0x300000,0x400000,\
  34. 0xd80000,0x1200000,0x3880000,0x7200000,0x9000000,0x14000000,\
  35. 0x32800000,0x48000000,0xa3000000 };
  36. void dissolve_in(grs_bitmap * bitmap )
  37. {
  38. int height, width, zz;
  39. int rwidth, cwidth; /* bit width for rows, for columns */
  40. int regwidth; /* "width" of sequence generator */
  41. long mask; /* mask to XOR with to create sequence */
  42. int rowshift; /* shift distance to get row */
  43. /* from element */
  44. int colmask; /* mask to extract column from element */
  45. unsigned long element; /* one element of random */ /* sequence */
  46. int row, column; /* row and column for one pixel */
  47. /* Find the mask to produce all rows and columns. */
  48. height = bitmap->bm_h;
  49. width = bitmap->bm_w;
  50. rwidth = bitwidth (height); /* how many bits needed for height? */
  51. cwidth = bitwidth (width); /* how many bits needed for width? */
  52. regwidth = rwidth + cwidth; /* how wide must the register be? */
  53. mask = randmasks[regwidth]; /* which mask is for that width? */
  54. /* Find values to extract row and col numbers from each element. */
  55. rowshift = cwidth; /* find dist to shift to get top bits (row) */
  56. colmask = (1<<cwidth)-1; /* find mask to extract */
  57. /* bottom bits (col) */
  58. /* Now cycle through all sequence elements. */
  59. element = 1; /* 1st element (could be any nonzero) */
  60. do {
  61. for (zz=0; zz < 100; zz++);
  62. row = element >> rowshift; /* find row number for this pixel */
  63. column = element & colmask; /* and how many columns across? */
  64. /* does element fall in the array? */
  65. /* ...must check row AND column */
  66. if ((row < height) && (column < width)) {
  67. // Draw the (r,c)'th pixel
  68. gr_setcolor(gr_ugpixel( bitmap, column, row ));
  69. gr_upixel(column, row);
  70. }
  71. /* Compute the next sequence element */
  72. if (element & 1) /* is the low bit set? */
  73. element = (element >>1)^mask; /* yes: shift value, */
  74. else
  75. element = (element >>1); /* no: just shift the value */
  76. } while (element != 1); /* loop until we return to */
  77. /* original element */
  78. gr_setcolor(gr_ugpixel( bitmap, 0, 0 ));
  79. gr_upixel(0,0);
  80. }