Skip to content

Updated AVIReader and AVIWriter to work on 64-bit systems. #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions Sources/Video.VFW/AVIReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace AForge.Video.VFW
using System.Drawing;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
using AForge;
using AForge.Video;

/// <summary>
/// AVI files reading using Video for Windows.
Expand Down Expand Up @@ -348,24 +348,30 @@ public Bitmap GetNextFrame( )
if ( bitmapInfoHeader.height > 0 )
{
// it`s a bottom-top image
int dst = imageData.Scan0.ToInt32( ) + dstStride * ( height - 1 );
int src = DIB.ToInt32( ) + Marshal.SizeOf( typeof( Win32.BITMAPINFOHEADER ) );
int dst = dstStride * ( height - 1 );
int src = Marshal.SizeOf( typeof( Win32.BITMAPINFOHEADER ) );

for ( int y = 0; y < height; y++ )
{
Win32.memcpy( dst, src, srcStride );
Win32.CopyMemory(
IntPtr.Add( imageData.Scan0, dst ),
IntPtr.Add( DIB, src ),
( uint )srcStride );

dst -= dstStride;
src += srcStride;
}
}
else
{
// it`s a top bootom image
int dst = imageData.Scan0.ToInt32( );
int src = DIB.ToInt32( ) + Marshal.SizeOf( typeof( Win32.BITMAPINFOHEADER ) );
int src = Marshal.SizeOf( typeof( Win32.BITMAPINFOHEADER ) );

// copy the whole image
Win32.memcpy( dst, src, srcStride * height );
Win32.CopyMemory(
imageData.Scan0,
IntPtr.Add( DIB, src ),
( uint )( srcStride * height ) );
}

// unlock bitmap data
Expand Down
9 changes: 6 additions & 3 deletions Sources/Video.VFW/AVIWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -402,12 +402,15 @@ public void AddFrame( Bitmap frameImage )
int srcStride = imageData.Stride;
int dstStride = stride;

int src = imageData.Scan0.ToInt32( ) + srcStride * ( height - 1 );
int dst = buffer.ToInt32( );
int src = srcStride * ( height - 1 );
int dst = 0;

for ( int y = 0; y < height; y++ )
{
Win32.memcpy( dst, src, dstStride );
Win32.CopyMemory(
IntPtr.Add( imageData.Scan0, dst ),
IntPtr.Add( buffer, src ),
( uint )dstStride );
dst += dstStride;
src -= srcStride;
}
Expand Down
10 changes: 3 additions & 7 deletions Sources/Video.VFW/Win32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,14 @@ internal static class Win32
/// Copy a block of memory.
/// </summary>
///
/// <param name="dst">Destination pointer.</param>
/// <param name="dest">Destination pointer.</param>
/// <param name="src">Source pointer.</param>
/// <param name="count">Memory block's length to copy.</param>
///
/// <returns>Return's the value of <b>dst</b> - pointer to destination.</returns>
///
[DllImport( "ntdll.dll", CallingConvention = CallingConvention.Cdecl )]
public static extern int memcpy(
int dst,
int src,
int count );

[DllImport("kernel32.dll", EntryPoint = "CopyMemory", SetLastError = false)]
public static extern void CopyMemory(IntPtr dest, IntPtr src, uint count);

// --- Video for Windows Functions

Expand Down