android:camera中HAL层在UI中划线

2015年11月26日 Android 2条评论 阅读4388次

android camera的HAL层中是一些和硬件相关的中间处理,这里是无法得到UI的,因为无法直接控制画面,如果想在camera预览画面上显示一些信息,可以通过改变camera每一帧的实际数据来得到相应的效果。


下面是在HAL层camera中划线的一段代码。输入参数包括了当前帧数据的luma分量和chroma分量,还有就是划线起始点和终止点的坐标xy数值。


//paint
void paintLine(unsigned char *luma, unsigned char *chroma, int xx1, int yy1, int xx2, int yy2) {
    // check pixel
    if (xx1 == xx2 && yy1 == yy2) {
        paintPixel(luma, chroma, xx1, yy1);
        return;
    }
    // paint line
    double x1 = xx1;
    double y1 = yy1;
    double x2 = xx2;
    double y2 = yy2;
    if (abs(x2 - x1) >= abs(y2 - y1)) {
        double pitch = (y2 - y1) / (x2 - x1);
        if (x2 >= x1) {
            for (double i = x1; i <= x2; i++) {
                paintPixel(luma, chroma, (int)i, (int)((i-x1) * pitch + y1));
            }
        } else {
            for (double i = x2; i <= x1; i++) {
                paintPixel(luma, chroma, (int)i, (int)((i - x2) * pitch + y2));
            }
        }
    } else {
        double pitch = (x2 - x1) / (y2 - y1);
        if (y2 >= y1) {
            for (double i = y1; i <= y2; i++) {
                paintPixel(luma, chroma, (int)((i - y1) * pitch + x1), (int)i);
            }
        } else {
            for (double i = y2; i <= y1; i++) {
                paintPixel(luma, chroma, (int)((i - y2) * pitch + x2), (int)i);
            }
        }
    }
}



void paintPixel(unsigned char *luma, unsigned char *chroma, int x, int y) {
    luma[y * nPicWidth + x] = 255;
    chroma[y / 2 * nPicWidth + x] = 128;
    chroma[y / 2 * nPicWidth + x + 1] = 128;
}




当然通过自定义一些数学模型,也可以在画面中描画出一些其他形状的图形了。

PS:上面的代码会在(xx1, yy1)点和(xx2, yy2)点之间划出一条红色线段。

红色的控制在paintPixel方法中控制。




分享本文至:

WRITTEN BY

avatar
本文标签:androidHAL
看了本文是不是觉得很赞,那就赶紧点击下面按钮分享给身边的朋友吧!

2 条评论

  1. avatar sallysoldit

    <a href="http://www.danielbroman.com/arizona-diamondbacks-jersey-purple-nflh">arizona diamondbacks jersey purple</a> <a href="http://www.integrityphx.com/ottawa-senators-hockey-jersey-nfli">ottawa senators hockey jersey</a> <a href="http://www.onthecar.com/2014-15-ac-milan-22-kaka-home-soccer-shirt-kit-nflh">2014 15 ac milan 22 kaka home soccer shirt kit</a> <a href="http://www.sallysoldit.com/nike-air-max-90-triple-hvid-junior-shoese">nike air max 90 triple hvid junior</a> <a href="http://www.hairsalonlush.com/t-shirt-ralph-lauren-v-neck-poloh">t shirt ralph lauren v neck</a> <a href="http://www.robverheulen.com/adidas-soccers-sko-gr%C3%A5-orange-foota">adidas soccers sko gr氓 orange</a>
    [url=http://www.sallysoldit.com/]sallysoldit[/url]

  2. avatar fizalisfresh

    <a href="http://www.wuxiangtaichi.com/mens-nike-zoom-structure-18-black-red-shoesh">mens nike zoom structure 18 black red</a> <a href="http://www.culdesacmag.com/hombres-asics-asics-gel-kinsei-2-oro-p%C3%BArpura-zapatosp">hombres asics asics gel kinsei 2 oro p煤rpura</a> <a href="http://www.livinggreedy.com/nike-lebron-12-mujeres-cielo-azul-negro-zapatosk">nike lebron 12 mujeres cielo azul negro</a> <a href="http://www.clickstroy.com/the-north-face-apex-bionic-soft-shell-jacket-women-northfaceh">the north face apex bionic soft shell jacket women</a> <a href="http://www.zotorrent.com/nike-free-tr-dam%C3%A4nner-grau-himmelblau-schuhej">nike free tr dam盲nner grau himmelblau</a> <a href="http://www.viptarimas.com/herre-nike-air-max-lunar-1-gr%C3%A5-guld-skoh">herre nike air max lunar 1 gr氓 guld</a>
    fizalisfresh http://www.fizalisfresh.com/

欢迎留言




用户登录

sitemap