//功能:输入想要打马赛克的坐标点,宽,高以及每个边需要划分的块数进行打马赛克
//只能处理位图,根据不同色深定义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. CenOS下firefox browser (火狐浏览器)无法播放网页音乐的解决方法

    新装载的Firefox或许无法播放网页音频,解决方法如下: 1. 下载并安装 flashplayer插件&&下载网址:https://get.adobe.com/flashplayer ...

  2. Scalaz(22)- 泛函编程思维: Coerce Monadic Thinking

    马上进入新的一年2016了,来点轻松点的内容吧.前面写过一篇关于用Reader实现依赖注入管理的博文(Scalaz(16)- Monad:依赖注入-Dependency Injection By Re ...

  3. iOS 获取网络图片的大小

    一直都在找关于获取网络图片的大小的方法, 今天找到了一个能解决的办法 ,如下 1, 导入框架 #import <ImageIO/ImageIO.h> 2. 使用此方法得到image的siz ...

  4. String类型中ToString hashCode equals compareTo等方法的经典实现

    private final char value[]; private int hash; // Default to 0 public String(String original) { this. ...

  5. Virtual Box和Linux的网络配置盲记

    近来可能在虚拟机重装了Linux的缘故,在用yum安装软件时出现错误,在提示上连接镜像网站时,都是"linux counldn't resolve host"这样的提示.我估计是l ...

  6. Redis-持久化

    Redis 持久化 Redis 提供了不同持久化范围的选项: RDB 持久化以指定的时间间隔执行数据集的即时点(point-in-time)快照. AOF 持久化在服务端记录每次收到的写操作,在服务器 ...

  7. Visual Studio Code 使用 ESLint 增强代码风格检查

    前言 在团队协作开发中,为了统一代码风格,避免一些低级错误,应该设有团队成员统一遵守的编码规范.很多语言都提供了Lint工具来实现这样的功能,JavaScript也有类似的工具:ESLint.除了可以 ...

  8. 使用 HTML5 Canvas 绘制出惊艳的水滴效果

    HTML5 在不久前正式成为推荐标准,标志着全新的 Web 时代已经来临.在众多 HTML5 特性中,Canvas 元素用于在网页上绘制图形,该元素标签强大之处在于可以直接在 HTML 上进行图形操作 ...

  9. Type.js – 帮助你更好的控制网页字体排版

    Type.js 是一款很好的网页字体排版工具.它可以让你使用新的 CSS 属性,在网页上试下更精细的排版控制.设置很简单.上传 type.js 到您的网站,并在你的 HTML 链接中引用.接下来,你就 ...

  10. ZeroClipboard – 轻松实现复制文本到剪贴板功能

    ZeroClipboard 库提供了一种把文本复制到剪贴板的简单方法.Zero 表示该库是不可见的,用户界面则完全取决于你. 该库完全兼容 Flash Player 10.0.0 或以上版本,这就要求 ...