Search
lxdream.org :: lxdream/src/util.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/util.c
changeset 736:a02d1475ccfd
prev674:377d987db8f2
next768:b2a54f6864eb
author nkeynes
date Mon Jul 14 07:44:42 2008 +0000 (13 years ago)
permissions -rw-r--r--
last change Re-indent everything consistently
Fix include guards for consistency as well
file annotate diff log raw
1.1 --- a/src/util.c Mon May 26 10:42:18 2008 +0000
1.2 +++ b/src/util.c Mon Jul 14 07:44:42 2008 +0000
1.3 @@ -63,11 +63,11 @@
1.4 {
1.5 uint32_t len = 0;
1.6 if( s == NULL ) {
1.7 - fwrite( &len, sizeof(len), 1, f );
1.8 + fwrite( &len, sizeof(len), 1, f );
1.9 } else {
1.10 - len = strlen(s)+1;
1.11 - fwrite( &len, sizeof(len), 1, f );
1.12 - fwrite( s, len, 1, f );
1.13 + len = strlen(s)+1;
1.14 + fwrite( &len, sizeof(len), 1, f );
1.15 + fwrite( s, len, 1, f );
1.16 }
1.17 }
1.18
1.19 @@ -76,7 +76,7 @@
1.20 uint32_t len;
1.21 fread( &len, sizeof(len), 1, f );
1.22 if( len != 0 ) {
1.23 - fread( s, len > maxlen ? maxlen : len, 1, f );
1.24 + fread( s, len > maxlen ? maxlen : len, 1, f );
1.25 }
1.26 return len;
1.27 }
1.28 @@ -107,10 +107,10 @@
1.29 int status = uncompress( p, &size, tmp, csize );
1.30 g_free(tmp);
1.31 if( status == Z_OK ) {
1.32 - return count;
1.33 + return count;
1.34 } else {
1.35 - fprintf( stderr, "Error reading compressed data\n" );
1.36 - return 0;
1.37 + fprintf( stderr, "Error reading compressed data\n" );
1.38 + return 0;
1.39 }
1.40 }
1.41
1.42 @@ -118,20 +118,20 @@
1.43 {
1.44 unsigned int i, j;
1.45 for( i =0; i<length; i+=16 ) {
1.46 - fprintf( f, "%08X:", i);
1.47 - for( j=i; j<i+16; j++ ) {
1.48 - if( (j % 4) == 0 )
1.49 - fprintf( f, " " );
1.50 - if( j < length )
1.51 - fprintf( f, " %02X", (unsigned int)(data[j]) );
1.52 - else
1.53 - fprintf( f, " " );
1.54 - }
1.55 - fprintf( f, " " );
1.56 - for( j=i; j<i+16 && j<length; j++ ) {
1.57 - fprintf( f, "%c", isprint(data[j]) ? data[j] : '.' );
1.58 - }
1.59 - fprintf( f, "\n" );
1.60 + fprintf( f, "%08X:", i);
1.61 + for( j=i; j<i+16; j++ ) {
1.62 + if( (j % 4) == 0 )
1.63 + fprintf( f, " " );
1.64 + if( j < length )
1.65 + fprintf( f, " %02X", (unsigned int)(data[j]) );
1.66 + else
1.67 + fprintf( f, " " );
1.68 + }
1.69 + fprintf( f, " " );
1.70 + for( j=i; j<i+16 && j<length; j++ ) {
1.71 + fprintf( f, "%c", isprint(data[j]) ? data[j] : '.' );
1.72 + }
1.73 + fprintf( f, "\n" );
1.74 }
1.75 }
1.76
1.77 @@ -144,14 +144,14 @@
1.78 {
1.79 unsigned int i, j;
1.80 for( i =0; i<length>>2; i+=wordsPerLine ) {
1.81 - fprintf( f, "%08X:", i);
1.82 - for( j=i; j<i+wordsPerLine; j++ ) {
1.83 - if( j < length )
1.84 - fprintf( f, " %08X", (unsigned int)(data[j]) );
1.85 - else
1.86 - fprintf( f, " " );
1.87 - }
1.88 - fprintf( f, "\n" );
1.89 + fprintf( f, "%08X:", i);
1.90 + for( j=i; j<i+wordsPerLine; j++ ) {
1.91 + if( j < length )
1.92 + fprintf( f, " %08X", (unsigned int)(data[j]) );
1.93 + else
1.94 + fprintf( f, " " );
1.95 + }
1.96 + fprintf( f, "\n" );
1.97 }
1.98 }
1.99
1.100 @@ -161,54 +161,54 @@
1.101 png_bytep p;
1.102 png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
1.103 if (!png_ptr) {
1.104 - return FALSE;
1.105 + return FALSE;
1.106 }
1.107
1.108 png_infop info_ptr = png_create_info_struct(png_ptr);
1.109 if (!info_ptr) {
1.110 - png_destroy_write_struct(&png_ptr, NULL);
1.111 - return FALSE;
1.112 + png_destroy_write_struct(&png_ptr, NULL);
1.113 + return FALSE;
1.114 }
1.115 -
1.116 +
1.117 if( setjmp(png_jmpbuf(png_ptr)) ) {
1.118 - png_destroy_write_struct(&png_ptr, &info_ptr);
1.119 - return FALSE;
1.120 + png_destroy_write_struct(&png_ptr, &info_ptr);
1.121 + return FALSE;
1.122 }
1.123 png_init_io( png_ptr, f );
1.124 switch( buffer->colour_format ) {
1.125 case COLFMT_BGR888:
1.126 - coltype = PNG_COLOR_TYPE_RGB;
1.127 - break;
1.128 + coltype = PNG_COLOR_TYPE_RGB;
1.129 + break;
1.130 case COLFMT_BGRA8888:
1.131 - coltype = PNG_COLOR_TYPE_RGB_ALPHA;
1.132 - break;
1.133 + coltype = PNG_COLOR_TYPE_RGB_ALPHA;
1.134 + break;
1.135 case COLFMT_BGR0888:
1.136 - coltype = PNG_COLOR_TYPE_RGB;
1.137 - break;
1.138 + coltype = PNG_COLOR_TYPE_RGB;
1.139 + break;
1.140 default:
1.141 - coltype = PNG_COLOR_TYPE_RGB;
1.142 + coltype = PNG_COLOR_TYPE_RGB;
1.143 }
1.144 png_set_IHDR(png_ptr, info_ptr, buffer->width, buffer->height,
1.145 - 8, coltype, PNG_INTERLACE_NONE,
1.146 - PNG_COMPRESSION_TYPE_DEFAULT,
1.147 - PNG_FILTER_TYPE_DEFAULT );
1.148 + 8, coltype, PNG_INTERLACE_NONE,
1.149 + PNG_COMPRESSION_TYPE_DEFAULT,
1.150 + PNG_FILTER_TYPE_DEFAULT );
1.151 png_write_info(png_ptr, info_ptr);
1.152 if( buffer->colour_format == COLFMT_BGR0888 ) {
1.153 - png_set_filler(png_ptr, 0, PNG_FILLER_AFTER);
1.154 + png_set_filler(png_ptr, 0, PNG_FILLER_AFTER);
1.155 }
1.156 png_set_bgr(png_ptr);
1.157 if( buffer->inverted ) {
1.158 - p = (png_bytep)(buffer->data + (buffer->height*buffer->rowstride) - buffer->rowstride);
1.159 - for(i=0; i<buffer->height; i++ ) {
1.160 - png_write_row(png_ptr, p);
1.161 - p-=buffer->rowstride;
1.162 - }
1.163 + p = (png_bytep)(buffer->data + (buffer->height*buffer->rowstride) - buffer->rowstride);
1.164 + for(i=0; i<buffer->height; i++ ) {
1.165 + png_write_row(png_ptr, p);
1.166 + p-=buffer->rowstride;
1.167 + }
1.168 } else {
1.169 - p = (png_bytep)buffer->data;
1.170 - for(i=0; i<buffer->height; i++ ) {
1.171 - png_write_row(png_ptr, p);
1.172 - p+=buffer->rowstride;
1.173 - }
1.174 + p = (png_bytep)buffer->data;
1.175 + for(i=0; i<buffer->height; i++ ) {
1.176 + png_write_row(png_ptr, p);
1.177 + p+=buffer->rowstride;
1.178 + }
1.179 }
1.180 png_write_end(png_ptr, info_ptr);
1.181 png_destroy_write_struct(&png_ptr, &info_ptr);
1.182 @@ -220,37 +220,37 @@
1.183 png_bytep p;
1.184 int i;
1.185 png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,
1.186 - NULL, NULL, NULL);
1.187 + NULL, NULL, NULL);
1.188 if (!png_ptr) {
1.189 - return NULL;
1.190 + return NULL;
1.191 }
1.192
1.193 png_infop info_ptr = png_create_info_struct(png_ptr);
1.194 if (!info_ptr) {
1.195 - png_destroy_read_struct(&png_ptr, NULL, NULL);
1.196 - return NULL;
1.197 + png_destroy_read_struct(&png_ptr, NULL, NULL);
1.198 + return NULL;
1.199 }
1.200 -
1.201 +
1.202 png_infop end_info = png_create_info_struct(png_ptr);
1.203 if (!end_info) {
1.204 - png_destroy_read_struct(&png_ptr, &info_ptr, NULL );
1.205 - return NULL;
1.206 + png_destroy_read_struct(&png_ptr, &info_ptr, NULL );
1.207 + return NULL;
1.208 }
1.209
1.210 if( setjmp(png_jmpbuf(png_ptr)) ) {
1.211 - png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
1.212 - return NULL;
1.213 + png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
1.214 + return NULL;
1.215 }
1.216
1.217 png_init_io(png_ptr, f);
1.218 png_read_info(png_ptr, info_ptr);
1.219 -
1.220 +
1.221 png_uint_32 width, height;
1.222 int bit_depth, color_type, interlace_type,
1.223 - compression_type, filter_method;
1.224 + compression_type, filter_method;
1.225 png_get_IHDR(png_ptr, info_ptr, &width, &height,
1.226 - &bit_depth, &color_type, &interlace_type,
1.227 - &compression_type, &filter_method);
1.228 + &bit_depth, &color_type, &interlace_type,
1.229 + &compression_type, &filter_method);
1.230 assert( interlace_type == PNG_INTERLACE_NONE );
1.231 int rowbytes = png_get_rowbytes(png_ptr, info_ptr);
1.232 int channels = png_get_channels(png_ptr, info_ptr);
1.233 @@ -263,15 +263,15 @@
1.234 buffer->size = rowbytes*height;
1.235 buffer->inverted = FALSE;
1.236 if( channels == 4 ) {
1.237 - buffer->colour_format = COLFMT_BGRA8888;
1.238 + buffer->colour_format = COLFMT_BGRA8888;
1.239 } else if( channels == 3 ) {
1.240 - buffer->colour_format = COLFMT_RGB888;
1.241 + buffer->colour_format = COLFMT_RGB888;
1.242 }
1.243 -
1.244 +
1.245 p = (png_bytep)buffer->data;
1.246 for( i=0; i<height; i++ ) {
1.247 - png_read_row(png_ptr, p, NULL );
1.248 - p += rowbytes;
1.249 + png_read_row(png_ptr, p, NULL );
1.250 + p += rowbytes;
1.251 }
1.252
1.253 png_read_end(png_ptr, end_info);
1.254 @@ -296,10 +296,10 @@
1.255 {
1.256 int l = get_log_level_from_string(str);
1.257 if( l == -1 ) {
1.258 - return FALSE;
1.259 + return FALSE;
1.260 } else {
1.261 - global_msg_level = l;
1.262 - return TRUE;
1.263 + global_msg_level = l;
1.264 + return TRUE;
1.265 }
1.266 }
1.267
1.268 @@ -310,18 +310,18 @@
1.269 va_list ap;
1.270
1.271 if( level > global_msg_level ) {
1.272 - return; // ignored
1.273 + return; // ignored
1.274 }
1.275
1.276 va_start(ap, msg);
1.277 gchar *text = g_strdup_vprintf( msg, ap );
1.278 va_end(ap);
1.279 -
1.280 +
1.281 if( level <= EMIT_ERR ) {
1.282 - if( gui_error_dialog( text ) ) {
1.283 - g_free(text);
1.284 - return;
1.285 - }
1.286 + if( gui_error_dialog( text ) ) {
1.287 + g_free(text);
1.288 + return;
1.289 + }
1.290 }
1.291
1.292
.