EFFECTS.C 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
  12. */
  13. /*
  14. * $Source: f:/miner/source/2d/rcs/effects.c $
  15. * $Revision: 1.5 $
  16. * $Author: john $
  17. * $Date: 1994/11/18 22:51:04 $
  18. *
  19. * special effects stuff
  20. *
  21. * $Log: effects.c $
  22. * Revision 1.5 1994/11/18 22:51:04 john
  23. * Changed a bunch of shorts to ints in calls.
  24. *
  25. * Revision 1.4 1994/04/22 11:16:00 john
  26. * *** empty log message ***
  27. *
  28. * Revision 1.3 1994/02/01 13:18:45 john
  29. * *** empty log message ***
  30. *
  31. * Revision 1.2 1993/10/26 13:18:15 john
  32. * *** empty log message ***
  33. *
  34. * Revision 1.1 1993/10/25 14:56:56 john
  35. * Initial revision
  36. *
  37. *
  38. */
  39. #pragma off (unreferenced)
  40. static char rcsid[] = "$Id: effects.c 1.5 1994/11/18 22:51:04 john Exp $";
  41. #pragma on (unreferenced)
  42. #include <stdlib.h>
  43. #include <stdio.h>
  44. #include "mem.h"
  45. #include "gr.h"
  46. #include "grdef.h"
  47. #include "effect2d.h"
  48. int bitwidth(unsigned int n)
  49. {
  50. int width = 0;
  51. while ( n!=0 ) {
  52. n >>= 1;
  53. width++;
  54. }
  55. return width;
  56. }
  57. long randmasks[] = { 0,0,0x03,0x06,0x0c,0x14,0x30,0x60,0xb8,\
  58. 0x110,0x240,0x500,0xca0,0x1b00,0x3500,0x6000,0xb400,\
  59. 0x12000,0x204000,0x720000,0x90000,0x140000,0x300000,0x400000,\
  60. 0xd80000,0x1200000,0x3880000,0x7200000,0x9000000,0x14000000,\
  61. 0x32800000,0x48000000,0xa3000000 };
  62. void dissolve_in(grs_bitmap * bitmap )
  63. {
  64. int height, width, zz;
  65. int rwidth, cwidth; /* bit width for rows, for columns */
  66. int regwidth; /* "width" of sequence generator */
  67. long mask; /* mask to XOR with to create sequence */
  68. int rowshift; /* shift distance to get row */
  69. /* from element */
  70. int colmask; /* mask to extract column from element */
  71. unsigned long element; /* one element of random */ /* sequence */
  72. int row, column; /* row and column for one pixel */
  73. /* Find the mask to produce all rows and columns. */
  74. height = bitmap->bm_h;
  75. width = bitmap->bm_w;
  76. rwidth = bitwidth (height); /* how many bits needed for height? */
  77. cwidth = bitwidth (width); /* how many bits needed for width? */
  78. regwidth = rwidth + cwidth; /* how wide must the register be? */
  79. mask = randmasks[regwidth]; /* which mask is for that width? */
  80. /* Find values to extract row and col numbers from each element. */
  81. rowshift = cwidth; /* find dist to shift to get top bits (row) */
  82. colmask = (1<<cwidth)-1; /* find mask to extract */
  83. /* bottom bits (col) */
  84. /* Now cycle through all sequence elements. */
  85. element = 1; /* 1st element (could be any nonzero) */
  86. do {
  87. for (zz=0; zz < 100; zz++);
  88. row = element >> rowshift; /* find row number for this pixel */
  89. column = element & colmask; /* and how many columns across? */
  90. /* does element fall in the array? */
  91. /* ...must check row AND column */
  92. if ((row < height) && (column < width)) {
  93. // Draw the (r,c)'th pixel
  94. gr_setcolor(gr_ugpixel( bitmap, column, row ));
  95. gr_upixel(column, row);
  96. }
  97. /* Compute the next sequence element */
  98. if (element & 1) /* is the low bit set? */
  99. element = (element >>1)^mask; /* yes: shift value, */
  100. else
  101. element = (element >>1); /* no: just shift the value */
  102. } while (element != 1); /* loop until we return to */
  103. /* original element */
  104. gr_setcolor(gr_ugpixel( bitmap, 0, 0 ));
  105. gr_upixel(0,0);
  106. }
  107.