Я пытаюсь передать указатель rgb, который инициализируется с memset равным 0, а затем проходит через него, чтобы поместить 32-разрядное целое число только в те границы, которые я создаю, с помощью ввода высоты и ширины (h и w), а также смещения от верхний левый угол 2-го массива (х и у). после компиляции у меня появляется значение с указателем printf сразу после его создания, которое дает правильное значение (в моем случае 0xFFFFFF с и ввод 255 255 255 для rgb), но после того, как оно передается в функцию rgb2yuv, оно устанавливается в 0, когда я печатаю там.
Любые предложения будут великолепны!
#include <stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<fcntl.h>
#include<errno.h>
#include<string.h>
/*global definitions*/
#define WIDTH 480
#define HEIGHT 240
/*global declarations*/
int w,h,scrn, bytewrite;
unsigned char red, green, blue;
static unsigned long rgb[WIDTH][HEIGHT];
/*function declarations*/
void colorq();
void rgb_rectdraw(int x, int y, int w, int h, unsigned char red ,
unsigned char green, unsigned char blue, unsigned long *rgb);
void rgb2yuv(unsigned long *rgb);
/*
Function Name: main
Purpose: main function
*/
int main(int argc, char** argv){
printf("\n");
int x, y;
/*call colorq to create a 32bit number of RGB*/
colorq();
/ *call rgb_rectdraw to draw a rectangle RGB array*/
rgb_rectdraw(x, y, w, h, red, green, blue, rgb);
/*call rgb2yuv to take the RGB array and covert it to a YUV array*/
rgb2yuv(rgb);
return 0;
}
/*
Function name: color q
Purpose: asks user to input colors from 0 to 255 in RGB format
*/
void colorq(){
printf("Please enter a color for Red Green and Blue from 0 to 255:\n");
scanf("%hu", &red);
scanf("%hu", &green);
scanf("%hu", &blue);
printf("\n");
return;
}
/*
Function name: rectdraw
Purpose: Draws a rectangle array
*/
void rgb_rectdraw(int x, int y, int w, int h,unsigned char red,
unsigned char green, unsigned char blue,unsigned long *rgb){
unsigned long rgbpixel;
/* testing only take out when
finished debugging why red is always 0 after scanf */
red = 255;
printf("red set to 255 for debugging\n");
/*creates a 32-bit number of RGB*/
rgbpixel = (red<<16)|(green<<8)|blue;
printf("%#x\n",rgbpixel);
/*create array of width w height h*/
/*initialize array*/
memset (rgb, 0,sizeof(HEIGHT*WIDTH));
int i, j, startx, stopx, starty, stopy;
printf("enter width and height of rectangle in pixels\n");
scanf("%d %d", &w, &h);
printf("enter offset x pixels and y pixels of rectangle:\n");
scanf("%d %d", &x, &y);
startx=x;
starty=y;
stopx=x+w;
stopy=y+w;
/* creates array of w and h of int rgh */
for(i=startx; i <= stopx; i++){
for(j=starty; j <= stopy; j++){
rgb = rgbpixel;
}
j = 0;
}
printf("original rgb %#x\n",rgb);
return ;
}
/*
*Function Name: rgb2yuv
*Purpose: convert the RGB array to a YUV array
*/
void rgb2yuv(unsigned long *rgb){
int i,j;
printf("ptrpassed = %#x\n",*rgb);
for(i=0; i<=WIDTH;i++){
for(j=0; j<=HEIGHT; j++){
}
}
printf("\n");
return;
}