<blockquote>
  <p>Here's a quote from Petzold:</p>
  
  <blockquote>
    <p>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.</p>
    
    <p>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.</p>
    
    <p>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.</p>
  </blockquote>
  
  <p><strong>Source:</strong> Charles Petzold, <em>Programming for Windows 5th Edition</em>, Chapter
  15.</p>
</blockquote>

<p>from
<a href="https://stackoverflow.com/questions/8346115/why-are-bmps-stored-upside-down">https://stackoverflow.com/questions/8346115/why-are-bmps-stored-upside-down</a></p>

CC BY-SA 4.0
2019-05-28T02:32:01.300Z
2019-05-28T09:44:03.240Z
2019-05-28T09:44:03.240Z
daven11
<p>I'm studying Microsoft Windows Bitmap File Format, extension BMP.<br>
I'm curious to know why scanlines are stored on file from bottom to up: the last scanline on image is the first line on file and the first scanline on image is the last line on file.<br>
The documents that I have read do not explain it.</p>

CC BY-SA 4.0
2019-05-28T09:40:00.990Z
That...is entirely a matter of taste and how you define your image data layout. There is no universal "first" or "last". 50% of formats store them bottom-up and 50% top-down. The first line in the file *is* the first scanline because it's...the first scanline in the file's order. What you *could* argue is that Windows normally prefers a top-down coordinate system in the rest of its 2D operations (although, that's also largely configurable). In light of *that context* this layout might indeed seem unusual. But don't fall in the trap of thinking there's a universal order the file ought to have.
Christian Rau
<image>
Why BMP file format last line of image is first line on file?
alvalongo
# Why BMP file format last line of image is first line on file?

(Asked by: username_0 on 2019-05-27)

I'm studying Microsoft Windows Bitmap File Format, extension BMP.  
I'm curious to know why scanlines are stored on file from bottom to up: the last scanline on image is the first line on file and the first scanline on image is the last line on file.  
The documents that I have read do not explain it.

**Tags:** image

> **Comments:**
> **username_1**: That...is entirely a matter of taste and how you define your image data layout. There is no universal "first" or "last". 50% of formats store them bottom-up and 50% top-down. The first line in the file *is* the first scanline because it's...the first scanline in the file's order. What you *could* argue is that Windows normally prefers a top-down coordinate system in the rest of its 2D operations (although, that's also largely configurable). In light of *that context* this layout might indeed seem unusual. But don't fall in the trap of thinking there's a universal order the file ought to have.  

---

## 1 answers

### Answer by username_2 on 2019-05-28. Score: 7

> Here's a quote from Petzold:
>
> > 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.
>
> **Source:** Charles Petzold, *Programming for Windows 5th Edition*, Chapter
> 15.

from
<https://stackoverflow.com/questions/8346115/why-are-bmps-stored-upside-down>


---

