android:camera中HAL层在UI中划线

2015年11月26日 Android 5条评论 阅读3389次

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
看了本文是不是觉得很赞,那就赶紧点击下面按钮分享给身边的朋友吧!

5 条评论

  1. avatar 5my463sz

    <a href="http://www.wwc3s90g.com/nike-free-run-3.0-v6-vert-jaune-kurpesa">nike free run 3.0 v6 vert jaune</a> <a href="http://www.18ykuccs.com/nike-mercurial-superfly-sort-volt-academy-pack-chaussuresb">nike mercurial superfly sort volt academy pack</a> <a href="http://www.ofv56fjb.com/air-max-thea-noble-rouge-hair-obuvd">air max thea noble rouge hair</a> <a href="http://www.iwd661th.com/jordan-low-top-11-wei%C3%9F-and-rot-chaussuresa">jordan low top 11 wei脽 and rot</a> <a href="http://www.lv5sb333.com/air-jordan-5-retro-rosado-and-negro-man-butya">air jordan 5 retro rosado and negro man</a> <a href="http://www.dzpzobo7.com/nike-zoom-pegasus-31-bleu-lagoon-yoga-scarpef">nike zoom pegasus 31 bleu lagoon yoga</a>
    5my463sz http://www.5my463sz.com/

  2. avatar perlai

    <a href="http://www.shoutwithus.com/nike-lebron-rosa-gul-scarpea">nike lebron rosa gul</a> <a href="http://www.vigodog.com/adidas-cc-ride-m-enfants-chaussures-rose-marron-chaussuresf">adidas cc ride m enfants chaussures rose marron</a> <a href="http://www.brandsdh.com/nike-hyperdunk-2013-noir-gris-rose-kurpese">nike hyperdunk 2013 noir gris rose</a> <a href="http://www.colorngrey.com/air-max-tn-todas-rojo-obuva">air max tn todas rojo</a> <a href="http://www.leviandval.com/k%C3%B8be-long-sleeve-polo-shirts-polox">k酶be long sleeve polo shirts</a> <a href="http://www.naomisbooks.com/herre-salomon-xt-hornet-lilla-gul-schuhed">herre salomon xt hornet lilla gul</a>
    perlai http://www.perlai.com/

  3. avatar chiveshow

    <a href="http://www.andrewghall.com/spurs-9-tony-parker-white-new-latin-nights-stitched-nba-jersey-nflr">spurs 9 tony parker white new latin nights stitched nba jersey</a> <a href="http://www.axsomnelson.com/nike-zoom-pegasus-34-dam%C3%A4nner-gold-schwarz-kurpese">nike zoom pegasus 34 dam盲nner gold schwarz</a> <a href="http://www.bharatovation.com/herren-nike-roshe-run-high-gr%C3%BCn-rosa-schuhee">herren nike roshe run high gr眉n rosa</a> <a href="http://www.factorxf.com/adidas-zx-flux-camo-for-venta-obuvf">adidas zx flux camo for venta</a> <a href="http://www.jotrdesigns.com/new-balance-990-du-vin-chaussuresa">new balance 990 du vin</a> <a href="http://www.laserlegging.com/adidas-originals-stan-smith-rosado-butya">adidas originals stan smith rosado</a>
    chiveshow http://www.chiveshow.com/

  4. avatar kalraslan

    <a href="http://www.albainmaz.com/nike-free-tr-flyknit-5.0-orange-sky-blue-skob">nike free tr flyknit 5.0 orange sky blue</a> <a href="http://www.seemyvcard.com/latest-technology-philadelphia-phillies-new-era-mlb-twisted-fit-9fifty-snapback-cap-navy-red-hate">latest technology philadelphia phillies new era mlb twisted fit 9fifty snapback cap navy red</a> <a href="http://www.joegauntlett.com/green-grey-mens-adidas-forum-mid-shoes-runninge">green grey mens adidas forum mid shoes</a> <a href="http://www.rpnailsalon.com/nike-free-run-kvinders-l%C3%B8b-sko-lime-gr%C3%B8n-schuhea">nike free run kvinders l酶b sko lime gr酶n</a> <a href="http://www.hrubinlaser.com/nike-lunar-dunk-high-sp-tz-gym-rot-scarpeb">nike lunar dunk high sp tz gym rot</a> <a href="http://www.pruvitallday.com/nike-air-max-2019-green-uk-shoeso">nike air max 2019 green uk</a>
    [url=http://www.kalraslan.com/]kalraslan[/url]

  5. avatar rayyanstore

    <a href="http://www.itsaposter.com/michael-kors-fulton-large-black-leather-shoulder-bag-mkr">michael kors fulton large black leather shoulder bag</a> <a href="http://www.naomisbooks.com/jordan-1-flight-2-black-white-red-sneakere">jordan 1 flight 2 black white red</a> <a href="http://www.pennphone.com/game-josh-mccown-jersey-tampa-bay-buccaneers-12-drift-fashion-red-nflb">game josh mccown jersey tampa bay buccaneers 12 drift fashion red</a> <a href="http://www.jpstallard.com/billig-nike-kyrie-2-dam%C3%A4nner-gr%C3%BCn-shoesc">billig nike kyrie 2 dam盲nner gr眉n</a> <a href="http://www.tabbstore.com/air-jordan-7-purple-easter-skog">air jordan 7 purple easter</a> <a href="http://www.allforbnb.com/air-max-90-white-gold-top-sportsf">air max 90 white gold top</a>
    rayyanstore http://www.rayyanstore.com/

欢迎留言




用户登录

sitemap