//功能:输入想要打马赛克的坐标点,宽,高以及每个边需要划分的块数进行打马赛克
//只能处理位图,根据不同色深定义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的更多相关文章

随机推荐

  1. Gym 101102C---Bored Judge(区间最大值)

    题目链接 http://codeforces.com/gym/101102/problem/C problem description Judge Bahosain was bored at ACM ...

  2. sso demo mysql ( cas )

    基本配置 参考之前得随笔  http://www.cnblogs.com/rocky-fang/p/5354947.html 1. tomcat-cas 修改配置 1.1 在D:\test\sso\t ...

  3. Java --HashMap源码解析

    兴趣所致研究一下HashMap的源码,写下自己的理解,基于JDK1.8. 本文大概分析HashMap的put(),get(),resize()三个方法. 首先让我们来看看put()方法. public ...

  4. nginx+uwsgi 部署 django

    预装:nginx,  django Django站点tree |Site |-----Blog(自建的项目) |-----Manage.py |-----Site(setting url wsgi-. ...

  5. jdbc应用程序连接Oracle rac的URL写法:

    1.应用程序连接Oracle rac的URL写法: #Oracle(AMS) jdbc.driverClassName=oracle.jdbc.driver.OracleDriver jdbc.url ...

  6. 熟悉scss

    //html <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <ti ...

  7. Vue.js – 基于 MVVM 实现交互式的 Web 界面

    Vue.js 是用于构建交互式的 Web  界面的库.它提供了 MVVM 数据绑定和一个可组合的组件系统,具有简单.灵活的 API.从技术上讲, Vue.js 集中在 MVVM 模式上的视图模型层,并 ...

  8. 【Bootstrap】2.作品展示站点

    假设我们已经想好了要给自己的作品弄一个在线站点.一如既往,时间紧迫.我们需要快一点,但作品展示效果又必须专业.当然,站点还得是响应式的,能够在各种设备上正常浏览,因为这是我们向目标客户推销时的卖点.这 ...

  9. 浅析css布局模型2

    上节对整个布局模型进行了概述,这节先谈一下布局模型的几个属性. z-index属性 该属性是检索或设置对象的层叠顺序,默认值为auto,遵循其父对象的定位. 并级的对象,该属性的值越大,则被层叠在最上 ...

  10. AE选中要素

    private void 选中要素ToolStripMenuItem_Click(object sender, EventArgs e) { if(axMapControl2.LayerCount&l ...