디시인사이드 갤러리

갤러리 이슈박스, 최근방문 갤러리

갤러리 본문 영역

C언어 배운지 한달 반된 쓰래기같은 프로그래머 구제좀 해주세여

sdfs(121.157) 2012.02.14 23:15:33
조회 139 추천 0 댓글 9

#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->image_width, sizeof (unsigned int), 1, fp);
 fread (&bmp_header->image_height, sizeof (unsigned int), 1, fp);
 fread (&bmp_header->number_of_planes_and_number_of_bits_per_pixel, 4, 1, fp);
 fread (&bmp_header->compression_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->number_of_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->image_width, sizeof (unsigned int), 1, wp);
 fwrite (&bmp_header->image_height, sizeof (unsigned int), 1, wp);
 fwrite (&bmp_header->number_of_planes_and_number_of_bits_per_pixel, 4,
  1, wp);
 fwrite (&bmp_header->compression_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->number_of_important_colors, sizeof (unsigned int),
  1, wp);
}
void change_color_BluetoZero (char * image_pixel_ptr,
 BMP_Header * bmp_header, FILE *fp)
{
fread (image_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_one_line
  = bmp_header->image_width*3;
 unsigned int padding_size =
   (4 - (pure_number_of_bytes_per_one_line % 4)) %4;
  // (pure_number_of_bytes_per_one_line % 4);
 char *p = image_pixel_ptr;
 unsigned int one_line_width_with_padding
  = bmp_header->image_width*3 + padding_size;
for (unsigned int i = 0; i < bmp_header->image_height; i++)
for (unsigned int j = 0; j < bmp_header->image_width; j++)
{
int first_byte_postion_in_a_line = i * one_line_width_with_padding;

   image_pixel_ptr[first_byte_postion_in_a_line+(j*3)] =image_pixel_ptr[first_byte_postion_in_a_line+(j*3)] - 10;
}
 
 /*
 for (int i = 0; i < 10; i++) //bmp_header->image_height
  for (int j = 0; j < bmp_header->image_width; j++ )
  {
      int first_byte_postion_in_a_line =
    i*one_line_width_with_padding;
   image_pixel_ptr[first_byte_postion_in_a_line+(j*3)] =255;
   image_pixel_ptr[first_byte_postion_in_a_line+(j*2)] =0;
   image_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 * image_pixel_ptr;
 image_pixel_ptr  = (char *)malloc(bmp_header.image_size_with_padding_in_bytes);
 change_color_BluetoZero (image_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 (image_pixel_ptr, bmp_header.image_size_with_padding_in_bytes
  , 1, wp);
 fclose(fp);
 fclose(wp);
 free(image_pixel_ptr);
 
}


변수가 너무 길다거나 하는건 제발 무시해줘..

bmp 파일을 오픈해서 이것저것 해보는중인데

내가 성공한건 사진에서 원하는 색을 변경하는것까지..

이제 더 나아가 사진 좌우대칭을 바꾼다거나 상하를 돌려보고싶은데

이건 언어문제가 아니라 내가 돌머리라서 어떻게 짜야할지모르겠다.

대충 for문만 고치면 될거가튼데..

추천 비추천

0

고정닉 0

0

댓글 영역

전체 댓글 0
본문 보기

하단 갤러리 리스트 영역

왼쪽 컨텐츠 영역

갤러리 리스트 영역

갤러리 리스트
번호 제목 글쓴이 작성일 조회 추천
설문 뛰어난 운동 신경으로 남자와 싸워도 이길 것 같은 여자 스타는? 운영자 25/11/24 - -
AD 대학생 필수템! What's in my Bag 운영자 25/11/21 - -
303248 gui vs cui [3] 서현빠돌이갤로그로 이동합니다. 12.02.15 114 0
303247 리눅스는 제대로 쓸려면 멀티 부팅 하면 안됨. ㅇㅇ [4] ☎v2.0™갤로그로 이동합니다. 12.02.15 109 0
303246 횽들아 서현이랑 사귀려면 어찌해야 하나여?? [2] 서현빠돌이갤로그로 이동합니다. 12.02.15 81 0
303245 예전에 hotmail에서 메일서버를 윈도아니고 프리비에스디썼다던데 ㄴㅇㄹ(112.136) 12.02.15 38 0
303244 맥은 BSD 계승한거져?? [1] [성대아싸]갤로그로 이동합니다. 12.02.15 81 0
303243 예전에 성능때문에 윈도우서버 안썼다지만 요새는 죄다 윈도서버 [1] ㄴㅇㄹ(112.136) 12.02.15 75 0
303242 리눅스를 쓰는데 x윈도우만 쓰면 변태인가염?? [1] 서현빠돌이갤로그로 이동합니다. 12.02.15 66 0
303241 BSD 계열 사용하다가 Linux 사용하면. ㅇㅇ ☎v2.0™갤로그로 이동합니다. 12.02.15 76 0
303240 밥은 먹고 겔질 하는거냐??? 서현빠돌이갤로그로 이동합니다. 12.02.15 46 0
303239 리눅스 머하러 쓰냐. 프리비에스디가 있는데 [1] ㄴㅇㄹ(112.136) 12.02.15 94 0
303238 리눅스 쓰는 애들 보면 대부분 윈도우 멀티부팅함 ㅋㅋ [8] ㅇㅇㅇ(58.77) 12.02.15 257 0
303237 으헝.. 도와주세염 ㅠㅠ [5] 코딩...?갤로그로 이동합니다. 12.02.15 55 0
303235 [떡밥] 횽들 심심한데 스도쿠 만드는 코드 짜봐용.ㅋㅋㅋ [3] 생물학(122.35) 12.02.15 97 0
303234 솔직히 리눅스 왜쓰냐? [9] ㅇㅇㅇ(58.77) 12.02.15 143 0
303233 성다아싸 소환 [5] C_Perl갤로그로 이동합니다. 12.02.15 65 0
303231 수학공부좀 기초부터 다시하고싶은데요.. 봉크라이시스갤로그로 이동합니다. 12.02.15 59 0
303230 내가 예전에 말이지 생물학(122.35) 12.02.15 38 0
303227 늅늅 성대아싸횽 서몬! [5] dogfootson갤로그로 이동합니다. 12.02.15 71 0
303223 내가 원조 거칠게다 ㅋㅋㅋㅋㅋ [1] 서현빠돌이갤로그로 이동합니다. 12.02.15 84 0
303221 수학적 사고능력 키우려면 어떻게 해야함 [5] 1(118.220) 12.02.15 100 0
303220 거칠게 닉 쓰는거 곽횽인데... [1] 쿄스케갤로그로 이동합니다. 12.02.15 66 0
303214 2주정도 아무생각없이 노니까 봉크라이시스갤로그로 이동합니다. 12.02.15 38 0
303212 음ㅠ님들아ㅜㅜ [7] 코딩...?갤로그로 이동합니다. 12.02.15 66 0
303210 DB 잘아는 놈 없냐? [2] 호석갤로그로 이동합니다. 12.02.15 105 0
303209 형들 나 자료모으기용 블로그 만들려는데 어느곳이 쓸만한가요? [4] +어게인갤로그로 이동합니다. 12.02.15 82 0
303208 형님들 늅늅이 입갤했습니다 아노니갤로그로 이동합니다. 12.02.15 35 0
303206 아래 글 보고 저도.... 달팽이 배열.... 해봣서요....... [3] 속력왕김달팽(59.7) 12.02.15 83 0
303205 책을 많이 읽어야 지식이 늘어나는데 [2] y녀6디리(220.118) 12.02.15 55 0
303204 여행이나 함 갈까 y녀6디리(220.118) 12.02.15 31 0
303203 괜찮아 너희들 올때까지 난 여기서 기다림ㅋ y녀6디리(220.118) 12.02.15 24 0
303202 명불허전 프갤ㅋ [1] y녀6디리(220.118) 12.02.15 50 0
303201 이제 아스 소환해도 안나옴? y녀6디리(220.118) 12.02.15 30 0
303200 리눅스 리눅스 하는데 [2] y녀6디리(220.118) 12.02.15 81 0
303199 일찍자니까 일찍일어난닼ㅋㅋ y녀6디리(220.118) 12.02.15 45 0
303198 군대 꿈꿨다 [1] 쿄스케갤로그로 이동합니다. 12.02.15 51 0
303197 형들 늅늅이 오늘도 질문할게요 [2] gaenim갤로그로 이동합니다. 12.02.15 52 0
303196 파이썬 잘하는성님들 Hardtack9갤로그로 이동합니다. 12.02.15 66 0
303195 퇴갤 생물학(122.35) 12.02.15 33 0
303194 나 졸업식 때 말인데 (아싸형 덧글 점) [3] 생물학(122.35) 12.02.15 84 0
303192 리눅스...테마관련 질문 [1] 데헷(220.86) 12.02.15 59 0
303190 형들 , JAVA문제인데 내가 너무 어렵게 생각하고 있는것같아 [3] 싸이의홈스틸갤로그로 이동합니다. 12.02.15 97 0
303189 백트랙 리눅스??? [2] 데헷(220.86) 12.02.15 100 0
303188 애들은 5분, 프로그래머는 1시간 걸리는 문제 [22] goding(221.143) 12.02.15 275 0
303186 리눅스는 젠투지 무슨 소리야 [1] kukyakya(143.248) 12.02.15 82 0
303185 백트랙 리눅스 간지 작렬 [8] [성대아싸]갤로그로 이동합니다. 12.02.15 218 0
303184 리눅스는 데비안입니다 데비안 [1] ㅅㄷㅂ(112.218) 12.02.15 51 0
303182 리눅스 걍 바탕화면에다가 conky 설치만 해도 간지남 [2] [성대아싸]갤로그로 이동합니다. 12.02.15 92 0
303181 솔까 리눅스 허세 맥 허세 있지 ㅂㅈㄷ(220.76) 12.02.15 66 0
303180 리눅스 허세 킹 데헷(220.86) 12.02.15 62 0
303179 리눅스는 카와이하지 [1] dot(125.128) 12.02.15 63 0
갤러리 내부 검색
제목+내용게시물 정렬 옵션

오른쪽 컨텐츠 영역

실시간 베스트

1/8

디시미디어

디시이슈

1/2