Bonjour,

je viens de créer un programme en C qui diminue la taille d'une bitmap par 2 et la resize. Le problème c'est que je dois l'optimiser afin qu'il soit plus rapide. Je pensais utiliser les pointeurs mais je ne vois pas vraiment comment faire. Voici mon code:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include <stdio.h>
#include <stdlib.h> // malloc
#include <string.h> // memset
#include <stdint.h> // uintxx_t types
 
#include "time_measure.h"
#include "image_utils.h"
 
int basic_data_processing(process_data_t * process_data);
 
 
int init_process_data(process_data_t * process_data, int argc, const char * argv[]) {
	int status = 0, read_fd = -1;
	uint32_t i = 0;
	uint32_t width=0, height=0;
 
	if( process_data != NULL ) {
		memset(process_data, 0, sizeof(process_data_t));
		// affect processing function
		process_data->data_processing_function = basic_data_processing;
 
		switch( argc ) {
			case 2:
				// read BMP file
				read_fd = open(argv[1], O_RDONLY
#ifdef WIN32
											 | O_BINARY
#endif // WIN32
											 );
				if( read_fd != -1 ) {
					status = read_bmp_header(read_fd, &process_data->source_header);
					if( status != -1 ) {
						switch( process_data->source_header.bits_per_pixel ) {
							case 8 :
								status = read_bmp_file_8(read_fd, &process_data->source_header, &process_data->source_bitmap);
								if( status != -1 ) {
                                                                        width=process_data->source_header.width;
                                                                         height= process_data->source_header.height;
                                                                           printf("%d\n", height);
                                                                          printf("%d\n", width);
									status = 0; // status may be positive at this point
									// allocate and initialize destination bitmap
									process_data->destination_bitmap = (uint8_t *) malloc((process_data->source_header.width/2) * (process_data->source_header.height/2) * sizeof(uint8_t));
									if( process_data->destination_bitmap ) {
										process_data->output_file_path = suffixed_filename(argv[1], " (reduced).bmp");
									} else status = -2; // bitmap allocation issue
								} else printf("BMP content read failed\n");
								break;
							default:
								printf("\"%s\" : has %d bits per pixels only 8 bpp is supported\n", argv[1], process_data->source_header.bits_per_pixel);
								break;
						} // switch header.bits_per_pixel
					} else printf("BMP header read failed\n");
				} else printf("open file failed\n");
				break;
			default:
				printf("usage : %s <output BMP file path>\n", argv[0]);
				status = -3;
				break;
		}
	} else status = -1; // parameter issue
 
	return status;
}
 
/***************************Méthode Initiale*************************************/
int basic_data_processing(process_data_t * process_data) {
 
	uint32_t x = 0;
    uint32_t y = 0;
    int32_t pixel, pixel_droit, pixel_bas, pixel_diag, moyenne;
	int status = 0;
	uint32_t width=process_data->source_header.width, height= process_data->source_header.height;
	uint8_t * source_pointer = NULL;
	uint8_t * destination_pointer = NULL;
	uint32_t counter = 0;
 
 
	if( (process_data != NULL) && (process_data->source_bitmap != NULL) && (process_data->destination_bitmap != NULL) ) {
 
		source_pointer = process_data->source_bitmap;
		destination_pointer = process_data->destination_bitmap;
 
       for(y=0; y<height; y++){
                	for(x=0; x<width; x++){
 
                             pixel=source_pointer[x+y*width];
                             pixel_droit=source_pointer[x+1+y*width];
    	                     pixel_bas=source_pointer[x+(y+1)*width];
    	                     pixel_diag=source_pointer[(x+1)+(y+1)*width];
 
                             moyenne=(pixel+pixel_droit+pixel_bas+pixel_diag)/4;
 
                  if( destination_pointer != NULL ) {
 
                     destination_pointer[(x/2)+(y/2)*(width/2)] = moyenne;
 
                   }
                    x++;
              }
              y++;
        }
	} else status = -1; // parameter issue
 
	return status;
}
 
 
int dispose_process_data(process_data_t * process_data) {
	int status = 0;
	uint32_t width=process_data->source_header.width, height=process_data->source_header.height;
 
	if( (process_data != NULL) ) {
		if( process_data->source_bitmap != NULL ) {
			free(process_data->source_bitmap);
			process_data->source_bitmap = NULL;
		}
		if( process_data->destination_bitmap != NULL ) {
			if( process_data->output_file_path ) {
				// save bitmap in BMP format
				process_data->source_header.width = width/2;
                process_data->source_header.height=height/2;
 
				save_bitmap(process_data->output_file_path, &process_data->source_header, process_data->destination_bitmap);
			}
			free(process_data->destination_bitmap);
			process_data->destination_bitmap = NULL;
		}
	} else status = -1; // parameter issue
 
	return status;
}
Si quelqu'un à des idées je serais ravi.

Merci