Gstreamer学习3.1------使用appsrc灌颜色信号数据

时间:2024-07-15 22:32:29

这个视频内容讲解的离散余弦变换,讲的很好,

离散余弦变换可视化讲解_哔哩哔哩_bilibili

其中讲到,把颜色变化转换为曲线的处理,

在前面的学习中,我们知道了可以向appsrc来灌数据来进行显示

Gstreamer学习3----灌数据给管线之appsrc_gstreamer appsrc-****博客

这里,我们也可以使用appsrc来实现这个信号图,

1. 从图片中读取到数据,比如读取的bmp图片,

2,每一次显示时,在appsrc里灌入颜色数据

需要设计一下曲线移动时的显示,

附,bmp读取数据

#include <stdio.h>
#include <stdint.h>

typedef struct {
    uint8_t blue;
    uint8_t green;
    uint8_t red;
} RGBPixel;

typedef struct {
    uint8_t type[2];          // "BM"
    uint32_t file_size;       // Size of the file in bytes
    uint16_t reserved1;       // Reserved, should be zero
    uint16_t reserved2;       // Reserved, should be zero
    uint32_t offset;          // Offset to the pixel array from the beginning of the file
    uint32_t dib_header_size; // Size of the DIB header in bytes
    int32_t width;            // Width of the image in pixels
    int32_t height;           // Height of the image in pixels
    uint16_t planes;          // Number of color planes
    uint16_t bits_per_pixel;  // Number of bits per pixel
    uint32_t compression;     // Compression method used
    uint32_t bitmap_data_size;// Size of the bitmap data in bytes
    int32_t x_pixels_per_m;   // Horizontal resolution in pixels per meter
    int32_t y_pixels_per_m;   // Vertical resolution in pixels per meter
    uint32_t num_colors_used; // Number of colors in the palette
    uint32_t important_colors;// Number of important colors
} BMPHeader;

void read_bmp(const char *filename) {
    FILE *file;
    BMPHeader header;
    RGBPixel *pixels;
    size_t row_size;
    size_t padding;
    size_t i, j;

    file = fopen(filename, "rb");
    if (!file) {
        fprintf(stderr, "Failed to open file %s\n", filename);
        return;
    }

    // Read the BMP header
    fread(&header, sizeof(BMPHeader), 1, file);

    // Calculate the row size and padding
    row_size = (header.width * header.bits_per_pixel + 7) / 8;
    padding = (4 - (row_size % 4)) % 4;

    // Allocate memory for the pixels
    pixels = malloc(header.height * row_size);

    // Seek to the beginning of the pixel data
    fseek(file, header.offset, SEEK_SET);

    // Read each row of pixels
    for (i = 0; i < header.height; i++) {
        // Read one row of pixels
        fread(pixels + i * row_size, 1, row_size, file);

        // Print the pixel values for this row
        for (j = 0; j < header.width; j++) {
            printf("Pixel (%d,%d): R=%02X G=%02X B=%02X\n",
                   j, header.height - i - 1,
                   ((RGBPixel*)(pixels + i * row_size))[j].red,
                   ((RGBPixel*)(pixels + i * row_size))[j].green,
                   ((RGBPixel*)(pixels + i * row_size))[j].blue);
        }
    }

    // Close the file and free the allocated memory
    fclose(file);
    free(pixels);
}

int main(int argc, char *argv[]) {
    if (argc != 2) {
        fprintf(stderr, "Usage: %s <filename.bmp>\n", argv[0]);
        return 1;
    }
    read_bmp(argv[1]);
    return 0;
}