Commit 58d2349d authored by Fiona Glaser's avatar Fiona Glaser

Massive cosmetic and syntax cleanup

Convert all applicable loops to use C99 loop index syntax.
Clean up most inconsistent syntax in ratecontrol.c, visualize, ppc, etc.
Replace log(x)/log(2) constructs with log2, and similar with log10.
Fix all -Wshadow violations.
Fix visualize support.
parent 3b31b6cd
......@@ -787,21 +787,14 @@ const uint16_t x264_cabac_entropy[128][2] =
void x264_cabac_context_init( x264_cabac_t *cb, int i_slice_type, int i_qp, int i_model )
{
const int8_t (*cabac_context_init)[460][2];
int i;
if( i_slice_type == SLICE_TYPE_I )
{
cabac_context_init = &x264_cabac_context_init_I;
}
else
{
cabac_context_init = &x264_cabac_context_init_PB[i_model];
}
for( i = 0; i < 460; i++ )
{
for( int i = 0; i < 460; i++ )
cb->state[i] = x264_clip3( (((*cabac_context_init)[i][0] * i_qp) >> 4) + (*cabac_context_init)[i][1], 1, 126 );
}
}
void x264_cabac_encode_init( x264_cabac_t *cb, uint8_t *p_data, uint8_t *p_end )
......@@ -824,9 +817,7 @@ static inline void x264_cabac_putbyte( x264_cabac_t *cb )
cb->i_queue -= 8;
if( (out & 0xff) == 0xff )
{
cb->i_bytes_outstanding++;
}
else
{
int carry = out >> 8;
......@@ -886,10 +877,9 @@ void x264_cabac_encode_bypass( x264_cabac_t *cb, int b )
void x264_cabac_encode_ue_bypass( x264_cabac_t *cb, int exp_bits, int val )
{
int k, i;
uint32_t x;
for( k = exp_bits; val >= (1<<k); k++ )
val -= 1<<k;
x = (((1<<(k-exp_bits))-1)<<(k+1))+val;
uint32_t x = (((1<<(k-exp_bits))-1)<<(k+1))+val;
k = 2*k+1-exp_bits;
i = ((k-1)&7)+1;
do {
......
......@@ -451,8 +451,7 @@ int x264_param_apply_profile( x264_param_t *param, const char *profile )
static int parse_enum( const char *arg, const char * const *names, int *dst )
{
int i;
for( i = 0; names[i]; i++ )
for( int i = 0; names[i]; i++ )
if( !strcmp( arg, names[i] ) )
{
*dst = i;
......@@ -527,10 +526,10 @@ int x264_param_parse( x264_param_t *p, const char *name, const char *value )
if( strchr( name, '_' ) ) // s/_/-/g
{
char *p;
char *c;
name_buf = strdup(name);
while( (p = strchr( name_buf, '_' )) )
*p = '-';
while( (c = strchr( name_buf, '_' )) )
*c = '-';
name = name_buf;
}
......@@ -892,9 +891,9 @@ int x264_param_parse( x264_param_t *p, const char *name, const char *value )
p->rc.f_aq_strength = atof(value);
OPT("pass")
{
int i = x264_clip3( atoi(value), 0, 3 );
p->rc.b_stat_write = i & 1;
p->rc.b_stat_read = i & 2;
int pass = x264_clip3( atoi(value), 0, 3 );
p->rc.b_stat_write = pass & 1;
p->rc.b_stat_read = pass & 2;
}
OPT("stats")
{
......
......@@ -165,8 +165,8 @@ static ALWAYS_INLINE void x264_median_mv( int16_t *dst, int16_t *a, int16_t *b,
static ALWAYS_INLINE int x264_predictor_difference( int16_t (*mvc)[2], intptr_t i_mvc )
{
int sum = 0, i;
for( i = 0; i < i_mvc-1; i++ )
int sum = 0;
for( int i = 0; i < i_mvc-1; i++ )
{
sum += abs( mvc[i][0] - mvc[i+1][0] )
+ abs( mvc[i][1] - mvc[i+1][1] );
......
......@@ -167,7 +167,7 @@ uint32_t x264_cpu_detect( void )
/* 6/9 (pentium-m "banias"), 6/13 (pentium-m "dothan"), and 6/14 (core1 "yonah")
* theoretically support sse2, but it's significantly slower than mmx for
* almost all of x264's functions, so let's just pretend they don't. */
if( family==6 && (model==9 || model==13 || model==14) )
if( family == 6 && (model == 9 || model == 13 || model == 14) )
{
cpu &= ~(X264_CPU_SSE2|X264_CPU_SSE3);
assert(!(cpu&(X264_CPU_SSSE3|X264_CPU_SSE4)));
......@@ -188,14 +188,15 @@ uint32_t x264_cpu_detect( void )
{
// Cache and TLB Information
static const char cache32_ids[] = { 0x0a, 0x0c, 0x41, 0x42, 0x43, 0x44, 0x45, 0x82, 0x83, 0x84, 0x85, 0 };
static const char cache64_ids[] = { 0x22, 0x23, 0x25, 0x29, 0x2c, 0x46, 0x47, 0x49, 0x60, 0x66, 0x67, 0x68, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7c, 0x7f, 0x86, 0x87, 0 };
static const char cache64_ids[] = { 0x22, 0x23, 0x25, 0x29, 0x2c, 0x46, 0x47, 0x49, 0x60, 0x66, 0x67,
0x68, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7c, 0x7f, 0x86, 0x87, 0 };
uint32_t buf[4];
int max, i=0, j;
int max, i = 0;
do {
x264_cpu_cpuid( 2, buf+0, buf+1, buf+2, buf+3 );
max = buf[0]&0xff;
buf[0] &= ~0xff;
for(j=0; j<4; j++)
for( int j = 0; j < 4; j++ )
if( !(buf[j]>>31) )
while( buf[j] )
{
......@@ -241,9 +242,7 @@ uint32_t x264_cpu_detect( void )
int error = sysctl( selectors, 2, &has_altivec, &length, NULL, 0 );
if( error == 0 && has_altivec != 0 )
{
cpu |= X264_CPU_ALTIVEC;
}
return cpu;
}
......@@ -252,7 +251,7 @@ uint32_t x264_cpu_detect( void )
uint32_t x264_cpu_detect( void )
{
static void (* oldsig)( int );
static void (*oldsig)( int );
oldsig = signal( SIGILL, sigill_handler );
if( sigsetjmp( jmpbuf, 1 ) )
......
......@@ -38,16 +38,13 @@ int x264_dct8_weight2_zigzag[2][64];
static void dct4x4dc( int16_t d[16] )
{
int16_t tmp[16];
int s01, s23;
int d01, d23;
int i;
for( i = 0; i < 4; i++ )
for( int i = 0; i < 4; i++ )
{
s01 = d[i*4+0] + d[i*4+1];
d01 = d[i*4+0] - d[i*4+1];
s23 = d[i*4+2] + d[i*4+3];
d23 = d[i*4+2] - d[i*4+3];
int s01 = d[i*4+0] + d[i*4+1];
int d01 = d[i*4+0] - d[i*4+1];
int s23 = d[i*4+2] + d[i*4+3];
int d23 = d[i*4+2] - d[i*4+3];
tmp[0*4+i] = s01 + s23;
tmp[1*4+i] = s01 - s23;
......@@ -55,12 +52,12 @@ static void dct4x4dc( int16_t d[16] )
tmp[3*4+i] = d01 + d23;
}
for( i = 0; i < 4; i++ )
for( int i = 0; i < 4; i++ )
{
s01 = tmp[i*4+0] + tmp[i*4+1];
d01 = tmp[i*4+0] - tmp[i*4+1];
s23 = tmp[i*4+2] + tmp[i*4+3];
d23 = tmp[i*4+2] - tmp[i*4+3];
int s01 = tmp[i*4+0] + tmp[i*4+1];
int d01 = tmp[i*4+0] - tmp[i*4+1];
int s23 = tmp[i*4+2] + tmp[i*4+3];
int d23 = tmp[i*4+2] - tmp[i*4+3];
d[i*4+0] = ( s01 + s23 + 1 ) >> 1;
d[i*4+1] = ( s01 - s23 + 1 ) >> 1;
......@@ -72,16 +69,13 @@ static void dct4x4dc( int16_t d[16] )
static void idct4x4dc( int16_t d[16] )
{
int16_t tmp[16];
int s01, s23;
int d01, d23;
int i;
for( i = 0; i < 4; i++ )
for( int i = 0; i < 4; i++ )
{
s01 = d[i*4+0] + d[i*4+1];
d01 = d[i*4+0] - d[i*4+1];
s23 = d[i*4+2] + d[i*4+3];
d23 = d[i*4+2] - d[i*4+3];
int s01 = d[i*4+0] + d[i*4+1];
int d01 = d[i*4+0] - d[i*4+1];
int s23 = d[i*4+2] + d[i*4+3];
int d23 = d[i*4+2] - d[i*4+3];
tmp[0*4+i] = s01 + s23;
tmp[1*4+i] = s01 - s23;
......@@ -89,12 +83,12 @@ static void idct4x4dc( int16_t d[16] )
tmp[3*4+i] = d01 + d23;
}
for( i = 0; i < 4; i++ )
for( int i = 0; i < 4; i++ )
{
s01 = tmp[i*4+0] + tmp[i*4+1];
d01 = tmp[i*4+0] - tmp[i*4+1];
s23 = tmp[i*4+2] + tmp[i*4+3];
d23 = tmp[i*4+2] - tmp[i*4+3];
int s01 = tmp[i*4+0] + tmp[i*4+1];
int d01 = tmp[i*4+0] - tmp[i*4+1];
int s23 = tmp[i*4+2] + tmp[i*4+3];
int d23 = tmp[i*4+2] - tmp[i*4+3];
d[i*4+0] = s01 + s23;
d[i*4+1] = s01 - s23;
......@@ -106,13 +100,10 @@ static void idct4x4dc( int16_t d[16] )
static inline void pixel_sub_wxh( int16_t *diff, int i_size,
uint8_t *pix1, int i_pix1, uint8_t *pix2, int i_pix2 )
{
int y, x;
for( y = 0; y < i_size; y++ )
for( int y = 0; y < i_size; y++ )
{
for( x = 0; x < i_size; x++ )
{
for( int x = 0; x < i_size; x++ )
diff[x + y*i_size] = pix1[x] - pix2[x];
}
pix1 += i_pix1;
pix2 += i_pix2;
}
......@@ -122,16 +113,15 @@ static void sub4x4_dct( int16_t dct[16], uint8_t *pix1, uint8_t *pix2 )
{
int16_t d[16];
int16_t tmp[16];
int i;
pixel_sub_wxh( d, 4, pix1, FENC_STRIDE, pix2, FDEC_STRIDE );
for( i = 0; i < 4; i++ )
for( int i = 0; i < 4; i++ )
{
const int s03 = d[i*4+0] + d[i*4+3];
const int s12 = d[i*4+1] + d[i*4+2];
const int d03 = d[i*4+0] - d[i*4+3];
const int d12 = d[i*4+1] - d[i*4+2];
int s03 = d[i*4+0] + d[i*4+3];
int s12 = d[i*4+1] + d[i*4+2];
int d03 = d[i*4+0] - d[i*4+3];
int d12 = d[i*4+1] - d[i*4+2];
tmp[0*4+i] = s03 + s12;
tmp[1*4+i] = 2*d03 + d12;
......@@ -139,12 +129,12 @@ static void sub4x4_dct( int16_t dct[16], uint8_t *pix1, uint8_t *pix2 )
tmp[3*4+i] = d03 - 2*d12;
}
for( i = 0; i < 4; i++ )
for( int i = 0; i < 4; i++ )
{
const int s03 = tmp[i*4+0] + tmp[i*4+3];
const int s12 = tmp[i*4+1] + tmp[i*4+2];
const int d03 = tmp[i*4+0] - tmp[i*4+3];
const int d12 = tmp[i*4+1] - tmp[i*4+2];
int s03 = tmp[i*4+0] + tmp[i*4+3];
int s12 = tmp[i*4+1] + tmp[i*4+2];
int d03 = tmp[i*4+0] - tmp[i*4+3];
int d12 = tmp[i*4+1] - tmp[i*4+2];
dct[i*4+0] = s03 + s12;
dct[i*4+1] = 2*d03 + d12;
......@@ -184,17 +174,16 @@ static int sub4x4_dct_dc( uint8_t *pix1, uint8_t *pix2 )
static void sub8x8_dct_dc( int16_t dct[4], uint8_t *pix1, uint8_t *pix2 )
{
int d0, d1, d2, d3;
dct[0] = sub4x4_dct_dc( &pix1[0], &pix2[0] );
dct[1] = sub4x4_dct_dc( &pix1[4], &pix2[4] );
dct[2] = sub4x4_dct_dc( &pix1[4*FENC_STRIDE+0], &pix2[4*FDEC_STRIDE+0] );
dct[3] = sub4x4_dct_dc( &pix1[4*FENC_STRIDE+4], &pix2[4*FDEC_STRIDE+4] );
/* 2x2 DC transform */
d0 = dct[0] + dct[1];
d1 = dct[2] + dct[3];
d2 = dct[0] - dct[1];
d3 = dct[2] - dct[3];
int d0 = dct[0] + dct[1];
int d1 = dct[2] + dct[3];
int d2 = dct[0] - dct[1];
int d3 = dct[2] - dct[3];
dct[0] = d0 + d1;
dct[2] = d2 + d3;
dct[1] = d0 - d1;
......@@ -205,15 +194,13 @@ static void add4x4_idct( uint8_t *p_dst, int16_t dct[16] )
{
int16_t d[16];
int16_t tmp[16];
int x, y;
int i;
for( i = 0; i < 4; i++ )
for( int i = 0; i < 4; i++ )
{
const int s02 = dct[0*4+i] + dct[2*4+i];
const int d02 = dct[0*4+i] - dct[2*4+i];
const int s13 = dct[1*4+i] + (dct[3*4+i]>>1);
const int d13 = (dct[1*4+i]>>1) - dct[3*4+i];
int s02 = dct[0*4+i] + dct[2*4+i];
int d02 = dct[0*4+i] - dct[2*4+i];
int s13 = dct[1*4+i] + (dct[3*4+i]>>1);
int d13 = (dct[1*4+i]>>1) - dct[3*4+i];
tmp[i*4+0] = s02 + s13;
tmp[i*4+1] = d02 + d13;
......@@ -221,12 +208,12 @@ static void add4x4_idct( uint8_t *p_dst, int16_t dct[16] )
tmp[i*4+3] = s02 - s13;
}
for( i = 0; i < 4; i++ )
for( int i = 0; i < 4; i++ )
{
const int s02 = tmp[0*4+i] + tmp[2*4+i];
const int d02 = tmp[0*4+i] - tmp[2*4+i];
const int s13 = tmp[1*4+i] + (tmp[3*4+i]>>1);
const int d13 = (tmp[1*4+i]>>1) - tmp[3*4+i];
int s02 = tmp[0*4+i] + tmp[2*4+i];
int d02 = tmp[0*4+i] - tmp[2*4+i];
int s13 = tmp[1*4+i] + (tmp[3*4+i]>>1);
int d13 = (tmp[1*4+i]>>1) - tmp[3*4+i];
d[0*4+i] = ( s02 + s13 + 32 ) >> 6;
d[1*4+i] = ( d02 + d13 + 32 ) >> 6;
......@@ -235,9 +222,9 @@ static void add4x4_idct( uint8_t *p_dst, int16_t dct[16] )
}
for( y = 0; y < 4; y++ )
for( int y = 0; y < 4; y++ )
{
for( x = 0; x < 4; x++ )
for( int x = 0; x < 4; x++ )
p_dst[x] = x264_clip_uint8( p_dst[x] + d[y*4+x] );
p_dst += FDEC_STRIDE;
}
......@@ -264,22 +251,22 @@ static void add16x16_idct( uint8_t *p_dst, int16_t dct[16][16] )
****************************************************************************/
#define DCT8_1D {\
const int s07 = SRC(0) + SRC(7);\
const int s16 = SRC(1) + SRC(6);\
const int s25 = SRC(2) + SRC(5);\
const int s34 = SRC(3) + SRC(4);\
const int a0 = s07 + s34;\
const int a1 = s16 + s25;\
const int a2 = s07 - s34;\
const int a3 = s16 - s25;\
const int d07 = SRC(0) - SRC(7);\
const int d16 = SRC(1) - SRC(6);\
const int d25 = SRC(2) - SRC(5);\
const int d34 = SRC(3) - SRC(4);\
const int a4 = d16 + d25 + (d07 + (d07>>1));\
const int a5 = d07 - d34 - (d25 + (d25>>1));\
const int a6 = d07 + d34 - (d16 + (d16>>1));\
const int a7 = d16 - d25 + (d34 + (d34>>1));\
int s07 = SRC(0) + SRC(7);\
int s16 = SRC(1) + SRC(6);\
int s25 = SRC(2) + SRC(5);\
int s34 = SRC(3) + SRC(4);\
int a0 = s07 + s34;\
int a1 = s16 + s25;\
int a2 = s07 - s34;\
int a3 = s16 - s25;\
int d07 = SRC(0) - SRC(7);\
int d16 = SRC(1) - SRC(6);\
int d25 = SRC(2) - SRC(5);\
int d34 = SRC(3) - SRC(4);\
int a4 = d16 + d25 + (d07 + (d07>>1));\
int a5 = d07 - d34 - (d25 + (d25>>1));\
int a6 = d07 + d34 - (d16 + (d16>>1));\
int a7 = d16 - d25 + (d34 + (d34>>1));\
DST(0) = a0 + a1 ;\
DST(1) = a4 + (a7>>2);\
DST(2) = a2 + (a3>>1);\
......@@ -292,21 +279,20 @@ static void add16x16_idct( uint8_t *p_dst, int16_t dct[16][16] )
static void sub8x8_dct8( int16_t dct[64], uint8_t *pix1, uint8_t *pix2 )
{
int i;
int16_t tmp[64];
pixel_sub_wxh( tmp, 8, pix1, FENC_STRIDE, pix2, FDEC_STRIDE );
#define SRC(x) tmp[x*8+i]
#define DST(x) tmp[x*8+i]
for( i = 0; i < 8; i++ )
for( int i = 0; i < 8; i++ )
DCT8_1D
#undef SRC
#undef DST
#define SRC(x) tmp[i*8+x]
#define DST(x) dct[x*8+i]
for( i = 0; i < 8; i++ )
for( int i = 0; i < 8; i++ )
DCT8_1D
#undef SRC
#undef DST
......@@ -321,22 +307,22 @@ static void sub16x16_dct8( int16_t dct[4][64], uint8_t *pix1, uint8_t *pix2 )
}
#define IDCT8_1D {\
const int a0 = SRC(0) + SRC(4);\
const int a2 = SRC(0) - SRC(4);\
const int a4 = (SRC(2)>>1) - SRC(6);\
const int a6 = (SRC(6)>>1) + SRC(2);\
const int b0 = a0 + a6;\
const int b2 = a2 + a4;\
const int b4 = a2 - a4;\
const int b6 = a0 - a6;\
const int a1 = -SRC(3) + SRC(5) - SRC(7) - (SRC(7)>>1);\
const int a3 = SRC(1) + SRC(7) - SRC(3) - (SRC(3)>>1);\
const int a5 = -SRC(1) + SRC(7) + SRC(5) + (SRC(5)>>1);\
const int a7 = SRC(3) + SRC(5) + SRC(1) + (SRC(1)>>1);\
const int b1 = (a7>>2) + a1;\
const int b3 = a3 + (a5>>2);\
const int b5 = (a3>>2) - a5;\
const int b7 = a7 - (a1>>2);\
int a0 = SRC(0) + SRC(4);\
int a2 = SRC(0) - SRC(4);\
int a4 = (SRC(2)>>1) - SRC(6);\
int a6 = (SRC(6)>>1) + SRC(2);\
int b0 = a0 + a6;\
int b2 = a2 + a4;\
int b4 = a2 - a4;\
int b6 = a0 - a6;\
int a1 = -SRC(3) + SRC(5) - SRC(7) - (SRC(7)>>1);\
int a3 = SRC(1) + SRC(7) - SRC(3) - (SRC(3)>>1);\
int a5 = -SRC(1) + SRC(7) + SRC(5) + (SRC(5)>>1);\
int a7 = SRC(3) + SRC(5) + SRC(1) + (SRC(1)>>1);\
int b1 = (a7>>2) + a1;\
int b3 = a3 + (a5>>2);\
int b5 = (a3>>2) - a5;\
int b7 = a7 - (a1>>2);\
DST(0, b0 + b7);\
DST(1, b2 + b5);\
DST(2, b4 + b3);\
......@@ -349,20 +335,18 @@ static void sub16x16_dct8( int16_t dct[4][64], uint8_t *pix1, uint8_t *pix2 )
static void add8x8_idct8( uint8_t *dst, int16_t dct[64] )
{
int i;
dct[0] += 32; // rounding for the >>6 at the end
#define SRC(x) dct[x*8+i]
#define DST(x,rhs) dct[x*8+i] = (rhs)
for( i = 0; i < 8; i++ )
for( int i = 0; i < 8; i++ )
IDCT8_1D
#undef SRC
#undef DST
#define SRC(x) dct[i*8+x]
#define DST(x,rhs) dst[i + x*FDEC_STRIDE] = x264_clip_uint8( dst[i + x*FDEC_STRIDE] + ((rhs) >> 6) );
for( i = 0; i < 8; i++ )
for( int i = 0; i < 8; i++ )
IDCT8_1D
#undef SRC
#undef DST
......@@ -378,9 +362,8 @@ static void add16x16_idct8( uint8_t *dst, int16_t dct[4][64] )
static void inline add4x4_idct_dc( uint8_t *p_dst, int16_t dc )
{
int i;
dc = (dc + 32) >> 6;
for( i = 0; i < 4; i++, p_dst += FDEC_STRIDE )
for( int i = 0; i < 4; i++, p_dst += FDEC_STRIDE )
{
p_dst[0] = x264_clip_uint8( p_dst[0] + dc );
p_dst[1] = x264_clip_uint8( p_dst[1] + dc );
......@@ -399,8 +382,7 @@ static void add8x8_idct_dc( uint8_t *p_dst, int16_t dct[4] )
static void add16x16_idct_dc( uint8_t *p_dst, int16_t dct[16] )
{
int i;
for( i = 0; i < 4; i++, dct += 4, p_dst += 4*FDEC_STRIDE )
for( int i = 0; i < 4; i++, dct += 4, p_dst += 4*FDEC_STRIDE )
{
add4x4_idct_dc( &p_dst[ 0], dct[0] );
add4x4_idct_dc( &p_dst[ 4], dct[1] );
......@@ -537,12 +519,11 @@ void x264_dct_init( int cpu, x264_dct_function_t *dctf )
void x264_dct_init_weights( void )
{
int i, j;
for( j=0; j<2; j++ )
for( int j = 0; j < 2; j++ )
{
for( i=0; i<16; i++ )
for( int i = 0; i < 16; i++ )
x264_dct4_weight2_zigzag[j][i] = x264_dct4_weight2_tab[ x264_zigzag_scan4[j][i] ];
for( i=0; i<64; i++ )
for( int i = 0; i < 64; i++ )
x264_dct8_weight2_zigzag[j][i] = x264_dct8_weight2_tab[ x264_zigzag_scan8[j][i] ];
}
}
......@@ -707,11 +688,10 @@ static int zigzag_sub_8x8_field( int16_t level[64], const uint8_t *p_src, uint8_
static void zigzag_interleave_8x8_cavlc( int16_t *dst, int16_t *src, uint8_t *nnz )
{
int i,j;
for( i=0; i<4; i++ )
for( int i = 0; i < 4; i++ )
{
int nz = 0;
for( j=0; j<16; j++ )
for( int j = 0; j < 16; j++ )
{
nz |= src[i+j*4];
dst[i*16+j] = src[i+j*4];
......
/*****************************************************************************
* x264: h264 encoder
* x264: x11 interface for visualization module
*****************************************************************************
* Copyright (C) 2005 Tuukka Toivonen <tuukkat@ee.oulu.fi>
*
......@@ -29,201 +29,184 @@
static long event_mask = ConfigureNotify|ExposureMask|KeyPressMask|ButtonPressMask|StructureNotifyMask|ResizeRedirectMask;
static Display *disp_display = NULL;
static struct disp_window {
int init;
Window window;
static struct disp_window
{
int init;
Window window;
} disp_window[10];
static inline void disp_chkerror(int cond, char *e) {
if (!cond) return;
fprintf(stderr, "error: %s\n", e ? e : "?");
abort();
static inline void disp_chkerror( int cond, char *e )
{
if( !cond )
return;
fprintf( stderr, "error: %s\n", e ? e : "?" );
abort();
}
static void disp_init_display(void) {
Visual *visual;
int dpy_class;
int screen;
int dpy_depth;
if (disp_display != NULL) return;
memset(&disp_window, 0, sizeof(disp_window));
disp_display = XOpenDisplay("");
disp_chkerror(!disp_display, "no display");
screen = DefaultScreen(disp_display);
visual = DefaultVisual(disp_display, screen);
dpy_class = visual->class;
dpy_depth = DefaultDepth(disp_display, screen);
disp_chkerror(!((dpy_class == TrueColor && dpy_depth == 32)
|| (dpy_class == TrueColor && dpy_depth == 24)
|| (dpy_class == TrueColor && dpy_depth == 16)
|| (dpy_class == PseudoColor && dpy_depth == 8)),
"requires 8 bit PseudoColor or 16/24/32 bit TrueColor display");
static void disp_init_display()
{
Visual *visual;
int dpy_class;
int screen;
int dpy_depth;
if( disp_display )
return;
memset( &disp_window, 0, sizeof(disp_window) );
disp_display = XOpenDisplay( "" );
disp_chkerror( !disp_display, "no display" );
screen = DefaultScreen( disp_display );
visual = DefaultVisual( disp_display, screen );
dpy_class = visual->class;
dpy_depth = DefaultDepth( disp_display, screen );
disp_chkerror( !((dpy_class == TrueColor && dpy_depth == 32)
|| (dpy_class == TrueColor && dpy_depth == 24)
|| (dpy_class == TrueColor && dpy_depth == 16)
|| (dpy_class == PseudoColor && dpy_depth == 8)),
"requires 8 bit PseudoColor or 16/24/32 bit TrueColor display" );
}
static void disp_init_window(int num, int width, int height, const unsigned char *tit) {
XSizeHints *shint;
XSetWindowAttributes xswa;
XEvent xev;
int screen = DefaultScreen(disp_display);
Visual *visual = DefaultVisual (disp_display, screen);
unsigned int fg, bg;
unsigned int mask;
char title[200];
Window window;
int dpy_depth;
if (tit) {
snprintf(title, 200, "%s: %i/disp", tit, num);
} else {
snprintf(title, 200, "%i/disp", num);
}
shint = XAllocSizeHints();
disp_chkerror(!shint, "memerror");
shint->min_width = shint->max_width = shint->width = width;
shint->min_height = shint->max_height = shint->height = height;
shint->flags = PSize | PMinSize | PMaxSize;
disp_chkerror(num<0 || num>=10, "bad win num");
if (!disp_window[num].init) {
disp_window[num].init = 1;
bg = WhitePixel(disp_display, screen);
fg = BlackPixel(disp_display, screen);
dpy_depth = DefaultDepth(disp_display, screen);
if (dpy_depth==32 || dpy_depth==24 || dpy_depth==16) {
mask |= CWColormap;
xswa.colormap = XCreateColormap(disp_display, DefaultRootWindow(disp_display), visual, AllocNone);
}
xswa.background_pixel = bg;
xswa.border_pixel = fg;
xswa.backing_store = Always;
xswa.backing_planes = -1;
xswa.bit_gravity = NorthWestGravity;
mask = CWBackPixel | CWBorderPixel | CWBackingStore | CWBackingPlanes | CWBitGravity;
window = XCreateWindow(disp_display, DefaultRootWindow(disp_display),
shint->x, shint->y, shint->width, shint->height,
1, dpy_depth, InputOutput, visual, mask, &xswa);
disp_window[num].window = window;
XSelectInput(disp_display, window, event_mask);
XSetStandardProperties(disp_display, window, title, title, None, NULL, 0, shint); /* Tell other applications about this window */
XMapWindow(disp_display, window); /* Map window. */
do { /* Wait for map. */
XNextEvent(disp_display, &xev);
} while (xev.type!=MapNotify || xev.xmap.event!=window);
//XSelectInput(disp_display, window, KeyPressMask); /* XSelectInput(display, window, NoEventMask);*/
}
window = disp_window[num].window;
XSetStandardProperties(disp_display, window, title, title, None, NULL, 0, shint); /* Tell other applications about this window */
XResizeWindow(disp_display, window, width, height);
XSync(disp_display, 1);
XFree(shint);
static void disp_init_window( int num, int width, int height, const unsigned char *title )
{
XSetWindowAttributes xswa;
XEvent xev;
int screen = DefaultScreen(disp_display);
Visual *visual = DefaultVisual (disp_display, screen);
char buf[200];
Window window;
if( title )
snprintf( buf, 200, "%s: %i/disp", title, num );
else
snprintf( buf, 200, "%i/disp", num );
XSizeHints *shint = XAllocSizeHints();
disp_chkerror( !shint, "memerror" );
shint->min_width = shint->max_width = shint->width = width;
shint->min_height = shint->max_height = shint->height = height;
shint->flags = PSize | PMinSize | PMaxSize;
disp_chkerror( num < 0 || num >= 10, "bad win num" );
if( !disp_window[num].init )
{
unsigned int mask = 0;
disp_window[num].init = 1;
unsigned int bg = WhitePixel( disp_display, screen );
unsigned int fg = BlackPixel( disp_display, screen );
int dpy_depth = DefaultDepth( disp_display, screen );
if( dpy_depth==32 || dpy_depth==24 || dpy_depth==16 )
{
mask |= CWColormap;
xswa.colormap = XCreateColormap( disp_display, DefaultRootWindow( disp_display ), visual, AllocNone );