<commit_before>/*
 * laserscan-fb.c
 *
 * Copyright(c) 2007-2017 <NAME> <<EMAIL>>
 * Official site: http://xboot.org
 * Mobile phone: +86-18665388956
 * QQ: 8192542
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

#include <xboot.h>
#include <fb/fb.h>
#include <laserscan/laserscan.h>

struct laserscan_fb_pdata_t {
	u8_t r, g, b, a;
	u32_t color;
	float x, y;
	float tx, ty;
	float a11, a12, a13;
	float a21, a22, a23;
	float a31, a32, a33;

	struct fb_t * fb;
	void * pixels;
	int width, height;
	int w2, h2;
	int bytes_per_pixel;
};

static inline void fb_projective_transformation(struct laserscan_fb_pdata_t * pdat, float x, float y, float * tx, float * ty)
{
	float w = pdat->a13 * x + pdat->a23 * y + pdat->a33;
	*tx = (pdat->a11 * x + pdat->a21 * y + pdat->a31) / w;
	*ty = (pdat->a12 * x + pdat->a22 * y + pdat->a32) / w;
	if(*tx < -1)
		*tx = -1;
	else if(*tx > 1)
		*tx = 1;
	if(*ty < -1)
		*ty = -1;
	else if(*ty > 1)
		*ty = 1;
}

static inline void fb_set_pixel(struct laserscan_fb_pdata_t * pdat, int x, int y)
{
	*((u32_t *)((u8_t *)pdat->pixels + (y * pdat->width + x) * pdat->bytes_per_pixel)) = pdat->color;
}

static inline void fb_line(struct laserscan_fb_pdata_t * pdat, int x1, int y1, int x2, int y2)
{
	int dx = x2 - x1;
	int dy = y2 - y1;
	int e, s;
	int sx = dx > 0;
	int sy = dy > 0;

	if(!sx)
		dx = -dx;
	if(!sy)
		dy = -dy;
	s = dx > dy;

	fb_set_pixel(pdat, x1, y1);
	if(s)
	{
		e = (dy << 1) - dx;
		while(x1 != x2)
		{
			if(e < 0)
			{
				sx ? x1++ : x1--;
				e += dy << 1;
				fb_set_pixel(pdat, x1, y1);
			}
			else
			{
				sy ? y1++ : y1--;<commit_msg>[laserscan]fix laserscan-fb<commit_after>/*
 * laserscan-fb.c
 *
 * Copyright(c) 2007-2017 <NAME> <<EMAIL>>
 * Official site: http://xboot.org
 * Mobile phone: +86-18665388956
 * QQ: 8192542
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

#include <xboot.h>
#include <fb/fb.h>
#include <laserscan/laserscan.h>

struct laserscan_fb_pdata_t {
	u8_t r, g, b, a;
	u32_t color;
	float x, y;
	float tx, ty;
	float a11, a12, a13;
	float a21, a22, a23;
	float a31, a32, a33;

	struct fb_t * fb;
	void * pixels;
	int width, height;
	int w2, h2;
	int bytes_per_pixel;
};

static inline void fb_projective_transformation(struct laserscan_fb_pdata_t * pdat, float x, float y, float * tx, float * ty)
{
	float w = pdat->a13 * x + pdat->a23 * y + pdat->a33;
	*tx = (pdat->a11 * x + pdat->a21 * y + pdat->a31) / w;
	*ty = (pdat->a12 * x + pdat->a22 * y + pdat->a32) / w;
}

static inline void fb_set_pixel(struct laserscan_fb_pdata_t * pdat, int x, int y)
{
	if((x >= 0) && (x < pdat->width) && (y >= 0) && (y < pdat->height))
		*((u32_t *)((u8_t *)pdat->pixels + (y * pdat->width + x) * pdat->bytes_per_pixel)) = pdat->color;
}

static inline void fb_line(struct laserscan_fb_pdata_t * pdat, int x1, int y1, int x2, int y2)
{
	int dx = x2 - x1;
	int dy = y2 - y1;
	int e, s;
	int sx = dx > 0;
	int sy = dy > 0;

	if(!sx)
		dx = -dx;
	if(!sy)
		dy = -dy;
	s = dx > dy;

	fb_set_pixel(pdat, x1, y1);
	if(s)
	{
		e = (dy << 1) - dx;
		while(x1 != x2)
		{
			if(e < 0)
			{
				sx ? x1++ : x1--;
				e += dy << 1;
				fb_set_pixel(pdat, x1, y1);
			}
			else
			{
				sy ? y1++ : y1--;
{'fraction_non_alphanumeric': 0.1411790780141844, 'fraction_numerical': 0.050975177304964536, 'mean_word_length': 3.0657657657657658, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '524004', 'n_tokens_mistral': 2018, 'n_tokens_neox': 1818, 'n_words': 612}