I have two options.
- receiving and processing pixel data in a flat array.
If I choose it, I have to use single pointer. I have to use this code in every repeated pixel data process.
int getIndex(int row, int col){
return row*(Image_Width) + col;
}
for (int i ...){
for (int j ...){
R[getIndex(i,j)]
G[getIndex(i,j)]
B[getIndex(i,j)]
}
}
- receiving and processing pixel data in a double array.
If I choose it, I have to use a pointer-to-pointer. I don't need to use getIndex().
I want to know the pros and cons of the two options and which one is efficient.
This is an example of using a single array and a double array to perform constant multiplication for each pixel data.
B = (unsigned char *)malloc(ImgSize);
G = (unsigned char *)malloc(ImgSize);
R = (unsigned char *)malloc(ImgSize);
for (int i = 0; i < ImgSize; i++){
B[i] = fgetc(f);
G[i] = fgetc(f);
R[i] = fgetc(f);
}
for (int i = 0; i < Height; i++){
for(int j = 0; j < Width; j++){
B[getIndex(i,j)] = int(B[getIndex(i,j)]*num);
G[getIndex(i,j)] = int(G[getIndex(i,j)]*num);
R[getIndex(i,j)] = int(R[getIndex(i,j)]*num);
}
}
dB = (unsigned char **)malloc(hInfo.biHeight * sizeof(unsigned char *));
dG = (unsigned char **)malloc(hInfo.biHeight * sizeof(unsigned char *));
dR = (unsigned char **)malloc(hInfo.biHeight * sizeof(unsigned char *));
for (int i = 0 ; i < hInfo.biHeight; i++){
*(dB+i) = (unsigned char *)malloc(hInfo.biWidth * sizeof(unsigned char));
*(dG+i) = (unsigned char *)malloc(hInfo.biWidth * sizeof(unsigned char));
*(dR+i) = (unsigned char *)malloc(hInfo.biWidth * sizeof(unsigned char));
}
for (int i = 0; i < hInfo.biHeight; i++){
for (int j = 0; j < hInfo.biWidth; j++){
dB[i][j] = fgetc(f);
dG[i][j] = fgetc(f);
dR[i][j] = fgetc(f);
}
}
for (int i = 0; i < Height; i++){
for(int j = 0; j < Width; j++){
dB[i][j] = int(dB[i][j]*num);
dG[i][j] = int(dG[i][j]*num);
dR[i][j] = int(dR[i][j]*num);
}
}
doublefloating-point object. Please use pointer-to-pointer instead." This is exactly the reason I was confused at first about your question, "single" and "double" usually refer to 4 and 8-bit floating-point format.