pikl 0.2.8 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +9 -0
 - data/License.txt +0 -0
 - data/Manifest.txt +17 -17
 - data/README.txt +0 -0
 - data/config/hoe.rb +9 -6
 - data/config/requirements.rb +0 -0
 - data/ext/pikl/extconf.rb +0 -0
 - data/ext/pikl/pikl.h +617 -465
 - data/ext/pikl/pikl_affine.c +38 -91
 - data/ext/pikl/pikl_affine.h +0 -0
 - data/ext/pikl/pikl_bitmap.c +0 -0
 - data/ext/pikl/pikl_bitmap.h +0 -0
 - data/ext/pikl/pikl_blur.c +4 -8
 - data/ext/pikl/pikl_blur.h +0 -0
 - data/ext/pikl/pikl_camera.c +218 -0
 - data/ext/pikl/{pikl_effect3.h → pikl_camera.h} +2 -2
 - data/ext/pikl/pikl_composite.c +175 -0
 - data/ext/pikl/pikl_composite.h +12 -0
 - data/ext/pikl/pikl_decrease.c +110 -45
 - data/ext/pikl/pikl_decrease.h +0 -7
 - data/ext/pikl/pikl_divide.c +116 -0
 - data/ext/pikl/pikl_divide.h +11 -0
 - data/ext/pikl/pikl_effect.c +583 -151
 - data/ext/pikl/pikl_effect.h +32 -6
 - data/ext/pikl/pikl_enhance.c +274 -0
 - data/ext/pikl/pikl_enhance.h +20 -0
 - data/ext/pikl/pikl_io.c +174 -23
 - data/ext/pikl/pikl_io.h +0 -0
 - data/ext/pikl/pikl_jpeg.c +0 -0
 - data/ext/pikl/pikl_jpeg.h +0 -0
 - data/ext/pikl/pikl_pattern.c +383 -357
 - data/ext/pikl/pikl_pattern.h +0 -0
 - data/ext/pikl/pikl_pixel.c +173 -0
 - data/ext/pikl/{pikl_trim.h → pikl_pixel.h} +2 -2
 - data/ext/pikl/pikl_png.c +0 -0
 - data/ext/pikl/pikl_png.h +0 -0
 - data/ext/pikl/pikl_private.h +12 -5
 - data/ext/pikl/pikl_resize.c +0 -0
 - data/ext/pikl/pikl_resize.h +0 -0
 - data/ext/pikl/pikl_rotate.c +409 -51
 - data/ext/pikl/pikl_rotate.h +8 -0
 - data/ext/pikl/pikl_scrap.c +263 -483
 - data/ext/pikl/pikl_scrap.h +0 -0
 - data/ext/pikl/pikl_special.c +168 -0
 - data/ext/pikl/{pikl_effect4.h → pikl_special.h} +2 -2
 - data/ext/pikl/pikl_voronoi.c +320 -0
 - data/ext/pikl/pikl_voronoi.h +37 -0
 - data/lib/pikl.rb +4 -2
 - data/lib/pikl/color.rb +47 -0
 - data/lib/pikl/const.rb +106 -22
 - data/lib/pikl/errors.rb +0 -0
 - data/lib/pikl/ext.rb +115 -8
 - data/lib/pikl/filter.rb +371 -0
 - data/lib/pikl/image.rb +124 -117
 - data/lib/pikl/version.rb +2 -2
 - data/setup.rb +0 -0
 - data/test/sample.jpg +0 -0
 - data/test/test_helper.rb +0 -0
 - data/test/test_pikl_image.rb +0 -14
 - data/test/test_pikl_image2.rb +541 -0
 - metadata +35 -23
 - data/ext/pikl/decrease/fsdither.h +0 -554
 - data/ext/pikl/decrease/median.c +0 -1179
 - data/ext/pikl/decrease/median.h +0 -7
 - data/ext/pikl/decrease/neuquan5.c +0 -563
 - data/ext/pikl/decrease/neuquant.h +0 -62
 - data/ext/pikl/decrease/wu.c +0 -447
 - data/ext/pikl/decrease/wu.h +0 -7
 - data/ext/pikl/pikl_effect2.c +0 -240
 - data/ext/pikl/pikl_effect2.h +0 -55
 - data/ext/pikl/pikl_effect3.c +0 -266
 - data/ext/pikl/pikl_effect4.c +0 -495
 - data/ext/pikl/pikl_rotate2.c +0 -312
 - data/ext/pikl/pikl_rotate2.h +0 -19
 - data/ext/pikl/pikl_trim.c +0 -28
 
| 
         @@ -0,0 +1,175 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            #include "pikl_composite.h"
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            //=============================================================================
         
     | 
| 
      
 4 
     | 
    
         
            +
            // pkl_composite
         
     | 
| 
      
 5 
     | 
    
         
            +
            //=============================================================================
         
     | 
| 
      
 6 
     | 
    
         
            +
            PKLExport int pkl_composite(PKLImage parent, PKLImage child, int xpos, int ypos, PKLColor transcolor)
         
     | 
| 
      
 7 
     | 
    
         
            +
            {
         
     | 
| 
      
 8 
     | 
    
         
            +
            	int tw, th, i, j, px, py, cx, cy;
         
     | 
| 
      
 9 
     | 
    
         
            +
            	
         
     | 
| 
      
 10 
     | 
    
         
            +
            	if(parent->channel != child->channel) return(1);
         
     | 
| 
      
 11 
     | 
    
         
            +
            	if(child->width > parent->width || child->height > parent->height) return(1);
         
     | 
| 
      
 12 
     | 
    
         
            +
            	if(xpos+child->width<0 || xpos>=parent->width ||
         
     | 
| 
      
 13 
     | 
    
         
            +
            	   ypos+child->height<0 || ypos>=parent->height) return(0);
         
     | 
| 
      
 14 
     | 
    
         
            +
            	
         
     | 
| 
      
 15 
     | 
    
         
            +
            	tw = xpos<0 ? child->width+xpos : (xpos+child->width >= parent->width) ? parent->width-xpos : child->width;
         
     | 
| 
      
 16 
     | 
    
         
            +
            	th = ypos<0 ? child->height+ypos : (ypos+child->height >= parent->height) ? parent->height-ypos : child->height;
         
     | 
| 
      
 17 
     | 
    
         
            +
            	px = xpos<0 ? 0 : xpos;
         
     | 
| 
      
 18 
     | 
    
         
            +
            	py = ypos<0 ? 0 : ypos;
         
     | 
| 
      
 19 
     | 
    
         
            +
            	cx = xpos<0 ? -xpos : 0;
         
     | 
| 
      
 20 
     | 
    
         
            +
            	cy = ypos<0 ? -ypos : 0;
         
     | 
| 
      
 21 
     | 
    
         
            +
            	
         
     | 
| 
      
 22 
     | 
    
         
            +
            	if(transcolor){
         
     | 
| 
      
 23 
     | 
    
         
            +
            		//�����F���ݒ肳��Ă��鎞
         
     | 
| 
      
 24 
     | 
    
         
            +
            		int s, t;
         
     | 
| 
      
 25 
     | 
    
         
            +
            		for(i=py,j=cy; i<th+py; i++,j++){
         
     | 
| 
      
 26 
     | 
    
         
            +
            			for(s=px,t=cx; t<cx+tw; s++,t++){
         
     | 
| 
      
 27 
     | 
    
         
            +
            				if( memcmp(&child->image[(j*child->width+t)*child->channel], transcolor->color, child->channel) ){
         
     | 
| 
      
 28 
     | 
    
         
            +
            					memcpy(&parent->image[(i*parent->width+s)*parent->channel],
         
     | 
| 
      
 29 
     | 
    
         
            +
            						   &child->image[(j*child->width+t)*child->channel], child->channel);
         
     | 
| 
      
 30 
     | 
    
         
            +
            				}
         
     | 
| 
      
 31 
     | 
    
         
            +
            			}
         
     | 
| 
      
 32 
     | 
    
         
            +
            		}
         
     | 
| 
      
 33 
     | 
    
         
            +
            	}else{
         
     | 
| 
      
 34 
     | 
    
         
            +
            		//�����F���ݒ肳��Ă��Ȃ���
         
     | 
| 
      
 35 
     | 
    
         
            +
            		for(i=py,j=cy; i<th+py; i++,j++){
         
     | 
| 
      
 36 
     | 
    
         
            +
            			memcpy(&parent->image[(i*parent->width+px)*parent->channel],
         
     | 
| 
      
 37 
     | 
    
         
            +
            				   &child->image[(j*child->width+cx)*child->channel], tw*child->channel);
         
     | 
| 
      
 38 
     | 
    
         
            +
            		}
         
     | 
| 
      
 39 
     | 
    
         
            +
            	}
         
     | 
| 
      
 40 
     | 
    
         
            +
            	return(0);
         
     | 
| 
      
 41 
     | 
    
         
            +
            }
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
            //=============================================================================
         
     | 
| 
      
 44 
     | 
    
         
            +
            // pkl_alphablend
         
     | 
| 
      
 45 
     | 
    
         
            +
            //=============================================================================
         
     | 
| 
      
 46 
     | 
    
         
            +
            PKLExport int pkl_alphablend(PKLImage parent, PKLImage child, int xpos, int ypos, int alpha)
         
     | 
| 
      
 47 
     | 
    
         
            +
            {
         
     | 
| 
      
 48 
     | 
    
         
            +
            	int tw, th, i, j, k, pp, cp, px, py, cx, cy, s, t;
         
     | 
| 
      
 49 
     | 
    
         
            +
            	
         
     | 
| 
      
 50 
     | 
    
         
            +
            	if(parent->channel != child->channel) return(1);
         
     | 
| 
      
 51 
     | 
    
         
            +
            	if(child->width > parent->width || child->height > parent->height) return(1);
         
     | 
| 
      
 52 
     | 
    
         
            +
            	if(xpos+child->width<0 || xpos>=parent->width ||
         
     | 
| 
      
 53 
     | 
    
         
            +
            	   ypos+child->height<0 || ypos>=parent->height) return(0);
         
     | 
| 
      
 54 
     | 
    
         
            +
            	
         
     | 
| 
      
 55 
     | 
    
         
            +
            	tw = xpos<0 ? child->width+xpos : (xpos+child->width >= parent->width) ? parent->width-xpos : child->width;
         
     | 
| 
      
 56 
     | 
    
         
            +
            	th = ypos<0 ? child->height+ypos : (ypos+child->height >= parent->height) ? parent->height-ypos : child->height;
         
     | 
| 
      
 57 
     | 
    
         
            +
            	px = xpos<0 ? 0 : xpos;
         
     | 
| 
      
 58 
     | 
    
         
            +
            	py = ypos<0 ? 0 : ypos;
         
     | 
| 
      
 59 
     | 
    
         
            +
            	cx = xpos<0 ? -xpos : 0;
         
     | 
| 
      
 60 
     | 
    
         
            +
            	cy = ypos<0 ? -ypos : 0;
         
     | 
| 
      
 61 
     | 
    
         
            +
            	
         
     | 
| 
      
 62 
     | 
    
         
            +
            	if(alpha<0){
         
     | 
| 
      
 63 
     | 
    
         
            +
            		//child�̎��݂͂̂Ƀ���K�p
         
     | 
| 
      
 64 
     | 
    
         
            +
            		double alp;
         
     | 
| 
      
 65 
     | 
    
         
            +
            		
         
     | 
| 
      
 66 
     | 
    
         
            +
            		for(i=py,j=cy; i<th+py; i++,j++){
         
     | 
| 
      
 67 
     | 
    
         
            +
            			for(s=px,t=cx; t<cx+tw; s++,t++){
         
     | 
| 
      
 68 
     | 
    
         
            +
            				alp = sin(j*M_PI/child->height) * sin(t*M_PI/child->width);
         
     | 
| 
      
 69 
     | 
    
         
            +
            				pp = (i*parent->width+s)*parent->channel;
         
     | 
| 
      
 70 
     | 
    
         
            +
            				cp = (j*child->width+t)*child->channel;
         
     | 
| 
      
 71 
     | 
    
         
            +
            				for(k=0; k<parent->channel; k++)
         
     | 
| 
      
 72 
     | 
    
         
            +
            					parent->image[pp+k] =PKL_COLOR_CLIP(parent->image[pp+k]*(1.0-alp) + child->image[cp+k]*alp);
         
     | 
| 
      
 73 
     | 
    
         
            +
            			}
         
     | 
| 
      
 74 
     | 
    
         
            +
            		}
         
     | 
| 
      
 75 
     | 
    
         
            +
            	}else{
         
     | 
| 
      
 76 
     | 
    
         
            +
            		//child�S�̂Ƀ���K�p
         
     | 
| 
      
 77 
     | 
    
         
            +
            		int alp=PKL_COLOR_CLIP(alpha);
         
     | 
| 
      
 78 
     | 
    
         
            +
            		const int limits=PKL_COLOR-1;
         
     | 
| 
      
 79 
     | 
    
         
            +
            		
         
     | 
| 
      
 80 
     | 
    
         
            +
            		for(i=py,j=cy; i<th+py; i++,j++){
         
     | 
| 
      
 81 
     | 
    
         
            +
            			for(s=px,t=cx; t<cx+tw; s++,t++){
         
     | 
| 
      
 82 
     | 
    
         
            +
            				pp = (i*parent->width+s)*parent->channel;
         
     | 
| 
      
 83 
     | 
    
         
            +
            				cp = (j*child->width+t)*child->channel;
         
     | 
| 
      
 84 
     | 
    
         
            +
            				for(k=0; k<parent->channel; k++)
         
     | 
| 
      
 85 
     | 
    
         
            +
            					parent->image[pp+k] =PKL_COLOR_CLIP((parent->image[pp+k]*alp + child->image[cp+k]*(limits-alp)) / limits);
         
     | 
| 
      
 86 
     | 
    
         
            +
            			}
         
     | 
| 
      
 87 
     | 
    
         
            +
            		}
         
     | 
| 
      
 88 
     | 
    
         
            +
            	}
         
     | 
| 
      
 89 
     | 
    
         
            +
            	return(0);
         
     | 
| 
      
 90 
     | 
    
         
            +
            }
         
     | 
| 
      
 91 
     | 
    
         
            +
             
     | 
| 
      
 92 
     | 
    
         
            +
            //=============================================================================
         
     | 
| 
      
 93 
     | 
    
         
            +
            // pkl_shadowframe
         
     | 
| 
      
 94 
     | 
    
         
            +
            //=============================================================================
         
     | 
| 
      
 95 
     | 
    
         
            +
            PKLExport int pkl_shadowframe(PKLImage pkl, int margin, PKLColor backcolor, PKLColor shadowcolor)
         
     | 
| 
      
 96 
     | 
    
         
            +
            {
         
     | 
| 
      
 97 
     | 
    
         
            +
            	unsigned char *img, back[PKL_CHANNEL], shadow[PKL_CHANNEL];
         
     | 
| 
      
 98 
     | 
    
         
            +
            	int i, j, w, h;
         
     | 
| 
      
 99 
     | 
    
         
            +
             
     | 
| 
      
 100 
     | 
    
         
            +
            	if(margin<=0) return(1);
         
     | 
| 
      
 101 
     | 
    
         
            +
             
     | 
| 
      
 102 
     | 
    
         
            +
            	w = pkl->width;
         
     | 
| 
      
 103 
     | 
    
         
            +
            	h = pkl->height;
         
     | 
| 
      
 104 
     | 
    
         
            +
            	img = pkl->image;
         
     | 
| 
      
 105 
     | 
    
         
            +
            	pkl->width = w + margin*3;
         
     | 
| 
      
 106 
     | 
    
         
            +
            	pkl->height = h + margin*3;
         
     | 
| 
      
 107 
     | 
    
         
            +
            	
         
     | 
| 
      
 108 
     | 
    
         
            +
            	pkl->image = malloc(pkl->width*pkl->height*pkl->channel);
         
     | 
| 
      
 109 
     | 
    
         
            +
            	if(!pkl->image) return(1);
         
     | 
| 
      
 110 
     | 
    
         
            +
            	memset(pkl->image, 0, pkl->width*pkl->height*pkl->channel);
         
     | 
| 
      
 111 
     | 
    
         
            +
             
     | 
| 
      
 112 
     | 
    
         
            +
            	//for(i=0; i<pkl->channel; i++){
         
     | 
| 
      
 113 
     | 
    
         
            +
            	//	back[i] = (backcolor>>((pkl->channel-i)*8) & 0xFF);
         
     | 
| 
      
 114 
     | 
    
         
            +
            	//	shadow[i] = (shadowcolor>>((pkl->channel-i)*8) & 0xFF);
         
     | 
| 
      
 115 
     | 
    
         
            +
            	//}
         
     | 
| 
      
 116 
     | 
    
         
            +
            	if(backcolor) memcpy(back, backcolor->color, pkl->channel);
         
     | 
| 
      
 117 
     | 
    
         
            +
            	else          memset(back, 0xff, pkl->channel);
         
     | 
| 
      
 118 
     | 
    
         
            +
             
     | 
| 
      
 119 
     | 
    
         
            +
            	if(shadowcolor) memcpy(shadow, shadowcolor->color, pkl->channel);
         
     | 
| 
      
 120 
     | 
    
         
            +
            	else            memset(shadow, 0, pkl->channel);
         
     | 
| 
      
 121 
     | 
    
         
            +
            	
         
     | 
| 
      
 122 
     | 
    
         
            +
            	//�w�i�F�ݒ�
         
     | 
| 
      
 123 
     | 
    
         
            +
            	for(i=0; i<pkl->width*pkl->height*pkl->channel; i+=pkl->channel)
         
     | 
| 
      
 124 
     | 
    
         
            +
            		memcpy(&pkl->image[i], back, pkl->channel);
         
     | 
| 
      
 125 
     | 
    
         
            +
            	
         
     | 
| 
      
 126 
     | 
    
         
            +
            	//�t���[���ݒ�
         
     | 
| 
      
 127 
     | 
    
         
            +
            	for(i=margin*2; i<h+margin*2; i++)
         
     | 
| 
      
 128 
     | 
    
         
            +
            		for(j=margin*2; j<w+margin*2; j++)
         
     | 
| 
      
 129 
     | 
    
         
            +
            			memcpy(&pkl->image[(i*pkl->width+j)*pkl->channel], shadow, pkl->channel);
         
     | 
| 
      
 130 
     | 
    
         
            +
            	
         
     | 
| 
      
 131 
     | 
    
         
            +
            	//shadowframe�����(�P�Ƀu���[)
         
     | 
| 
      
 132 
     | 
    
         
            +
            	pkl_gaussblur(pkl, 5.0);
         
     | 
| 
      
 133 
     | 
    
         
            +
            	
         
     | 
| 
      
 134 
     | 
    
         
            +
            	for(i=margin,j=0; i<h+margin; i++,j++)
         
     | 
| 
      
 135 
     | 
    
         
            +
            		memcpy(&pkl->image[(i*pkl->width+margin)*pkl->channel], &img[(j*w)*pkl->channel], w*pkl->channel);
         
     | 
| 
      
 136 
     | 
    
         
            +
            	
         
     | 
| 
      
 137 
     | 
    
         
            +
            	free(img);
         
     | 
| 
      
 138 
     | 
    
         
            +
            	return(0);
         
     | 
| 
      
 139 
     | 
    
         
            +
            }
         
     | 
| 
      
 140 
     | 
    
         
            +
             
     | 
| 
      
 141 
     | 
    
         
            +
             
     | 
| 
      
 142 
     | 
    
         
            +
            //=============================================================================
         
     | 
| 
      
 143 
     | 
    
         
            +
            // pkl_randomshadow
         
     | 
| 
      
 144 
     | 
    
         
            +
            //=============================================================================
         
     | 
| 
      
 145 
     | 
    
         
            +
            PKLExport int pkl_randomshadow(PKLImage canvas, PKLImage pasteimage, int top, int left, int margin, PKLColor shadowcolor)
         
     | 
| 
      
 146 
     | 
    
         
            +
            {
         
     | 
| 
      
 147 
     | 
    
         
            +
            	PKLImage shadow;
         
     | 
| 
      
 148 
     | 
    
         
            +
            	int i, j;
         
     | 
| 
      
 149 
     | 
    
         
            +
            	unsigned char shcolor[PKL_CHANNEL];
         
     | 
| 
      
 150 
     | 
    
         
            +
            	
         
     | 
| 
      
 151 
     | 
    
         
            +
            	if(canvas->color != pasteimage->color) return(1);
         
     | 
| 
      
 152 
     | 
    
         
            +
            	
         
     | 
| 
      
 153 
     | 
    
         
            +
            	//�V���h�E�t���[�������
         
     | 
| 
      
 154 
     | 
    
         
            +
            	shadow = pkl_canvas(pasteimage->width, pasteimage->height, pasteimage->color, NULL);
         
     | 
| 
      
 155 
     | 
    
         
            +
            	if(!shadow) return(1);
         
     | 
| 
      
 156 
     | 
    
         
            +
            	
         
     | 
| 
      
 157 
     | 
    
         
            +
            	//for(i=0; i<shadow->channel; i++)
         
     | 
| 
      
 158 
     | 
    
         
            +
            	//	shcolor[i] = (shadowcolor>>((shadow->channel-i)*8) & 0xFF);
         
     | 
| 
      
 159 
     | 
    
         
            +
            	if(shadowcolor) memcpy(shcolor, shadowcolor->color, canvas->channel);
         
     | 
| 
      
 160 
     | 
    
         
            +
            	else            memset(shcolor, 0, canvas->channel);
         
     | 
| 
      
 161 
     | 
    
         
            +
            	
         
     | 
| 
      
 162 
     | 
    
         
            +
            	for(i=0; i<pasteimage->height; i++)
         
     | 
| 
      
 163 
     | 
    
         
            +
            		for(j=0; j<pasteimage->width; j++)
         
     | 
| 
      
 164 
     | 
    
         
            +
            			memcpy(&shadow->image[(i*shadow->width+j)*shadow->channel], shcolor, shadow->channel);
         
     | 
| 
      
 165 
     | 
    
         
            +
            	
         
     | 
| 
      
 166 
     | 
    
         
            +
            	//�o���オ�����V���h�E�t���[�����L�����o�X�ɓ\��t����
         
     | 
| 
      
 167 
     | 
    
         
            +
            	pkl_alphablend(canvas, shadow, top+margin, left+margin, -1);
         
     | 
| 
      
 168 
     | 
    
         
            +
            	pkl_alphablend(canvas, shadow, top+margin, left+margin, -1);
         
     | 
| 
      
 169 
     | 
    
         
            +
            	pkl_alphablend(canvas, shadow, top+margin, left+margin, -1);
         
     | 
| 
      
 170 
     | 
    
         
            +
            	pkl_close(shadow);
         
     | 
| 
      
 171 
     | 
    
         
            +
            	
         
     | 
| 
      
 172 
     | 
    
         
            +
            	//�I���W�i���C���[�W��\��
         
     | 
| 
      
 173 
     | 
    
         
            +
            	pkl_composite(canvas, pasteimage, top, left, NULL);
         
     | 
| 
      
 174 
     | 
    
         
            +
            	return(0);
         
     | 
| 
      
 175 
     | 
    
         
            +
            }
         
     | 
    
        data/ext/pikl/pikl_decrease.c
    CHANGED
    
    | 
         @@ -1,76 +1,141 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            #include "pikl_decrease.h"
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
      
 3 
     | 
    
         
            +
            static void gray_normal(PKLImage pkl, unsigned char *gray);
         
     | 
| 
      
 4 
     | 
    
         
            +
            static void gray_median(PKLImage pkl, unsigned char *gray);
         
     | 
| 
      
 5 
     | 
    
         
            +
            static void gray_average(PKLImage pkl, unsigned char *gray);
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
       3 
7 
     | 
    
         
             
            //=============================================================================
         
     | 
| 
       4 
     | 
    
         
            -
            //  
     | 
| 
      
 8 
     | 
    
         
            +
            // pkl_gray
         
     | 
| 
       5 
9 
     | 
    
         
             
            //=============================================================================
         
     | 
| 
       6 
     | 
    
         
            -
            PKLExport int  
     | 
| 
      
 10 
     | 
    
         
            +
            PKLExport int pkl_gray(PKLImage pkl, PKL_GRAYTYPE type)
         
     | 
| 
       7 
11 
     | 
    
         
             
            {
         
     | 
| 
       8 
     | 
    
         
            -
            	unsigned char  
     | 
| 
       9 
     | 
    
         
            -
            	int i, j;
         
     | 
| 
      
 12 
     | 
    
         
            +
            	unsigned char *gray;
         
     | 
| 
       10 
13 
     | 
    
         | 
| 
       11 
14 
     | 
    
         
             
            	if(pkl->color!=PKL_RGB) return(1);
         
     | 
| 
       12 
     | 
    
         
            -
            	 
     | 
| 
      
 15 
     | 
    
         
            +
            	
         
     | 
| 
      
 16 
     | 
    
         
            +
            	gray = malloc(pkl->height * pkl->width);
         
     | 
| 
      
 17 
     | 
    
         
            +
            	if(!gray) return(1);
         
     | 
| 
      
 18 
     | 
    
         
            +
            	
         
     | 
| 
      
 19 
     | 
    
         
            +
            	switch(type){
         
     | 
| 
      
 20 
     | 
    
         
            +
            		case PKL_GRAY_NRM:
         
     | 
| 
      
 21 
     | 
    
         
            +
            			gray_normal(pkl, gray);
         
     | 
| 
      
 22 
     | 
    
         
            +
            			break;
         
     | 
| 
      
 23 
     | 
    
         
            +
            		case PKL_GRAY_MED:
         
     | 
| 
      
 24 
     | 
    
         
            +
            			gray_median(pkl, gray);
         
     | 
| 
      
 25 
     | 
    
         
            +
            			break;
         
     | 
| 
      
 26 
     | 
    
         
            +
            		case PKL_GRAY_AVE:
         
     | 
| 
      
 27 
     | 
    
         
            +
            			gray_average(pkl, gray);
         
     | 
| 
      
 28 
     | 
    
         
            +
            			break;
         
     | 
| 
      
 29 
     | 
    
         
            +
            		default:
         
     | 
| 
      
 30 
     | 
    
         
            +
            			return(1);
         
     | 
| 
      
 31 
     | 
    
         
            +
            	}
         
     | 
| 
      
 32 
     | 
    
         
            +
            	
         
     | 
| 
      
 33 
     | 
    
         
            +
            	free(pkl->image);
         
     | 
| 
      
 34 
     | 
    
         
            +
            	pkl->image = gray;
         
     | 
| 
      
 35 
     | 
    
         
            +
            	pkl->channel=1;
         
     | 
| 
      
 36 
     | 
    
         
            +
            	pkl->color=PKL_GRAYSCALE;
         
     | 
| 
      
 37 
     | 
    
         
            +
            	return(0);
         
     | 
| 
      
 38 
     | 
    
         
            +
            }
         
     | 
| 
       13 
39 
     | 
    
         | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
      
 40 
     | 
    
         
            +
            //=================================================================================
         
     | 
| 
      
 41 
     | 
    
         
            +
            // gs_nrm(���d���ϖ@)
         
     | 
| 
      
 42 
     | 
    
         
            +
            //=================================================================================
         
     | 
| 
      
 43 
     | 
    
         
            +
            static void gray_normal(PKLImage pkl, unsigned char *gray)
         
     | 
| 
      
 44 
     | 
    
         
            +
            {
         
     | 
| 
      
 45 
     | 
    
         
            +
            	int i, j;
         
     | 
| 
      
 46 
     | 
    
         
            +
            	
         
     | 
| 
      
 47 
     | 
    
         
            +
            	for(i=0; i<pkl->height; i++){
         
     | 
| 
      
 48 
     | 
    
         
            +
            		for(j=0; j<pkl->width; j++){
         
     | 
| 
      
 49 
     | 
    
         
            +
            			gray[i*pkl->width+j] =
         
     | 
| 
      
 50 
     | 
    
         
            +
            					pkl->image[(i*pkl->width+j)*pkl->channel  ] * 0.298912 +
         
     | 
| 
      
 51 
     | 
    
         
            +
            					pkl->image[(i*pkl->width+j)*pkl->channel+1] * 0.586611 +
         
     | 
| 
      
 52 
     | 
    
         
            +
            					pkl->image[(i*pkl->width+j)*pkl->channel+2] * 0.114478;
         
     | 
| 
      
 53 
     | 
    
         
            +
            		}
         
     | 
| 
      
 54 
     | 
    
         
            +
            	}
         
     | 
| 
      
 55 
     | 
    
         
            +
            }
         
     | 
| 
       16 
56 
     | 
    
         | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
      
 57 
     | 
    
         
            +
            //=================================================================================
         
     | 
| 
      
 58 
     | 
    
         
            +
            // gs_med(���Ԓl�@)
         
     | 
| 
      
 59 
     | 
    
         
            +
            //=================================================================================
         
     | 
| 
      
 60 
     | 
    
         
            +
            static void gray_median(PKLImage pkl, unsigned char *gray)
         
     | 
| 
      
 61 
     | 
    
         
            +
            {
         
     | 
| 
      
 62 
     | 
    
         
            +
            	int i, j;
         
     | 
| 
      
 63 
     | 
    
         
            +
            	unsigned char mx, mn;
         
     | 
| 
      
 64 
     | 
    
         
            +
            	
         
     | 
| 
      
 65 
     | 
    
         
            +
            	for(i=0; i<pkl->height; i++){
         
     | 
| 
      
 66 
     | 
    
         
            +
            		for(j=0; j<pkl->width; j++){
         
     | 
| 
      
 67 
     | 
    
         
            +
            			mx = pkl->image[(i*pkl->width+j)*pkl->channel];
         
     | 
| 
      
 68 
     | 
    
         
            +
            			mx = PKL_MAX(pkl->image[(i*pkl->width+j)*pkl->channel+1], mx);
         
     | 
| 
      
 69 
     | 
    
         
            +
            			mx = PKL_MAX(pkl->image[(i*pkl->width+j)*pkl->channel+2], mx);
         
     | 
| 
      
 70 
     | 
    
         
            +
            			
         
     | 
| 
      
 71 
     | 
    
         
            +
            			mn = pkl->image[(i*pkl->width+j)*pkl->channel];
         
     | 
| 
      
 72 
     | 
    
         
            +
            			mn = PKL_MAX(pkl->image[(i*pkl->width+j)*pkl->channel+1], mn);
         
     | 
| 
      
 73 
     | 
    
         
            +
            			mn = PKL_MAX(pkl->image[(i*pkl->width+j)*pkl->channel+2], mn);
         
     | 
| 
      
 74 
     | 
    
         
            +
            			
         
     | 
| 
      
 75 
     | 
    
         
            +
            			gray[i*pkl->width+j] = (mx + mn) * 0.5;
         
     | 
| 
      
 76 
     | 
    
         
            +
            		}
         
     | 
| 
      
 77 
     | 
    
         
            +
            	}
         
     | 
| 
      
 78 
     | 
    
         
            +
            }
         
     | 
| 
       18 
79 
     | 
    
         | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
      
 80 
     | 
    
         
            +
            //=================================================================================
         
     | 
| 
      
 81 
     | 
    
         
            +
            // gs_ave(�P�����ϖ@)
         
     | 
| 
      
 82 
     | 
    
         
            +
            //=================================================================================
         
     | 
| 
      
 83 
     | 
    
         
            +
            static void gray_average(PKLImage pkl, unsigned char *gray)
         
     | 
| 
      
 84 
     | 
    
         
            +
            {
         
     | 
| 
      
 85 
     | 
    
         
            +
            	int i, j;
         
     | 
| 
       21 
86 
     | 
    
         | 
| 
       22 
     | 
    
         
            -
            	 
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
      
 87 
     | 
    
         
            +
            	for(i=0; i<pkl->height; i++){
         
     | 
| 
      
 88 
     | 
    
         
            +
            		for(j=0; j<pkl->width; j++){
         
     | 
| 
      
 89 
     | 
    
         
            +
            			gray[i*pkl->width+j] = 
         
     | 
| 
      
 90 
     | 
    
         
            +
            				(pkl->image[(i*pkl->width+j)*pkl->channel  ] +
         
     | 
| 
      
 91 
     | 
    
         
            +
            				 pkl->image[(i*pkl->width+j)*pkl->channel+1] +
         
     | 
| 
      
 92 
     | 
    
         
            +
            				 pkl->image[(i*pkl->width+j)*pkl->channel+2]) / 3;
         
     | 
| 
      
 93 
     | 
    
         
            +
            		}
         
     | 
| 
      
 94 
     | 
    
         
            +
            	}
         
     | 
| 
       24 
95 
     | 
    
         
             
            }
         
     | 
| 
       25 
96 
     | 
    
         | 
| 
       26 
97 
     | 
    
         
             
            //=============================================================================
         
     | 
| 
       27 
     | 
    
         
            -
            //  
     | 
| 
      
 98 
     | 
    
         
            +
            // pkl_rgb
         
     | 
| 
       28 
99 
     | 
    
         
             
            //=============================================================================
         
     | 
| 
       29 
     | 
    
         
            -
            PKLExport int  
     | 
| 
      
 100 
     | 
    
         
            +
            PKLExport int pkl_rgb(PKLImage pkl)
         
     | 
| 
       30 
101 
     | 
    
         
             
            {
         
     | 
| 
       31 
     | 
    
         
            -
            	unsigned char  
     | 
| 
      
 102 
     | 
    
         
            +
            	unsigned char *rgb, k;
         
     | 
| 
       32 
103 
     | 
    
         
             
            	int i, j;
         
     | 
| 
       33 
104 
     | 
    
         | 
| 
       34 
     | 
    
         
            -
            	if(pkl->color!= 
     | 
| 
       35 
     | 
    
         
            -
            	if(ncolors<=0 || ncolors>256) return(1);
         
     | 
| 
       36 
     | 
    
         
            -
            	if(sample<=0 || sample>30) return(1);
         
     | 
| 
      
 105 
     | 
    
         
            +
            	if(pkl->color!=PKL_CMYK) return(1);
         
     | 
| 
       37 
106 
     | 
    
         | 
| 
       38 
     | 
    
         
            -
            	 
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
            	 
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
      
 107 
     | 
    
         
            +
            	rgb = malloc(pkl->height * pkl->width * 3);
         
     | 
| 
      
 108 
     | 
    
         
            +
            	if(!rgb) return(1);
         
     | 
| 
      
 109 
     | 
    
         
            +
            	
         
     | 
| 
      
 110 
     | 
    
         
            +
            	for(i=0; i<pkl->height; i++){
         
     | 
| 
      
 111 
     | 
    
         
            +
            		for(j=0; j<pkl->width; j++){
         
     | 
| 
      
 112 
     | 
    
         
            +
            			k = pkl->image[(i*pkl->width+j)*pkl->channel+3];
         
     | 
| 
      
 113 
     | 
    
         
            +
            			rgb[(i*pkl->width+j)*3  ] = ~(255 - pkl->image[(i*pkl->width+j)*pkl->channel  ] + k);
         
     | 
| 
      
 114 
     | 
    
         
            +
            			rgb[(i*pkl->width+j)*3+1] = ~(255 - pkl->image[(i*pkl->width+j)*pkl->channel+1] + k);
         
     | 
| 
      
 115 
     | 
    
         
            +
            			rgb[(i*pkl->width+j)*3+2] = ~(255 - pkl->image[(i*pkl->width+j)*pkl->channel+2] + k);
         
     | 
| 
      
 116 
     | 
    
         
            +
            		}
         
     | 
| 
      
 117 
     | 
    
         
            +
            	}
         
     | 
| 
      
 118 
     | 
    
         
            +
            	
         
     | 
| 
      
 119 
     | 
    
         
            +
            	free(pkl->image);
         
     | 
| 
      
 120 
     | 
    
         
            +
            	pkl->image = rgb;
         
     | 
| 
      
 121 
     | 
    
         
            +
            	pkl->channel=3;
         
     | 
| 
      
 122 
     | 
    
         
            +
            	pkl->color=PKL_RGB;
         
     | 
| 
       46 
123 
     | 
    
         
             
            	return(0);
         
     | 
| 
       47 
124 
     | 
    
         
             
            }
         
     | 
| 
       48 
125 
     | 
    
         | 
| 
       49 
126 
     | 
    
         
             
            //=============================================================================
         
     | 
| 
       50 
     | 
    
         
            -
            //  
     | 
| 
      
 127 
     | 
    
         
            +
            // pkl_2c
         
     | 
| 
       51 
128 
     | 
    
         
             
            //=============================================================================
         
     | 
| 
       52 
     | 
    
         
            -
            PKLExport int  
     | 
| 
      
 129 
     | 
    
         
            +
            PKLExport int pkl_2c(PKLImage pkl, int threshold)
         
     | 
| 
       53 
130 
     | 
    
         
             
            {
         
     | 
| 
       54 
     | 
    
         
            -
            	unsigned char QuantizedPalette[256*3], *QuantizedPicture;
         
     | 
| 
       55 
     | 
    
         
            -
            	unsigned char *p, *q;
         
     | 
| 
       56 
131 
     | 
    
         
             
            	int i;
         
     | 
| 
       57 
132 
     | 
    
         | 
| 
       58 
     | 
    
         
            -
            	if(pkl->color!= 
     | 
| 
       59 
     | 
    
         
            -
            	if( 
     | 
| 
      
 133 
     | 
    
         
            +
            	if(pkl->color!=PKL_GRAYSCALE) return(1);
         
     | 
| 
      
 134 
     | 
    
         
            +
            	if(threshold<0 || threshold>255) return(1);
         
     | 
| 
      
 135 
     | 
    
         
            +
            	
         
     | 
| 
      
 136 
     | 
    
         
            +
            	for(i=0; i<pkl->height*pkl->width; i++)
         
     | 
| 
      
 137 
     | 
    
         
            +
            		pkl->image[i] = pkl->image[i]<threshold ? 0 : 255;
         
     | 
| 
       60 
138 
     | 
    
         | 
| 
       61 
     | 
    
         
            -
            	QuantizedPicture = malloc(pkl->width*pkl->height);
         
     | 
| 
       62 
     | 
    
         
            -
             
     | 
| 
       63 
     | 
    
         
            -
            	wuReduce(pkl->image, ncolors, pkl->width*pkl->height, QuantizedPicture, QuantizedPalette);
         
     | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
       65 
     | 
    
         
            -
            	p = pkl->image;
         
     | 
| 
       66 
     | 
    
         
            -
            	q = QuantizedPicture;
         
     | 
| 
       67 
     | 
    
         
            -
            	for(i=0; i<pkl->height*pkl->width; i++){
         
     | 
| 
       68 
     | 
    
         
            -
            		*p++ = QuantizedPalette[ (*q)*3+0 ];
         
     | 
| 
       69 
     | 
    
         
            -
            		*p++ = QuantizedPalette[ (*q)*3+1 ];
         
     | 
| 
       70 
     | 
    
         
            -
            		*p++ = QuantizedPalette[ (*q)*3+2 ];
         
     | 
| 
       71 
     | 
    
         
            -
            		q++;
         
     | 
| 
       72 
     | 
    
         
            -
            	}
         
     | 
| 
       73 
     | 
    
         
            -
            	free(QuantizedPicture);
         
     | 
| 
       74 
139 
     | 
    
         
             
            	return(0);
         
     | 
| 
       75 
140 
     | 
    
         
             
            }
         
     | 
| 
       76 
141 
     | 
    
         | 
    
        data/ext/pikl/pikl_decrease.h
    CHANGED
    
    
| 
         @@ -0,0 +1,116 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            #include "pikl_divide.h"
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            //=============================================================================
         
     | 
| 
      
 4 
     | 
    
         
            +
            // pkl_tileslit
         
     | 
| 
      
 5 
     | 
    
         
            +
            //=============================================================================
         
     | 
| 
      
 6 
     | 
    
         
            +
            PKLExport int pkl_tileslit(PKLImage pkl, int area, int shift)
         
     | 
| 
      
 7 
     | 
    
         
            +
            {
         
     | 
| 
      
 8 
     | 
    
         
            +
            	unsigned char *wrk;
         
     | 
| 
      
 9 
     | 
    
         
            +
            	int i, j, k, tx, ty;
         
     | 
| 
      
 10 
     | 
    
         
            +
            	int w, h, offsetx, offsety;
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
            	if(shift==0) return(0);
         
     | 
| 
      
 13 
     | 
    
         
            +
            	if(area<=1 || (area>pkl->width || area>pkl->height)) return(1);
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
            	wrk = malloc(pkl->width*pkl->height*pkl->channel);
         
     | 
| 
      
 16 
     | 
    
         
            +
            	if(!wrk) return(1);
         
     | 
| 
      
 17 
     | 
    
         
            +
            	memset(wrk, 0, pkl->width*pkl->height*pkl->channel);
         
     | 
| 
      
 18 
     | 
    
         
            +
            	
         
     | 
| 
      
 19 
     | 
    
         
            +
            	//invert
         
     | 
| 
      
 20 
     | 
    
         
            +
            	for(i=0; i<pkl->height*pkl->width*pkl->channel; i++)
         
     | 
| 
      
 21 
     | 
    
         
            +
            		wrk[i] = (pkl->image[i] ^ 0xff);
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
            	srand(1);
         
     | 
| 
      
 24 
     | 
    
         
            +
            	for(i=0; i<pkl->height; i+=area){
         
     | 
| 
      
 25 
     | 
    
         
            +
            		for(j=0; j<pkl->width; j+=area){
         
     | 
| 
      
 26 
     | 
    
         
            +
            			//�i�q�̂��炵��
         
     | 
| 
      
 27 
     | 
    
         
            +
            			offsetx = rand()%(shift*2+1)-shift;
         
     | 
| 
      
 28 
     | 
    
         
            +
            			offsety = rand()%(shift*2+1)-shift;
         
     | 
| 
      
 29 
     | 
    
         
            +
            			
         
     | 
| 
      
 30 
     | 
    
         
            +
            			h = i+area>pkl->height ? pkl->height : i+area;
         
     | 
| 
      
 31 
     | 
    
         
            +
            			for(k=i; k<h; k++){
         
     | 
| 
      
 32 
     | 
    
         
            +
            				tx = j+offsetx<0 ? 0 : j+offsetx>=pkl->width ? pkl->width-1 : j+offsetx;
         
     | 
| 
      
 33 
     | 
    
         
            +
            				ty = k+offsety<0 ? 0 : k+offsety>=pkl->height ? pkl->height-1 : k+offsety;
         
     | 
| 
      
 34 
     | 
    
         
            +
            				w = tx+area > pkl->width ? pkl->width-tx : area;
         
     | 
| 
      
 35 
     | 
    
         
            +
            				memcpy(&wrk[(ty*pkl->width+tx)*pkl->channel], &pkl->image[(k*pkl->width+j)*pkl->channel], w*pkl->channel);
         
     | 
| 
      
 36 
     | 
    
         
            +
            			}
         
     | 
| 
      
 37 
     | 
    
         
            +
            		}
         
     | 
| 
      
 38 
     | 
    
         
            +
            	}
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
            	free(pkl->image);
         
     | 
| 
      
 41 
     | 
    
         
            +
            	pkl->image = wrk;
         
     | 
| 
      
 42 
     | 
    
         
            +
            	return(0);
         
     | 
| 
      
 43 
     | 
    
         
            +
            }
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
            //=============================================================================
         
     | 
| 
      
 46 
     | 
    
         
            +
            // pkl_splitframe
         
     | 
| 
      
 47 
     | 
    
         
            +
            //=============================================================================
         
     | 
| 
      
 48 
     | 
    
         
            +
            PKLExport int pkl_splitframe(PKLImage pkl, PKLColor backcolor, int wbs, int hbs, int margin, int frame)
         
     | 
| 
      
 49 
     | 
    
         
            +
            {
         
     | 
| 
      
 50 
     | 
    
         
            +
            	unsigned char *wrk;
         
     | 
| 
      
 51 
     | 
    
         
            +
            	int i, j, k, s, t, u, tx, ty;
         
     | 
| 
      
 52 
     | 
    
         
            +
            	int offsetx, offsety, width, height, fw, fh;
         
     | 
| 
      
 53 
     | 
    
         
            +
            	int warea, harea;
         
     | 
| 
      
 54 
     | 
    
         
            +
            	int shift=5;
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
      
 56 
     | 
    
         
            +
            	if(wbs<=0 || hbs<=0) return(1);
         
     | 
| 
      
 57 
     | 
    
         
            +
            	if(margin<0) return(1);
         
     | 
| 
      
 58 
     | 
    
         
            +
            	if(frame<1) return(1);
         
     | 
| 
      
 59 
     | 
    
         
            +
             
     | 
| 
      
 60 
     | 
    
         
            +
            	//1�̕����G���A�̃C���[�W�T�C�Y
         
     | 
| 
      
 61 
     | 
    
         
            +
            	warea = pkl->width / wbs;
         
     | 
| 
      
 62 
     | 
    
         
            +
            	harea = pkl->height / hbs;
         
     | 
| 
      
 63 
     | 
    
         
            +
            	//1�̃G���A�̃T�C�Y(�t���[���T�C�Y���܂�)
         
     | 
| 
      
 64 
     | 
    
         
            +
            	fw = warea + frame*2;
         
     | 
| 
      
 65 
     | 
    
         
            +
            	fh = harea + frame*2;
         
     | 
| 
      
 66 
     | 
    
         
            +
            	//�ŏI�I�ȃL�����o�X�̑傫��
         
     | 
| 
      
 67 
     | 
    
         
            +
            	width = fw * wbs + margin*2;
         
     | 
| 
      
 68 
     | 
    
         
            +
            	height = fh * hbs + margin*2;
         
     | 
| 
      
 69 
     | 
    
         
            +
             
     | 
| 
      
 70 
     | 
    
         
            +
            	wrk = malloc(width*height*pkl->channel);
         
     | 
| 
      
 71 
     | 
    
         
            +
            	if(!wrk) return(1);
         
     | 
| 
      
 72 
     | 
    
         
            +
            	
         
     | 
| 
      
 73 
     | 
    
         
            +
            	//�w�i�F�̐ݒ�
         
     | 
| 
      
 74 
     | 
    
         
            +
            	//for(i=0; i<pkl->channel; i++)
         
     | 
| 
      
 75 
     | 
    
         
            +
            	//	color[i] = (backcolor>>((pkl->channel-i)*8) & 0xFF);
         
     | 
| 
      
 76 
     | 
    
         
            +
            	if(backcolor){
         
     | 
| 
      
 77 
     | 
    
         
            +
            		for(i=0; i<width*height; i++)
         
     | 
| 
      
 78 
     | 
    
         
            +
            			memcpy(&wrk[i*pkl->channel], backcolor->color, pkl->channel);
         
     | 
| 
      
 79 
     | 
    
         
            +
            	}else{
         
     | 
| 
      
 80 
     | 
    
         
            +
            		memset(wrk, 0xff, width*height*pkl->channel);
         
     | 
| 
      
 81 
     | 
    
         
            +
            	}
         
     | 
| 
      
 82 
     | 
    
         
            +
             
     | 
| 
      
 83 
     | 
    
         
            +
            	srand(1);
         
     | 
| 
      
 84 
     | 
    
         
            +
            	for(i=margin,s=0; i<height-margin; i+=fh,s+=harea){
         
     | 
| 
      
 85 
     | 
    
         
            +
            		for(j=margin,t=0; j<width-margin; j+=fw,t+=warea){
         
     | 
| 
      
 86 
     | 
    
         
            +
            			offsetx = rand()%(shift*2+1)-shift;
         
     | 
| 
      
 87 
     | 
    
         
            +
            			offsety = rand()%(shift*2+1)-shift;
         
     | 
| 
      
 88 
     | 
    
         
            +
            			
         
     | 
| 
      
 89 
     | 
    
         
            +
            			//�t�H�g�t���[��
         
     | 
| 
      
 90 
     | 
    
         
            +
            			k = i+offsety<0 ? 0 : i+offsety+fh>height ? height-fh : i+offsety;
         
     | 
| 
      
 91 
     | 
    
         
            +
            			for(ty=k; ty<k+fh; ty++){
         
     | 
| 
      
 92 
     | 
    
         
            +
            				tx = j+offsetx<0 ? 0 : j+offsetx+fw>width ? width-fw : j+offsetx;
         
     | 
| 
      
 93 
     | 
    
         
            +
            				//�w�i�F(��)
         
     | 
| 
      
 94 
     | 
    
         
            +
            				memset(&wrk[(ty*width+tx)*pkl->channel], 0xFF, fw*pkl->channel);
         
     | 
| 
      
 95 
     | 
    
         
            +
            				//�V�n�̃t���[��
         
     | 
| 
      
 96 
     | 
    
         
            +
            				if(ty==k || ty==k+fh-1)
         
     | 
| 
      
 97 
     | 
    
         
            +
            					memset(&wrk[(ty*width+tx)*pkl->channel], 0x00, fw*pkl->channel);
         
     | 
| 
      
 98 
     | 
    
         
            +
            				//���E�̃t���[��
         
     | 
| 
      
 99 
     | 
    
         
            +
            				memset(&wrk[(ty*width+tx)*pkl->channel], 0x00, pkl->channel);
         
     | 
| 
      
 100 
     | 
    
         
            +
            				memset(&wrk[(ty*width+tx+fw-1)*pkl->channel], 0x00, pkl->channel);
         
     | 
| 
      
 101 
     | 
    
         
            +
            			}
         
     | 
| 
      
 102 
     | 
    
         
            +
            			//�C���[�W
         
     | 
| 
      
 103 
     | 
    
         
            +
            			k = i+offsety<0 ? frame : i+offsety+fh>height ? height-fh+frame : i+offsety+frame;
         
     | 
| 
      
 104 
     | 
    
         
            +
            			for(ty=k,u=s; ty<k+harea; ty++,u++){
         
     | 
| 
      
 105 
     | 
    
         
            +
            				tx = j+offsetx<0 ? frame : j+offsetx+fw>width ? width-fw+frame : j+offsetx+frame;
         
     | 
| 
      
 106 
     | 
    
         
            +
            				memcpy(&wrk[(ty*width+tx)*pkl->channel], &pkl->image[(u*pkl->width+t)*pkl->channel], warea*pkl->channel);
         
     | 
| 
      
 107 
     | 
    
         
            +
            			}
         
     | 
| 
      
 108 
     | 
    
         
            +
            		}
         
     | 
| 
      
 109 
     | 
    
         
            +
            	}
         
     | 
| 
      
 110 
     | 
    
         
            +
            	
         
     | 
| 
      
 111 
     | 
    
         
            +
            	free(pkl->image);
         
     | 
| 
      
 112 
     | 
    
         
            +
            	pkl->image = wrk;
         
     | 
| 
      
 113 
     | 
    
         
            +
            	pkl->width = width;
         
     | 
| 
      
 114 
     | 
    
         
            +
            	pkl->height = height;
         
     | 
| 
      
 115 
     | 
    
         
            +
            	return(0);
         
     | 
| 
      
 116 
     | 
    
         
            +
            }
         
     |