ロゴ メインコンテンツへ
RSSフィード
「ソフトウェア開発」に関連する記事一覧

C++ 画像に別の画像を配置するテンプレート関数

2013/08/27
(この記事の文字数: 125)
C++ 

画像データの上に別の画像データを重ねて一枚の画像にするテンプレート関数を作ったので載せておきます。いつも通り画像横幅のアライメントは無視してますので、アライメントが考慮されている画像データで使う場合は修正が必要です。

引数が多すぎて訳わからないですね。


/**
 * @param io_bottom_img The data of base image
 * @param btm_img_w     Width of io_bottom_img
 * @param btm_img_h     Height of io_bottom_img
 * @param in_top_img    The data of image to place on io_bottom_img
 * @param top_img_w     Width of in_top_img
 * @param top_img_h     Height of in_top_img
 * @param center_x      X coordinate of center point for in_top_img
 * @param center_y      Y coordinate of center point for in_top_img
 * @param place_x       X coordinate to place in_top_img on io_bottom_img
 * @param place_y       Y coordinate to place in_top_img on io_bottom_img
 */
template<typename _TopImgType, typename _BottomImgType>
void PlaceImageOnImage(
    _BottomImgType *io_bottom_img,
    s32 btm_img_w, s32 btm_img_h,
    const _TopImgType *in_top_img,
    s32 top_img_w, s32 top_img_h, s32 num_channels,
    s32 center_x, s32 center_y,
    s32 place_x, s32 place_y
)
{
    for( s32 y=0; y<top_img_h; ++y )
    {
        s32 y_dst = y + place_y - center_y;
        if( y_dst < 0 )
        {
            y = y - y_dst - 1;
            continue;
        }
        for( s32 x=0; x<top_img_w; ++x )
        {
            s32 x_dst = x + place_x - center_x;
            if( x_dst < 0 )
            {
                x = x - x_dst - 1;
                continue;
            }
            s32 i_dst = ( y_dst*btm_img_w + x_dst ) * num_channels;
            s32 i_src = ( y*top_img_w + x ) * num_channels;
            for( s32 c=0; c<num_channels; ++c )
            {
                io_bottom_img[i_dst+c] = in_top_img[i_src+c];
            }
        }
    }
}

  このエントリーをはてなブックマークに追加  

<<「ソフトウェア開発」の記事一覧に戻る

<<「ソフトウェア開発」の次の記事
「ソフトウェア開発」の前の記事 >>

コメント(0 件)



コンテンツロード: 0.0079 sec
Copyright(C)2006-2024 puarts All Rights Reserved