zoukankan      html  css  js  c++  java
  • work

    #include <stdio.h>

    #include <iostream>
    #include <memory>

    template<class T>
    class Surface
    {
    public:
    Surface(){
    width = 0;
    height = 0;
    allocate_self = true;
    memset(stride,0,sizeof(stride));
    }
    virtual ~Surface() {
    }
    virtual int create(int width, int height, int * stride)=0;
    virtual int create(int width, int height, uint8_t * const * data, int * stride)=0;
    virtual void release() {
    for (int i = 0; i != 4; ++i) {
    data[0].reset();
    }
    };
    uint8_t* getPtr() const {
    return data[0].get();
    }
    void getPtr(uint8_t* const * res_data) const {
    for (int i = 0; i != 4; ++i) {
    res_data[i] = data[i].get();
    }
    }
    public:
    int width;
    int height;
    int stride[4];

    protected:
    std::shared_ptr<T> data[4];
    bool allocate_self;
    };

    template<class T>
    class SurfaceGray :public Surface<T>
    {
    public:
    int create(int _width, int _height, int * _stride)
    {
    allocate_self = true;
    data[0] = std::make_shared<uint8_t>( _stride[0]*height );
    width = _width;
    height = _height;
    memcpy( stride, _stride, sizeof(int)*4 );
    return 0;
    }
    int create(int _width, int _height, uint8_t * const * _data, int * _stride)
    {
    allocate_self = false;
    width = _width;
    height = _height;
    for (int i = 0; i != 4; ++i) {
    if (_data[i]) {
    //data[i] = std::make_shared<uint8_t>(_data[i]);
    stride[i] = _stride[i];
    }

    }
    return 0;
    }
    private:
    };


    int main()
    {
    SurfaceGray<uint8_t> pic;
    int stride[4] = {1920,0,0,0};
    pic.create(1920, 1080, stride);
    uint8_t* data = pic.getPtr();
    pic.release();
    return 0;
    }

  • 相关阅读:
    从零开始入门 K8s | 应用编排与管理
    209. Minimum Size Subarray Sum
    208. Implement Trie (Prefix Tree)
    207. Course Schedule
    203. Remove Linked List Elements
    183. Customers Who Never Order
    182. Duplicate Emails
    181. Employees Earning More Than Their Managers
    1261. Find Elements in a Contaminated Binary Tree
    1260. Shift 2D Grid
  • 原文地址:https://www.cnblogs.com/luoyinjie/p/11970100.html
Copyright © 2011-2022 走看看