19a57b7d2SSøren Schmidt /*- 25e53a4f9SPedro F. Giffuni * SPDX-License-Identifier: BSD-3-Clause 35e53a4f9SPedro F. Giffuni * 4bf3f9db6SUlrich Spörlein * Copyright (c) 1991-1997 Søren Schmidt 59a57b7d2SSøren Schmidt * All rights reserved. 69a57b7d2SSøren Schmidt * 79a57b7d2SSøren Schmidt * Redistribution and use in source and binary forms, with or without 89a57b7d2SSøren Schmidt * modification, are permitted provided that the following conditions 99a57b7d2SSøren Schmidt * are met: 109a57b7d2SSøren Schmidt * 1. Redistributions of source code must retain the above copyright 119a57b7d2SSøren Schmidt * notice, this list of conditions and the following disclaimer, 129a57b7d2SSøren Schmidt * in this position and unchanged. 139a57b7d2SSøren Schmidt * 2. Redistributions in binary form must reproduce the above copyright 149a57b7d2SSøren Schmidt * notice, this list of conditions and the following disclaimer in the 159a57b7d2SSøren Schmidt * documentation and/or other materials provided with the distribution. 169a57b7d2SSøren Schmidt * 3. The name of the author may not be used to endorse or promote products 1721dc7d4fSJens Schweikhardt * derived from this software without specific prior written permission. 189a57b7d2SSøren Schmidt * 199a57b7d2SSøren Schmidt * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 209a57b7d2SSøren Schmidt * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 219a57b7d2SSøren Schmidt * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 229a57b7d2SSøren Schmidt * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 239a57b7d2SSøren Schmidt * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 249a57b7d2SSøren Schmidt * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 259a57b7d2SSøren Schmidt * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 269a57b7d2SSøren Schmidt * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 279a57b7d2SSøren Schmidt * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 289a57b7d2SSøren Schmidt * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 299a57b7d2SSøren Schmidt */ 309a57b7d2SSøren Schmidt 31e67f5b9fSMatthew Dillon #include <sys/cdefs.h> 32e67f5b9fSMatthew Dillon __FBSDID("$FreeBSD$"); 33e67f5b9fSMatthew Dillon 349a57b7d2SSøren Schmidt #include <sys/types.h> 359a57b7d2SSøren Schmidt #include <signal.h> 3600d25f51SPoul-Henning Kamp #include <sys/fbio.h> 379a57b7d2SSøren Schmidt #include "vgl.h" 389a57b7d2SSøren Schmidt 395acf51eaSKazutaka YOKOTA #define min(x, y) (((x) < (y)) ? (x) : (y)) 405acf51eaSKazutaka YOKOTA 419a57b7d2SSøren Schmidt static byte mask[8] = {0xff, 0x7f, 0x3f, 0x1f, 0x0f, 0x07, 0x03, 0x01}; 429a57b7d2SSøren Schmidt static int color2bit[16] = {0x00000000, 0x00000001, 0x00000100, 0x00000101, 439a57b7d2SSøren Schmidt 0x00010000, 0x00010001, 0x00010100, 0x00010101, 449a57b7d2SSøren Schmidt 0x01000000, 0x01000001, 0x01000100, 0x01000101, 459a57b7d2SSøren Schmidt 0x01010000, 0x01010001, 0x01010100, 0x01010101}; 469a57b7d2SSøren Schmidt 479a57b7d2SSøren Schmidt static void 489a57b7d2SSøren Schmidt WriteVerticalLine(VGLBitmap *dst, int x, int y, int width, byte *line) 499a57b7d2SSøren Schmidt { 509a57b7d2SSøren Schmidt int i, pos, last, planepos, start_offset, end_offset, offset; 515acf51eaSKazutaka YOKOTA int len; 529a57b7d2SSøren Schmidt unsigned int word = 0; 539a57b7d2SSøren Schmidt byte *address; 545acf51eaSKazutaka YOKOTA byte *VGLPlane[4]; 559a57b7d2SSøren Schmidt 569a57b7d2SSøren Schmidt switch (dst->Type) { 579a57b7d2SSøren Schmidt case VIDBUF4: 585acf51eaSKazutaka YOKOTA case VIDBUF4S: 599a57b7d2SSøren Schmidt start_offset = (x & 0x07); 609a57b7d2SSøren Schmidt end_offset = (x + width) & 0x07; 615acf51eaSKazutaka YOKOTA i = (width + start_offset) / 8; 625acf51eaSKazutaka YOKOTA if (end_offset) 635acf51eaSKazutaka YOKOTA i++; 645acf51eaSKazutaka YOKOTA VGLPlane[0] = VGLBuf; 655acf51eaSKazutaka YOKOTA VGLPlane[1] = VGLPlane[0] + i; 665acf51eaSKazutaka YOKOTA VGLPlane[2] = VGLPlane[1] + i; 675acf51eaSKazutaka YOKOTA VGLPlane[3] = VGLPlane[2] + i; 689a57b7d2SSøren Schmidt pos = 0; 699a57b7d2SSøren Schmidt planepos = 0; 705acf51eaSKazutaka YOKOTA last = 8 - start_offset; 719a57b7d2SSøren Schmidt while (pos < width) { 729a57b7d2SSøren Schmidt word = 0; 739a57b7d2SSøren Schmidt while (pos < last && pos < width) 749a57b7d2SSøren Schmidt word = (word<<1) | color2bit[line[pos++]&0x0f]; 759a57b7d2SSøren Schmidt VGLPlane[0][planepos] = word; 769a57b7d2SSøren Schmidt VGLPlane[1][planepos] = word>>8; 779a57b7d2SSøren Schmidt VGLPlane[2][planepos] = word>>16; 789a57b7d2SSøren Schmidt VGLPlane[3][planepos] = word>>24; 799a57b7d2SSøren Schmidt planepos++; 805acf51eaSKazutaka YOKOTA last += 8; 819a57b7d2SSøren Schmidt } 829a57b7d2SSøren Schmidt planepos--; 839a57b7d2SSøren Schmidt if (end_offset) { 849a57b7d2SSøren Schmidt word <<= (8 - end_offset); 859a57b7d2SSøren Schmidt VGLPlane[0][planepos] = word; 869a57b7d2SSøren Schmidt VGLPlane[1][planepos] = word>>8; 879a57b7d2SSøren Schmidt VGLPlane[2][planepos] = word>>16; 889a57b7d2SSøren Schmidt VGLPlane[3][planepos] = word>>24; 899a57b7d2SSøren Schmidt } 909a57b7d2SSøren Schmidt if (start_offset || end_offset) 919a57b7d2SSøren Schmidt width+=8; 925acf51eaSKazutaka YOKOTA width /= 8; 935acf51eaSKazutaka YOKOTA outb(0x3ce, 0x01); outb(0x3cf, 0x00); /* set/reset enable */ 945acf51eaSKazutaka YOKOTA outb(0x3ce, 0x08); outb(0x3cf, 0xff); /* bit mask */ 959a57b7d2SSøren Schmidt for (i=0; i<4; i++) { 969a57b7d2SSøren Schmidt outb(0x3c4, 0x02); 979a57b7d2SSøren Schmidt outb(0x3c5, 0x01<<i); 989a57b7d2SSøren Schmidt outb(0x3ce, 0x04); 999a57b7d2SSøren Schmidt outb(0x3cf, i); 1005acf51eaSKazutaka YOKOTA pos = VGLAdpInfo.va_line_width*y + x/8; 1015acf51eaSKazutaka YOKOTA if (dst->Type == VIDBUF4) { 1029a57b7d2SSøren Schmidt if (end_offset) 1035acf51eaSKazutaka YOKOTA VGLPlane[i][planepos] |= dst->Bitmap[pos+planepos] & mask[end_offset]; 1045acf51eaSKazutaka YOKOTA if (start_offset) 1055acf51eaSKazutaka YOKOTA VGLPlane[i][0] |= dst->Bitmap[pos] & ~mask[start_offset]; 1065acf51eaSKazutaka YOKOTA bcopy(&VGLPlane[i][0], dst->Bitmap + pos, width); 1075acf51eaSKazutaka YOKOTA } else { /* VIDBUF4S */ 1085acf51eaSKazutaka YOKOTA if (end_offset) { 1095acf51eaSKazutaka YOKOTA offset = VGLSetSegment(pos + planepos); 1105acf51eaSKazutaka YOKOTA VGLPlane[i][planepos] |= dst->Bitmap[offset] & mask[end_offset]; 1115acf51eaSKazutaka YOKOTA } 1125acf51eaSKazutaka YOKOTA offset = VGLSetSegment(pos); 1135acf51eaSKazutaka YOKOTA if (start_offset) 1145acf51eaSKazutaka YOKOTA VGLPlane[i][0] |= dst->Bitmap[offset] & ~mask[start_offset]; 1155acf51eaSKazutaka YOKOTA for (last = width; ; ) { 1165acf51eaSKazutaka YOKOTA len = min(VGLAdpInfo.va_window_size - offset, last); 1175acf51eaSKazutaka YOKOTA bcopy(&VGLPlane[i][width - last], dst->Bitmap + offset, len); 1185acf51eaSKazutaka YOKOTA pos += len; 1195acf51eaSKazutaka YOKOTA last -= len; 1205acf51eaSKazutaka YOKOTA if (last <= 0) 1215acf51eaSKazutaka YOKOTA break; 1225acf51eaSKazutaka YOKOTA offset = VGLSetSegment(pos); 1235acf51eaSKazutaka YOKOTA } 1245acf51eaSKazutaka YOKOTA } 1259a57b7d2SSøren Schmidt } 1269a57b7d2SSøren Schmidt break; 1279a57b7d2SSøren Schmidt case VIDBUF8X: 1285acf51eaSKazutaka YOKOTA address = dst->Bitmap + VGLAdpInfo.va_line_width * y + x/4; 1299a57b7d2SSøren Schmidt for (i=0; i<4; i++) { 1309a57b7d2SSøren Schmidt outb(0x3c4, 0x02); 1315e7a62b2SKazutaka YOKOTA outb(0x3c5, 0x01 << ((x + i)%4)); 1325e7a62b2SKazutaka YOKOTA for (planepos=0, pos=i; pos<width; planepos++, pos+=4) 1339a57b7d2SSøren Schmidt address[planepos] = line[pos]; 1345e7a62b2SKazutaka YOKOTA if ((x + i)%4 == 3) 1355e7a62b2SKazutaka YOKOTA ++address; 1369a57b7d2SSøren Schmidt } 1379a57b7d2SSøren Schmidt break; 1385acf51eaSKazutaka YOKOTA case VIDBUF8S: 139933d455fSNicolas Souchu case VIDBUF16S: 140933d455fSNicolas Souchu case VIDBUF24S: 141933d455fSNicolas Souchu case VIDBUF32S: 142933d455fSNicolas Souchu width = width * dst->PixelBytes; 143933d455fSNicolas Souchu pos = (dst->VXsize * y + x) * dst->PixelBytes; 144933d455fSNicolas Souchu while (width > 0) { 145933d455fSNicolas Souchu offset = VGLSetSegment(pos); 146933d455fSNicolas Souchu i = min(VGLAdpInfo.va_window_size - offset, width); 147933d455fSNicolas Souchu bcopy(line, dst->Bitmap + offset, i); 148933d455fSNicolas Souchu line += i; 149933d455fSNicolas Souchu pos += i; 150933d455fSNicolas Souchu width -= i; 151933d455fSNicolas Souchu } 152933d455fSNicolas Souchu break; 1539a57b7d2SSøren Schmidt case MEMBUF: 154b8e788b6SBruce Evans case VIDBUF8: 155933d455fSNicolas Souchu case VIDBUF16: 156933d455fSNicolas Souchu case VIDBUF24: 157933d455fSNicolas Souchu case VIDBUF32: 158933d455fSNicolas Souchu address = dst->Bitmap + (dst->VXsize * y + x) * dst->PixelBytes; 159933d455fSNicolas Souchu bcopy(line, address, width * dst->PixelBytes); 160933d455fSNicolas Souchu break; 1619a57b7d2SSøren Schmidt default: 162a96d3de6SGarrett Wollman ; 1639a57b7d2SSøren Schmidt } 1649a57b7d2SSøren Schmidt } 1659a57b7d2SSøren Schmidt 1669a57b7d2SSøren Schmidt static void 1679a57b7d2SSøren Schmidt ReadVerticalLine(VGLBitmap *src, int x, int y, int width, byte *line) 1689a57b7d2SSøren Schmidt { 1699a57b7d2SSøren Schmidt int i, bit, pos, count, planepos, start_offset, end_offset, offset; 1705acf51eaSKazutaka YOKOTA int width2, len; 1719a57b7d2SSøren Schmidt byte *address; 1725acf51eaSKazutaka YOKOTA byte *VGLPlane[4]; 1739a57b7d2SSøren Schmidt 1749a57b7d2SSøren Schmidt switch (src->Type) { 1755acf51eaSKazutaka YOKOTA case VIDBUF4S: 1769a57b7d2SSøren Schmidt start_offset = (x & 0x07); 1779a57b7d2SSøren Schmidt end_offset = (x + width) & 0x07; 1785acf51eaSKazutaka YOKOTA count = (width + start_offset) / 8; 1799a57b7d2SSøren Schmidt if (end_offset) 1809a57b7d2SSøren Schmidt count++; 1815acf51eaSKazutaka YOKOTA VGLPlane[0] = VGLBuf; 1825acf51eaSKazutaka YOKOTA VGLPlane[1] = VGLPlane[0] + count; 1835acf51eaSKazutaka YOKOTA VGLPlane[2] = VGLPlane[1] + count; 1845acf51eaSKazutaka YOKOTA VGLPlane[3] = VGLPlane[2] + count; 1855acf51eaSKazutaka YOKOTA for (i=0; i<4; i++) { 1865acf51eaSKazutaka YOKOTA outb(0x3ce, 0x04); 1875acf51eaSKazutaka YOKOTA outb(0x3cf, i); 1885acf51eaSKazutaka YOKOTA pos = VGLAdpInfo.va_line_width*y + x/8; 1895acf51eaSKazutaka YOKOTA for (width2 = count; width2 > 0; ) { 1905acf51eaSKazutaka YOKOTA offset = VGLSetSegment(pos); 1915acf51eaSKazutaka YOKOTA len = min(VGLAdpInfo.va_window_size - offset, width2); 1925acf51eaSKazutaka YOKOTA bcopy(src->Bitmap + offset, &VGLPlane[i][count - width2], len); 1935acf51eaSKazutaka YOKOTA pos += len; 1945acf51eaSKazutaka YOKOTA width2 -= len; 1955acf51eaSKazutaka YOKOTA } 1965acf51eaSKazutaka YOKOTA } 1975acf51eaSKazutaka YOKOTA goto read_planar; 1985acf51eaSKazutaka YOKOTA case VIDBUF4: 1995acf51eaSKazutaka YOKOTA address = src->Bitmap + VGLAdpInfo.va_line_width * y + x/8; 2005acf51eaSKazutaka YOKOTA start_offset = (x & 0x07); 2015acf51eaSKazutaka YOKOTA end_offset = (x + width) & 0x07; 2025acf51eaSKazutaka YOKOTA count = (width + start_offset) / 8; 2035acf51eaSKazutaka YOKOTA if (end_offset) 2045acf51eaSKazutaka YOKOTA count++; 2055acf51eaSKazutaka YOKOTA VGLPlane[0] = VGLBuf; 2065acf51eaSKazutaka YOKOTA VGLPlane[1] = VGLPlane[0] + count; 2075acf51eaSKazutaka YOKOTA VGLPlane[2] = VGLPlane[1] + count; 2085acf51eaSKazutaka YOKOTA VGLPlane[3] = VGLPlane[2] + count; 2099a57b7d2SSøren Schmidt for (i=0; i<4; i++) { 2109a57b7d2SSøren Schmidt outb(0x3ce, 0x04); 2119a57b7d2SSøren Schmidt outb(0x3cf, i); 2129a57b7d2SSøren Schmidt bcopy(address, &VGLPlane[i][0], count); 2139a57b7d2SSøren Schmidt } 2145acf51eaSKazutaka YOKOTA read_planar: 2159a57b7d2SSøren Schmidt pos = 0; 2169a57b7d2SSøren Schmidt planepos = 0; 2175acf51eaSKazutaka YOKOTA bit = 7 - start_offset; 2189a57b7d2SSøren Schmidt while (pos < width) { 2195acf51eaSKazutaka YOKOTA for (; bit >= 0 && pos < width; bit--, pos++) { 2209a57b7d2SSøren Schmidt line[pos] = (VGLPlane[0][planepos] & (1<<bit) ? 1 : 0) | 2219a57b7d2SSøren Schmidt ((VGLPlane[1][planepos] & (1<<bit) ? 1 : 0) << 1) | 2229a57b7d2SSøren Schmidt ((VGLPlane[2][planepos] & (1<<bit) ? 1 : 0) << 2) | 2239a57b7d2SSøren Schmidt ((VGLPlane[3][planepos] & (1<<bit) ? 1 : 0) << 3); 2249a57b7d2SSøren Schmidt } 2259a57b7d2SSøren Schmidt planepos++; 2265acf51eaSKazutaka YOKOTA bit = 7; 2279a57b7d2SSøren Schmidt } 2289a57b7d2SSøren Schmidt break; 2299a57b7d2SSøren Schmidt case VIDBUF8X: 2305acf51eaSKazutaka YOKOTA address = src->Bitmap + VGLAdpInfo.va_line_width * y + x/4; 2319a57b7d2SSøren Schmidt for (i=0; i<4; i++) { 2329a57b7d2SSøren Schmidt outb(0x3ce, 0x04); 2335e7a62b2SKazutaka YOKOTA outb(0x3cf, (x + i)%4); 2345e7a62b2SKazutaka YOKOTA for (planepos=0, pos=i; pos<width; planepos++, pos+=4) 2359a57b7d2SSøren Schmidt line[pos] = address[planepos]; 2365e7a62b2SKazutaka YOKOTA if ((x + i)%4 == 3) 2375e7a62b2SKazutaka YOKOTA ++address; 2389a57b7d2SSøren Schmidt } 2399a57b7d2SSøren Schmidt break; 2405acf51eaSKazutaka YOKOTA case VIDBUF8S: 241933d455fSNicolas Souchu case VIDBUF16S: 242933d455fSNicolas Souchu case VIDBUF24S: 243933d455fSNicolas Souchu case VIDBUF32S: 244933d455fSNicolas Souchu width = width * src->PixelBytes; 245933d455fSNicolas Souchu pos = (src->VXsize * y + x) * src->PixelBytes; 246933d455fSNicolas Souchu while (width > 0) { 247933d455fSNicolas Souchu offset = VGLSetSegment(pos); 248933d455fSNicolas Souchu i = min(VGLAdpInfo.va_window_size - offset, width); 249933d455fSNicolas Souchu bcopy(src->Bitmap + offset, line, i); 250933d455fSNicolas Souchu line += i; 251933d455fSNicolas Souchu pos += i; 252933d455fSNicolas Souchu width -= i; 253933d455fSNicolas Souchu } 254933d455fSNicolas Souchu break; 2559a57b7d2SSøren Schmidt case MEMBUF: 256b8e788b6SBruce Evans case VIDBUF8: 257933d455fSNicolas Souchu case VIDBUF16: 258933d455fSNicolas Souchu case VIDBUF24: 259933d455fSNicolas Souchu case VIDBUF32: 260933d455fSNicolas Souchu address = src->Bitmap + (src->VXsize * y + x) * src->PixelBytes; 261933d455fSNicolas Souchu bcopy(address, line, width * src->PixelBytes); 262933d455fSNicolas Souchu break; 2639a57b7d2SSøren Schmidt default: 264a96d3de6SGarrett Wollman ; 2659a57b7d2SSøren Schmidt } 2669a57b7d2SSøren Schmidt } 2679a57b7d2SSøren Schmidt 2689a57b7d2SSøren Schmidt int 2699a57b7d2SSøren Schmidt __VGLBitmapCopy(VGLBitmap *src, int srcx, int srcy, 2709a57b7d2SSøren Schmidt VGLBitmap *dst, int dstx, int dsty, int width, int hight) 2719a57b7d2SSøren Schmidt { 272*1e4abf1dSBruce Evans int srcline, dstline, yend, yextra, ystep; 2739a57b7d2SSøren Schmidt 2745acf51eaSKazutaka YOKOTA if (srcx>src->VXsize || srcy>src->VYsize 2755acf51eaSKazutaka YOKOTA || dstx>dst->VXsize || dsty>dst->VYsize) 2769a57b7d2SSøren Schmidt return -1; 2779a57b7d2SSøren Schmidt if (srcx < 0) { 2789a57b7d2SSøren Schmidt width=width+srcx; dstx-=srcx; srcx=0; 2799a57b7d2SSøren Schmidt } 2809a57b7d2SSøren Schmidt if (srcy < 0) { 2819a57b7d2SSøren Schmidt hight=hight+srcy; dsty-=srcy; srcy=0; 2829a57b7d2SSøren Schmidt } 2839a57b7d2SSøren Schmidt if (dstx < 0) { 2849a57b7d2SSøren Schmidt width=width+dstx; srcx-=dstx; dstx=0; 2859a57b7d2SSøren Schmidt } 2869a57b7d2SSøren Schmidt if (dsty < 0) { 2879a57b7d2SSøren Schmidt hight=hight+dsty; srcy-=dsty; dsty=0; 2889a57b7d2SSøren Schmidt } 2895acf51eaSKazutaka YOKOTA if (srcx+width > src->VXsize) 2905acf51eaSKazutaka YOKOTA width=src->VXsize-srcx; 2915acf51eaSKazutaka YOKOTA if (srcy+hight > src->VYsize) 2925acf51eaSKazutaka YOKOTA hight=src->VYsize-srcy; 2935acf51eaSKazutaka YOKOTA if (dstx+width > dst->VXsize) 2945acf51eaSKazutaka YOKOTA width=dst->VXsize-dstx; 2955acf51eaSKazutaka YOKOTA if (dsty+hight > dst->VYsize) 2965acf51eaSKazutaka YOKOTA hight=dst->VYsize-dsty; 2979a57b7d2SSøren Schmidt if (width < 0 || hight < 0) 2989a57b7d2SSøren Schmidt return -1; 299*1e4abf1dSBruce Evans yend = srcy + hight; 300*1e4abf1dSBruce Evans yextra = 0; 301*1e4abf1dSBruce Evans ystep = 1; 302*1e4abf1dSBruce Evans if (src->Bitmap == dst->Bitmap && srcy < dsty) { 303*1e4abf1dSBruce Evans yend = srcy; 304*1e4abf1dSBruce Evans yextra = hight - 1; 305*1e4abf1dSBruce Evans ystep = -1; 306*1e4abf1dSBruce Evans } 3079a57b7d2SSøren Schmidt if (src->Type == MEMBUF) { 308*1e4abf1dSBruce Evans for (srcline = srcy + yextra, dstline = dsty + yextra; srcline != yend; 309*1e4abf1dSBruce Evans srcline += ystep, dstline += ystep) { 3109a57b7d2SSøren Schmidt WriteVerticalLine(dst, dstx, dstline, width, 311aa1ce985SBruce Evans src->Bitmap+(srcline*src->VXsize+srcx)*dst->PixelBytes); 3129a57b7d2SSøren Schmidt } 3139a57b7d2SSøren Schmidt } 3149a57b7d2SSøren Schmidt else if (dst->Type == MEMBUF) { 3159a57b7d2SSøren Schmidt for (srcline=srcy, dstline=dsty; srcline<srcy+hight; srcline++, dstline++) { 3169a57b7d2SSøren Schmidt ReadVerticalLine(src, srcx, srcline, width, 317aa1ce985SBruce Evans dst->Bitmap+(dstline*dst->VXsize+dstx)*src->PixelBytes); 3189a57b7d2SSøren Schmidt } 3199a57b7d2SSøren Schmidt } 3209a57b7d2SSøren Schmidt else { 3215acf51eaSKazutaka YOKOTA byte buffer[2048]; /* XXX */ 3225acf51eaSKazutaka YOKOTA byte *p; 3235acf51eaSKazutaka YOKOTA 324fbc6daa1SBruce Evans if (width * src->PixelBytes > sizeof(buffer)) { 325fbc6daa1SBruce Evans p = malloc(width * src->PixelBytes); 3265acf51eaSKazutaka YOKOTA if (p == NULL) 3275acf51eaSKazutaka YOKOTA return 1; 3285acf51eaSKazutaka YOKOTA } else { 3295acf51eaSKazutaka YOKOTA p = buffer; 3309a57b7d2SSøren Schmidt } 331*1e4abf1dSBruce Evans for (srcline = srcy + yextra, dstline = dsty + yextra; srcline != yend; 332*1e4abf1dSBruce Evans srcline += ystep, dstline += ystep) { 3335acf51eaSKazutaka YOKOTA ReadVerticalLine(src, srcx, srcline, width, p); 3345acf51eaSKazutaka YOKOTA WriteVerticalLine(dst, dstx, dstline, width, p); 3355acf51eaSKazutaka YOKOTA } 336fbc6daa1SBruce Evans if (width * src->PixelBytes > sizeof(buffer)) 3375acf51eaSKazutaka YOKOTA free(p); 3389a57b7d2SSøren Schmidt } 3399a57b7d2SSøren Schmidt return 0; 3409a57b7d2SSøren Schmidt } 3419a57b7d2SSøren Schmidt 3429a57b7d2SSøren Schmidt int 3439a57b7d2SSøren Schmidt VGLBitmapCopy(VGLBitmap *src, int srcx, int srcy, 3449a57b7d2SSøren Schmidt VGLBitmap *dst, int dstx, int dsty, int width, int hight) 3459a57b7d2SSøren Schmidt { 3469a57b7d2SSøren Schmidt int error; 3479a57b7d2SSøren Schmidt 348014ddcbcSBruce Evans if (src->Type != MEMBUF) 349014ddcbcSBruce Evans VGLMouseFreeze(srcx, srcy, width, hight, 0); 350014ddcbcSBruce Evans if (dst->Type != MEMBUF) 3519a57b7d2SSøren Schmidt VGLMouseFreeze(dstx, dsty, width, hight, 0); 3529a57b7d2SSøren Schmidt error = __VGLBitmapCopy(src, srcx, srcy, dst, dstx, dsty, width, hight); 353014ddcbcSBruce Evans if (src->Type != MEMBUF || dst->Type != MEMBUF) 3549a57b7d2SSøren Schmidt VGLMouseUnFreeze(); 3559a57b7d2SSøren Schmidt return error; 3569a57b7d2SSøren Schmidt } 3579a57b7d2SSøren Schmidt 3585acf51eaSKazutaka YOKOTA VGLBitmap 3595acf51eaSKazutaka YOKOTA *VGLBitmapCreate(int type, int xsize, int ysize, byte *bits) 3605acf51eaSKazutaka YOKOTA { 3615acf51eaSKazutaka YOKOTA VGLBitmap *object; 3625acf51eaSKazutaka YOKOTA 3635acf51eaSKazutaka YOKOTA if (type != MEMBUF) 3645acf51eaSKazutaka YOKOTA return NULL; 3655acf51eaSKazutaka YOKOTA if (xsize < 0 || ysize < 0) 3665acf51eaSKazutaka YOKOTA return NULL; 3675acf51eaSKazutaka YOKOTA object = (VGLBitmap *)malloc(sizeof(*object)); 3685acf51eaSKazutaka YOKOTA if (object == NULL) 3695acf51eaSKazutaka YOKOTA return NULL; 3705acf51eaSKazutaka YOKOTA object->Type = type; 3715acf51eaSKazutaka YOKOTA object->Xsize = xsize; 3725acf51eaSKazutaka YOKOTA object->Ysize = ysize; 3735acf51eaSKazutaka YOKOTA object->VXsize = xsize; 3745acf51eaSKazutaka YOKOTA object->VYsize = ysize; 3755acf51eaSKazutaka YOKOTA object->Xorigin = 0; 3765acf51eaSKazutaka YOKOTA object->Yorigin = 0; 3775acf51eaSKazutaka YOKOTA object->Bitmap = bits; 378fbc6daa1SBruce Evans object->PixelBytes = VGLDisplay->PixelBytes; 3795acf51eaSKazutaka YOKOTA return object; 3805acf51eaSKazutaka YOKOTA } 3815acf51eaSKazutaka YOKOTA 3825acf51eaSKazutaka YOKOTA void 3835acf51eaSKazutaka YOKOTA VGLBitmapDestroy(VGLBitmap *object) 3845acf51eaSKazutaka YOKOTA { 3855acf51eaSKazutaka YOKOTA if (object->Bitmap) 3865acf51eaSKazutaka YOKOTA free(object->Bitmap); 3875acf51eaSKazutaka YOKOTA free(object); 3885acf51eaSKazutaka YOKOTA } 3895acf51eaSKazutaka YOKOTA 3905acf51eaSKazutaka YOKOTA int 3915acf51eaSKazutaka YOKOTA VGLBitmapAllocateBits(VGLBitmap *object) 3925acf51eaSKazutaka YOKOTA { 393fbc6daa1SBruce Evans object->Bitmap = malloc(object->VXsize*object->VYsize*object->PixelBytes); 3945acf51eaSKazutaka YOKOTA if (object->Bitmap == NULL) 3955acf51eaSKazutaka YOKOTA return -1; 3965acf51eaSKazutaka YOKOTA return 0; 3975acf51eaSKazutaka YOKOTA } 398