BMP 파일을 열어보면 파일안의 내용이 상하반전되어 저장되어 있다. 그 이유는 다음과 같다.

처음에 IBM(OS/2)에서 좌표 체계 만들 때, 윈도우, 그래픽, 비트맵 등 전부다 통일성을 가지길 원했다.
이에 다같이 모여 회의를 했는데, 프로그래머를 비롯한 대부분의 사람들은 위쪽에서 아래쪽으로 데이터를 나타내길 원했다. 하지만 하드코어 그래픽 개발자들은 수학적 방식에 의한 Bottom up 방식을 원했다. 많은 논의 끝에 결국은 하드코어 그래픽 개발자들이 원하는 방식대로 되었다.

Bottoms Up!

Like most bitmap formats, the pixel bits in the DIB are organized in horizontal rows, sometimes also called “scan lines” from the terminology of video display hardware. The number of rows is equal to the bcHeight field of the BITMAPCOREHEADER structure. However, unlike most bitmap formats, the DIB begins with the bottom row of the image and proceeds up through the image.

Let’s establish some terminology here. When I say “top row” and “bottom row,” I mean the top and bottom of the visual image as it appears when correctly displayed on the monitor or printer page. The top row of a portrait is hair; the bottom row of a portrait is chin. When I say “first row,” I mean the row of pixels that is found directly after the color table in the DIB file. And when I say “last row,” I mean the row of pixels at the very end of the file.

So, in DIBs, the bottom row of the image is the first row of the file, and the top row of the image is the last row in the file. This is called a bottom-up organization. Because this organization is counterintuitive, you may ask why it’s done this way.

Well, it all goes back to the OS/2 Presentation Manager. Someone at IBM decided that all coordinate systems in PM—including those for windows, graphics, and bitmaps—should be consistent. This provoked a debate: Most people, including programmers who have worked with full-screen text programming or windowing environments, think in terms of vertical coordinates that increase going down the screen. However, hardcore computer graphics programmers approach the video display from a perspective that originates in the mathematics of analytic geometry. This involves a rectangular (or Cartesian) coordinate system where increasing vertical coordinates go up in space.

In short, the mathematicians won. Everything in PM was saddled with a bottom-left origin, including window coordinates. And that’s how DIBs came to be this way.

출처 :

https://kldp.org/node/154866

https://www-user.tu-chemnitz.de/~heha/petzold/ch15b.htm#bottoms%20Up

 

Tags: ,

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.