123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601 |
- {
- Free Pascal port of the Hermes C library.
- Copyright (C) 2001-2003 Nikolay Nikolov ([email protected])
- Original C version by Christian Nentwich ([email protected])
- This library 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
- with the following modification:
- As a special exception, the copyright holders of this library give you
- permission to link this library with independent modules to produce an
- executable, regardless of the license terms of these independent modules,and
- to copy and distribute the resulting executable under terms of your choice,
- provided that you also meet, for each linked independent module, the terms
- and conditions of the license of that module. An independent module is a
- module which is not derived from or based on this library. If you modify
- this library, you may extend this exception to your version of the library,
- but you are not obligated to do so. If you do not wish to do so, delete this
- exception statement from your version.
- This library 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 this library; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- }
- {
- Generic format conversion routines for the HERMES library
- Copyright (c) 1998 Christian Nentwich ([email protected])
- This source code is licensed under the GNU LGPL
- Please refer to the file COPYING.LIB contained in the distribution for
- licensing conditions
- }
- procedure ConvertP_Generic32_A_Generic32_A(iface: PHermesConverterInterface); cdecl;
- var
- s_pixel, r, g, b, a: Uint32;
- count: DWord;
- source, dest: PUint8;
- begin
- source := iface^.s_pixels; dest := iface^.d_pixels;
- repeat
- count := iface^.s_width;
- repeat
- s_pixel := PUint32(source)^;
- r := ((s_pixel shr iface^.info.r_right) shl iface^.info.r_left) and
- iface^.mask_r;
- g := ((s_pixel shr iface^.info.g_right) shl iface^.info.g_left) and
- iface^.mask_g;
- b := ((s_pixel shr iface^.info.b_right) shl iface^.info.b_left) and
- iface^.mask_b;
- a := ((s_pixel shr iface^.info.a_right) shl iface^.info.a_left) and
- iface^.mask_a;
- PUint32(dest)^ := r or g or b or a;
- Inc(source, 4);
- Inc(dest, 4);
- Dec(count);
- until count = 0;
- Inc(source, iface^.s_add);
- Inc(dest, iface^.d_add);
- Dec(iface^.s_height);
- until iface^.s_height = 0;
- end;
- procedure ConvertP_Generic32_A_Generic24_A(iface: PHermesConverterInterface); cdecl;
- var
- s_pixel, r, g, b, a: Uint32;
- d_ptr: PUint8;
- count: DWord;
- source, dest: PUint8;
- begin
- d_ptr := PUint8(@s_pixel) + (R_32 - R_24);
- source := iface^.s_pixels; dest := iface^.d_pixels;
- repeat
- count := iface^.s_width;
- repeat
- s_pixel := PUint32(source)^;
- r := ((s_pixel shr iface^.info.r_right) shl iface^.info.r_left) and
- iface^.mask_r;
- g := ((s_pixel shr iface^.info.g_right) shl iface^.info.g_left) and
- iface^.mask_g;
- b := ((s_pixel shr iface^.info.b_right) shl iface^.info.b_left) and
- iface^.mask_b;
- a := ((s_pixel shr iface^.info.a_right) shl iface^.info.a_left) and
- iface^.mask_a;
- s_pixel := r or g or b or a;
- (dest+0)^ := (d_ptr+0)^;
- (dest+1)^ := (d_ptr+1)^;
- (dest+2)^ := (d_ptr+2)^;
- Inc(source, 4);
- Inc(dest, 3);
- Dec(count);
- until count = 0;
- Inc(source, iface^.s_add);
- Inc(dest, iface^.d_add);
- Dec(iface^.s_height);
- until iface^.s_height = 0;
- end;
- procedure ConvertP_Generic32_A_Generic16_A(iface: PHermesConverterInterface); cdecl;
- var
- s_pixel, r, g, b, a: Uint32;
- count: DWord;
- source, dest: PUint8;
- begin
- source := iface^.s_pixels; dest := iface^.d_pixels;
- repeat
- count := iface^.s_width shr 1;
- if count <> 0 then
- repeat
- r := (((PUint32(source)^) shr iface^.info.r_right) shl iface^.info.r_left) and
- iface^.mask_r;
- g := (((PUint32(source)^) shr iface^.info.g_right) shl iface^.info.g_left) and
- iface^.mask_g;
- b := (((PUint32(source)^) shr iface^.info.b_right) shl iface^.info.b_left) and
- iface^.mask_b;
- a := (((PUint32(source)^) shr iface^.info.a_right) shl iface^.info.a_left) and
- iface^.mask_a;
- s_pixel := (r or g or b or a) shl DWORD_SMALLINT0_SHL;
- r := ((((PUint32(source)+1)^) shr iface^.info.r_right) shl iface^.info.r_left) and
- iface^.mask_r;
- g := ((((PUint32(source)+1)^) shr iface^.info.g_right) shl iface^.info.g_left) and
- iface^.mask_g;
- b := ((((PUint32(source)+1)^) shr iface^.info.b_right) shl iface^.info.b_left) and
- iface^.mask_b;
- a := ((((PUint32(source)+1)^) shr iface^.info.a_right) shl iface^.info.a_left) and
- iface^.mask_a;
- s_pixel := s_pixel or ((r or g or b or a) shl DWORD_SMALLINT1_SHL);
- PUint32(dest)^ := s_pixel;
- Inc(source, 8);
- Inc(dest, 4);
- Dec(count);
- until count = 0;
- { Trailing pixel }
- if (iface^.s_width and 1) <> 0 then
- begin
- r := (((PUint32(source)^) shr iface^.info.r_right) shl iface^.info.r_left) and
- iface^.mask_r;
- g := (((PUint32(source)^) shr iface^.info.g_right) shl iface^.info.g_left) and
- iface^.mask_g;
- b := (((PUint32(source)^) shr iface^.info.b_right) shl iface^.info.b_left) and
- iface^.mask_b;
- a := (((PUint32(source)^) shr iface^.info.a_right) shl iface^.info.a_left) and
- iface^.mask_a;
- PUint16(dest)^ := r or g or b or a;
- Inc(dest, 2);
- Inc(source, 4);
- end;
- Inc(source, iface^.s_add);
- Inc(dest, iface^.d_add);
- Dec(iface^.s_height);
- until iface^.s_height = 0;
- end;
- procedure ConvertP_Generic32_A_Generic8_A(iface: PHermesConverterInterface); cdecl;
- var
- s_pixel, r, g, b, a: Uint32;
- count: DWord;
- source, dest: PUint8;
- begin
- source := iface^.s_pixels; dest := iface^.d_pixels;
- repeat
- count := iface^.s_width;
- repeat
- s_pixel := PUint32(source)^;
- r := ((s_pixel shr iface^.info.r_right) shl iface^.info.r_left) and
- iface^.mask_r;
- g := ((s_pixel shr iface^.info.g_right) shl iface^.info.g_left) and
- iface^.mask_g;
- b := ((s_pixel shr iface^.info.b_right) shl iface^.info.b_left) and
- iface^.mask_b;
- a := ((s_pixel shr iface^.info.a_right) shl iface^.info.a_left) and
- iface^.mask_a;
- dest^ := r or g or b or a;
- Inc(source, 4);
- Inc(dest);
- Dec(count);
- until count = 0;
- Inc(source, iface^.s_add);
- Inc(dest, iface^.d_add);
- Dec(iface^.s_height);
- until iface^.s_height = 0;
- end;
- procedure ConvertP_Generic24_A_Generic32_A(iface: PHermesConverterInterface); cdecl;
- var
- s_pixel, r, g, b, a: Uint32;
- count: DWord;
- source, dest: PUint8;
- begin
- source := iface^.s_pixels; dest := iface^.d_pixels;
- repeat
- count := iface^.s_width;
- repeat
- s_pixel := ((PUint32(source+R_24)^) shl 16) or
- ((PUint32(source+G_24)^) shl 8) or
- (PUint32(source+B_24)^);
- r := ((s_pixel shr iface^.info.r_right) shl iface^.info.r_left) and
- iface^.mask_r;
- g := ((s_pixel shr iface^.info.g_right) shl iface^.info.g_left) and
- iface^.mask_g;
- b := ((s_pixel shr iface^.info.b_right) shl iface^.info.b_left) and
- iface^.mask_b;
- a := ((s_pixel shr iface^.info.a_right) shl iface^.info.a_left) and
- iface^.mask_a;
- PUint32(dest)^ := r or g or b or a;
- Inc(source, 3);
- Inc(dest, 4);
- Dec(count);
- until count = 0;
- Inc(source, iface^.s_add);
- Inc(dest, iface^.d_add);
- Dec(iface^.s_height);
- until iface^.s_height = 0;
- end;
- procedure ConvertP_Generic24_A_Generic24_A(iface: PHermesConverterInterface); cdecl;
- var
- s_pixel, r, g, b, a: Uint32;
- d_ptr: PUint8;
- count: DWord;
- source, dest: PUint8;
- begin
- d_ptr := PUint8(@s_pixel) + (R_32 - R_24);
- source := iface^.s_pixels; dest := iface^.d_pixels;
- repeat
- count := iface^.s_width;
- repeat
- s_pixel := ((PUint32(source+R_24)^) shl 16) or
- ((PUint32(source+G_24)^) shl 8) or
- (PUint32(source+B_24)^);
- r := ((s_pixel shl iface^.info.r_left) shr iface^.info.r_right) and
- iface^.mask_r;
- g := ((s_pixel shl iface^.info.g_left) shr iface^.info.g_right) and
- iface^.mask_g;
- b := ((s_pixel shl iface^.info.b_left) shr iface^.info.b_right) and
- iface^.mask_b;
- a := ((s_pixel shl iface^.info.a_left) shr iface^.info.a_right) and
- iface^.mask_a;
- s_pixel := r or g or b or a;
- (dest + 0)^ := (d_ptr + 0)^;
- (dest + 1)^ := (d_ptr + 1)^;
- (dest + 2)^ := (d_ptr + 2)^;
- Inc(source, 3);
- Inc(dest, 3);
- Dec(count);
- until count = 0;
- Inc(source, iface^.s_add);
- Inc(dest, iface^.d_add);
- Dec(iface^.s_height);
- until iface^.s_height = 0;
- end;
- procedure ConvertP_Generic24_A_Generic16_A(iface: PHermesConverterInterface); cdecl;
- var
- s_pixel, r, g, b, a: Uint32;
- count: DWord;
- source, dest: PUint8;
- begin
- source := iface^.s_pixels; dest := iface^.d_pixels;
- repeat
- count := iface^.s_width;
- repeat
- s_pixel := ((PUint32(source+R_24)^) shl 16) or
- ((PUint32(source+G_24)^) shl 8) or
- (PUint32(source+B_24)^);
- r := ((s_pixel shr iface^.info.r_right) shl iface^.info.r_left) and
- iface^.mask_r;
- g := ((s_pixel shr iface^.info.g_right) shl iface^.info.g_left) and
- iface^.mask_g;
- b := ((s_pixel shr iface^.info.b_right) shl iface^.info.b_left) and
- iface^.mask_b;
- a := ((s_pixel shr iface^.info.a_right) shl iface^.info.a_left) and
- iface^.mask_a;
- PUint16(dest)^ := r or g or b or a;
- Inc(source, 3);
- Inc(dest, 2);
- Dec(count);
- until count = 0;
- Inc(source, iface^.s_add);
- Inc(dest, iface^.d_add);
- Dec(iface^.s_height);
- until iface^.s_height = 0;
- end;
- procedure ConvertP_Generic24_A_Generic8_A(iface: PHermesConverterInterface); cdecl;
- var
- s_pixel, r, g, b, a: Uint32;
- count: DWord;
- source, dest: PUint8;
- begin
- source := iface^.s_pixels; dest := iface^.d_pixels;
- repeat
- count := iface^.s_width;
- repeat
- s_pixel := ((PUint32(source+R_24)^) shl 16) or
- ((PUint32(source+G_24)^) shl 8) or
- (PUint32(source+B_24)^);
- r := ((s_pixel shr iface^.info.r_right) shl iface^.info.r_left) and
- iface^.mask_r;
- g := ((s_pixel shr iface^.info.g_right) shl iface^.info.g_left) and
- iface^.mask_g;
- b := ((s_pixel shr iface^.info.b_right) shl iface^.info.b_left) and
- iface^.mask_b;
- a := ((s_pixel shr iface^.info.a_right) shl iface^.info.a_left) and
- iface^.mask_a;
- dest^ := r or g or b or a;
- Inc(source, 3);
- Inc(dest);
- Dec(count);
- until count = 0;
- Inc(source, iface^.s_add);
- Inc(dest, iface^.d_add);
- Dec(iface^.s_height);
- until iface^.s_height = 0;
- end;
- procedure ConvertP_Generic16_A_Generic32_A(iface: PHermesConverterInterface); cdecl;
- var
- s_pixel, r, g, b, a: Uint32;
- count: DWord;
- source, dest: PUint8;
- begin
- source := iface^.s_pixels; dest := iface^.d_pixels;
- repeat
- count := iface^.s_width;
- repeat
- s_pixel := PUint16(source)^;
- r := ((s_pixel shr iface^.info.r_right) shl iface^.info.r_left) and
- iface^.mask_r;
- g := ((s_pixel shr iface^.info.g_right) shl iface^.info.g_left) and
- iface^.mask_g;
- b := ((s_pixel shr iface^.info.b_right) shl iface^.info.b_left) and
- iface^.mask_b;
- a := ((s_pixel shr iface^.info.a_right) shl iface^.info.a_left) and
- iface^.mask_a;
- PUint32(dest)^ := r or g or b or a;
- Inc(source, 2);
- Inc(dest, 4);
- Dec(count);
- until count = 0;
- Inc(source, iface^.s_add);
- Inc(dest, iface^.d_add);
- Dec(iface^.s_height);
- until iface^.s_height = 0;
- end;
- procedure ConvertP_Generic16_A_Generic24_A(iface: PHermesConverterInterface); cdecl;
- var
- s_pixel, r, g, b, a: Uint32;
- d_ptr: PUint8;
- count: DWord;
- source, dest: PUint8;
- begin
- d_ptr := PUint8(@s_pixel) + (R_32 - R_24);
- source := iface^.s_pixels; dest := iface^.d_pixels;
- repeat
- count := iface^.s_width;
- repeat
- s_pixel := PUint16(source)^;
- r := ((s_pixel shr iface^.info.r_right) shl iface^.info.r_left) and
- iface^.mask_r;
- g := ((s_pixel shr iface^.info.g_right) shl iface^.info.g_left) and
- iface^.mask_g;
- b := ((s_pixel shr iface^.info.b_right) shl iface^.info.b_left) and
- iface^.mask_b;
- a := ((s_pixel shr iface^.info.a_right) shl iface^.info.a_left) and
- iface^.mask_a;
- s_pixel := r or g or b or a;
- (dest + 0)^ := (d_ptr + 0)^;
- (dest + 1)^ := (d_ptr + 1)^;
- (dest + 2)^ := (d_ptr + 2)^;
- Inc(source, 2);
- Inc(dest, 3);
- Dec(count);
- until count = 0;
- Inc(source, iface^.s_add);
- Inc(dest, iface^.d_add);
- Dec(iface^.s_height);
- until iface^.s_height = 0;
- end;
- procedure ConvertP_Generic16_A_Generic16_A(iface: PHermesConverterInterface); cdecl;
- var
- s_pixel, r, g, b, a: Uint32;
- count: DWord;
- source, dest: PUint8;
- begin
- source := iface^.s_pixels; dest := iface^.d_pixels;
- repeat
- count := iface^.s_width;
- repeat
- s_pixel := PUint16(source)^;
- r := ((s_pixel shr iface^.info.r_right) shl iface^.info.r_left) and
- iface^.mask_r;
- g := ((s_pixel shr iface^.info.g_right) shl iface^.info.g_left) and
- iface^.mask_g;
- b := ((s_pixel shr iface^.info.b_right) shl iface^.info.b_left) and
- iface^.mask_b;
- a := ((s_pixel shr iface^.info.a_right) shl iface^.info.a_left) and
- iface^.mask_a;
- PUint16(dest)^ := r or g or b or a;
- Inc(source, 2);
- Inc(dest, 2);
- Dec(count);
- until count = 0;
- Inc(source, iface^.s_add);
- Inc(dest, iface^.d_add);
- Dec(iface^.s_height);
- until iface^.s_height = 0;
- end;
- procedure ConvertP_Generic16_A_Generic8_A(iface: PHermesConverterInterface); cdecl;
- var
- s_pixel, r, g, b, a: Uint32;
- count: DWord;
- source, dest: PUint8;
- begin
- source := iface^.s_pixels; dest := iface^.d_pixels;
- repeat
- count := iface^.s_width;
- repeat
- s_pixel := PUint16(source)^;
- r := ((s_pixel shr iface^.info.r_right) shl iface^.info.r_left) and
- iface^.mask_r;
- g := ((s_pixel shr iface^.info.g_right) shl iface^.info.g_left) and
- iface^.mask_g;
- b := ((s_pixel shr iface^.info.b_right) shl iface^.info.b_left) and
- iface^.mask_b;
- a := ((s_pixel shr iface^.info.a_right) shl iface^.info.a_left) and
- iface^.mask_a;
- dest^ := r or g or b or a;
- Inc(source, 2);
- Inc(dest);
- Dec(count);
- until count = 0;
- Inc(source, iface^.s_add);
- Inc(dest, iface^.d_add);
- Dec(iface^.s_height);
- until iface^.s_height = 0;
- end;
- { -------------------------------------------------------------------------
- STRETCH CONVERTERS
- ------------------------------------------------------------------------- }
- procedure ConvertP_Generic32_A_Generic32_A_S(iface: PHermesConverterInterface); cdecl;
- var
- s_pixel, r, g, b, a: Uint32;
- count: DWord;
- source, dest: PUint8;
- dx, dy, x, y: DWord;
- begin
- source := iface^.s_pixels;
- dest := iface^.d_pixels;
- dy := (iface^.s_height shl 16) div iface^.d_height;
- dx := (iface^.s_width shl 16) div iface^.d_width;
- y := 0;
- repeat
- count := iface^.d_width;
- x := 0;
- repeat
- s_pixel := (PUint32(source)+(x shr 16))^;
- r := ((s_pixel shr iface^.info.r_right) shl iface^.info.r_left) and
- iface^.mask_r;
- g := ((s_pixel shr iface^.info.g_right) shl iface^.info.g_left) and
- iface^.mask_g;
- b := ((s_pixel shr iface^.info.b_right) shl iface^.info.b_left) and
- iface^.mask_b;
- a := ((s_pixel shr iface^.info.a_right) shl iface^.info.a_left) and
- iface^.mask_a;
- PUint32(dest)^ := r or g or b or a;
- Inc(x, dx);
- Inc(dest, 4);
- Dec(count);
- until count = 0;
- Inc(dest, iface^.d_add);
- Inc(y, dy);
- Inc(source, (y shr 16)*DWord(iface^.s_pitch));
- y := y and $ffff;
- Dec(iface^.d_height);
- until iface^.d_height = 0;
- end;
- procedure ConvertP_Generic32_A_Generic16_A_S(iface: PHermesConverterInterface); cdecl;
- var
- s_pixel, r, g, b, a: Uint32;
- count: DWord;
- source, dest: PUint8;
- dx, dy, x, y: DWord;
- begin
- source := iface^.s_pixels;
- dest := iface^.d_pixels;
- dy := (iface^.s_height shl 16) div iface^.d_height;
- dx := (iface^.s_width shl 16) div iface^.d_width;
- y := 0;
- repeat
- count := iface^.d_width;
- x := 0;
- repeat
- s_pixel := (PUint32(source)+(x shr 16))^;
- r := ((s_pixel shr iface^.info.r_right) shl iface^.info.r_left) and
- iface^.mask_r;
- g := ((s_pixel shr iface^.info.g_right) shl iface^.info.g_left) and
- iface^.mask_g;
- b := ((s_pixel shr iface^.info.b_right) shl iface^.info.b_left) and
- iface^.mask_b;
- a := ((s_pixel shr iface^.info.a_right) shl iface^.info.a_left) and
- iface^.mask_a;
- PUint16(dest)^ := r or g or b or a;
- Inc(x, dx);
- Inc(dest, 2);
- Dec(count);
- until count = 0;
- Inc(dest, iface^.d_add);
- Inc(y, dy);
- Inc(source, (y shr 16)*DWord(iface^.s_pitch));
- y := y and $ffff;
- Dec(iface^.d_height);
- until iface^.d_height = 0;
- end;
|