Windows는 DDB에 대해 어떤식으로 얼마나 메모리를 할당하는가?

gerran의 이미지

:?
Programming Windows -Charles Petzold- 의 chapter 14 page 775 한글판에서...

//////////////////////////////////////////////////////////////////////////////////
DDB 생성

HBITMAP bBitmap;

hBitmap = CreateBitmap(cx, cy, cPlanes, cBitPixel, bits);

DeleteObject(hBitmap);
//////////////////////////////////////////////////////////////////////////////////

ex)
hBitmap = CreateBitmap(7, 9, 5, 3, NULL);

이 함수가 호출되는 동안 Windows는 함수에 전달된 정보를 저장하고 픽셀 bit를 위한
메모리를 할당하는 작업을 수행합니다. 대충 계산해서 이 비트맵에는 7x9x5x3 즉, 945bit
(118byte)가 필요합니다.
*그러나 Windows가 비트맵의 메모리를 할당할 때, *각 픽셀의 행은
*짝수번째 byte를 갖게된다. 따라서 다음과 같은 계산이 나옵니다.
(--> 한글판은 짝수번째라고 되어 있으나 아마 영문판에는 2배가 아닐런지.. 저의 착각일
수도.. ^^)

어쨌든...
iWidthBytes = 2 * ((cx * cBitPixel + 15) / 16);
or
iWidthBytes = (cx * BitsPixel + 15) & ~15) >> 3;

따라서, DDB에 할당된 메모리는 다음과 같이 계산됩니다.

iBitmapBytes = cy * cPlanes * iWidthBytes;

이 예제에서 iWidthBytes는 4byte이고 iBitmapBytes는 180byte가 됩니다.

질문의 요지는!
*Windows는 왜 각 행에 대해 2배의 메모리를 할당할까요?

체스맨의 이미지

ex) hBitmap = CreateBitmap(7, 9, 5, 3, NULL);
질문 드리고 싶은게 위 예제가 그 책에 나와 있는 건가요?

라인당 2배가 아니라, 짝수번째 바이트라면 라인당 많아야
2바이트 미만이 더 할당된다는 얘깁니다.

DIB 는 4배수로 정렬하는 것으로 알고 있구요. 특정 배수로
주소를 정렬하는 것은 효율과 bus error 같은 메모리 오류를
피하기 때문인 이유가 가장 일반적이라고 봐야 겠죠.

Orion Project : http://orionids.org

charsyam의 이미지

일단 BMP 포맷의 경우 4배수로 정렬이 됩니다.

그리고 컬러에 따라서 256 컬러면

1byte 1컬러(실제로는 팔레트 인덱스, 팔레트는 RGB 값을 가짐)

16bit 컬러면 2byte 1컬러, 32bit면 3byte 1 컬러가 됩니다.

그럼 고운 하루.

=========================
CharSyam ^^ --- 고운 하루
=========================

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.