my_mosaic
//功能:输入想要打马赛克的坐标点,宽,高以及每个边需要划分的块数进行打马赛克
//只能处理位图,根据不同色深定义depth即可
//还没写从文件头读取图片分辨率
#include<unistd.h>
#include<stdio.h>
#include<stdlib.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#define depth 4
static int mask(char(*pic)[600*depth],
const int x,const int y,const int w,const int h){
int i=0,j=0,q=0;
//存储色块的颜色
char color_std[depth];
for(q=0;q<depth;q++){
color_std[q]=pic[y][depth*x+q];
}
for(j=y;j<y+h;j++){
for(i=depth*x;i<depth*x+w*depth;i+=depth){
for(q=0;q<depth;q++){
pic[j][i+q]=color_std[q];
}
}
}
}
int reg(char* filename,const int x,\
const int y,const int w,const int h,const int num){
int fd=open(filename,O_RDWR);
lseek(fd,54,SEEK_SET);
int i=0,j=0,q=0,p=0;
char pic[450][600*depth];
read(fd,pic,sizeof(pic));
//计算需要画图的点和区域
for(j=y;j<y+h-1;j+=h/num){
for(i=x;i<x+w-1;i+=(w/num)) {
mask(pic,i,j,w/num,h/num);
}
}
lseek(fd,54,SEEK_SET);
write(fd,pic,sizeof(pic));
close(fd);
}
int main(int argc, const char *argv[])
{
int x=atoi(argv[1]);
int y=atoi(argv[2]);
int w=atoi(argv[3]);
int h=atoi(argv[4]);
int n=atoi(argv[5]);
reg("./image",/*W,H,*/x,y,w,h,n);
return 0;
}


my_mosaic的更多相关文章
随机推荐
- [java] StringBuilder / StringBuffer / String 建立字符串
1.三者在建立新字符串速度方面的比较: StringBuilder > StringBuffer > String 2.线程安全性: StringBuilder:线程非安全的 Str ...
- NYOJ 746---整数划分(四)(区间DP)
题目链接 描述 暑假来了,hrdv 又要留学校在参加ACM集训了,集训的生活非常Happy(ps:你懂得),可是他最近遇到了一个难题,让他百思不得其解,他非常郁闷..亲爱的你能帮帮他吗? 问题是我们经 ...
- springmvc参数绑定
1. @PathVariable当使用@RequestMapping URI template 样式映射时, 即 someUrl/{paramId}, 这时的paramId可通过 @Pathvaria ...
- Baraja演示15种不同的洗牌特效
实例演示 下载地址 实例代码 实例演示 实例代码 <div class="container"> <header class="clearfix&q ...
- jquery实现点击上移到顶部功能(转)
---恢复内容开始--- 本文转载自W3CPLUS, jQuery制作go to top按钮 每每看到网友Blog的页面底部或中间有一个按钮回到页面顶部,羡慕死人了,但自己就是做不出这样的效果.后来在 ...
- sap去除后缀0方法
原贴地址:http://fuhesap.com/SAP/179.html SHIFT str LEFT DELETING LEADING '0'.如果要在layout显示不出前面的0 格式: & ...
- SharePoint Error - The SharePoint server was moved to a different location.
错误 The SharePoint server was moved to a different location. ( Error from SharePoint site: HttpStatus ...
- [ javascript canvas isPointInPath(x,y) 判断点是否在最后绘制的图形中 ] javascript canvas isPointInPath(x,y) 判断点是否在最后绘制的图形中方法演示 效果之三
<!DOCTYPE html> <html lang='zh-cn'> <head> <title>Insert you title</title ...
- 判断scrollview是否滚动到了底部
调用函数判断如下:if(getScrollY() + getHeight() >= computeVerticalScrollRange()){ Log.d(TAG," ...
- ios 怎么解决Could not find Developer Disk Image