2 * common.cpp -- Blackmagic Design DeckLink common functions
3 * Copyright (C) 2012 Dan Dennedy <dan@dennedy.org>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with consumer library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 char* getCString( DLString aDLString )
28 char* CString = (char*) malloc( 64 );
29 CFStringGetCString( aDLString, CString, 64, kCFStringEncodingMacRoman );
33 void freeCString( char* aCString )
35 if ( aCString ) free( aCString );
38 void freeDLString( DLString aDLString )
40 if ( aDLString ) CFRelease( aDLString );
45 char* getCString( DLString aDLString )
50 int size = WideCharToMultiByte( CP_UTF8, 0, aDLString, -1, NULL, 0, NULL, NULL );
53 CString = new char[ size ];
54 size = WideCharToMultiByte( CP_UTF8, 0, aDLString, -1, CString, size, NULL, NULL );
65 void freeCString( char* aCString )
70 void freeDLString( DLString aDLString )
72 if ( aDLString ) free( (void*) aDLString );
77 char* getCString( DLString aDLString )
79 return aDLString? (char*) aDLString : NULL;
82 void freeCString( char* aCString )
86 void freeDLString( DLString aDLString )
88 if ( aDLString ) free( (void*) aDLString );
94 void swab2( const void *from, void *to, int n )
103 "movdqa 0(%[from]), %%xmm0 \n\t"
104 "add $0x10, %[from] \n\t"
106 /* duplicate to temp registers */
107 "movdqa %%xmm0, %%xmm1 \n\t"
109 /* shift right temp register */
110 "psrlw $8, %%xmm1 \n\t"
112 /* shift left main register */
113 "psllw $8, %%xmm0 \n\t"
115 /* compose them back */
116 "por %%xmm0, %%xmm1 \n\t"
119 "movdqa %%xmm1, 0(%[to]) \n\t"
120 "add $0x10, %[to] \n\t"
123 "jnz loop_start \n\t"
126 : [from]"r"(from), [to]"r"(to), [cnt]"r"(n / SWAB_STEP)
130 from = (unsigned char*) from + n - (n % SWAB_STEP);
131 to = (unsigned char*) to + n - (n % SWAB_STEP);