It is currently Tue Apr 07, 2020 9:50 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: [Thanks]:24to32, 32to24
PostPosted: Sat Feb 11, 2012 10:44 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon Jan 12, 2004 11:40 pm
Posts: 761
Location: Okazaki, JAPAN
I am advancing the optimization of the source code not depend in Win32API.
In the image data processing and the audio processing, it has the problem.
Very slow...

As for PureBasic, this processing cannot be done.
The processing of fastest is requested.

Could you create this tips?

Code:
Procedure Image32to24(Memory.l,ImageNumber.l)
  ; Very slow and Depend Win32API
  Protected TemporaryDC.l, TemporaryBitmap.BITMAP, TemporaryBitmapInfo.BITMAPINFO
 
  TemporaryDC = CreateDC_("DISPLAY", #Null, #Null, #Null)
 
  GetObject_(ImageID(ImageNumber), SizeOf(BITMAP), TemporaryBitmap.BITMAP)
 
  TemporaryBitmapInfo\bmiHeader\biSize        = SizeOf(BITMAPINFOHEADER)
  TemporaryBitmapInfo\bmiHeader\biWidth       = TemporaryBitmap\bmWidth
  TemporaryBitmapInfo\bmiHeader\biHeight      = -TemporaryBitmap\bmHeight
  TemporaryBitmapInfo\bmiHeader\biPlanes      = 1
  TemporaryBitmapInfo\bmiHeader\biBitCount    = 32
  TemporaryBitmapInfo\bmiHeader\biCompression = #BI_RGB
 
  SetDIBits_(TemporaryDC, ImageID(ImageNumber), 0, TemporaryBitmap\bmHeight, Memory, TemporaryBitmapInfo, #DIB_RGB_COLORS)
 
  DeleteDC_(TemporaryDC)
 
  ;/ Very Difficult  HELP ME !!!!
  ; Protected ImageW.l = ImageWidth(ImageNumber)
  ; Protected ImageH.l = ImageHeight(ImageNumber)
  ; Protected ImageSize.l = ImageW*3*ImageH
  ; Protected Color_from.l, Address.l=0
  ; For SP_Y=0 To ImageH -1
  ; For SP_X=0 To ImageW -1
  ; Color_from = PeekL(Memory+((SP_X+SP_Y*ImageW)*4))
  ; Color_from = Red(Color_from) <<16 + Green(Color_from) << 8 +Blue(Color_from)
  ; PokeBits(Memory+Address,0,24, Color_from)
  ; Address + 3
  ; Next
  ; Next
 
EndProcedure

Procedure Image24to32(Memory.l, ImageNumber.l, Rotate.b=0)
  ; Slow and but not depend Win32API
  Protected SP_X.l, SP_Y.l, Temp.l, Color_from.l
 
  StartDrawing(ImageOutput(ImageNumber))
    For SP_Y=0 To OutputHeight()-1
      For SP_X=0 To OutputWidth()-1
        If Rotate ; rotate 90
          Temp = ((OutputHeight()- SP_Y - 1) + (SP_X * OutputHeight())) << 2
        Else
          Temp = (SP_Y*OutputWidth()+ SP_X) << 2
        EndIf
        Color_from = Point(SP_X, SP_Y)
        Color_from = Red(Color_from)<<16 + Green(Color_from)<<8 + Blue(Color_from)
        PokeL(Memory+Temp, Color_from)
      Next
    Next
  StopDrawing()
EndProcedure

Procedure Poke24(Memory.l, 24data.l, BlockSize.l)
  ; need Audio application
  ; 32bit Wave Integer to 24 bit Wave Integer for format only
EndProcedure

Procedure Peek24(Memory.l, 32data.l,BlockSize.l)
  ; need Audio Application for future
  ; 24 bit Wave Integer to 32 bit Wave Integer for format only
EndProcedure

Global *Image24, *Image32

CreateImage(0, 6400, 4800, 24)
CreateImage(1, 6400, 4800. 32)
StartDrawing(ImageOutput(0))
  *Image24 = DrawingBuffer()
StopDrawing()
StartDrawing(ImageOutput(1)
  *Image32 = DrawingBuffer()
StopDrawing()

;/ I hope this call like.
Image24to32(0, *Image24, 1, *Image32)
Image32to24(1, *Image32, 0, *Image24)
Poke24(*AudioBuffer, *buffer, 2) ; Stereo
Peek24(*AudioBuffer, *buffer, 2) ; Stereo

End


Thank you.

_________________
My homepage in Japan - Bug head Nontallion
My facebook page.


Last edited by oryaaaaa on Mon Feb 27, 2012 4:40 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: 24to32, 32to24, Help me
PostPosted: Sat Feb 11, 2012 3:51 pm 
Offline
Addict
Addict
User avatar

Joined: Mon Jul 25, 2005 3:51 pm
Posts: 3649
Location: Utah, USA
I'm not sure if the codeyou posted for converting images is real or if it is just psuedo-code. The procedure's parameters don't match your examples.

Code:
;procedures and parameters declared as
Image32to24(Memory.l,ImageNumber.l)
Image24to32(Memory.l, ImageNumber.l, Rotate.b=0)

;example use
Image24to32(0, *Image24, 1, *Image32)
Image32to24(1, *Image32, 0, *Image24)


What should the parameters be?

_________________
Image


Top
 Profile  
Reply with quote  
 Post subject: Re: 24to32, 32to24, Help me
PostPosted: Sun Feb 12, 2012 9:44 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Aug 08, 2004 5:21 am
Posts: 3606
Location: Netherlands
Max value 24 bit int : 8388607
Max value 32 bit int : 2147483647

How do you want the 24 > 32 conversion ?

1. Keep the same number ( fast but if I'm correct the volume would be lower )
2. Multiply * 256 ( fast, max value 2147483392 [32 bit max value - 255] )
3. Multiply * 256.0000303984 ( slower, max value 2147483647 [32 bit max value] )


Top
 Profile  
Reply with quote  
 Post subject: Re: 24to32, 32to24, Help me
PostPosted: Mon Feb 13, 2012 1:04 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon Jan 12, 2004 11:40 pm
Posts: 761
Location: Okazaki, JAPAN
Sorry, I was busy.

For Image, I wrote code. Before I used follows code.
This tips is very slow. coz 8192x8192 imaging. I am creating photo print software.
In Future, 15000x1000 imaging will use at Digital still camera. then this tips don't use future.
DrawingBuffer used, 3x Speed up.
1. TIFF LOAD 32bit
2. GrabImage or DrawImage
3. SaveImage ..... Create dust image.
I add code at 2, DrawImage & $FFFFFF, Mask Process. 3 is OK. 32to24 need & $FFFFFF.
Maybe, Purebasic TIFF load and SaveImage Process Problem. Display is OK.
Code:
Procedure CopyImageToMemory(ImageNumber.l, Memory.l)
 
  Protected TemporaryDC.l, TemporaryBitmap.BITMAP, TemporaryBitmapInfo.BITMAPINFO
 
  TemporaryDC = CreateDC_("DISPLAY", #Null, #Null, #Null)
 
  GetObject_(ImageID(ImageNumber), SizeOf(BITMAP), TemporaryBitmap.BITMAP)
 
  TemporaryBitmapInfo\bmiHeader\biSize        = SizeOf(BITMAPINFOHEADER)
  TemporaryBitmapInfo\bmiHeader\biWidth       = TemporaryBitmap\bmWidth
  TemporaryBitmapInfo\bmiHeader\biHeight      = -TemporaryBitmap\bmHeight
  TemporaryBitmapInfo\bmiHeader\biPlanes      = 1
  TemporaryBitmapInfo\bmiHeader\biBitCount    = 32
  TemporaryBitmapInfo\bmiHeader\biCompression = #BI_RGB
 
  GetDIBits_(TemporaryDC, ImageID(ImageNumber), 0, TemporaryBitmap\bmHeight, Memory, TemporaryBitmapInfo, #DIB_RGB_COLORS)
 
  DeleteDC_(TemporaryDC)
 
EndProcedure

Procedure CopyImageToMemory2(ImageNumber.l, Memory.l)
  Shared PrinterDC
  Protected  TemporaryBitmap.BITMAP, TemporaryBitmapInfo.BITMAPINFO
   
  GetObject_(ImageID(ImageNumber), SizeOf(BITMAP), @TemporaryBitmap.BITMAP)
 
  TemporaryBitmapInfo\bmiHeader\biSize        = SizeOf(BITMAPINFOHEADER)
  TemporaryBitmapInfo\bmiHeader\biWidth       = TemporaryBitmap\bmWidth
  TemporaryBitmapInfo\bmiHeader\biHeight      = -TemporaryBitmap\bmHeight
  TemporaryBitmapInfo\bmiHeader\biPlanes      = 1
  TemporaryBitmapInfo\bmiHeader\biBitCount    = 32
  TemporaryBitmapInfo\bmiHeader\biCompression = #BI_RGB
  GetDIBits_(PrinterDC, ImageID(ImageNumber), 0, TemporaryBitmap\bmHeight, Memory, TemporaryBitmapInfo, #DIB_RGB_COLORS)
EndProcedure

Procedure CopyMemoryToImage(Memory.l,ImageNumber.l)
 
  Protected TemporaryDC.l, TemporaryBitmap.BITMAP, TemporaryBitmapInfo.BITMAPINFO
 
  TemporaryDC = CreateDC_("DISPLAY", #Null, #Null, #Null)
 
  GetObject_(ImageID(ImageNumber), SizeOf(BITMAP), TemporaryBitmap.BITMAP)
 
  TemporaryBitmapInfo\bmiHeader\biSize        = SizeOf(BITMAPINFOHEADER)
  TemporaryBitmapInfo\bmiHeader\biWidth       = TemporaryBitmap\bmWidth
  TemporaryBitmapInfo\bmiHeader\biHeight      = -TemporaryBitmap\bmHeight
  TemporaryBitmapInfo\bmiHeader\biPlanes      = 1
  TemporaryBitmapInfo\bmiHeader\biBitCount    = 32
  TemporaryBitmapInfo\bmiHeader\biCompression = #BI_RGB
 
  SetDIBits_(TemporaryDC, ImageID(ImageNumber), 0, TemporaryBitmap\bmHeight, Memory, TemporaryBitmapInfo, #DIB_RGB_COLORS)
 
  DeleteDC_(TemporaryDC)
 
EndProcedure


2. For Audio

I want to ALL way, If it is honest. CPU today can be sped up in the process in cpu cache.
The target of the software that I think about has CPU that is faster than Core2Duo.
SSE4.1 using is OK. Before my audio code.
Code:
Procedure.l Float32toInt32(*Float32, len.l)
  ; #Float32toInt24_LittleEdian = 1
  ; #Float32toInt24_BigEdian = 2
  Protected tmpIn.f, tmp.l ;, len2.l
  For i = 0 To len-1 Step 4
    tmpIn = PeekF(*Float32+i)
    tmpIn * $7FFFFFF0
    tmp = Int(tmpIn)
    PokeL(*Float32+i, tmp)
    ; If flg=#Float32toInt24_LittleEdian
    ; PokeA(*Int24 +len2 , ( tmp >> 8 )&$FF )
    ; PokeA(*Int24 +len2 +1, ( tmp >> 16 )&$FF )
    ; PokeA(*Int24 +len2 +2, ( tmp >> 24 )&$FF )
    ; len2 +3
    ; Else
    ; PokeA(*Int24 +len2 , ( tmp >> 24 )&$FF )
    ; PokeA(*Int24 +len2 +1, ( tmp >> 16 )&$FF )
    ; PokeA(*Int24 +len2 +2, ( tmp >>8 )&$FF )
    ; len2 +3
    ; EndIf 
  Next
  ; ;WriteData(10, *Int24, len2-8)
  ; Debug "LEN2>>"+Str(len2)
  ; Debug len*0.75+3
  ; ProcedureReturn len2
EndProcedure
 
; Procedure Float32toInt24(*in_buf, in_len.l, *out_buf)
  ; Protected Result.l
  ; !PXOR xmm5, xmm5 ; R
  ; !MOV Esi, $7FFFFFFF
  ; !MOVD xmm5, Esi
  ; !XOR Esi, Esi
  ; !XOR Edi, Edi
  ; !MOV Esi, [p.p_in_buf]
  ; !MOV Edi, [p.p_out_buf]
  ; For i=0 To in_len Step 4
    ; !XOR Ebx, Ebx
    ; !PXOR xmm0, xmm0 ; L
    ; !MOVSS xmm0, [Esi] ; L
    ; !ADD Esi,4
    ; !MULSS xmm0, xmm5
    ; !CVTSS2SI Ebx, xmm0
    ; !MOV [Edi], Ebx
    ; !ADD Edi, 3
  ; Next
  ; ; For i=0 To len Step 4
    ; ; Result = PeekF(*in_buf+i*4) * 8388607
    ; ; PokeA(*out_buf+i*3, (Result >> 16)&$FF)
    ; ; PokeA(*out_buf+i*3+1, (Result >> 8)&$FF)
    ; ; PokeA(*out_buf+i*3+2, Result&$FF)
  ; ; Next
; EndProcedure


The SINCE interpolations, I posted before are 32 bits Float.
I worried from the experience of making it using neither BASS nor FOOD
the audio processing because of processing that the bit conversion was
fatal and slow. The code in which CPU cache was used with
the MultiThreading was written. Moreover, the memory buffer of 200MB
or more was needed.

I need ...
Float32 to int24, int24 to Float32, int24 to int32, and int32 to int24.
and need in future
Float64 to int32, int24 to Float64, etc

His character was too bad though I had consulted the audio programmer in Japan.
He created most high quality audio player in the world at 2003. It's freeware.
In Time, KarlKox asissted me.
Here, SINC code. more fast.
http://karlkox.blogspot.com/2009/05/pro ... ie-de.html

But I did not understand it, coz very difficult.
resiult
KarlKox wrote:
Mais ces deux simples différences sont éloquentes :
- code PureBasic : 6520 ms en moyenne,
- code SSE2 : 170 ms en moyenne.


My audio souce code (I needed 4 month 24/7)
http://purebasic.coolverse.jp/_userdata/nr3.7z

It was pointed out it was higher than ten dollars when it tried to
set 1000 yen, and was rejected the license to FMOD.
$1 = 80 yen. but correct rate is $1= 130 yen, 1 euro = 150 yen.

BASS cannot be mastered by the error's of the memory processing
occurring easily. When 5000 lines are passed, it doesn't understand
even if the cause of the error passes one month.

I had failed very much before the support of KarlKox though
PortAudio was used easily. Now, Bug fixed.

then I used WaveOut only. Japanese resouces wrote about int16
and float32 only. I didn't know about int24.

The acquaintance of the highest audio consultation in Japan
told it to support Int24 last year. He worked USB-DAC design
about Styleaudio CARAT-Ruby, Topaz, Topaz signature.
The product of Topaz signature is the first customer satisfaction
measurement place in Japan.

If I will make new audio player, need int24 process.

_________________
My homepage in Japan - Bug head Nontallion
My facebook page.


Top
 Profile  
Reply with quote  
 Post subject: Re: 24to32, 32to24, Help me
PostPosted: Mon Feb 13, 2012 11:18 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Aug 08, 2004 5:21 am
Posts: 3606
Location: Netherlands
Try if this works for you
Code:
Procedure Float32ToInt24(*in_buf, *out_buf, num_samples)
 
  ; converts 2 samples at the same time so num_samples
  ; needs to be a multiple of 2.
 
  EnableASM
  !mov eax, 0x007fffff
  !cvtsi2sd xmm1, eax
  !movlhps xmm1, xmm1
  mov eax, *in_buf
  mov edx, *out_buf
  mov ecx, num_samples
  !shr ecx, 1
  !push ebx
  !flt32int24loop:
  !cvtps2pd xmm0, [eax]
  !mulpd xmm0, xmm1
  !cvtpd2dq xmm0, xmm0
  !movd [edx], xmm0
  !psrldq xmm0, 4
  !movd ebx, xmm0
  !mov word [edx + 3], bx
  !shr ebx, 16
  !mov byte [edx + 5], bl
  !add eax, 8
  !add edx, 6
  !dec ecx
  !jnz flt32int24loop
  !pop ebx
  DisableASM
EndProcedure

Procedure Int24ToFloat32(*in_buf, *out_buf, num_samples)
 
  ; converts 2 samples at the same time so num_samples
  ; needs to be a multiple of 2.
 
  EnableASM
  !mov eax, 1
  !cvtsi2sd xmm1, eax
  !mov eax, 0x007fffff
  !cvtsi2sd xmm0, eax
  !divsd xmm1, xmm0
  !movlhps xmm1, xmm1
  mov eax, *in_buf
  mov edx, *out_buf
  mov ecx, num_samples
  !shr ecx, 1
  !push ebx
  !int24flt32loop:
  !mov ebx, dword [eax + 2]
  !sar ebx, 8
  !cvtsi2sd xmm0, ebx
  !pslldq xmm0, 8
  !mov ebx, dword [eax]
  !shl ebx, 8
  !sar ebx, 8
  !cvtsi2sd xmm0, ebx
  !mulpd xmm0, xmm1
  !cvtpd2ps xmm0, xmm0
  !movlps [edx], xmm0
  !add eax, 6
  !add edx, 8
  !dec ecx
  !jnz int24flt32loop
  !pop ebx
  DisableASM 
EndProcedure

Procedure Float32ToInt32(*in_buf, *out_buf, num_samples)
 
  ; converts 2 samples at the same time so num_samples
  ; needs to be a multiple of 2.
 
  EnableASM
  !mov eax, 0x7fffffff
  !cvtsi2sd xmm1, eax
  !movlhps xmm1, xmm1
  mov eax, *in_buf
  mov edx, *out_buf
  mov ecx, num_samples
  !shr ecx, 1
  !flt32int32loop:
  !cvtps2pd xmm0, [eax]
  !mulpd xmm0, xmm1
  !cvtpd2dq xmm0, xmm0
  !movq [edx], xmm0
  !add eax, 8
  !add edx, 8
  !dec ecx
  !jnz flt32int32loop
  DisableASM
EndProcedure

Procedure Int32ToFloat32(*in_buf, *out_buf, num_samples)
 
  ; converts 2 samples at the same time so num_samples
  ; needs to be a multiple of 2.
 
  EnableASM
  !mov eax, 1
  !cvtsi2sd xmm1, eax
  !mov eax, 0x7fffffff
  !cvtsi2sd xmm0, eax
  !divsd xmm1, xmm0
  !movlhps xmm1, xmm1
  mov eax, *in_buf
  mov edx, *out_buf
  mov ecx, num_samples
  !shr ecx, 1
  !int32flt32loop:
  !cvtdq2pd xmm0, [eax]
  !mulpd xmm0, xmm1
  !cvtpd2ps xmm0, xmm0
  !movlps [edx], xmm0
  !add eax, 8
  !add edx, 8
  !dec ecx
  !jnz int32flt32loop
  DisableASM 
EndProcedure

Procedure Int24ToInt32(*in_buf, *out_buf, num_samples)
 
  ; converts 2 samples at the same time so num_samples
  ; needs to be a multiple of 2.
 
  EnableASM
  !mov eax, 0x7fffffff
  !cvtsi2sd xmm1, eax
  !mov eax, 0x007fffff
  !cvtsi2sd xmm0, eax
  !divsd xmm1, xmm0
  !movlhps xmm1, xmm1
  mov eax, *in_buf
  mov edx, *out_buf
  mov ecx, num_samples
  !shr ecx, 1
  !push ebx
  !int24int32loop:
  !mov ebx, dword [eax + 2]
  !sar ebx, 8
  !cvtsi2sd xmm0, ebx
  !pslldq xmm0, 8
  !mov ebx, dword [eax]
  !shl ebx, 8
  !sar ebx, 8
  !cvtsi2sd xmm0, ebx
  !mulpd xmm0, xmm1
  !cvtpd2dq xmm0, xmm0
  !movq [edx], xmm0
  !add eax, 6
  !add edx, 8
  !dec ecx
  !jnz int24int32loop
  !pop ebx
  DisableASM 
EndProcedure

Procedure Int32ToInt24(*in_buf, *out_buf, num_samples)
 
  ; converts 2 samples at the same time so num_samples
  ; needs to be a multiple of 2.
 
  EnableASM
  !mov eax, 0x007fffff
  !cvtsi2sd xmm1, eax
  !mov eax, 0x7fffffff
  !cvtsi2sd xmm0, eax
  !divsd xmm1, xmm0
  !movlhps xmm1, xmm1
  mov eax, *in_buf
  mov edx, *out_buf
  mov ecx, num_samples
  !shr ecx, 1
  !push ebx
  !int32int24loop:
  !cvtpi2pd xmm0, [eax]
  !mulpd xmm0, xmm1
  !cvtpd2dq xmm0, xmm0
  !movd [edx], xmm0
  !psrldq xmm0, 4
  !movd ebx, xmm0
  !mov word [edx + 3], bx
  !shr ebx, 16
  !mov byte [edx + 5], bl 
  !add eax, 8
  !add edx, 6
  !dec ecx
  !jnz int32int24loop
  !pop ebx
  DisableASM 
EndProcedure


Top
 Profile  
Reply with quote  
 Post subject: Re: 24to32, 32to24, Help me
PostPosted: Mon Feb 13, 2012 9:35 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon Jan 12, 2004 11:40 pm
Posts: 761
Location: Okazaki, JAPAN
Thank you. I will use it for your world. I think next audio project.
I sincerely appreciate for your kindness.

I did study your code. I think you are really cool.
http://camera.coolverse.jp/_src/sc208/camera01.gif

_________________
My homepage in Japan - Bug head Nontallion
My facebook page.


Top
 Profile  
Reply with quote  
 Post subject: Re: 24to32, 32to24, Help me
PostPosted: Sun Feb 26, 2012 5:21 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon Jan 12, 2004 11:40 pm
Posts: 761
Location: Okazaki, JAPAN
hello.

very difficult. could you help me? <Coding question>
viewtopic.php?f=13&t=49216

Original Code
viewtopic.php?f=12&t=49059

Thank you

_________________
My homepage in Japan - Bug head Nontallion
My facebook page.


Top
 Profile  
Reply with quote  
 Post subject: Re: [Thanks]:24to32, 32to24
PostPosted: Mon Feb 27, 2012 4:44 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon Jan 12, 2004 11:40 pm
Posts: 761
Location: Okazaki, JAPAN
Thanks All.

This method has quickened x4 than WIn32API.

FIXED "EBX to BX"
Code:
Procedure Int24ToInt32(*in_buf, *out_buf, num_samples.l)
  !MOV Eax, [p.p_in_buf]
  !MOV Edx, [p.p_out_buf]
  !MOV Ecx, [p.v_num_samples]
  !PUSH Ebx
  !int24int32loop:
  !MOV bx, [Eax]
  !MOV byte [Edx], bl
  !MOV byte [Edx+1], bh
  !MOV bx, [Eax+1]
  !MOV byte [Edx+2], bh
  !MOV byte [Edx+3], 0xFF
  !ADD Eax, 3
  !ADD Edx, 4
  !DEC Ecx
  !JNZ int24int32loop
  !POP Ebx
EndProcedure
 
; CreateImage(#TemporaryImage, ImageWidth(#Image), ImageHeight(#Image), 32)
; StartDrawing(ImageOutput(#Image))
  ; V_art\Buffer = DrawingBuffer()
  ; V_art\width  = OutputWidth()
  ; V_art\height = OutputHeight()
; StopDrawing()
; StartDrawing(ImageOutput(#TemporaryImage))
  ; V_tmp\Buffer = DrawingBuffer()
  ; V_tmp\width  = V_art\width
  ; V_tmp\height = V_art\height
; StopDrawing()
; IsImage(#TemporaryImage)
    ; ;
; add1 = V_art\width*3 +V_art\width%4 : add2 = V_art\width*4
; For Y=0 To V_art\height -1
  ; Int24ToInt32(V_art\Buffer, V_tmp\Buffer, V_art\width) 
  ; V_art\Buffer + add1 :  V_tmp\Buffer + add2
; Next

Procedure Int32ToInt24(*in_buf, *out_buf, num_samples.l)
  !MOV Eax, [p.p_in_buf]
  !MOV Edx, [p.p_out_buf]
  !MOV Ecx, [p.v_num_samples]
  !PUSH Ebx
  !int32int24loop:
  !MOV bx, [Eax]
  !MOV byte [Edx], bl
  !MOV byte [Edx+1], bh
  !MOV bx, [Eax+1]
  !MOV byte [Edx+2], bh
  !ADD Eax, 4
  !ADD Edx, 3
  !DEC Ecx
  !JNZ int32int24loop
  !POP Ebx
EndProcedure

; CreateImage(#TemporaryImage, ImageWa, ImageHa, 24)
; StartDrawing(ImageOutput(#TemporaryImage))
  ; V_art\Buffer = DrawingBuffer()
  ; V_art\width  = ImageWa
  ; V_art\height = ImageHa
; StopDrawing()
; StartDrawing(ImageOutput(#Vpre))
  ; V_tmp\Buffer = DrawingBuffer()
  ; V_tmp\width  = ImageWidth(#Vpre)
  ; V_tmp\height = ImageHeight(#Vpre)
; StopDrawing()
; tmp_i = 0 : tmp_o = 0 : add2 = V_tmp\width*3+V_tmp\width%4 :add1 = V_tmp\width*4
; For Y=0 To V_tmp\height -1
  ; Int32ToInt24(V_tmp\Buffer+tmp_i, V_art\Buffer+tmp_o, V_tmp\width)   
  ; tmp_i +  add1 : tmp_o + add2
; Next
; FreeImage(#Vpre) : ResizeImage(#TemporaryImage, ImageW, ImageH)
; CopyImage(#TemporaryImage, #Vpre)
; FreeImage(#TemporaryImage)

_________________
My homepage in Japan - Bug head Nontallion
My facebook page.


Last edited by oryaaaaa on Mon Feb 27, 2012 9:32 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: [Thanks]:24to32, 32to24
PostPosted: Mon Feb 27, 2012 6:27 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Aug 08, 2004 5:21 am
Posts: 3606
Location: Netherlands
Wouldn't it be faster to store a dword at once instead of using bytes ?
Something like this ...
Code:
Procedure RGBA2RGB(*in_buf, *out_buf, num_pixels)
  EnableASM
  mov eax, *in_buf
  mov edx, *out_buf
  mov ecx, num_pixels
  !push ebx
  !jmp rgba2rgb_entry
  !rgba2rgb_loop:
  !mov ebx, [eax]
  !mov [edx], ebx
  !add eax, 4
  !add edx, 3
  !rgba2rgb_entry:
  !dec ecx
  !jnz rgba2rgb_loop
  !mov ebx, [eax]
  !mov [edx], bx
  !shr bx, 16
  !mov [edx + 2], bl
  !pop ebx
  DisableASM   
EndProcedure

Procedure RGB2RGBA(*in_buf, *out_buf, num_pixels)
  EnableASM
  mov eax, *in_buf
  mov edx, *out_buf
  mov ecx, num_pixels
  !push ebx
  !jmp rgb2rgba_entry
  !rgb2rgba_loop:
  !mov ebx, [eax]
  !or ebx, 0xff000000
  !mov [edx], ebx
  !add eax, 3
  !add edx, 4
  !rgb2rgba_entry:
  !dec ecx
  !jnz rgb2rgba_loop
  !mov bh, 0xff
  !mov bl, [eax + 2]
  !shl ebx, 16
  !mov bx, [eax]
  !mov [edx], ebx
  !pop ebx
  DisableASM   
EndProcedure

I haven't checked the speed so I'm not sure if it is really faster.


Top
 Profile  
Reply with quote  
 Post subject: Re: [Thanks]:24to32, 32to24
PostPosted: Mon Feb 27, 2012 9:57 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon Jan 12, 2004 11:40 pm
Posts: 761
Location: Okazaki, JAPAN
Thank you.

coz I simply dislike debugging of the assembler.
24bit Image .... ImageWith*3 + ImageWith%4 (1 line)

_________________
My homepage in Japan - Bug head Nontallion
My facebook page.


Top
 Profile  
Reply with quote  
 Post subject: Re: [Thanks]:24to32, 32to24
PostPosted: Mon Feb 27, 2012 10:04 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Aug 08, 2004 5:21 am
Posts: 3606
Location: Netherlands
It would be possible to create a ASM function with an extra line_width parameter so the asm code can realign each line for you.
The fastest way probably is to use 32 bit color values for everything in your program.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye