Ragazzi sto cercando di unire questo codice ma sono in alto mare mi dite cosa sbaglio
# include <stdio.h>
# define PI 3.14
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
typedef struct
{
unsigned char RGB[3];
}RGB;
typedef struct
{
unsigned int size;
int width,height;
unsigned short int planes;
unsigned short int bpp;
unsigned int compression;
unsigned int imagesize;
int xresolution,yresolution;
unsigned int colours;
unsigned int impcolours;
}INFOHEADER;
// ********** Create Matrix **********
RGB** createMatrix(int height,int width){
RGB** Matrix;
int i;
Matrix = (RGB **) malloc (sizeof (RGB*) * height);
if (Matrix == NULL){
perror("***** No memory available*****");
exit(0);
}
for (i=0;i<height;i++){
Matrix[i] = (RGB *) malloc (sizeof(RGB) * width);
if (Matrix[i] == NULL){
perror("***** No memory available *****");
exit(0);
}
}
return(Matrix);
}
// ********** Verify if the file is BMP *********
void isBMP(FILE* arq){
char type[3];
unsigned short int bpp;
fseek(arq,0,0);
fread(type,1,2,arq);
type[2] = '\0';
fseek(arq,28,0);
fread(&bpp,1,2,arq);
if (strcmp(type,"BM") || (bpp != 24)){
printf("\nThe file is not BMP format or is not 24 bits\n");
exit(0);
}
}
// ********** Read BMP info from file **********
INFOHEADER readInfo(FILE* arq){
INFOHEADER info;
// Image Width in pixels
fseek(arq,18,0);
fread(&info.width,1,4,arq);
// Image Height in pixels
fseek(arq,22,0);
fread(&info.height,1,4,arq);
// Color depth, BPP (bits per pixel)
fseek(arq,28,0);
fread(&info.bpp,1,2,arq);
// Compression type
// 0 = Normmally
// 1 = 8 bits per pixel
// 2 = 4 bits per pixel
fseek(arq,30,0);
fread(&info.compression,1,4,arq);
// Image size in bytes
fseek(arq,34,0);
fread(&info.imagesize,1,4,arq);
// Number of color used (NCL)
// value = 0 for full color set
fseek(arq,46,0);
fread(&info.colours,1,4,arq);
// Number of important color (NIC)
// value = 0 means all collors important
fseek(arq,50,0);
fread(&info.impcolours,1,4,arq);
return(info);
}
RGB** loadImage(FILE* arq, RGB** Matrix,int height,int width){
int i,j;
RGB tmp;
long pos = 51;
fseek(arq,0,0);
for (i=0; i<height; i++){
for (j=0; j<width; j++){
pos+= 3;
fseek(arq,pos,0);
fread(&tmp,(sizeof(RGB)),1,arq);
Matrix[i][j] = tmp;
}
}
return(Matrix);
}
void dct(float [][]); // Function prototypes
void idct(float [][]); // Function prototypes
void dct(float inMatrix[8][8]){
double dct,
Cu,
sum,
Cv;
int i,
j,
u,
h = 0,
v;
FILE * fp = fopen("mydata.csv", "w");
float dctMatrix[8][8],
greyLevel;
for (u = 0; u < 8; ++u) {
for (v = 0; v < 8; ++v) {
if (u == 0) {
Cu = 1.0 / sqrt(2.0);
} else {
Cu = 1.0;
}
if (v == 0) {
Cv = 1.0 / sqrt(2.0);
} else {
Cu = (1.0);
}
sum = 0.0;
for (i = 0; i < 8; i++) {
for (j = 0; j < 8; j++) {
// Level around 0
greyLevel = inMatrix[i][j];
dct = greyLevel * cos((2 * i + 1) * u * PI / 16.0) *
cos((2 * j + 1) * v * PI / 16.0);
sum += dct;
}
}
dctMatrix[u][v] = 0.25 * Cu * Cv * sum;
fprintf(fp, "\n %f", dctMatrix[u][v]);
}
fprintf(fp, "\n");
}
idct(dctMatrix);
}
void idct(float dctMatrix[8][8]){
double idct,
Cu,
sum,
Cv;
int i,
j,
u,
v;
float idctMatrix[8][8],
greyLevel;
FILE * fp = fopen("mydata.csv", "a");
fprintf(fp, "\n Inverse DCT");
for (i = 0; i < 8; ++i) {
for (j = 0; j < 8; ++j) {
sum = 0.0;
for (u = 0; u < 8; u++) {
for (v = 0; v < 8; v++) {
if (u == 0) {
Cu = 1.0 / sqrt(2.0);
} else {
Cu = 1.0;
}
if (v == 0) {
Cv = 1.0 / sqrt(2.0);
} else {
Cu = (1.0);
}
// Level around 0
greyLevel = dctMatrix[u][v];
idct = (greyLevel * cos((2 * i + 1) * u * PI / 16.0) *
cos((2 * j + 1) * v * PI / 16.0));
sum += idct;
}
}
idctMatrix[i][j] = 0.25 * Cu * Cv * sum;
fprintf(fp, "\n %f", idctMatrix[i][j]);
}
fprintf(fp, "\n");
}
}
int main() {
int height, width;
FILE* arq = fopen("lena512.bmp", "r");
/* in your main program you just call */
/* the bitmap file 24 bits */
RGB** Matrix_aux;
RGB** Matrix;
INFOHEADER info;
info = readInfo(arq);
height = info.height;
width = info.width;
Matrix_aux = createMatrix(height,width);
Matrix = loadImage(arq,Matrix_aux,height,width);
int i , j;
for(i=0;i<height;i++){
for(j=0;j<width;j++){
printf("\n %d,%d,%d",Matrix[i][j].RGB[0],Matrix[i][j].RGB[1],Matrix[i][j].RGB[2]);
}
}
printf("\n tool=%d l3ard=%d",height,width);
return 0;
float
testBlockA[8][8] = { {255, 255, 255, 255, 255, 255, 255, 255},
{255, 255, 255, 255, 255, 255, 255, 255},
{255, 255, 255, 255, 255, 255, 255, 255},
{255, 255, 255, 255, 255, 255, 255, 255},
{255, 255, 255, 255, 255, 255, 255, 255},
{255, 255, 255, 255, 255, 255, 255, 255},
{255, 255, 255, 255, 255, 255, 255, 255},
{255, 255, 255, 255, 255, 255, 255, 255} },
testBlockB[8][8] = {{255, 0, 255, 0, 255, 0, 255, 0},
{0, 255, 0, 255, 0, 255, 0, 255},
{255, 0, 255, 0, 255, 0, 255, 0},
{0, 255, 0, 255, 0, 255, 0, 255},
{255, 0, 255, 0, 255, 0, 255, 0},
{0, 255, 0, 255, 0, 255, 0, 255},
{255, 0, 255, 0, 255, 0, 255, 0},
{0, 255, 0, 255, 0, 255, 0, 255} };
dct(testBlockB);
}