summaryrefslogtreecommitdiffstats
path: root/kernel/ksquirrel-libs
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-02-24 17:43:19 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-02-24 17:43:19 +0000
commit0292059f4a16434600564cfa3f0ad2309a508a54 (patch)
treed95953cd53011917c4df679b96aedca39401b54f /kernel/ksquirrel-libs
downloadlibksquirrel-0292059f4a16434600564cfa3f0ad2309a508a54.tar.gz
libksquirrel-0292059f4a16434600564cfa3f0ad2309a508a54.zip
Added libksquirrel for KDE3
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/libraries/libksquirrel@1095624 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kernel/ksquirrel-libs')
-rw-r--r--kernel/ksquirrel-libs/Makefile.am8
-rw-r--r--kernel/ksquirrel-libs/fileio.cpp136
-rw-r--r--kernel/ksquirrel-libs/fmt_utils.cpp187
3 files changed, 331 insertions, 0 deletions
diff --git a/kernel/ksquirrel-libs/Makefile.am b/kernel/ksquirrel-libs/Makefile.am
new file mode 100644
index 0000000..54258cb
--- /dev/null
+++ b/kernel/ksquirrel-libs/Makefile.am
@@ -0,0 +1,8 @@
+INCLUDES = -I../include
+
+# create small development library. KSquirrel will use it.
+lib_LTLIBRARIES = libksquirrel-libs.la
+
+libksquirrel_libs_la_SOURCES = fileio.cpp fmt_utils.cpp
+
+libksquirrel_libs_la_LDFLAGS = ${SQ_RELEASE} \ No newline at end of file
diff --git a/kernel/ksquirrel-libs/fileio.cpp b/kernel/ksquirrel-libs/fileio.cpp
new file mode 100644
index 0000000..b7cea5c
--- /dev/null
+++ b/kernel/ksquirrel-libs/fileio.cpp
@@ -0,0 +1,136 @@
+/* This file is part of ksquirrel-libs (http://ksquirrel.sf.net)
+
+ Copyright (c) 2004 Dmitry Baryshev <[email protected]>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation;
+ either version 2 of the License, or (at your option) any later
+ 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "ksquirrel-libs/fileio.h"
+
+// implement read methods
+ifstreamK::ifstreamK() : ifstream()
+{}
+
+bool ifstreamK::readK(void *data, int size)
+{
+ read((char *)data, size);
+
+ return good();
+}
+
+bool ifstreamK::getS(char *s, const int sz)
+{
+ getline(s, sz);
+
+ return good();
+}
+
+bool ifstreamK::be_getchar(u8 *c)
+{
+ return readK(c, 1);
+}
+
+bool ifstreamK::be_getshort(u16 *s)
+{
+ u8 buf[2];
+
+ if(!readK(buf, 2))
+ return false;
+
+ *s = (buf[0] << 8) + buf[1];
+
+ return good();
+}
+
+bool ifstreamK::be_getlong(u32 *l)
+{
+ u8 buf[4];
+
+ if(!readK(buf, 4))
+ return false;
+
+ *l = (buf[0] << 24) + (buf[1] << 16) + (buf[2] << 8) + (buf[3]);
+
+ return good();
+}
+
+void ifstreamK::close()
+{
+ ifstream::close();
+
+ clear();
+}
+
+bool ifstreamK::readCHex(u32 &hex)
+{
+ s8 prefix1, prefix2;
+ s8 h[9], c;
+ u32 i = 0;
+
+ if(!readK(&prefix1, sizeof(s8)))
+ return false;
+
+ if(!readK(&prefix2, sizeof(s8)))
+ return false;
+
+ if(prefix1 != '0' || prefix2 != 'x')
+ return false;
+
+ while(true)
+ {
+ if(!readK(&c, sizeof(s8)))
+ return false;
+
+ if(c < '0' || c > '9')
+ {
+ if(c != 'A' && c != 'B' && c != 'C' && c != 'D' && c != 'E' && c != 'F')
+ {
+ seekg(-1, ios::cur);
+ break;
+ }
+ }
+
+ h[i++] = c;
+ }
+
+ h[i] = '\0';
+
+ hex = strtol(h, NULL, 16);
+
+ return good();
+}
+
+
+// implement write methods
+ofstreamK::ofstreamK() : ofstream()
+{}
+
+bool ofstreamK::writeK(void *data, int size)
+{
+ write((char *)data, size);
+
+ return good();
+}
+
+void ofstreamK::close()
+{
+ ofstream::close();
+
+ clear();
+}
diff --git a/kernel/ksquirrel-libs/fmt_utils.cpp b/kernel/ksquirrel-libs/fmt_utils.cpp
new file mode 100644
index 0000000..306fee9
--- /dev/null
+++ b/kernel/ksquirrel-libs/fmt_utils.cpp
@@ -0,0 +1,187 @@
+/* This file is part of ksquirrel-libs (http://ksquirrel.sf.net)
+
+ Copyright (c) 2004 Dmitry Baryshev <[email protected]>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation;
+ either version 2 of the License, or (at your option) any later
+ 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+#include <stdio.h>
+#include <string.h>
+
+#include "ksquirrel-libs/fmt_utils.h"
+#include "ksquirrel-libs/fmt_defs.h"
+
+#include <sstream>
+
+void fmt_utils::fillAlpha(RGBA *scan, int w, u8 value)
+{
+ if(scan)
+ {
+ for(int i = 0;i < w;i++)
+ (scan + i)->a = value;
+ }
+}
+
+void fmt_utils::flipv(s8 *image, s32 bytes_w, s32 h)
+{
+ s32 i;
+
+ if(!image)
+ return;
+
+ s8 *hptr = new s8 [bytes_w];
+
+ if(!hptr)
+ return;
+
+ for(i = 0; i < h/2; i++)
+ {
+ memcpy(hptr, image + i * bytes_w, bytes_w);
+ memcpy(image + i * bytes_w, image + (h - i - 1) * bytes_w, bytes_w);
+ memcpy(image + (h - i - 1) * bytes_w, hptr, bytes_w);
+ }
+
+ delete hptr;
+}
+
+void fmt_utils::fliph(s8 *image, s32 w, s32 h, s32 bpp)
+{
+ s32 x, y, x2;
+ s32 bpl = w * bpp;
+ s8 a[bpp], *t;
+
+ if(!image)
+ return;
+
+ for(y = 0;y < h;y++)
+ {
+ for(x = 0, x2 = w-1;x < w/2;x++,x2--)
+ {
+ t = image + y*bpl;
+
+ memcpy(a, t + x2*bpp, bpp);
+ memcpy(t + x2*bpp, t + x*bpp, bpp);
+ memcpy(t + x*bpp, a, bpp);
+ }
+ }
+}
+
+u16 fmt_utils::konvertWord(u16 a)
+{
+ u16 i = a, b;
+
+ b = i & 255;
+ b = b << 8;
+ b = b|0;
+ i = i >> 8;
+ i = i|0;
+
+ return i|b;
+}
+
+u32 fmt_utils::konvertLong(u32 a)
+{
+ u32 i = a, b, c;
+ u16 m, n;
+
+ b = i >> 16; // high word
+ c = i << 16;
+ c = c >> 16; // low word
+
+ m = (u16)b;
+ n = (u16)c;
+
+ m = fmt_utils::konvertWord(m);
+ n = fmt_utils::konvertWord(n);
+
+ b = m;
+ c = n;
+ c = c << 16;
+
+ b = b|0;
+ c = c|0;
+
+ return b|c;
+}
+
+std::string fmt_utils::colorSpaceByBpp(const int bpp)
+{
+ switch(bpp)
+ {
+ case 1:
+ return std::string("Monochrome");
+
+ case 4:
+ case 8:
+ case 15:
+ case 16:
+ return std::string("Color indexed");
+
+ case 24:
+ return std::string("RGB");
+
+ case 32:
+ return std::string("RGBA");
+
+ default:
+ return std::string("Unknown");
+ }
+}
+
+void fmt_utils::expandMono1Byte(const u32 byte, u8 *array)
+{
+ u8 mask = 0x80;
+ u8 *p = array;
+ u8 b = byte & 0xff;
+
+ for(s32 i = 0;i < 8;i++)
+ {
+ *p = (b & mask) ? 1 : 0;
+
+ p++;
+ mask >>= 1;
+ }
+}
+
+void fmt_utils::expandMono2Byte(const u32 byte, u8 *array)
+{
+ u16 mask = 0x8000;
+ u8 *p = array;
+ u16 b = byte & 0xffff;
+
+ for(s32 i = 0;i < 16;i++)
+ {
+ *p = (b & mask) ? 1 : 0;
+
+ p++;
+ mask >>= 1;
+ }
+}
+
+void fmt_utils::expandMono4Byte(const u32 byte, u8 *array)
+{
+ u32 mask = 0x80000000;
+ u8 *p = array;
+ u32 b = byte & 0xffffffff;
+
+ for(s32 i = 0;i < 32;i++)
+ {
+ *p = (b & mask) ? 1 : 0;
+
+ p++;
+ mask >>= 1;
+ }
+}