⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 libfbx-stretch.c

📁 libfxb是linux下只写操作framebuffer的一个轻量级的库。
💻 C
字号:
/* *  libfbx-stretch.c -- Surface Stretching Functions *  (C)opyright 2000-2001 U4X Labs * *  Written by: Mike Bourgeous <nitrogen@u4x.org> *              Sat Sep 2 16:28:14 EDT 2000 * *  $Id: libfbx-stretch.c,v 1.5 2001/01/01 08:46:17 lethal Exp $ * *       Originally part of fbgraph.c, now separate.  Responsible for *  drawing scaled surfaces onto one another. * *  See ChangeLog for modifications, CREDITS for credits. *  			 *  All source herein is copyright U4X Labs and its original author.  *  Any code modifications or additions are (C)opyright the original  *  author and U4X Labs respectively. * *  libfbx is free software; you can redistribute it and/or modify it  *  under the terms of the GNU Lesser General Public License as  *  published by the Free Software Foundation; either version 2.1 of  *  the License, or (at your option) any later version. * *  libfbx 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 Lesser General Public License for more details. * *  You should have received a copy of the GNU Lesser General Public *  License along with libfbx; if not, write to the Free Software  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *  USA */#include <stdio.h>#include <errno.h>#include <fcntl.h>#include <unistd.h>#include <stdlib.h>#include <stdarg.h>#include <string.h>#include <signal.h>#include <time.h>#include <math.h>#include <linux/fb.h>#include <linux/kd.h>#include <sys/mman.h>#include <sys/ioctl.h>#include <sys/user.h>#include <termios.h>#include <ctype.h>#include <libfbx/libfbx.h>/* * Function:	fb_stretch_image() * Arguments:	source and destination surface, x and y positioners, * 		width and height to scale to. * Description: Stretches an image to specified width and height. */void fb_stretch_image(fb_surface *src, 			     fb_surface *dest, 			     int x, int y, 			     int w, int h){        int xpos = x, ypos = y;        int r, g, b;        float ratio_x;        float ratio_y;        int x1, y1;        register unsigned char *ptr1, *ptr2;        if (w == src->width && h == src->height)                fb_draw_image(src, dest, x, y);        ratio_x = (float)src->width / (float)w;        ratio_y = (float)src->height / (float)h;        ptr1 = (unsigned char *)(src->mem_pointer +                                 src->mem_offset +                                 ypos * src->line_size +                                 xpos * src->pixel_size);        ptr2 = (unsigned char *)(dest->mem_pointer +                                 dest->mem_offset +                                 (ypos - y) * dest->line_size);        for (ypos = y; ypos < y + h; ypos++)                for (xpos = x; xpos < x + w; xpos++) {                        x1 = (int)((xpos - x) * ratio_x);                        y1 = (int)((ypos - y) * ratio_y);                        fb_getpixel(x1, y1, &r, &g, &b, src);                        fb_putpixel(xpos, ypos, r, g, b, dest);                }}/* * Function:	fb_stretch_image_aa() * Arguments:	source and destination surface, x and y positioners, * 		new width and height. * Returns:	None * Description: */void fb_stretch_image_aa(fb_surface *src, 				fb_surface *dest, 				int x, int y, 				int w, int h){        int xpos = x, ypos = y;        float r, g, b;        int r1, g1, b1;        int r2, g2, b2;        int r3, g3, b3;        int r4, g4, b4;        float ratio_x;        float ratio_y;        float x1, y1;        float xerr, yerr;        float xfloat, yfloat;        if (w == src->width && h == src->height)                fb_draw_image(src, dest, x, y);        ratio_x = (float)src->width / (float)w;        ratio_y = (float)src->height / (float)h;        for (ypos = y; ypos < y + h; ypos++)                for (xpos = x; xpos < x + w; xpos++) {                        xfloat = (xpos - x) * ratio_x;                        yfloat = (ypos - y) * ratio_y;                        x1 = (int)xfloat;                        y1 = (int)yfloat;                        xerr = 1.0 - (xfloat - (float)x1);                        yerr = 1.0 - (yfloat - (float)y1);                        fb_getpixel(x1, y1, &r1, &g1, &b1, src);                        fb_getpixel(x1 + 1, y1, &r2, &g2, &b2, src);                        fb_getpixel(x1 + 1, y1 + 1, &r3, &g3, &b3, src);                        fb_getpixel(x1, y1 + 1, &r4, &g4, &b4, src);                        r = (float)r1 * xerr +                            (float)r2 * (1.0 - xerr) +                            (float)r3 * (1.0 - xerr) +                            (float)r4 * xerr;                        r += (float)r1 * yerr +                             (float)r2 * yerr +                             (float)r3 * (1.0 - yerr) +                             (float)r4 * (1.0 - yerr);                        r *= 0.25;                        g = (float)g1 * xerr +                            (float)g2 * (1.0 - xerr) +                            (float)g3 * (1.0 - xerr) +                            (float)g4 * xerr;                        g += (float)g1 * yerr +                             (float)g2 * yerr +                             (float)g3 * (1.0 - yerr) +                             (float)g4 * (1.0 - yerr);                        g *= 0.25;                        b = (float)b1 * xerr +                            (float)b2 * (1.0 - xerr) +                            (float)b3 * (1.0 - xerr) +                            (float)b4 * xerr;                        b += (float)b1 * yerr +                             (float)b2 * yerr +                             (float)b3 * (1.0 - yerr) +                             (float)b4 * (1.0 - yerr);                        b *= 0.25;#ifdef ENABLE_DEBUG                        if (xpos % 1 == 0 && ypos % 1 == 0)                                fprintf(debug_output, "fb_stretch_image: (x1, y1)"                                                      "= (%f, %f)\n ((r1, g1, b1), "                                                      "(r2, g2, b2), (r3, g3, b3), "                                                      "(r4, g4, b4)) = "                                                      "((%i, %i, %i),(%i, %i, %i), "                                                      "(%i, %i, %i), (%i, %i, %i)\n "                                                      "(r, g, b) = (%f, %f, %f)\n "                                                      "(xerr, yerr) = (%f, %f)\n"                                                      "(xfloat, yfloat) = (%f, %f)\n\n",                                                      x1, y1, r1, g1, b1, r2, g2, b2,                                                      r3, g3, b3, r4, g4, b4, r, g, b,                                                      xerr, yerr, xfloat, yfloat);#endif                        fb_putpixel(xpos, ypos, (int)r, (int)g, (int)b, dest);		}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -