summaryrefslogtreecommitdiffstats
path: root/kernel/kls_wal
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/kls_wal
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/kls_wal')
-rw-r--r--kernel/kls_wal/Makefile.am9
-rw-r--r--kernel/kls_wal/fmt_codec_wal.cpp172
-rw-r--r--kernel/kls_wal/fmt_codec_wal_defs.h42
-rw-r--r--kernel/kls_wal/q2pal.h266
4 files changed, 489 insertions, 0 deletions
diff --git a/kernel/kls_wal/Makefile.am b/kernel/kls_wal/Makefile.am
new file mode 100644
index 0000000..388c52b
--- /dev/null
+++ b/kernel/kls_wal/Makefile.am
@@ -0,0 +1,9 @@
+INCLUDES = -I../include
+
+pkglib_LTLIBRARIES = libkls_wal.la
+
+libkls_wal_la_SOURCES = fmt_codec_wal.cpp fmt_codec_wal_defs.h q2pal.h
+
+libkls_wal_la_LDFLAGS = ${SQ_RELEASE}
+
+libkls_wal_la_LIBADD = ${SQ_LOCAL_RPATH}
diff --git a/kernel/kls_wal/fmt_codec_wal.cpp b/kernel/kls_wal/fmt_codec_wal.cpp
new file mode 100644
index 0000000..a5b46d5
--- /dev/null
+++ b/kernel/kls_wal/fmt_codec_wal.cpp
@@ -0,0 +1,172 @@
+/* This file is part of ksquirrel-libs (http://ksquirrel.sf.net)
+
+ Copyright (c) 2005 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 <iostream>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include "ksquirrel-libs/fmt_types.h"
+#include "ksquirrel-libs/fileio.h"
+#include "ksquirrel-libs/fmt_utils.h"
+
+#include "fmt_codec_wal_defs.h"
+#include "fmt_codec_wal.h"
+
+#include "ksquirrel-libs/error.h"
+
+#include "q2pal.h"
+
+#include "../xpm/codec_wal.xpm"
+
+/*
+ *
+ * Quake2 WAL texture
+ *
+ */
+
+fmt_codec::fmt_codec() : fmt_codec_base()
+{}
+
+fmt_codec::~fmt_codec()
+{}
+
+void fmt_codec::options(codec_options *o)
+{
+ o->version = "0.2.0";
+ o->name = "Quake2 texture";
+ o->filter = "*.wal ";
+ o->config = "";
+ o->mime = "";
+ o->mimetype = "image/x-wal";
+ o->pixmap = codec_wal;
+ o->readable = true;
+ o->canbemultiple = true;
+ o->writestatic = false;
+ o->writeanimated = false;
+ o->needtempfile = false;
+}
+
+s32 fmt_codec::read_init(const std::string &file)
+{
+ frs.open(file.c_str(), ios::binary | ios::in);
+
+ if(!frs.good())
+ return SQE_R_NOFILE;
+
+ currentImage = -1;
+ read_error = false;
+
+ finfo.animated = false;
+
+ bits = NULL;
+
+ return SQE_OK;
+}
+
+s32 fmt_codec::read_next()
+{
+ currentImage++;
+
+ if(currentImage == 4)
+ return SQE_NOTOK;
+
+ if(!currentImage)
+ {
+ if(!frs.readK(&wal, sizeof(wal_header)))
+ return SQE_R_BADFILE;
+
+ neww = wal.width;
+ newh = wal.height;
+
+ fmt_metaentry mt;
+
+ mt.group = "Quake2 texture name";
+ mt.data = wal.name;
+ addmeta(mt);
+
+ mt.group = "Quake2 next texture name";
+ mt.data = wal.next_name;
+ addmeta(mt);
+ }
+ else
+ {
+ neww /= 2;
+ newh /= 2;
+ }
+
+ bits = (u8 *)realloc(bits, neww * newh);
+
+ if(!bits)
+ return SQE_R_NOMEMORY;
+
+ fmt_image image;
+
+ frs.seekg(wal.offset[currentImage], ios::beg);
+
+ if(!frs.good())
+ return SQE_R_BADFILE;
+
+ image.w = neww;
+ image.h = newh;
+ image.bpp = 8;
+ image.compression = "-";
+ image.colorspace = fmt_utils::colorSpaceByBpp(8);
+
+ finfo.image.push_back(image);
+
+ return SQE_OK;
+}
+
+s32 fmt_codec::read_next_pass()
+{
+ return SQE_OK;
+}
+
+s32 fmt_codec::read_scanline(RGBA *scan)
+{
+ fmt_image *im = image(currentImage);
+ fmt_utils::fillAlpha(scan, im->w);
+
+ if(!frs.readK(bits, im->w))
+ return SQE_R_BADFILE;
+
+ for(s32 i = 0;i < im->w;i++)
+ {
+ scan[i].r = q2pal[bits[i] * 3];
+ scan[i].g = q2pal[bits[i] * 3 + 1];
+ scan[i].b = q2pal[bits[i] * 3 + 2];
+ }
+
+ return SQE_OK;
+}
+
+void fmt_codec::read_close()
+{
+ frs.close();
+
+ finfo.meta.clear();
+ finfo.image.clear();
+
+ if(bits) free(bits);
+}
+
+#include "fmt_codec_cd_func.h"
diff --git a/kernel/kls_wal/fmt_codec_wal_defs.h b/kernel/kls_wal/fmt_codec_wal_defs.h
new file mode 100644
index 0000000..1e8210f
--- /dev/null
+++ b/kernel/kls_wal/fmt_codec_wal_defs.h
@@ -0,0 +1,42 @@
+/* This file is part of ksquirrel-libs (http://ksquirrel.sf.net)
+
+ Copyright (c) 2005 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.
+*/
+
+#ifndef KSQUIRREL_CODEC_DEFS_wal
+#define KSQUIRREL_CODEC_DEFS_wal
+
+typedef struct
+{
+ s8 name[32]; /* name of the texture */
+
+ u32 width; /* width (in pixels) of the largest mipmap level */
+ u32 height; /* height (in pixels) of the largest mipmap level */
+
+ s32 offset[4]; /* byte offset of the start of each of the 4 mipmap levels */
+
+ s8 next_name[32]; /* name of the next texture in the animation */
+
+ u32 flags;
+ u32 contents;
+ u32 value;
+
+}wal_header;
+
+#endif
diff --git a/kernel/kls_wal/q2pal.h b/kernel/kls_wal/q2pal.h
new file mode 100644
index 0000000..39530e5
--- /dev/null
+++ b/kernel/kls_wal/q2pal.h
@@ -0,0 +1,266 @@
+#ifndef Q2PAL_H
+#define Q2PAL_H
+
+/* Quake2 pallette taken from DevIL library (http://imagelib.org) */
+
+static const s8 q2pal[768] =
+{
+ 0, 0, 0,
+ 15, 15, 15,
+ 31, 31, 31,
+ 47, 47, 47,
+ 63, 63, 63,
+ 75, 75, 75,
+ 91, 91, 91,
+ 107, 107, 107,
+ 123, 123, 123,
+ 139, 139, 139,
+ 155, 155, 155,
+ 171, 171, 171,
+ 187, 187, 187,
+ 203, 203, 203,
+ 219, 219, 219,
+ 235, 235, 235,
+ 99, 75, 35,
+ 91, 67, 31,
+ 83, 63, 31,
+ 79, 59, 27,
+ 71, 55, 27,
+ 63, 47, 23,
+ 59, 43, 23,
+ 51, 39, 19,
+ 47, 35, 19,
+ 43, 31, 19,
+ 39, 27, 15,
+ 35, 23, 15,
+ 27, 19, 11,
+ 23, 15, 11,
+ 19, 15, 7,
+ 15, 11, 7,
+ 95, 95, 111,
+ 91, 91, 103,
+ 91, 83, 95,
+ 87, 79, 91,
+ 83, 75, 83,
+ 79, 71, 75,
+ 71, 63, 67,
+ 63, 59, 59,
+ 59, 55, 55,
+ 51, 47, 47,
+ 47, 43, 43,
+ 39, 39, 39,
+ 35, 35, 35,
+ 27, 27, 27,
+ 23, 23, 23,
+ 19, 19, 19,
+ 143, 119, 83,
+ 123, 99, 67,
+ 115, 91, 59,
+ 103, 79, 47,
+ 207, 151, 75,
+ 167, 123, 59,
+ 139, 103, 47,
+ 111, 83, 39,
+ 235, 159, 39,
+ 203, 139, 35,
+ 175, 119, 31,
+ 147, 99, 27,
+ 119, 79, 23,
+ 91, 59, 15,
+ 63, 39, 11,
+ 35, 23, 7,
+ 167, 59, 43,
+ 159, 47, 35,
+ 151, 43, 27,
+ 139, 39, 19,
+ 127, 31, 15,
+ 115, 23, 11,
+ 103, 23, 7,
+ 87, 19, 0,
+ 75, 15, 0,
+ 67, 15, 0,
+ 59, 15, 0,
+ 51, 11, 0,
+ 43, 11, 0,
+ 35, 11, 0,
+ 27, 7, 0,
+ 19, 7, 0,
+ 123, 95, 75,
+ 115, 87, 67,
+ 107, 83, 63,
+ 103, 79, 59,
+ 95, 71, 55,
+ 87, 67, 51,
+ 83, 63, 47,
+ 75, 55, 43,
+ 67, 51, 39,
+ 63, 47, 35,
+ 55, 39, 27,
+ 47, 35, 23,
+ 39, 27, 19,
+ 31, 23, 15,
+ 23, 15, 11,
+ 15, 11, 7,
+ 111, 59, 23,
+ 95, 55, 23,
+ 83, 47, 23,
+ 67, 43, 23,
+ 55, 35, 19,
+ 39, 27, 15,
+ 27, 19, 11,
+ 15, 11, 7,
+ 179, 91, 79,
+ 191, 123, 111,
+ 203, 155, 147,
+ 215, 187, 183,
+ 203, 215, 223,
+ 179, 199, 211,
+ 159, 183, 195,
+ 135, 167, 183,
+ 115, 151, 167,
+ 91, 135, 155,
+ 71, 119, 139,
+ 47, 103, 127,
+ 23, 83, 111,
+ 19, 75, 103,
+ 15, 67, 91,
+ 11, 63, 83,
+ 7, 55, 75,
+ 7, 47, 63,
+ 7, 39, 51,
+ 0, 31, 43,
+ 0, 23, 31,
+ 0, 15, 19,
+ 0, 7, 11,
+ 0, 0, 0,
+ 139, 87, 87,
+ 131, 79, 79,
+ 123, 71, 71,
+ 115, 67, 67,
+ 107, 59, 59,
+ 99, 51, 51,
+ 91, 47, 47,
+ 87, 43, 43,
+ 75, 35, 35,
+ 63, 31, 31,
+ 51, 27, 27,
+ 43, 19, 19,
+ 31, 15, 15,
+ 19, 11, 11,
+ 11, 7, 7,
+ 0, 0, 0,
+ 151, 159, 123,
+ 143, 151, 115,
+ 135, 139, 107,
+ 127, 131, 99,
+ 119, 123, 95,
+ 115, 115, 87,
+ 107, 107, 79,
+ 99, 99, 71,
+ 91, 91, 67,
+ 79, 79, 59,
+ 67, 67, 51,
+ 55, 55, 43,
+ 47, 47, 35,
+ 35, 35, 27,
+ 23, 23, 19,
+ 15, 15, 11,
+ 159, 75, 63,
+ 147, 67, 55,
+ 139, 59, 47,
+ 127, 55, 39,
+ 119, 47, 35,
+ 107, 43, 27,
+ 99, 35, 23,
+ 87, 31, 19,
+ 79, 27, 15,
+ 67, 23, 11,
+ 55, 19, 11,
+ 43, 15, 7,
+ 31, 11, 7,
+ 23, 7, 0,
+ 11, 0, 0,
+ 0, 0, 0,
+ 119, 123, 207,
+ 111, 115, 195,
+ 103, 107, 183,
+ 99, 99, 167,
+ 91, 91, 155,
+ 83, 87, 143,
+ 75, 79, 127,
+ 71, 71, 115,
+ 63, 63, 103,
+ 55, 55, 87,
+ 47, 47, 75,
+ 39, 39, 63,
+ 35, 31, 47,
+ 27, 23, 35,
+ 19, 15, 23,
+ 11, 7, 7,
+ 155, 171, 123,
+ 143, 159, 111,
+ 135, 151, 99,
+ 123, 139, 87,
+ 115, 131, 75,
+ 103, 119, 67,
+ 95, 111, 59,
+ 87, 103, 51,
+ 75, 91, 39,
+ 63, 79, 27,
+ 55, 67, 19,
+ 47, 59, 11,
+ 35, 47, 7,
+ 27, 35, 0,
+ 19, 23, 0,
+ 11, 15, 0,
+ 0, 255, 0,
+ 35, 231, 15,
+ 63, 211, 27,
+ 83, 187, 39,
+ 95, 167, 47,
+ 95, 143, 51,
+ 95, 123, 51,
+ 255, 255, 255,
+ 255, 255, 211,
+ 255, 255, 167,
+ 255, 255, 127,
+ 255, 255, 83,
+ 255, 255, 39,
+ 255, 235, 31,
+ 255, 215, 23,
+ 255, 191, 15,
+ 255, 171, 7,
+ 255, 147, 0,
+ 239, 127, 0,
+ 227, 107, 0,
+ 211, 87, 0,
+ 199, 71, 0,
+ 183, 59, 0,
+ 171, 43, 0,
+ 155, 31, 0,
+ 143, 23, 0,
+ 127, 15, 0,
+ 115, 7, 0,
+ 95, 0, 0,
+ 71, 0, 0,
+ 47, 0, 0,
+ 27, 0, 0,
+ 239, 0, 0,
+ 55, 55, 255,
+ 255, 0, 0,
+ 0, 0, 255,
+ 43, 43, 35,
+ 27, 27, 23,
+ 19, 19, 15,
+ 235, 151, 127,
+ 195, 115, 83,
+ 159, 87, 51,
+ 123, 63, 27,
+ 235, 211, 199,
+ 199, 171, 155,
+ 167, 139, 119,
+ 135, 107, 87,
+ 159, 91, 83
+};
+
+#endif