Assembly 如何绘制位图

Assembly 如何绘制位图,assembly,graphics,bitmap,Assembly,Graphics,Bitmap,我有在ASM文件中绘制像素的功能。现在我有了所有位图的像素。但是我怎么画呢?我试着每像素绘制一个像素,但BMP文件有120000个像素,分辨率要求160000。如何绘制位图?(这是24位位图,但我想画所有图像)什么是填充物-Vesa颜色与此类似吗? 多谢各位 编辑: 好的-我的BMP没有填充字节-因此我删除了dword对齐,它可以工作。。。如何确定BMP何时具有dword对齐 如何确定BMP何时具有dword对齐 BMP文件(DIB)中的扫描线应始终以DWORD对齐,除非图像使用RLE压缩(例如

我有在ASM文件中绘制像素的功能。现在我有了所有位图的像素。但是我怎么画呢?我试着每像素绘制一个像素,但BMP文件有120000个像素,分辨率要求160000。如何绘制位图?(这是24位位图,但我想画所有图像)什么是填充物-Vesa颜色与此类似吗? 多谢各位

编辑:

好的-我的BMP没有填充字节-因此我删除了dword对齐,它可以工作。。。如何确定BMP何时具有dword对齐

如何确定BMP何时具有dword对齐

BMP文件(DIB)中的扫描线应始终以DWORD对齐,除非图像使用RLE压缩(例如,请参见本手册最后一段)

可以按如下方式计算每条扫描线的DWORD数:

dwords = (int)(((biBitCount * biWidth) + 31) / 32);

(注意:如果
bibibitcount==15
则应使用16)。

好-此代码运行良好-仅缺少16位BMP-正在处理中

DrawImage:

    cmp word [ID], "BM"
    je DrawBMP

    ret

DrawBMP:

    cmp word [Depth], 24
    je DrawBMP24

    cmp word [Depth], 32
    je DrawBMP32

    ret

DrawBMP24:

    pushad
    mov [.X], eax
    mov [.Y], ebx
    mov [.x], eax
    mov [.y], ebx

    xor edx, edx
    mov [.align], edx
    mov ebx, 4

    mov eax, [Width]
    div ebx
    cmp edx, 0
    je .skip

    mov dword [.align], 1
    xor edx, edx

    mov eax, [Width]
    inc eax
    div ebx
    cmp edx, 0
    je .skip

    mov dword [.align], 2
    xor edx, edx

    mov eax, [Width]
    add eax, 2
    div ebx
    cmp edx, 0
    je .skip

    mov dword [.align], 3

.skip:

    mov esi, BMP
    add esi, [Offset]
    mov [.pointer], esi
    mov ebx, [Height]
    add [.y], ebx

.drawLine:

    mov esi, [.pointer]
    mov al, [esi]
    mov [.color], al
    mov al, [esi + 1]
    mov [.color + 1], al
    mov al, [esi + 2]
    mov [.color + 2], al
    add dword [.pointer], 3

    mov esi, .params
    call DrawPixel

    inc dword [.x]
    mov ebx, [Width]
    add ebx, [.X]
    cmp [.x], ebx
    jne .drawLine

    mov ebx, [.X]
    mov [.x], ebx
    dec dword [.y]

    mov ebx, [.pointer]
    add ebx, [.align]
    mov [.pointer], ebx

    mov ebx, [.Y]
    cmp [.y], ebx
    je .done

    jmp short .drawLine

.done:

    mov dword [.y], 0
    popad
    ret

.X dd 0
.Y dd 0
.align dd 0
.pointer dd 0

.params:

    .color dd 0
    .x dd 0
    .y dd 0

DrawBMP32:

    pushad
    mov [.X], eax
    mov [.Y], ebx
    mov [.x], eax
    mov [.y], ebx
    mov esi, BMP
    add esi, [Offset]
    mov [.pointer], esi
    mov ebx, [Height]
    add [.y], ebx

.drawLine:

    mov esi, [.pointer]
    mov eax, [esi]
    mov [.color], eax
    add dword [.pointer], 4

    mov esi, .params
    call DrawPixel

    inc dword [.x]
    mov ebx, [Width]
    add ebx, [.X]
    cmp [.x], ebx
    jne .drawLine

    mov ebx, [.X]
    mov [.x], ebx
    dec dword [.y]

    mov ebx, [.Y]
    cmp [.y], ebx
    je .done

    jmp short .drawLine

.done:

    mov dword [.y], 0
    popad
    ret

.X dd 0
.Y dd 0
.pointer dd 0
.params:

    .color dd 0
    .x dd 0
    .y dd 0
VESA(VBR)在这里:


您还没有指定要针对哪个操作系统、图形API和/或图形模式。为什么?我的问题很笼统。。。我只有一个问题:我如何确定BMP何时具有dword对齐?这里:1字节填充符这里:24位BMP中的两字节对齐。我的图像没有任何对齐。。。现在我在没有对齐的情况下画图,效果很好…你也在问如何画位图。但是每像素像素像素-在Vesa中…但这是问题-我的标题:42 4D 7A 53 07 00 00 00 00 7A 00 00 00 00 00 00 00 6C 00 00 00 00 00 00 00 90 01 00 00 90 01 00 00 00 00 00 00 00 01 00 18 00 00 00 00 00 00 00 00 00 53 07 00 13 00 00 00 00 00 00 13 00 00 00 00 13 00 00 00 00 00 00 00 00 00 00 00 00 00 13 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00?我无法读取hextump,因为我没有记住标题布局。压缩信息为零-因此它没有任何压缩。但它没有dword对齐。。。这张图片是从GIMP生成的。这张图片不是400像素宽吗?如果是这样,扫描线已经是双字对齐的,因为400*3==1200是4的倍数。因此不需要填充。但是-为什么所有像素上都有dword对齐?36h 3 00 FF 0 0 255红色,像素(0,1)39h 3 FF FF 255白色,像素(1,1)3Ch 2 00 00 0填充用于4字节对齐(可以是非零值)3Eh 3 FF 00 255 0蓝色,像素(0,0)41h 3 00 FF 0 255 0绿色,像素(1,0)44h 2 00 0 0填充用于4字节对齐(可以是非零值)这是个坏主意-任何分辨率都可以乘以3。。。(3种颜色-3字节…)
bits 16
org 0x7C00

Boot:

    mov dl, 0x80            ; 80 - FF => HardDisk
    mov si, .imageStruct
    mov cx, 14

.loadPart:

    mov ah, 0x42            ; Extended Read Sectors From Drive
    int 0x13

    add dword [.imageStruct + 6], 2144
    add word [.imageStruct + 8], 67

loop .loadPart

    mov ah, 0x42
    mov si, .kernelStruct
    int 0x13

    jnc InitializeVESA

    mov si, .error
    mov ah, 0xE
    mov cx, 29

.writeChar:

    lodsb
    int 0x10
    loop .writeChar

    mov ah, 0
    int 0x16                ; Wait for keystroke
    mov ax, 0
    int 0x19                ; Reboot the system

.imageStruct:

    dw 16
    dw 67
    dd BMP              ; Offset : Segment
    dq 26

.kernelStruct:

    dw 16               ; byte of structure length + empty byte
    dw sectorsForLoad       ; sectors for load count
    dd Kernel               ; out address
    dq 1                    ; start sector

.error db "Fatal Error! Press any key..."

InitializeVESA:

    in al, 0x92
    or al, 2
    out 0x92, al

    mov bx, 0x4118
    mov ax, 0x4F01
    mov di, ModeInfo
    mov cx, bx
    int 0x10

    mov ax, 0x4F02
    int 0x10

    cli
    lgdt [.GDTR]

    mov eax, cr0
    or al, 1
    mov cr0, eax

; CR0: PG|----RESERVED----|NE|ET|TS|EM|MP|PE
; PE Bit 0. The Protected Environment flag. This flag puts the system into protected mode when set.
; MP Bit 1. The Monitor Coprocessor flag. This flag controls the operation of the "WAIT" instruction.
; EM Bit 2. The Emulate flag. When this flag is set, coprocessor instructions will generate an exception.
; TS Bit 3. The Task Switched flag. This flag is set automatically when the processor switches to a new task.
; ET Bit 4. The Extension Type flag. ET (also called "R") tells us which type of coprocessor is installed. If ET = 0, an 80287 is installed. if ET = 1, an 80387 is installed.
; NE Bit 5. New exceptions. If this flag is clear, FPU exceptions arrive as interrupts. If set, as exceptions.
; PG Bit 31. The Paging flag. When this flag is set, memory paging is enabled. We will talk more about that in a second.

    mov ax, 0x8
    mov ds, ax
    mov es, ax
    mov ss, ax

    jmp 0x10:Kernel

.GDT dq 0, 0xCF92000000FFFF, 0xCF98000000FFFF

; Selector 0x00 cannot be used | 0x10 will be our code | 0x08 will be our data

.GDTR:

    dw 0x1F
    dd .GDT

times 510-($-$$) db 0
dw 0xAA55

%include "source/kernel/SMA.asm"
%include "source/kernel/features/Drawing.asm"
%include "source/kernel/features/Console.asm"
%include "source/kernel/features/Keyboard.asm"
%include "source/kernel/features/KeyMap.inc"
%include "source/kernel/features/Int.asm"
%include "source/kernel/features/String.asm"

times 512 - (($-$$) % 512) db 0
sectorsForLoad equ ($-$$-512) / 512

section .bss

ModeInfo:

    ModeAttributes resw 1
    WinAAttributes resb 1
    WinBAttributes resb 1
    WinGranularity resw 1
    WinSize resw 1
    WinASegment resw 1
    WinBSegment resw 1
    WinFuncPtr resd 1
    BytesPerScanLine resw 1
    ScreenWidth resw 1
    ScreenHeight resw 1
    XCharSize resb 1
    YCharSize resb 1
    NumberOfPlanes resb 1
    BitsPerPixel resb 1
    NumberOfBanks resb 1
    MemoryModel resb 1
    BankSize resb 1
    NumberOfImagePages resb 1
    ReservedPage resb 1
    RedMaskSize resb 1
    RedMaskPos resb 1
    GreenMaskSize resb 1
    GreenMaskPos resb 1
    BlueMaskSize resb 1
    BlueMaskPos resb 1
    ReservedMaskSize resb 1
    ReservedMaskPos resb 1
    DirectColorModeInfo resb 1
    ; VBE 2.0 extensions
    PhysBasePtr resd 1
    OffScreenMemOffset resd 1
    OffScreenMemSize resw 1

resb 206 ; Odsazení od ModeInfo

BMP:

    ID resw 1
    FileSize resd 1
    Reserved1 resb 1
    Reserved2 resb 1
    Reserved3 resb 1
    Reserved4 resb 1
    Offset resd 1
    HeaderLength resd 1
    Width resd 1
    Height resd 1
    NumOfPlanes resw 1
    Depth resw 1
    Compression resd 1
    BytesCount resd 1
    Hresolution resd 1
    Xresolution resd 1
    NumOfUsedColors resd 1
    NumOfImportantColors resd 1