测试rgb

Posted wxmcu

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了测试rgb相关的知识,希望对你有一定的参考价值。

#include <iostream>
#include <SDL.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
/*
 * Lesson 0: Test to make sure SDL is setup properly
 */
#undef main

const int SCREEN_WIDTH  = 640;
const int SCREEN_HEIGHT = 480;
//We‘ll just be using square tiles for now
const int TILE_SIZE = 40;

void logSDLError(std::ostream &os, const std::string &msg)
{
    os << msg << " error: " << SDL_GetError() << std::endl;
}
static void fill_yuv_image(uint8_t *data[4], int linesize[4],
                           int width, int height, int frame_index)
{
    int x, y;

    /* Y */
    for (y = 0; y < height; y++)
        for (x = 0; x < width; x++)
            data[0][y * linesize[0] + x] = x + y + frame_index * 3;

    /* Cb and Cr */
    for (y = 0; y < height / 2; y++) {
        for (x = 0; x < width / 2; x++) {
            data[1][y * linesize[1] + x] = 128 + y + frame_index * 2;
            data[2][y * linesize[2] + x] = 64 + x + frame_index * 5;
        }
    }
}

int main(int, char**){

    if (SDL_Init(SDL_INIT_EVERYTHING) != 0){
        logSDLError(std::cout, "SDL_Init");
        return 1;
    }

    SDL_Window *window = SDL_CreateWindow("Lesson 2", 100, 100, SCREEN_WIDTH,
        SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
    if (window == nullptr){
        logSDLError(std::cout, "CreateWindow");
        SDL_Quit();
        return 1;
    }
    SDL_Renderer *renderer = SDL_CreateRenderer(window, -1,
        SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
    if (renderer == nullptr){
        logSDLError(std::cout, "CreateRenderer");
        SDL_DestroyWindow(window);
        SDL_Quit();
        return 1;
    }

    SDL_RenderClear( renderer );
    SDL_RenderPresent( renderer );
    //SDL_Delay(3000);
#if 1
    int pic_h = 300;
    int pic_w = 300;
    SDL_Texture* sdlTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB32, SDL_TEXTUREACCESS_STREAMING,pic_w,pic_h);


    uint8_t *data[4];
    uint32_t * rgb_data = (uint32_t*)malloc(pic_h*pic_w*4);

    //data[0] = yuv_data ; //(uint8_t*)malloc(pic_h*pic_w*4);    // y
    //data[1] = yuv_data + pic_w*pic_h;//(uint8_t*)malloc(pic_h*pic_w);    //u (pic_h/2)*(pic_w/2)
    //data[2] = yuv_data + pic_w*pic_h + (pic_w*pic_h)/4; //(uint8_t*)malloc(pic_h*pic_w);    //v  (pic_h/2)*(pic_w/2)
    //data[3] = (uint8_t*)malloc(pic_h*pic_w);   // 0
    //int linesize[4];
    //linesize[0] = pic_w;
    //linesize[1] = pic_w/2;
    //linesize[2] = pic_w/2;
    //linesize[3] = 0;

    //fill_yuv_image(data,linesize,pic_w,pic_h,0);
    int i,j,k;
    for(i = 0 ; i < pic_h; i++)
    {
         for(j  =0 ; j < pic_w;j++)
         {
            rgb_data[i*pic_w + j] = 0xff000001;
         }
    }
    cout<< "eee"<<endl;
    SDL_UpdateTexture(sdlTexture,NULL,rgb_data ,pic_w);
    cout<< "fff"<<endl;
    SDL_Rect back_dst = {30,30,pic_w,pic_h};
    SDL_RenderCopy( renderer, sdlTexture, NULL, &back_dst);

    SDL_RenderPresent( renderer );
    SDL_Delay(3000);
#endif
    SDL_DestroyRenderer(renderer);
    SDL_DestroyWindow(window);
    SDL_Quit();
    std::cout<<"ok"<<std::endl;
    return 0;
}

以上是关于测试rgb的主要内容,如果未能解决你的问题,请参考以下文章

java:BufferedImage判断图像通道顺序并转RGB/BGR

CTS测试CtsWindowManagerDeviceTestCases模块的testShowWhenLockedImeActivityAndShowSoftInput测试fail项解决方法(代码片段

;~ 小部分AutoHotkey源代码片段测试模板2019年10月9日.ahk

typescript Angular 2测试片段。代码库https://developers.livechatinc.com/blog/category/programming/angular-2/

如何在片段着色器中进行自定义模板测试

typescript Angular最终版本的Angular 2测试片段。代码库https://developers.livechatinc.com/blog/category/programming