디시인사이드 갤러리

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

갤러리 본문 영역

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

sdfs(121.157) 2012.02.14 23:15:33
조회 143 추천 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 따뜻한 겨울나기! 방한용품 SALE 운영자 25/11/27 - -
303186 리눅스는 젠투지 무슨 소리야 [1] kukyakya(143.248) 12.02.15 85 0
303185 백트랙 리눅스 간지 작렬 [8] [성대아싸]갤로그로 이동합니다. 12.02.15 220 0
303184 리눅스는 데비안입니다 데비안 [1] ㅅㄷㅂ(112.218) 12.02.15 56 0
303182 리눅스 걍 바탕화면에다가 conky 설치만 해도 간지남 [2] [성대아싸]갤로그로 이동합니다. 12.02.15 96 0
303181 솔까 리눅스 허세 맥 허세 있지 ㅂㅈㄷ(220.76) 12.02.15 69 0
303180 리눅스 허세 킹 데헷(220.86) 12.02.15 62 0
303179 리눅스는 카와이하지 [1] dot(125.128) 12.02.15 64 0
303178 갑자기 플래시를 배워보고 시픈 충동이 드렀습니다. [성대아싸]갤로그로 이동합니다. 12.02.15 58 0
303177 존나 짜증난다 날 한나라당 알바로 몰아가는 새끼들이 너무싫다 ^0^갤로그로 이동합니다. 12.02.14 41 0
303176 들보 뭐하나 C_Perl갤로그로 이동합니다. 12.02.14 35 0
303175 천재VS노력파 [1] (58.75) 12.02.14 129 0
303174 리눅스 쓰는 사람은 모든걸 리눅스 콘솔창에서 해결하더라 ㄷㄷㄷ [6] 야요이갤로그로 이동합니다. 12.02.14 193 0
303172 리눅스는 이럴때 쓰라고있는거야 [2] 생물학(122.35) 12.02.14 104 0
303171 왜안돌아가 ㅡㅡ 좀봐줘... [12] (58.75) 12.02.14 86 0
303170 리눅스는 마우스 쓰기를 아주 귀찮아 하는사람이 써야하지 [2] 돌고래스피커갤로그로 이동합니다. 12.02.14 87 1
303169 WebGL 그저께 포스팅과 팀스터디 관련 [2] [성대아싸]갤로그로 이동합니다. 12.02.14 82 0
C언어 배운지 한달 반된 쓰래기같은 프로그래머 구제좀 해주세여 [9] sdfs(121.157) 12.02.14 143 0
303166 요세 본격적으로 C익히고 있는데 입문서 떼고 다음으로 볼꺼 추천좀여 [5] 꿈이없는곳갤로그로 이동합니다. 12.02.14 92 0
303165 난 웹 한번도배워본적이없어요 C_Perl갤로그로 이동합니다. 12.02.14 49 0
303164 프갤에서 입갤함. [2] 꿈이없는곳갤로그로 이동합니다. 12.02.14 51 0
303162 리눅스가 대세임?? [3] ㅋㄱ(183.96) 12.02.14 68 0
303161 누가 성대아싸 횽처럼 팀불로그 만들사람없어?? [5] C_Perl갤로그로 이동합니다. 12.02.14 72 0
303158 jsp 배운 좆대딩 써줄 횽아들 없나여? ^0^갤로그로 이동합니다. 12.02.14 46 0
303156 내 실력은 아직도 쓰레기였어 +어게인갤로그로 이동합니다. 12.02.14 49 0
303155 님들아 여기는 보충역 병특 뽑아줄 사람 없나여? ^0^갤로그로 이동합니다. 12.02.14 29 0
303154 리눅스 둘째치고 그냥 콘솔 터미널 창 몇개 뛰워놓으면 존내 있어보임 [1] 야요이갤로그로 이동합니다. 12.02.14 92 0
303153 리눅스 리얼 허세 뭐임 [3] [성대아싸]갤로그로 이동합니다. 12.02.14 101 0
303151 지금 나도 리눅스 허세부리고 있음 ㅎ [1] 정신차리고갤질해라갤로그로 이동합니다. 12.02.14 65 0
303150 리눅스 허세 2 C_Perl갤로그로 이동합니다. 12.02.14 53 0
303149 아나 리눅스 허세는 [4] C_Perl갤로그로 이동합니다. 12.02.14 109 0
303147 웹/보안 관련 문제들을 풀 수 있는 사이트입니다 [1] 파괘왕문복형(203.226) 12.02.14 50 0
303146 춰컬릿 받음 ㅁㄴㅇ(211.183) 12.02.14 24 0
303145 JSP 인력 파견업체 너무 한거 아냐.............?? [4] 야요이갤로그로 이동합니다. 12.02.14 145 0
303144 퇴갤한다 [2] y녀6디리(220.118) 12.02.14 40 0
303143 단층신경망을 짜 보아염... [1] 생각놀이갤로그로 이동합니다. 12.02.14 84 0
303141 웹 자동화 언어 어떤게 좋나요? 디씨클리너 제작 관련 ㅁㄴ(220.67) 12.02.14 73 0
303140 이번에 컴공들어가는 12학번 새내기입니다 [20] 아단님(211.207) 12.02.14 180 0
303139 누가 나 psp vita좀 사줘 [3] y녀6디리(220.118) 12.02.14 52 0
303138 쿄스케형 [1] SODMaster갤로그로 이동합니다. 12.02.14 36 0
303137 까놓고 말해서 리눅스 쓰는애들 컴퓨터좀 아는척 허세칠려고 쓰는거 아니냐. [16] ㅅㅅㅅ(58.77) 12.02.14 166 0
303136 연상한테 받은건 치지마라 [5] y녀6디리(220.118) 12.02.14 82 0
303135 ㅋㅋㅋㅋ 난 오늘 초콜릿 5개 받았지롱.. [4] 쿄스케갤로그로 이동합니다. 12.02.14 58 0
303134 작은 꿈이 잇엇다 y녀6디리(220.118) 12.02.14 43 0
303133 자바로 계산기 짜볼까 하는데요 ㅋ [2] SoliCode갤로그로 이동합니다. 12.02.14 68 0
303132 (파견)근무지 정보 공유 사이트 있나요? [1] Jai갤로그로 이동합니다. 12.02.14 53 0
303130 아 ㅠㅠ 도와주세염 ㅠㅠ [8] 코딩...?갤로그로 이동합니다. 12.02.14 62 0
303129 헐 나가려면 대체할 사람 구해놓고 나가라네;;;; [10] 쿄스케갤로그로 이동합니다. 12.02.14 155 0
303128 궁금한게 있다 [2] y녀6디리(220.118) 12.02.14 65 0
303127 형들아 .. 이거 하나만 쌍콤하게 질문!! [3] 코딩...?갤로그로 이동합니다. 12.02.14 62 0
303126 자바 개발자를 위한 XML 이 책 어때열? [8] 엔투갤로그로 이동합니다. 12.02.14 186 0
갤러리 내부 검색
제목+내용게시물 정렬 옵션

오른쪽 컨텐츠 영역

실시간 베스트

1/8

디시미디어

디시이슈

1/2