summaryrefslogtreecommitdiff
path: root/fbgl.h
blob: d92bfb7c5bfe482c22499904853e9df3601d1c33 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
// fbgl.h - v0.1.0 - public domain Levent Kaya 2024
// FBGL - Framebuffer Graphics Library
//
// This file provides both the interface and the implementation.
// To instantiate the implementation,
//      #define FBGL_IMPLEMENTATION
// in *ONE* source file, before #including this file.
//
//
// History:
//  - 0.1.0 First public release
//
// Status:
// 24/11/2024	texture rendering implemented
//
// Contributors:
//  @lvntky
//	@dario-loi
//
// LICENSE
//
//   See end of file for license information.

#ifndef __FBGL_H__
#define __FBGL_H__

#define VERSION "0.1.0"
#define NAME "FBGL"
#define DEFAULT_FB "/dev/fb0"
#define FBGL_MAX_KEYS 256 // Maximum number of keys to track

#include <fcntl.h>
#include <linux/fb.h>
#include <signal.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <termios.h>
#include <unistd.h>

#ifdef FBGL_USE_FREETYPE
#include <ft2build.h>
#include FT_FREETYPE_H
#endif // FBGL_USE_FREETYPE

/**
 * Structs
 */
typedef struct fbgl {
	int32_t width;
	int32_t height;
	int32_t fd;
	uint32_t screen_size;
	uint32_t *pixels;
	struct fb_var_screeninfo vinfo; // Variable screen information
	struct fb_fix_screeninfo finfo; // Fixed screen information
} fbgl_t;

typedef struct fbgl_window {
	int32_t x; // Top-left x-coordinate of the window
	int32_t y; // Top-left y-coordinate of the window
	uint32_t width; // Width of the window
	uint32_t height; // Height of the window
	fbgl_t *fb; // Pointer to the framebuffer context
} fbgl_window_t;

typedef struct fbgl_psf2_header {
	uint8_t magic[2]; // Magic number, should be {0x72, 0xB5}
	uint8_t version; // Version of PSF2 (usually 0)
	uint8_t header_size; // Size of the header (usually 32 bytes)
	uint16_t flags; // Flags (usually 0)
	uint16_t numglyphs; // Number of glyphs (characters)
	uint16_t bytes_per_glyph; // Number of bytes per glyph (depends on font size)
	uint16_t height; // Height of each character in pixels
	uint16_t width; // Width of each character in pixels
	uint8_t *glyphs; // Pointer to the glyph data
} fbgl_psf2_header_t;

typedef struct fbgl_point {
	int32_t x;
	int32_t y;
} fbgl_point_t;

typedef struct fbgl_tga_texture {
	uint16_t width;
	uint16_t height;
	uint32_t *data;
} fbgl_tga_texture_t;

typedef struct fbgl_keyboard {
	bool keys[FBGL_MAX_KEYS]; // Current state of each key
	bool prev_keys[FBGL_MAX_KEYS]; // Previous state of each key
	bool is_initialized; // Track if keyboard is initialized
} fbgl_keyboard_t;

/**
 * Key state function and variables
 *
 */
static struct termios orig_termios;
static fbgl_keyboard_t keyboard = { 0 };

#ifdef FBGL_HIDE_CURSOR
#include <linux/kd.h>
int fbgl_hide_cursor(int fd)
{
	int tty_fd = open("/dev/tty0", O_RDWR);
	if (tty_fd == -1) {
		perror("Error opening /dev/tty0");
		return -1;
	}

	if (ioctl(tty_fd, KDSETMODE, KD_GRAPHICS) == -1) {
		perror("Error setting graphics mode");
		close(tty_fd);
		return -1;
	}

	close(tty_fd);
	return 0;
}
#endif // FBGL_HIDE_CURSOR

#ifdef FBGL_USE_FREETYPE
FT_Library fbgl_freetype_init();
void fbgl_freetype_cleanup(FT_Library library);
FT_Face fbgl_load_font(FT_Library library, const char *font_path,
		       int font_size);
void fbgl_render_freetype_text(fbgl_t *fb, FT_Library library, FT_Face face,
			       const char *text, int x, int y);
#endif // FBGL_USE_FREETYPE

#ifdef __cplusplus
extern "C" {
#endif

/**
 * General purpose methods
 */
char const *fbgl_name_info(void);
char const *fbgl_version_info(void);
void fbgl_enable_raw_mode();
void fbgl_disable_raw_mode();
void fbgl_cleanup(int sig);
int fbgl_check_esc_key();
void fbgl_set_signal_handlers();

/*Create and destroy methods*/
int fbgl_init(const char *device, fbgl_t *fb);
void fbgl_destroy(fbgl_t *fb);

/**
 * Drawing functions
 */
void fbgl_clear(uint32_t color);
void fbgl_put_pixel(int x, int y, uint32_t color, fbgl_t *fb);
void fbgl_draw_line(fbgl_point_t x, fbgl_point_t y, uint32_t color, fbgl_t *fb);

/**
 * Display methods
 */
void fbgl_display();

/**
 * Access framebuffer data methods
 */
uint32_t *fb_get_data(fbgl_t const *fb);
uint32_t fb_get_width(fbgl_t const *fb);
uint32_t fb_get_height(fbgl_t const *fb);

/**
 * Shapes
 */
void fbgl_draw_rectangle_outline(fbgl_point_t top_left,
				 fbgl_point_t bottom_right, uint32_t color,
				 fbgl_t *fb);
void fbgl_draw_rectangle_filled(fbgl_point_t top_left,
				fbgl_point_t bottom_right, uint32_t color,
				fbgl_t *fb);

/**
 * texture
 */
fbgl_tga_texture_t *fbgl_load_tga_texture(const char *path);
void fbgl_destroy_texture(fbgl_tga_texture_t *texture);
void fbgl_draw_texture(fbgl_t *fb, fbgl_tga_texture_t const *texture, int32_t x,
		       int32_t y);

/**
 * Keyboard
 */
int fbgl_keyboard_init();
void fbgl_keyboard_clean();
void fbgl_keyboard_update();
bool fbgl_key_pressed(unsigned char key);
bool fbgl_key_released(unsigned char key);
bool fbgl_key_down(unsigned char key);

#ifdef FBGL_IMPLEMENTATION

char const *fbgl_name_info(void)
{
	return NAME;
}

char const *fbgl_version_info(void)
{
	return VERSION;
}

int fbgl_init(const char *device, fbgl_t *fb)
{
	if (!fb) {
		fprintf(stderr, "Error: fbgl_t pointer is NULL.");
		return -1;
	}

	fb->fd = device == NULL ? open(DEFAULT_FB, O_RDWR) :
				  open(device, O_RDWR);
	if (fb->fd == -1) {
		perror("Error openning framebuffer device");
		return -1;
	}

	if (ioctl(fb->fd, FBIOGET_FSCREENINFO, &fb->finfo) == -1) {
		perror("Error: Reading fixed information.");
		close(fb->fd);
		return -1;
	}
	if (ioctl(fb->fd, FBIOGET_VSCREENINFO, &fb->vinfo) == -1) {
		perror("Error reading variable information");
		close(fb->fd);
		return -1;
	}

#ifdef FBGL_HIDE_CURSOR
	fbgl_hide_cursor(fb->fd);
	fbgl_set_signal_handlers();
	fbgl_enable_raw_mode();
#endif // FBGL_HIDE_CURSOR

	fb->width = fb->vinfo.xres;
	fb->height = fb->vinfo.yres;
	fb->screen_size = fb->finfo.smem_len;

	// Map framebuffer to memory
	fb->pixels = (uint32_t *)mmap(NULL, fb->screen_size,
				      PROT_READ | PROT_WRITE, MAP_SHARED,
				      fb->fd, 0);
	if (fb->pixels == MAP_FAILED) {
		perror("Error mapping framebuffer device to memory");
		close(fb->fd);
		return -1;
	}

	return 0;
}

void fbgl_destroy(fbgl_t *fb)
{
	if (!fb || fb->fd == -1) {
		fprintf(stderr,
			"Error: framebuffer not initialized or already destroyed.\n");
		return;
	}

	if (fb->pixels && fb->pixels != MAP_FAILED) {
		munmap(fb->pixels, fb->screen_size);
	}

	close(fb->fd);
	fb->fd = -1;

#ifdef FBGL_HIDE_CURSOR
	fbgl_disable_raw_mode();
#endif // FBGL_HIDE_CURSOR
}

void fbgl_set_bg(fbgl_t *fb, uint32_t color)
{
#ifdef DEBUG
	if (!fb || fb->fd == -1) {
		fprintf(stderr, "Error: framebuffer not initialized.\n");
		return;
	}
#endif // DEBUG

	// Fill the entire framebuffer with the specified color
	for (int i = 0; i < fb->screen_size; i++) {
		fb->pixels[i] = color;
	}
}

void fbgl_put_pixel(int x, int y, uint32_t color, fbgl_t *fb)
{
#ifdef DEBUG
	if (!fb || !fb->pixels) {
		fprintf(stderr, "Error: framebuffer not initialized.\n");
		return;
	}

	if (x < 0 || x >= fb->width || y < 0 || y >= fb->height) {
		return; // Ignore out-of-bound coordinates
	}
#endif // DEBUG

	const size_t index = y * fb->width + x;
	fb->pixels[index] = color;
}

void fbgl_enable_raw_mode()
{
	struct termios raw;

	if (tcgetattr(STDIN_FILENO, &orig_termios) == -1) {
		perror("tcgetattr");
		exit(EXIT_FAILURE);
	}
	raw = orig_termios;
	raw.c_lflag &= ~(ECHO | ICANON);
	if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &raw) == -1) {
		perror("tcsetattr");
		exit(EXIT_FAILURE);
	}
}

void fbgl_disable_raw_mode()
{
	if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &orig_termios) == -1) {
		perror("tcsetattr");
	}
}

void fbgl_cleanup(int sig)
{
	fbgl_disable_raw_mode();
	printf("\033[2J\033[H"); // Clear the terminal screen and move the cursor to top-left
	exit(sig);
}

int fbgl_check_esc_key()
{
	char c;
	struct timeval tv = { 0, 0 }; // Timeout of 0, to poll immediately
	fd_set fds;
	FD_ZERO(&fds);
	FD_SET(STDIN_FILENO, &fds);

	// Check if there's input available
	if (select(STDIN_FILENO + 1, &fds, NULL, NULL, &tv) == -1) {
		perror("select");
		return 0;
	}

	if (FD_ISSET(STDIN_FILENO, &fds)) {
		if (read(STDIN_FILENO, &c, 1) == -1) {
			perror("read");
			return 0;
		}
		return c == 27; // ASCII value of the `Esc` key
	}

	return 0;
}

void fbgl_set_signal_handlers()
{
	struct sigaction sa;
	sa.sa_handler = fbgl_cleanup;
	sa.sa_flags = 0;
	sigemptyset(&sa.sa_mask);

	if (sigaction(SIGINT, &sa, NULL) == -1 ||
	    sigaction(SIGTERM, &sa, NULL) == -1) {
		perror("sigaction");
		exit(EXIT_FAILURE);
	}
}

#ifdef FBGL_USE_FREETYPE
FT_Library fbgl_freetype_init()
{
	FT_Library library;
	if (FT_Init_FreeType(&library)) {
		fprintf(stderr, "Could not init FreeType Library\n");
		return NULL;
	}
	return library;
}

void fbgl_freetype_cleanup(FT_Library library)
{
	if (library) {
		FT_Done_FreeType(library);
	}
}

FT_Face fbgl_load_font(FT_Library library, const char *font_path, int font_size)
{
	FT_Face face;
	if (FT_New_Face(library, font_path, 0, &face)) {
		fprintf(stderr, "Could not open font: %s\n", font_path);
		return NULL;
	}
	FT_Set_Pixel_Sizes(face, 0, font_size); // Set font size
	return face;
}

void fbgl_render_freetype_text(fbgl_t *fb, FT_Library library, FT_Face face,
			       const char *text, int32_t x, int32_t y)
{
	while (*text) {
		FT_Load_Char(face, *text, FT_LOAD_RENDER);
		FT_Bitmap bitmap = face->glyph->bitmap;

		// Draw the bitmap to framebuffer
		for (int32_t j = 0; j < bitmap.rows; j++) {
			for (int32_t i = 0; i < bitmap.width; i++) {
				if (bitmap.buffer[j * bitmap.width +
						  i]) { // Check pixel is not empty
					fbgl_put_pixel(x + i, y + j, 0xFF0000,
						       fb); // Draw white pixel
				}
			}
		}
		x += face->glyph->advance.x >>
		     6; // Move to the next character position
		++text;
	}
}

#endif // FBGL_USE_FREETYPE

void fbgl_draw_line(fbgl_point_t x, fbgl_point_t y, uint32_t color,
		    fbgl_t *buffer)
{
	const int32_t dx = abs(y.x - x.x);
	const int32_t dy = abs(y.y - x.y);

	const int32_t sx = (x.x < y.x) ? 1 : -1;
	const int32_t sy = (x.y < y.y) ? 1 : -1;

	int32_t err = dx - dy;

	while (1) {
		// Set the pixel at the current position
		fbgl_put_pixel(x.x, x.y, color, buffer);

		// If we've reached the end point, break
		if (x.x >= y.x && x.y >= y.y)
			break;

		const int32_t e2 = 2 * err;

		if (e2 > -dy) {
			err -= dy;
			x.x += sx;
		}

		if (e2 < dx) {
			err += dx;
			x.y += sy;
		}
	}
}
void fbgl_draw_rectangle_outline(fbgl_point_t top_left,
				 fbgl_point_t bottom_right, uint32_t color,
				 fbgl_t *fb)
{
	// Top horizontal line
	for (int x = top_left.x; x < bottom_right.x; x++) {
		fbgl_put_pixel(x, top_left.y, color, fb);
	}

	// Bottom horizontal line
	for (int x = top_left.x; x < bottom_right.x; x++) {
		fbgl_put_pixel(x, bottom_right.y - 1, color, fb);
	}

	// Left vertical line
	for (int y = top_left.y; y < bottom_right.y; y++) {
		fbgl_put_pixel(top_left.x, y, color, fb);
	}

	// Right vertical line
	for (int y = top_left.y; y < bottom_right.y; y++) {
		fbgl_put_pixel(bottom_right.x - 1, y, color, fb);
	}
}

void fbgl_draw_rectangle_filled(fbgl_point_t top_left,
				fbgl_point_t bottom_right, uint32_t color,
				fbgl_t *fb)
{
	for (int32_t y = top_left.y; y < bottom_right.y; y++) {
		// Manually set each pixel in the row
		for (int32_t x = top_left.x; x < bottom_right.x; x++) {
			fbgl_put_pixel(x, y, color, fb);
		}
	}
}
fbgl_tga_texture_t *fbgl_load_tga_texture(const char *path)
{
	FILE *file = fopen(path, "rb");
	if (!file) {
		perror("Unable to open texture file");
		return NULL;
	}

	// TGA header structure
	uint8_t header[18];
	if (fread(header, 1, sizeof(header), file) != sizeof(header)) {
		perror("Error reading TGA header");
		fclose(file);
		return NULL;
	}

	// Allocate texture structure
	fbgl_tga_texture_t *texture =
		(fbgl_tga_texture_t *)malloc(sizeof(fbgl_tga_texture_t));
	if (!texture) {
		perror("Failed to allocate texture structure");
		fclose(file);
		return NULL;
	}

	// Extract dimensions from header
	texture->width = header[12] | (header[13] << 8);
	texture->height = header[14] | (header[15] << 8);
	uint8_t bits_per_pixel = header[16];
	uint8_t image_descriptor = header[17];

	// Verify format support
	if (bits_per_pixel != 24 && bits_per_pixel != 32) {
		fprintf(stderr,
			"Unsupported TGA bit depth: %d (only 24 and 32-bit supported)\n",
			bits_per_pixel);
		free(texture);
		fclose(file);
		return NULL;
	}

	// Skip image ID field
	if (header[0]) {
		fseek(file, header[0], SEEK_CUR);
	}

	// Allocate pixel data
	size_t pixel_count = texture->width * texture->height;
	texture->data = (uint32_t *)malloc(pixel_count * sizeof(uint32_t));
	if (!texture->data) {
		perror("Failed to allocate pixel data");
		free(texture);
		fclose(file);
		return NULL;
	}

	// Read pixel data
	uint8_t *pixel_buffer = (uint8_t *)malloc(bits_per_pixel / 8);
	if (!pixel_buffer) {
		perror("Failed to allocate pixel buffer");
		free(texture->data);
		free(texture);
		fclose(file);
		return NULL;
	}

	// Determine if image is flipped (based on image descriptor)
	bool bottom_up = !(image_descriptor & 0x20);

	for (size_t i = 0; i < pixel_count; i++) {
		size_t pixel_index =
			bottom_up ?
				(texture->height - 1 - (i / texture->width)) *
						texture->width +
					(i % texture->width) :
				i;

		if (fread(pixel_buffer, 1, bits_per_pixel / 8, file) !=
		    bits_per_pixel / 8) {
			perror("Error reading pixel data");
			free(pixel_buffer);
			free(texture->data);
			free(texture);
			fclose(file);
			return NULL;
		}

		// Convert BGR(A) to RGBA
		uint32_t pixel = 0xFF000000; // Default alpha to 255
		pixel |= pixel_buffer[2] << 16; // R
		pixel |= pixel_buffer[1] << 8; // G
		pixel |= pixel_buffer[0]; // B
		if (bits_per_pixel == 32) {
			pixel = (pixel & 0x00FFFFFF) |
				(pixel_buffer[3] << 24); // A
		}

		texture->data[pixel_index] = pixel;
	}

	free(pixel_buffer);
	fclose(file);
	return texture;
}

void fbgl_destroy_texture(fbgl_tga_texture_t *texture)
{
	if (texture) {
		free(texture->data);
		free(texture);
	}
}

void fbgl_draw_texture(fbgl_t *fb, fbgl_tga_texture_t const *texture, int32_t x,
		       int32_t y)
{
	if (!fb || !texture || !texture->data) {
		return;
	}

	for (int ty = 0; ty < texture->height; ty++) {
		for (int tx = 0; tx < texture->width; tx++) {
			int screen_x = x + tx;
			int screen_y = y + ty;

			// Skip if outside screen bounds
			if (screen_x < 0 || screen_x >= fb->width ||
			    screen_y < 0 || screen_y >= fb->height) {
				continue;
			}

			uint32_t pixel =
				texture->data[ty * texture->width + tx];
			// Only draw if pixel is not fully transparent
			if ((pixel & 0xFF000000) != 0) {
				fbgl_put_pixel(screen_x, screen_y, pixel, fb);
			}
		}
	}
}

uint32_t fb_get_width(fbgl_t const *fb)
{
	return fb->width;
}

uint32_t fb_get_height(fbgl_t const *fb)
{
	return fb->height;
}

uint32_t *fb_get_data(fbgl_t const *fb)
{
	return fb->pixels;
}

#endif // FBGL_IMPLEMENTATION

#ifdef __cplusplus
} // extern "C"
#endif
#endif // __FBGL_H__

/*
------------------------------------------------------------------------------
This software is available under 2 licenses -- choose whichever you prefer.
------------------------------------------------------------------------------
ALTERNATIVE A - MIT License
Copyright (c) 2024 Levent Kaya
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
------------------------------------------------------------------------------
ALTERNATIVE B - Public Domain (www.unlicense.org)
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
software, either in source code form or as a compiled binary, for any purpose,
commercial or non-commercial, and by any means.
In jurisdictions that recognize copyright laws, the author or authors of this
software dedicate any and all copyright interest in the software to the public
domain. We make this dedication for the benefit of the public at large and to
the detriment of our heirs and successors. We intend this dedication to be an
overt act of relinquishment in perpetuity of all present and future rights to
this software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
------------------------------------------------------------------------------
*/