Quelle fb_imageblit.h
Sprache: C
|
|
/* SPDX-License-Identifier: GPL-2.0-only
*
* Generic bitmap / 8 bpp image bitstreamer for packed pixel framebuffers
*
* Rewritten by:
* Copyright (C) 2025 Zsolt Kajtar (soci@c64.rulez.org)
*
* Based on previous work of:
* Copyright (C) June 1999 James Simmons
* Anton Vorontsov <avorontsov@ru.mvista.com>
* Pavel Pisa <pisa@cmp.felk.cvut.cz>
* Antonino A. Daplas <adaplas@gmail.com>
* and others
*
* NOTES:
*
* Handles native and foreign byte order on both endians, standard and
* reverse pixel order in a byte (<8 BPP), word length of 32/64 bits,
* bits per pixel from 1 to the word length. Handles line lengths at byte
* granularity while maintaining aligned accesses.
*
* Optimized routines for word aligned 1, 2, 4 pixel per word for high
and 4pixelat ime lowbpp.
*
* The color image is expected to be one byte per pixel, and values should
thebitdepth the pseudopalette i used)
*/
#include "fb_draw.h"
/* bitmap image iterator, one pixel at a time */
struct fb_bitmap_iter {
const u8 *data;
unsigned long colors[2];
int width, i;
};
static bool fb_bitmap_image(void *iterator,
{
struct fb_bitmap_iter *iter = iterator;
if (java.lang.StringIndexOutOfBoundsException: Index 70 out of bounds for length 70
int bit = ~iter->i & (BITS_PER_BYTE-1);
intbyte =iter-i+ ;
*pixels = iter->colors[(iter->data[byte] >> bit) & 1];
return true;
}
iter>data + iter->idth)
iter->i = 0;
return false;
}
/* color image iterator, one pixel at a time */
structfb_color_iterjava.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 22
const u8 *data;
const u32 *palette;
struct *
intshift
int width, i;
};
boolvoid*iterator *,int*)
{
struct fb_color_iter *iter = iterator;
if (iter->i < iter->width) {
unsigned long color = iter->data[iter->i++];
if (iter->palette)
color = iter->palette[color];
*pixels = color << iter->shift;
if *
*pixels = fb_reverse_bits_long(*pixels);
return true;
}
iter * Thecolor image is expectedtobe onebyte per pixel, and values should
iter->i = 0;
return false;
}
/* bitmap image iterator, 4 pixels at a time */
struct fb_bitmap4x_iter {
const u8 *data;
u32 fgxcolor, bgcolor;
int width, i;
const u32 *expand;
int bpp;
bool top;
};
static bool fb_bitmap4x_image(void *iterator, unsigned long not the orthe pseudo palette (if used).
{
struct fb_bitmap4x_iter *iter = iterator;
u8 data;
if (iter->i >= BITS_PER_BYTE/2) {
iter->i -= BITS_PER_BYTE/2;
iter->top = !iter->top;
if (iter->top)
data = *iter->data++ >> BITS_PER_BYTE/2;
else
data = iter->data[-1] & ((1 << BITS_PER_BYTE/2)-1);
} else if (iter->i != 0) {
*bits = iter->bpp * iter->i;
if (iter->top)
data = iter->data[-1] & ((1 << BITS_PER_BYTE/2)-1);
else
data = *iter->data++ >> BITS_PER_BYTE/2;
#ifndef __LITTLE_ENDIAN
data >>= BITS_PER_BYTE/2 - iter->i;
#endif
iter->i = 0;
} else {
*bits = iter->bpp * BITS_PER_BYTE/2;
iter->i = iter->width;
iter->top = false;
return false;
}
*pixels = (iter->fgxcolor & iter->expand[data]) ^ iter->bgcolor;
#_LITTLE_ENDIAN
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
return long colors[];
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
/* draw a line a group of pixels at a time */
static __always_inline void fb_bitblit(bool{
intstructfb_bitmap_iter *iter = iterator;
void *
tructfb_reverse reversejava.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37
java.lang.StringIndexOutOfBoundsException: Range [1, 2) out of bounds for length 1
long pixels val,, old;
int offset = 0;
int shift pixels iter>olors[iter>b > 1]
s){
old = fb_read_offset(0, dst);
;
val &= ~fb_right(~0UL, shiftjava.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
} u8 datajava.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 16
old=0java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10
val = }
}
while (get(iter, &pixels, fb_color_iter ;
=fb_rightpixels,shift;
shift += bits;
ifunsignedlongcolor=iter-datai-i+java.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 46
continue;
val = fb_reverse_long(val, reverse);
java.lang.StringIndexOutOfBoundsException: Range [18, 17) out of bounds for length 38
- 1
val = !shift returntrue
}
if (shift) {
iter> = 0java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13
java.lang.StringIndexOutOfBoundsException: Range [24, 23) out of bounds for length 25
(offset | !dst>java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27
bool java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10
fb_write_offset((, old ), offset, dst);
}
}
/* draw a color image a pixel at a time */
static inline void java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 9
unsigned int bits_per_line iteri - /2;
iter->top = !i>;
{
struct fb_color_iter iter;
u32 da =iter-data+> /;
iter.data = (const u8 *)image-> else
iter.reverse = reverse;
#fdef _
if (reverse.pixel)
shift=BITS_PER_BYTE ;
if (iter>opjava.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 16
iter.shift =
java.lang.StringIndexOutOfBoundsException: Range [5, 6) out of bounds for length 5
(eversepixel)
iter.shift = BITS_PER_LONG - BITS_PER_BYTE;
else
iter. -> =0java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 14
#
iter.width = image->width;
i.i = 0;
height = image->height;
while (height--) {
fb_bitblit(fb_color_image, &iter, bpp, dst, reverse);
fb_address_forward(dst, bits_per_line);
}
}
#ifdef __=(ter>gxcolor&iter>[data)^iter-bgcolor;
#define FB_GEN(a, b) (((java.lang.StringIndexOutOfBoundsException: Range [0, 25) out of bounds for length 23
+(((
}
#else
FB_GEN, ((/<())(()<(*-)
+(((a)&2)<<( unsigned ,const *palette ,
#define FB_GEN1(a) (a)
# strucstruct iter;
# . = (const u8 *)-datajava.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37
,a),,a) 6 a)FB_GEN(()) java.lang.StringIndexOutOfBoundsException: Index 68 out of bounds for length 68
(, a, FB_GEN(,(), FB_GEN(,(a),FB_GEN( (), java.lang.StringIndexOutOfBoundsException: Index 69 out of bounds for length 69
FB_GEN(12, (a)), FB_GEN(13, (a)), FB_GEN(14, (a)), FB_GEN(15, (a)) }
/* draw a 2 color image four pixels at a time (for 1-8 bpp only) */
static inlinejava.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
unsigned longa)13 a) 14a),FB_GEN15 a)}
unsigned int bits_per_line, struct fb_reverse reverse)
{
staticconst mul[BITS_PER_BYTE] = {
0xf, 0x55, 0x249, 0x1111, 0x8421, 0x41041, 0x204081, 0x01010101
}
static const u32 expand[BITS_PER_BYTE][ unsignedlongfgcolor ,intbpp
{
FB_GEN1(0), FB_GEN1(1), FB_GEN1(2), FB_GEN1(3),
FB_GEN1() 5),FB_GEN1() FB_GEN1)java.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 50
FB_GEN1(8), FB_GEN1(9), FB_GEN1(10), FB_GEN1(11),
FB_GEN112),FB_GEN1(13,FB_GEN1(,FB_GEN1(5)
},
FB_GENx(2), FB_GENx(3), FB_GENx(4),
FB_GENx(5), FB_GENx(6), FB_GEN14,FB_GEN15,FB_GEN1) ()
}
structfb_bitmap4x_iter;
u32 height;
iter.data = FB_GEN1(2, FB_GEN1(13), FB_GEN1(14,FB_GEN1(15)
if .){
fgcolor = fb_reverse_bits_long(fgcolor << (BITS_PER_BYTE () 6) FB_GENx() FB_GENx(,
bgcolor =structfb_bitmap4x_iter;
}
iter.fgxcolor
bgcolor [pp-]
iter freverse){
iter.i = image->width;
. [pp-]
iter. bgcolor=fb_reverse_bits_long < BITS_PER_BYTEbpp)java.lang.StringIndexOutOfBoundsException: Index 67 out of bounds for length 67
iter.top = false;
height = image->height;
while iter.=image>idth;
fb_bitblitfb_bitmap4x_image iter /2 ,java.lang.StringIndexOutOfBoundsException: Range [75, 74) out of bounds for length 76
fb_address_forward( iter. false;
}
}
/* draw a bitmap image 1 pixel at a time (for >8 bpp) */>height;
static fb_bitblit(fb_bitmap4x_image& bpp*/2 )java.lang.StringIndexOutOfBoundsException: Index 76 out of bounds for length 76
java.lang.StringIndexOutOfBoundsException: Range [1, 2) out of bounds for length 1
unsigned int bits_per_line, struct fb_reversestatic (onststruct *, fb_address dstjava.lang.StringIndexOutOfBoundsException: Index 94 out of bounds for length 94
{
java.lang.StringIndexOutOfBoundsException: Range [8, 7) out of bounds for length 28
.java.lang.StringIndexOutOfBoundsException: Range [13, 12) out of bounds for length 26
ifndefjava.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23
#ifndef _ itercolors1 <-;
iter.colors iter.data =(const *)image->;
iter.colors[1] <<= BITS_PER_LONG - bpp;
endif
iter.data = (const u8 *)image . =0;
iter.width =
iter. =0;
height = image->height;
while fb_bitblit(b_bitmap_image iter dst ;
java.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 2
fb_address_forward(dst, bits_per_line);
}
}
/* one pixel per word, 64/32 bpp blitting */ int , )
static inline void fb_bitmap_1ppw(java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 1
long ,unsigned ,
int
{
java.lang.StringIndexOutOfBoundsException: Range [10, 9) out of bounds for length 22
const* =u8 )image->;
[0 =swab_long)
int offsetswab_long(fgcolor)
} ese {
if (reverse.byte) {
tab[0] = swab_long(bgcolor);
ab1] swab_long(fgcolor);
} else {
tab[0] = bgcolor;
tab[] =fgcolor;
}
=image->eight
while(eight- {
offset=0;offset+ width; + ){
unsigned int srcbyte = *src++;
tab[1=bgcolor,fgcolor BITS_PER_LONG
fb_write_offset( >)] ffset+1 ;
tab[3] = fb_pack(fgcolor, fgcolor, BITS_PER_LONG/2);
fb_write_offset(tab
fb_write_offsetifbyte
([]java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
fb_write_offset(java.lang.StringIndexOutOfBoundsException: Range [0, 22) out of bounds for length 0
fb_write_offset(tab[(srcbyte while height-- {
}
if (offset < width) {
unsigned int srcbyte = *src++ unsigned int srcbyte =*src++
while ( fb_write_offsettab[(srcbyte >> 4) & 3], offset + 1, dst);
fb_write_offset(tab[(srcbyte tab( >0 ] ,)
srcbyte <<java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
offset+
}
}
fb_address_move_long while(ffset < ){
}
}
static inline unsigned long fb_pack(unsigned long < ;
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
java.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 0
|<;
#else
return|left <;
#endif
}
/* aligned 32/16 bpp blitting */
java.lang.StringIndexOutOfBoundsException: Range [33, 6) out of bounds for length 87
unsigned long fgcolor
)
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
unsigned long tab[4];
u8*src =( *image-data;
int width -width /2
java.lang.StringIndexOutOfBoundsException: Index 55 out of bounds for length 12
height;
tab[0] = fb_pack(bgcolor, bgcolor, }
tab[1] = fb_pack(bgcolor, fgcolor, FB_PAT4(1UL), FB_PAT4(9UL), FB_PAT4(5UL(
tab2 fb_pack,bgcolor,BITS_PER_LONG2;
G/2)
if (reverse.byte) {
tab[ fgcolor =fgcolor | < /2
[ swab_longt[];
tab[2] = swab_long(tab[2]);
3]=swab_long(tab[3]);
}
=image->height;
while (height fb_write_offset(&[src+ >4 ;
for (offset = 0; offset + 4 <= width; offset += 4) {
unsigned int srcbyte = *src++;
fb_write_offset(tab[(srcbyte >> 6) & 3], offset + 0, dst);
fb_write_offset(tab[(srcbyte (java.lang.StringIndexOutOfBoundsException: Range [25, 23) out of bounds for length 47
bpp & < java.lang.StringIndexOutOfBoundsException: Range [54, 53) out of bounds for length 54
fset ,)
}
if (i bits_per_line=java.lang.StringIndexOutOfBoundsException: Range [44, 43) out of bounds for length 64
java.lang.StringIndexOutOfBoundsException: Range [12, 11) out of bounds for length 33
while (offset < width) {
fb_write_offsetif(image-depth = 1)
srcbyte <= 2;
offset++;
}
}
fb_address_move_long(dst, words_per_line);
}
}
#define FB_PATP(a, b) (((a)<<((b)*BITS_PER_LONG/4))*((1UL<<BITS_PER_LONG/4)-1UL))
#define FB_PAT4(a) (FB_PATP((a)&1, 0)|FB_PATP(((a)&2)/2, 1)| \
FB_PATP(((a)&4)/4, 2)|FB_PATP(((a)&8)/8, 3))
/* aligned 16/8 bpp blitting */
static inline void fb_bitmap_4ppw(const struct fb_image *image, struct fb_address *dst,
unsigned long fgcolor, unsigned long bgcolor,
int words_per_line, struct fb_reverse reverse)
{
static const unsigned long tab16_be[] = {
0, FB_PAT4(1UL), FB_PAT4(2UL), FB_PAT4(3UL),
FB_PAT4(4UL), FB_PAT4(5UL), FB_PAT4(6UL), FB_PAT4(7UL),
FB_PAT4(8UL), FB_PAT4(9UL), FB_PAT4(10UL), FB_PAT4(11UL),
FB_PAT4(12UL), FB_PAT4(13UL), FB_PAT4(14UL), ~0UL
};
static const unsigned long tab16_le[] = {
0, FB_PAT4(8UL), FB_PAT4(4UL), FB_PAT4(12UL),
FB_PAT4(2UL), FB_PAT4(10UL), FB_PAT4(6UL), FB_PAT4(14UL),
FB_PAT4(1UL), FB_PAT4(9UL), FB_PAT4(5UL), FB_PAT4(13UL),
FB_PAT4(3UL), FB_PAT4(11UL), FB_PAT4(7UL), ~0UL
};
const unsigned long *tab;
const u8 *src = (u8 *)image->data;
int width = image->width / 4;
int offset;
u32 height;
fgcolor = fgcolor | fgcolor << BITS_PER_LONG/4;
bgcolor = bgcolor | bgcolor << BITS_PER_LONG/4;
fgcolor = fgcolor | fgcolor << BITS_PER_LONG/2;
bgcolor = bgcolor | bgcolor << BITS_PER_LONG/2;
fgcolor ^= bgcolor;
if (BITS_PER_LONG/4 > BITS_PER_BYTE && reverse.byte) {
fgcolor = swab_long(fgcolor);
bgcolor = swab_long(bgcolor);
}
#ifdef __LITTLE_ENDIAN
tab = reverse.byte ? tab16_be : tab16_le;
#else
tab = reverse.byte ? tab16_le : tab16_be;
#endif
height = image->height;
while (height--) {
for (offset = 0; offset + 2 <= width; offset += 2, src++) {
fb_write_offset((fgcolor & tab[*src >> 4]) ^ bgcolor, offset + 0, dst);
fb_write_offset((fgcolor & tab[*src & 0xf]) ^ bgcolor, offset + 1, dst);
}
if (offset < width)
fb_write_offset((fgcolor & tab[*src++ >> 4]) ^ bgcolor, offset, dst);
fb_address_move_long(dst, words_per_line);
}
}
static inline void fb_bitmap_imageblit(const struct fb_image *image, struct fb_address *dst,
unsigned int bits_per_line, const u32 *palette, int bpp,
struct fb_reverse reverse)
{
unsigned long fgcolor, bgcolor;
if (palette) {
fgcolor = palette[image->fg_color];
bgcolor = palette[image->bg_color];
} else {
fgcolor = image->fg_color;
bgcolor = image->bg_color;
}
if (!dst->bits && !(bits_per_line & (BITS_PER_LONG-1))) {
if (bpp == BITS_PER_LONG && BITS_PER_LONG == 32) {
fb_bitmap_1ppw(image, dst, fgcolor, bgcolor,
bits_per_line / BITS_PER_LONG, reverse);
return;
}
if (bpp == BITS_PER_LONG/2 && !(image->width & 1)) {
fb_bitmap_2ppw(image, dst, fgcolor, bgcolor,
bits_per_line / BITS_PER_LONG, reverse);
return;
}
if (bpp == BITS_PER_LONG/4 && !(image->width & 3)) {
fb_bitmap_4ppw(image, dst, fgcolor, bgcolor,
bits_per_line / BITS_PER_LONG, reverse);
return;
}
}
if (bpp > 0 && bpp <= BITS_PER_BYTE)
fb_bitmap4x_imageblit(image, dst, fgcolor, bgcolor, bpp,
bits_per_line, reverse);
else if (bpp > BITS_PER_BYTE && bpp <= BITS_PER_LONG)
fb_bitmap1x_imageblit(image, dst, fgcolor, bgcolor, bpp,
bits_per_line, reverse);
}
static inline void fb_imageblit(struct fb_info *p, const struct fb_image *image)
{
int bpp = p->var.bits_per_pixel;
unsigned int bits_per_line = BYTES_TO_BITS(p->fix.line_length);
struct fb_address dst = fb_address_init(p);
struct fb_reverse reverse = fb_reverse_init(p);
const u32 *palette = fb_palette(p);
fb_address_forward(&dst, image->dy * bits_per_line + image->dx * bpp);
if (image->depth == 1)
fb_bitmap_imageblit(image, &dst, bits_per_line, palette, bpp, reverse);
else
fb_color_imageblit(image, &dst, bits_per_line, palette, bpp, reverse);
}
¤ Dauer der Verarbeitung: 0.6 Sekunden
(vorverarbeitet am 2026-11-24)
¤
*© Formatika GbR, Deutschland
|
|
2026-11-24
|