어제 오후부터 지금까지 계속 어떻게 구현할까 생각만하고 진짜 손도못댐 ㅠㅠㅠ

진짜 미치기 3초전임

포문이랑 그 주위에 있는걸 이용해서 이미지 상하든 좌우든 상관없으니 제발 누가

구현좀 해줘  ( 주석안에 있는건 사진에서 파란색요소를 없애는겅)


#include <stdio.h>
#include "BMP_header.h"
#include <malloc.h>

BMP_Header bmp_header;

void BMP_file_header_read (FILE *fp, BMP_Header * bmp_header){
fread (&bmp_header->charB, sizeof (char), 1, fp);
fread (&bmp_header->charM, sizeof (char), 1, fp);
fread (&bmp_header->filesize, sizeof (unsigned int), 1, fp);
fread (&bmp_header->reserved, sizeof (unsigned int), 1, fp);
fread (&bmp_header->pixel_offset, sizeof (unsigned int), 1, fp);
fread (&bmp_header->header_size, sizeof (unsigned int), 1, fp);
fread (&bmp_header->width, sizeof (unsigned int), 1, fp);
fread (&bmp_header->height, sizeof (unsigned int), 1, fp);
fread (&bmp_header->planes_n_and_bits_per_pixel_n, 4, 1, fp);
fread (&bmp_header->c_type, sizeof (unsigned int), 1, fp);
fread (&bmp_header->image_size_with_padding_in_bytes, sizeof (unsigned int), 1, fp);
fread (&bmp_header->horizontal_resolution, sizeof (unsigned int), 1, fp);
fread (&bmp_header->veritical_resolution, sizeof (unsigned int), 1, fp);
fread (&bmp_header->number_of_colors, sizeof (unsigned int), 1, fp);
fread (&bmp_header->important_colors, sizeof (unsigned int), 1, fp);
}

void BMP_file_header_write (FILE *wp, BMP_Header * bmp_header){
fwrite (&bmp_header->charB, sizeof (char), 1, wp);
fwrite (&bmp_header->charM, sizeof (char), 1, wp);
fwrite (&bmp_header->filesize, sizeof (unsigned int), 1, wp);
fwrite (&bmp_header->reserved, sizeof (unsigned int), 1, wp);
fwrite (&bmp_header->pixel_offset, sizeof (unsigned int), 1, wp);
fwrite (&bmp_header->header_size, sizeof (unsigned int), 1, wp);
fwrite (&bmp_header->width, sizeof (unsigned int), 1, wp);
fwrite (&bmp_header->height, sizeof (unsigned int), 1, wp);
fwrite (&bmp_header->planes_n_and_bits_per_pixel_n, 4,1, wp);
fwrite (&bmp_header->c_type, sizeof (unsigned int), 1, wp);
fwrite (&bmp_header->image_size_with_padding_in_bytes,sizeof (unsigned int), 1, wp);
fwrite (&bmp_header->horizontal_resolution, sizeof (unsigned int),1, wp);
fwrite (&bmp_header->veritical_resolution, sizeof (unsigned int),1, wp);
fwrite (&bmp_header->number_of_colors, sizeof (unsigned int),1, wp);
fwrite (&bmp_header->important_colors, sizeof (unsigned int),1, wp);
}

void image_flip (char * pixel_ptr, BMP_Header * bmp_header, FILE *fp){
 
 fread (pixel_ptr,bmp_header->image_size_with_padding_in_bytes,1,fp);

  // change the Blue part of each pixel to zero
  // first calculate the padding size
 unsigned int pure_number_of_bytes_per_line = bmp_header->width*3;

 unsigned int padding_size = (4 - (pure_number_of_bytes_per_line % 4)) %4;

   // (pure_number_of_bytes_per_line % 4);

 char *p = pixel_ptr;


 unsigned int one_line_width_with_padding = bmp_header->width*3 + padding_size;

 for (unsigned int i = 0; i < bmp_header->height; i++)

  for (unsigned int j = 0; j < bmp_header->width; j++){
  int first_byte_postion_in_a_line = i * one_line_width_with_padding;
  

  
  }
 
     /*
     for (int i = 0; i < 10; i++) //bmp_header->height
     for (int j = 0; j < bmp_header->width; j++ )
     {
     int first_byte_postion_in_a_line =
     i*one_line_width_with_padding;
     pixel_ptr[first_byte_postion_in_a_line+(j*3)] =255;
     pixel_ptr[first_byte_postion_in_a_line+(j*2)] =0;
     pixel_ptr[first_byte_postion_in_a_line+(j)] =0;
      }
     */ 

}
int main (void)
{
 // first read a bitmap file
 FILE * fp = fopen ("D:\\Desert.bmp", "rb"); // file open
 BMP_file_header_read (fp, &bmp_header);
 // BMP header information completely read
 // now read the pixel information
 // first prepare memory for the pixel data
 // with image_size_with_padding_in_bytes
 char * pixel_ptr;
 char * changed_img;
 pixel_ptr  = (char *)malloc(bmp_header.image_size_with_padding_in_bytes);
 changed_img  = (char *)malloc(bmp_header.image_size_with_padding_in_bytes);
 image_flip (pixel_ptr, &bmp_header, fp);

 // write a new bitmap file
 FILE * wp = fopen ("D:\\Blue_changed_BMP2.bmp", "wb");
 BMP_file_header_write (wp, &bmp_header);
 fwrite (pixel_ptr, bmp_header.image_size_with_padding_in_bytes,1, wp);

 fclose(fp);

 fclose(wp);

 free(pixel_ptr);
 
}