source: abuse/branches/pd/macabuse/src/smoosh.c @ 98

Last change on this file since 98 was 49, checked in by Sam Hocevar, 15 years ago
  • Imported original public domain release, for future reference.
  • Property svn:keywords set to Id
File size: 1.3 KB
Line 
1#include "jmalloc.hpp"
2#define PARTICLE_SIZE 2            // 2x2 block of pixels
3
4class particle
5{
6public :
7  unsigned char *pict;
8  int x,y;
9  particle *left,*right,*up,*down;
10  particle(int X, int Y, int size);
11  ~particle() { jfree(pict); }
12} ;
13
14particle::particle(int X, int Y, image *im, int size);
15{
16  x=X; y=Y;
17  left=right=up=down=NULL;
18  pict=(unsigned char *)jmalloc(size*size,"Particle");
19}
20
21class particle_image
22{
23  int particles;
24  particle *top;
25  int size;
26public :
27  particle_image(image *im, int particle_size);       // im will be erased!
28} ;
29
30
31particle_image::particle_image(image *im, int particle_size)     
32{
33  int x,y,py,p;
34  unsigned char *sl,*sl2;
35  top=NULL;
36  size=particle_size;
37
38  int matw=(im->width()+size-1)/size,math=(im->height()+size-1)/size;
39  particle *matrix[matw*math];
40
41
42  // break the image up into particles and store in a big matrix
43  for (y=0;y<im->height();y++)
44  {
45    sl=im->scan_line(y);
46    py=y/size;
47    for (x=0;x<im->width();x++,sl+=px)
48    {
49      px=x/size;
50      sl2=matrix[py*matw+px]->pict+(y%size)*size;      // address of particle image memory
51
52      int copy_size;
53
54      memset(sl2,0,size);
55     
56      if (*sl)
57      {
58        px=x/size;
59        py=y/size;
60      }
61
62  }
63  if (px<0)       // couldn't find any non-blank pixels
64    particles=0;
65  else
66    add_particle_line(px,py,im);
67}
Note: See TracBrowser for help on using the repository browser.