News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Back to drawing huge bitmaps

Started by minor28, August 25, 2010, 08:27:23 AM

Previous topic - Next topic

minor28

This is a continuation of my previous post and post.

My bitmaps are seacharts with sizes in general of 15000x10000 pixels compressed to ~5MB (*.kap files). Saved as an uncompressed bitmap ~120 MB.

I have three methods to read from the file on HDD.

  • Reading byte by byte and processing each byte before reading next byte saving the processed data in allocated pixel memory. When done drawing the image. This method takes a considerable time. (I haven't succeeded to measure the time). About 10 seconds.
  • Read whole file to a temporary allocated memory. Process each byte from memory saving in pixel memory. When done drawing the image. This method is faster and almost acceptable.
  • Alternating read and write with events and threads. The header data on disk is about 5000 bytes. Easy to read write with 7 events and 4 threads. However this will not have any marked effect on the read/write time. Now I have been struggling to alternating read/write of pixel data.

Last method: Read to first temp memory and write to pixeldata memory. Read again to second temp memory and write to same pixeldata memory. And so on. I have tryed different methods of events and threads. The best I have succeeded is reading writing two times then crash. The last doesn't paint the image.

Any suggesten how I could solve this.


bsbChart3 proc
LOCAL ThreadID:dword

mov rowIndex,0
mov memout,0
invoke crt_fopen,offset szFileName,ASTR("rb")
.if eax!=0
mov pFile,eax
lea edi,pMems
;Temporary memory1
invoke HeapAlloc,hHeap,HEAP_ZERO_MEMORY,TEMPSIZE
mov dword ptr [edi],eax
;Temporary memory2
invoke HeapAlloc,hHeap,HEAP_ZERO_MEMORY,TEMPSIZE
mov dword ptr [edi+4],eax

invoke CreateEvent,0,FALSE,FALSE,0
mov hRead1Event,eax
invoke CreateEvent,0,FALSE,TRUE,0
mov hRead2Event,eax
invoke CreateEvent,0,FALSE,FALSE,0
mov hWrite1Event,eax
invoke CreateEvent,0,FALSE,TRUE,0
mov hWrite2Event,eax

invoke CreateThread,0,0,offset Write1Thread,dword ptr [edi],0,addr ThreadID
invoke CloseHandle,eax

invoke CreateThread,0,0,offset Write2Thread,dword ptr [edi+4],0,addr ThreadID
invoke CloseHandle,eax

lea edi,hWriteEvents
mov eax,hWrite1Event
mov dword ptr [edi],eax
mov eax,hWrite2Event
mov dword ptr [edi+4],eax
invoke WaitForMultipleObjects,2,offset hWriteEvents,TRUE,INFINITE

invoke SetEvent,hPaint2Event ;Ready to run Paint (1 of 2)
invoke crt_fclose,pFile
invoke HeapFree,hHeap,HEAP_NO_SERIALIZE,dword ptr [edi]
invoke HeapFree,hHeap,HEAP_NO_SERIALIZE,dword ptr [edi+4]
.endif
ret
   
bsbChart3 endp



Write1Thread proc lParam
mov eax,bsbH
cmp eax,rowIndex
je @F ;All rows processed?

invoke WaitForSingleObject,hRead2Event,INFINITE
.if eax==0
invoke Read,lParam
;save data for Write1 before next read will change them
push readstart
push rowsread
push prevIndex
pop prevIndex1
pop rowsread1
pop readstart1
invoke SetEvent,hRead1Event ;Read finished
.endif

invoke WaitForSingleObject,hWrite2Event,INFINITE
.if eax==0
invoke Write1,lParam
invoke SetEvent,hWrite1Event ;Write1 finished
.endif
jmp Write1Thread

@@: ret

Write1Thread endp



Write2Thread proc lParam
mov eax,bsbH
cmp eax,rowIndex
je @F ;All rows processed?

invoke WaitForSingleObject,hRead1Event,INFINITE
.if eax==0
;save data for Write1 before next read will change them
push readstart
push rowsread
push prevIndex
pop prevIndex2
pop rowsread2
pop readstart2
invoke Read,lParam
invoke SetEvent,hRead2Event ;Read finised
.endif

invoke WaitForSingleObject,hWrite1Event,INFINITE
.if eax==0
invoke Write2,lParam
invoke SetEvent,hWrite2Event ;Write2 finished
.endif
jmp Write2Thread

@@: ret

Write2Thread endp


I will post the project when I have a function app.

Best regards

minor28

Now I have a version that paints the chart but chrashes "First-chance exception". I cannot trace the error. Can anyone else do that. I attach the project. You can download kap-file here.

dedndave

error c0000005 - priviledge exception
that means you are addressing memory that isn't yours
i usually get this exception after a function fails, but i did not verify success

sometimes, GetLastError is your friend   :bg

MichaelW

I think that should be access violation exception.

//
// MessageId: STATUS_ACCESS_VIOLATION
//
// MessageText:
//
//  The instruction at "0x%08lx" referenced memory at "0x%08lx". The memory could not be "%s".
//
#define STATUS_ACCESS_VIOLATION          ((NTSTATUS)0xC0000005L)    // winnt
eschew obfuscation

dedndave

my bad   :P
you'd think i would know - i have seen it a thousand times - lol

minor28

At last this version works. Counting tickcount: ~560 ms. If you read whole chart and then write it will take ~700 ms. The values vary a lot.

To read and write header takes about 50 ms, reading bsb bytes ~250 ms and writing bmp pixels ~500 ms.

Any idea how to speed upp this.

minor28

I don't need the hWrite1Event and hWrite2Event. This will speed up the app to about 400 ms. This version has also turned right side up of the image.