디시인사이드 갤러리

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

갤러리 본문 영역

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

sdfs(121.157) 2012.02.14 23:15:33
조회 140 추천 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 - -
공지 프로그래밍 갤러리 이용 안내 [97] 운영자 20.09.28 48749 65
2904410 33살 중소3년차 똥통인생 이스펙으로 중견입사 가능하냐..? ㅇㅇ(118.235) 04:59 12 0
2904408 지잡대 졸업 30살인데 학벌 세탁원하는데 학사편입vs대학원 ㅇㅇ(203.232) 04:30 13 0
2904407 Claude cli 오늘 첨 써봤는데 개발자 왜 필요하냐 프갤러(101.235) 04:26 14 0
2904389 Clair.IO.Poller: 이번에 설계했다가 gg친 API ㅋㅋ 나르시갤로그로 이동합니다. 02:59 31 0
2904375 진짜 프로그래머들 ㅈㄴ부럽다 [2] ㅅ스맨갤로그로 이동합니다. 02:18 64 0
2904367 코딩 걍 첨부터 막히는데 어캄 [2] ㅅ스맨갤로그로 이동합니다. 01:54 45 0
2904364 자바 언어 좋지.. 추억과 낭만이 깃들인 언어 ㅋㅋ [1] 나르시갤로그로 이동합니다. 01:45 38 0
2904363 거래소 api들 잘 다루고 싶으면 뭐 부터 배우면 될까요 선배님들 [3] 프갤러(114.204) 01:43 35 0
2904362 7번국도 드라이빙 때 좋을만한 브금 chironpractor갤로그로 이동합니다. 01:31 17 0
2904359 0x [1] 루도그담당(58.233) 01:22 27 0
2904358 접시 ㅇㅅㅇ [6] 헤르 미온느갤로그로 이동합니다. 01:12 45 0
2904357 태연 ㅇㅅㅇ 헤르 미온느갤로그로 이동합니다. 01:09 19 0
2904356 하루 한 번 헤르미온느 찬양 헤르 미온느갤로그로 이동합니다. 01:08 28 0
2904324 오픈소스 프로젝트를 하나 해볼까 [12] 에이도비갤로그로 이동합니다. 00:02 87 0
2904320 고 언어 음 좋지 나쁘지 않고 효율적이고 음 근데 [6] 프갤러(110.8) 11.23 55 0
2904316 www.basic4mcu.com 11월까지 서비스 종료 발명도둑잡기(118.216) 11.23 18 0
2904313 카리나가 맛집이넹 ♥냥덩이의우웅한하룽♥갤로그로 이동합니다. 11.23 54 0
2904309 그러고 보니 프갤에서 고랭 팬은 못본거 같은데 [3] chironpractor갤로그로 이동합니다. 11.23 46 0
2904303 클라우드 엔지니어 희망하는데 [2] 프갤러(118.235) 11.23 32 0
2904298 cursor 대체할만한거 있어? [2] ㅇㅇ(124.48) 11.23 44 0
2904295 개발만한 취미가 없는 것 같음 프갤러(61.73) 11.23 57 0
2904294 살면서 잘 한 일... 후배한테 노트북 키스킨 딱 맞는 카라스스킨 5천원 넥도리아(220.74) 11.23 14 0
2904291 에구궁.. 나님 일욜밤까지 모임하구와서 배불러양 [2] ♥냥덩이의우웅한하룽♥갤로그로 이동합니다. 11.23 49 0
2904289 웹디자인은 이미 AI때문에 망한듯 [1] 프갤러(220.70) 11.23 45 0
2904285 왜 극좌들은 하나같이 왕따 당하는걸까? [4] ♥냥덩이의우웅한하룽♥갤로그로 이동합니다. 11.23 44 0
2904266 인공지능 댓글 검사기 발명도둑잡기(118.216) 11.23 27 0
2904265 배달기사 레전드네 진짜; [7] 루도그담당(58.233) 11.23 72 0
2904264 [긴급속보] 한국 연구진이 노벨상 근거를 뒤집자 현재 난리난 천문학계 발명도둑잡기(118.216) 11.23 28 0
2904262 왕따재명 안쓰럽네 ㅠ ㅅ ㅠ [2] ♥냥덩이의우웅한하룽♥갤로그로 이동합니다. 11.23 45 1
2904261 소프트웨어 이름으로 이렁 거 어때? [4] 나르시갤로그로 이동합니다. 11.23 53 0
2904259 긴sql도 셸스크립트도 보기 싫은데 [10] 슈퍼막코더(116.64) 11.23 65 0
2904256 이거 이직 중인데 두개중 어디가야하노 [2] 프갤러(58.231) 11.23 40 0
2904255 베린이평가좀 [1] ㅇㅇ(39.7) 11.23 41 0
2904247 간철수도 어셈블리어한다는데 [2] 타이밍뒷.통수한방(1.213) 11.23 60 0
2904245 국비조언좀요 [2] 프갤러(220.86) 11.23 56 0
2904244 어셈 짜는 중인데 헷갈린다 이기 [12] 루도그담당(58.233) 11.23 88 0
2904243 폴리글랏 툴체인이 나오면 프갤에 평화가 오려나? [10] chironpractor갤로그로 이동합니다. 11.23 65 0
2904242 베이스 ㅍㅌㅊ? ㅇㅇ(203.232) 11.23 40 0
2904240 나 불렀서? ㅇㅅㅇ [6] 프갤러(49.165) 11.23 62 0
2904237 탑 클라스 명문대 진학 퍼펙트 합격 가이드!T 프갤러(121.142) 11.23 39 1
2904232 ❤✨☀⭐⚡☘⛩☃나님 시작합니당☃⛩☘⚡⭐☀✨❤ [3] ♥냥덩이의우웅한하룽♥갤로그로 이동합니다. 11.23 60 0
2904231 이제 러스트 빠돌이 프갤에 안 오겠군 ㅋㅋ [1] 나르시갤로그로 이동합니다. 11.23 46 0
2904230 언어 선택권도 수저순일텐데 [2] chironpractor갤로그로 이동합니다. 11.23 61 0
2904229 파이선 얼마나 개떡 같은데 ㅎㅎ [10] 나르시갤로그로 이동합니다. 11.23 66 0
2904226 언어에 자아의탁하는거? 뭐 그럴수 있음 [16] 박민준갤로그로 이동합니다. 11.23 138 2
2904222 좇센 노무 살기좋은 나라이긴해 타이밍뒷.통수한방(1.213) 11.23 33 0
2904221 파이썬 패키지 설치를 못해? [4] ㅇㅇ(211.234) 11.23 83 3
2904220 백화점 상품권 시세 크롤링하는건 불법일까요? [1] 프갤러(14.32) 11.23 33 0
2904217 요즘가수 머리 90년대같지 않습니까? [4] 헬마스터갤로그로 이동합니다. 11.23 59 0
갤러리 내부 검색
제목+내용게시물 정렬 옵션

오른쪽 컨텐츠 영역

실시간 베스트

1/8

디시미디어

디시이슈

1/2