这个视频内容讲解的离散余弦变换,讲的很好,
离散余弦变换可视化讲解_哔哩哔哩_bilibili
其中讲到,把颜色变化转换为曲线的处理,
在前面的学习中,我们知道了可以向appsrc来灌数据来进行显示
Gstreamer学习3----灌数据给管线之appsrc_gstreamer appsrc-CSDN博客
这里,我们也可以使用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 bytesuint16_t reserved1; // Reserved, should be zerouint16_t reserved2; // Reserved, should be zerouint32_t offset; // Offset to the pixel array from the beginning of the fileuint32_t dib_header_size; // Size of the DIB header in bytesint32_t width; // Width of the image in pixelsint32_t height; // Height of the image in pixelsuint16_t planes; // Number of color planesuint16_t bits_per_pixel; // Number of bits per pixeluint32_t compression; // Compression method useduint32_t bitmap_data_size;// Size of the bitmap data in bytesint32_t x_pixels_per_m; // Horizontal resolution in pixels per meterint32_t y_pixels_per_m; // Vertical resolution in pixels per meteruint32_t num_colors_used; // Number of colors in the paletteuint32_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 headerfread(&header, sizeof(BMPHeader), 1, file);// Calculate the row size and paddingrow_size = (header.width * header.bits_per_pixel + 7) / 8;padding = (4 - (row_size % 4)) % 4;// Allocate memory for the pixelspixels = malloc(header.height * row_size);// Seek to the beginning of the pixel datafseek(file, header.offset, SEEK_SET);// Read each row of pixelsfor (i = 0; i < header.height; i++) {// Read one row of pixelsfread(pixels + i * row_size, 1, row_size, file);// Print the pixel values for this rowfor (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 memoryfclose(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;
}