From f05d3452f734d5cb76992335b1f1df70014917fc Mon Sep 17 00:00:00 2001 From: Nicholas Niro Date: Mon, 21 Jan 2008 00:31:02 -0500 Subject: [PATCH] Implemented a new fixed version of the bitmap loading module which was tested and fixed from all it's old bugs that were such an annoyance. --- ChangeLog | 15 + configure | 3 +- configure.ac | 1 + include/neuro/bitmap.h | 2 + src/extlib/sdl.c | 2 +- src/extlib/x11.c | 2 +- src/misc/Makefile.am | 16 +- src/misc/Makefile.in | 178 +++++++-- src/misc/bitmap/Makefile.am | 12 + src/misc/{ => bitmap}/Makefile.in | 47 +-- src/misc/bitmap/core.c | 143 +++++++ src/misc/bitmap/intern_bitmap.h | 108 ++++++ src/misc/bitmap/io.c | 156 ++++++++ src/misc/{bitmap.c => bitmap/process.c} | 659 ++++++++++---------------------- version.mk | 4 +- 15 files changed, 805 insertions(+), 543 deletions(-) create mode 100644 src/misc/bitmap/Makefile.am copy src/misc/{ => bitmap}/Makefile.in (93%) create mode 100644 src/misc/bitmap/core.c create mode 100644 src/misc/bitmap/intern_bitmap.h create mode 100644 src/misc/bitmap/io.c rename src/misc/{bitmap.c => bitmap/process.c} (56%) diff --git a/ChangeLog b/ChangeLog index 851facc..bd768af 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2008-01-21 Nicholas Niro + * src/misc : + Created a new submodule called bitmap in its own + directory with its own small library. + + * src/misc/bitmap : + Spread the old bitmap.c file into 3 distinct source + files : core.c process.c and io.c. They compose + the now code that is used to load bitmaps from + bitmap files. + + * configure.ac : + The script was changed in order to implement the + new bitmap module. + 2007-12-16 Nicholas Niro * src/neuro_main.c : Implemented a new function (Neuro_SetNeuroDebugFilter) diff --git a/configure b/configure index d66cffc..2a12b05 100755 --- a/configure +++ b/configure @@ -23814,7 +23814,7 @@ includedir=$includedir/neuro echo # enumerate the Makefiles to be created - ac_config_files="$ac_config_files Makefile include/Makefile include/neuro/Makefile src/Makefile src/memory/Makefile src/video/Makefile src/events/Makefile src/extlib/Makefile src/misc/Makefile docs/Makefile" + ac_config_files="$ac_config_files Makefile include/Makefile include/neuro/Makefile src/Makefile src/memory/Makefile src/video/Makefile src/events/Makefile src/extlib/Makefile src/misc/Makefile src/misc/bitmap/Makefile docs/Makefile" # if the neuronet project is in the house, we handle it @@ -24444,6 +24444,7 @@ do "src/events/Makefile" ) CONFIG_FILES="$CONFIG_FILES src/events/Makefile" ;; "src/extlib/Makefile" ) CONFIG_FILES="$CONFIG_FILES src/extlib/Makefile" ;; "src/misc/Makefile" ) CONFIG_FILES="$CONFIG_FILES src/misc/Makefile" ;; + "src/misc/bitmap/Makefile" ) CONFIG_FILES="$CONFIG_FILES src/misc/bitmap/Makefile" ;; "docs/Makefile" ) CONFIG_FILES="$CONFIG_FILES docs/Makefile" ;; "src/neuronet/include/ebuf.h" ) CONFIG_LINKS="$CONFIG_LINKS src/neuronet/include/ebuf.h:include/neuro/ebuf.h" ;; "depfiles" ) CONFIG_COMMANDS="$CONFIG_COMMANDS depfiles" ;; diff --git a/configure.ac b/configure.ac index 594ac51..d196575 100644 --- a/configure.ac +++ b/configure.ac @@ -257,6 +257,7 @@ src/video/Makefile src/events/Makefile src/extlib/Makefile src/misc/Makefile +src/misc/bitmap/Makefile docs/Makefile ]) diff --git a/include/neuro/bitmap.h b/include/neuro/bitmap.h index 0a2519d..098500e 100644 --- a/include/neuro/bitmap.h +++ b/include/neuro/bitmap.h @@ -10,6 +10,8 @@ typedef struct BMP_CTX BMP_CTX; extern i8 Bitmap_Poll(BMP_CTX *ctx); extern BMP_CTX *Bitmap_CreateCTX(const char *path); +extern v_object *Bitmap_LoadBMP(const char *path); + extern v_object *Bitmap_DestroyCTX(BMP_CTX *ctx); #endif /* NOT __BITMAP_H */ diff --git a/src/extlib/sdl.c b/src/extlib/sdl.c index 2df353a..a8b23b0 100644 --- a/src/extlib/sdl.c +++ b/src/extlib/sdl.c @@ -352,7 +352,7 @@ Lib_LoadBMP(const char *path, v_object **img) chrono = Neuro_GetTickCount(); - *img = readBitmapFile(path); + *img = Bitmap_LoadBMP(path); Debug_Val(0, "Loading a bitmap took %d\n", Neuro_GetTickCount() - chrono); #else /* NOT NATIVE_BMP */ diff --git a/src/extlib/x11.c b/src/extlib/x11.c index 0fe8fbc..9eee814 100644 --- a/src/extlib/x11.c +++ b/src/extlib/x11.c @@ -875,7 +875,7 @@ Lib_LoadBMP(const char *path, v_object **img) chrono = Neuro_GetTickCount(); - *img = readBitmapFile(path); + *img = Bitmap_LoadBMP(path); Debug_Val(0, "Loading a bitmap took %d\n", Neuro_GetTickCount() - chrono); diff --git a/src/misc/Makefile.am b/src/misc/Makefile.am index 40e2314..85009d5 100644 --- a/src/misc/Makefile.am +++ b/src/misc/Makefile.am @@ -1,17 +1,15 @@ #!/bin/bash +SUBDIRS = bitmap + noinst_LTLIBRARIES = libmisc.la AM_CFLAGS= @NEUROFLAGS@ -libmisc_la_SOURCES = \ +libmisc_la_SOURCES = \ other.c \ - arg.c \ - bitmap.c - -#chgen.c - -#if USE_X11 -#libmisc_la_SOURCES += bitmap.c -#endif + arg.c +# bitmap.c +libmisc_la_LIBADD = \ + bitmap/libbitmap.la diff --git a/src/misc/Makefile.in b/src/misc/Makefile.in index 67f9994..ccc6063 100644 --- a/src/misc/Makefile.in +++ b/src/misc/Makefile.in @@ -50,8 +50,8 @@ mkinstalldirs = $(install_sh) -d CONFIG_HEADER = $(top_builddir)/include/neuro/config.h CONFIG_CLEAN_FILES = LTLIBRARIES = $(noinst_LTLIBRARIES) -libmisc_la_LIBADD = -am_libmisc_la_OBJECTS = other.lo arg.lo bitmap.lo +libmisc_la_DEPENDENCIES = bitmap/libbitmap.la +am_libmisc_la_OBJECTS = other.lo arg.lo libmisc_la_OBJECTS = $(am_libmisc_la_OBJECTS) DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)/include/neuro depcomp = $(SHELL) $(top_srcdir)/depcomp @@ -66,8 +66,15 @@ LINK = $(LIBTOOL) --tag=CC --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(AM_LDFLAGS) $(LDFLAGS) -o $@ SOURCES = $(libmisc_la_SOURCES) DIST_SOURCES = $(libmisc_la_SOURCES) +RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \ + html-recursive info-recursive install-data-recursive \ + install-exec-recursive install-info-recursive \ + install-recursive installcheck-recursive installdirs-recursive \ + pdf-recursive ps-recursive uninstall-info-recursive \ + uninstall-recursive ETAGS = etags CTAGS = ctags +DIST_SUBDIRS = $(SUBDIRS) DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) ACLOCAL = @ACLOCAL@ AMDEP_FALSE = @AMDEP_FALSE@ @@ -197,14 +204,18 @@ sharedstatedir = @sharedstatedir@ subdirs = @subdirs@ sysconfdir = @sysconfdir@ target_alias = @target_alias@ +SUBDIRS = bitmap noinst_LTLIBRARIES = libmisc.la AM_CFLAGS = @NEUROFLAGS@ libmisc_la_SOURCES = \ other.c \ - arg.c \ - bitmap.c + arg.c -all: all-am +# bitmap.c +libmisc_la_LIBADD = \ + bitmap/libbitmap.la + +all: all-recursive .SUFFIXES: .SUFFIXES: .c .lo .o .obj @@ -256,7 +267,6 @@ distclean-compile: -rm -f *.tab.c @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/arg.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bitmap.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/other.Plo@am__quote@ .c.o: @@ -290,6 +300,65 @@ distclean-libtool: -rm -f libtool uninstall-info-am: +# This directory's subdirectories are mostly independent; you can cd +# into them and run `make' without going through this Makefile. +# To change the values of `make' variables: instead of editing Makefiles, +# (1) if the variable is set in `config.status', edit `config.status' +# (which will cause the Makefiles to be regenerated when you run `make'); +# (2) otherwise, pass the desired values on the `make' command line. +$(RECURSIVE_TARGETS): + @set fnord $$MAKEFLAGS; amf=$$2; \ + dot_seen=no; \ + target=`echo $@ | sed s/-recursive//`; \ + list='$(SUBDIRS)'; for subdir in $$list; do \ + echo "Making $$target in $$subdir"; \ + if test "$$subdir" = "."; then \ + dot_seen=yes; \ + local_target="$$target-am"; \ + else \ + local_target="$$target"; \ + fi; \ + (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ + || case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \ + done; \ + if test "$$dot_seen" = "no"; then \ + $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \ + fi; test -z "$$fail" + +mostlyclean-recursive clean-recursive distclean-recursive \ +maintainer-clean-recursive: + @set fnord $$MAKEFLAGS; amf=$$2; \ + dot_seen=no; \ + case "$@" in \ + distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \ + *) list='$(SUBDIRS)' ;; \ + esac; \ + rev=''; for subdir in $$list; do \ + if test "$$subdir" = "."; then :; else \ + rev="$$subdir $$rev"; \ + fi; \ + done; \ + rev="$$rev ."; \ + target=`echo $@ | sed s/-recursive//`; \ + for subdir in $$rev; do \ + echo "Making $$target in $$subdir"; \ + if test "$$subdir" = "."; then \ + local_target="$$target-am"; \ + else \ + local_target="$$target"; \ + fi; \ + (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ + || case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \ + done && test -z "$$fail" +tags-recursive: + list='$(SUBDIRS)'; for subdir in $$list; do \ + test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) tags); \ + done +ctags-recursive: + list='$(SUBDIRS)'; for subdir in $$list; do \ + test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) ctags); \ + done + ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ unique=`for i in $$list; do \ @@ -300,10 +369,23 @@ ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) mkid -fID $$unique tags: TAGS -TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ +TAGS: tags-recursive $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ $(TAGS_FILES) $(LISP) tags=; \ here=`pwd`; \ + if ($(ETAGS) --etags-include --version) >/dev/null 2>&1; then \ + include_option=--etags-include; \ + empty_fix=.; \ + else \ + include_option=--include; \ + empty_fix=; \ + fi; \ + list='$(SUBDIRS)'; for subdir in $$list; do \ + if test "$$subdir" = .; then :; else \ + test ! -f $$subdir/TAGS || \ + tags="$$tags $$include_option=$$here/$$subdir/TAGS"; \ + fi; \ + done; \ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ @@ -316,7 +398,7 @@ TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ $$tags $$unique; \ fi ctags: CTAGS -CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ +CTAGS: ctags-recursive $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ $(TAGS_FILES) $(LISP) tags=; \ here=`pwd`; \ @@ -365,19 +447,35 @@ distdir: $(DISTFILES) || exit 1; \ fi; \ done + list='$(DIST_SUBDIRS)'; for subdir in $$list; do \ + if test "$$subdir" = .; then :; else \ + test -d "$(distdir)/$$subdir" \ + || $(mkdir_p) "$(distdir)/$$subdir" \ + || exit 1; \ + distdir=`$(am__cd) $(distdir) && pwd`; \ + top_distdir=`$(am__cd) $(top_distdir) && pwd`; \ + (cd $$subdir && \ + $(MAKE) $(AM_MAKEFLAGS) \ + top_distdir="$$top_distdir" \ + distdir="$$distdir/$$subdir" \ + distdir) \ + || exit 1; \ + fi; \ + done check-am: all-am -check: check-am +check: check-recursive all-am: Makefile $(LTLIBRARIES) -installdirs: -install: install-am -install-exec: install-exec-am -install-data: install-data-am -uninstall: uninstall-am +installdirs: installdirs-recursive +installdirs-am: +install: install-recursive +install-exec: install-exec-recursive +install-data: install-data-recursive +uninstall: uninstall-recursive install-am: all-am @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am -installcheck: installcheck-am +installcheck: installcheck-recursive install-strip: $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ @@ -393,24 +491,24 @@ distclean-generic: maintainer-clean-generic: @echo "This command is intended for maintainers to use" @echo "it deletes files that may require special tools to rebuild." -clean: clean-am +clean: clean-recursive clean-am: clean-generic clean-libtool clean-noinstLTLIBRARIES \ mostlyclean-am -distclean: distclean-am +distclean: distclean-recursive -rm -rf ./$(DEPDIR) -rm -f Makefile distclean-am: clean-am distclean-compile distclean-generic \ distclean-libtool distclean-tags -dvi: dvi-am +dvi: dvi-recursive dvi-am: -html: html-am +html: html-recursive -info: info-am +info: info-recursive info-am: @@ -418,50 +516,48 @@ install-data-am: install-exec-am: -install-info: install-info-am +install-info: install-info-recursive install-man: installcheck-am: -maintainer-clean: maintainer-clean-am +maintainer-clean: maintainer-clean-recursive -rm -rf ./$(DEPDIR) -rm -f Makefile maintainer-clean-am: distclean-am maintainer-clean-generic -mostlyclean: mostlyclean-am +mostlyclean: mostlyclean-recursive mostlyclean-am: mostlyclean-compile mostlyclean-generic \ mostlyclean-libtool -pdf: pdf-am +pdf: pdf-recursive pdf-am: -ps: ps-am +ps: ps-recursive ps-am: uninstall-am: uninstall-info-am -.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ - clean-libtool clean-noinstLTLIBRARIES ctags distclean \ - distclean-compile distclean-generic distclean-libtool \ - distclean-tags distdir dvi dvi-am html html-am info info-am \ - install install-am install-data install-data-am install-exec \ - install-exec-am install-info install-info-am install-man \ - install-strip installcheck installcheck-am installdirs \ - maintainer-clean maintainer-clean-generic mostlyclean \ - mostlyclean-compile mostlyclean-generic mostlyclean-libtool \ - pdf pdf-am ps ps-am tags uninstall uninstall-am \ - uninstall-info-am - +uninstall-info: uninstall-info-recursive -#chgen.c +.PHONY: $(RECURSIVE_TARGETS) CTAGS GTAGS all all-am check check-am \ + clean clean-generic clean-libtool clean-noinstLTLIBRARIES \ + clean-recursive ctags ctags-recursive distclean \ + distclean-compile distclean-generic distclean-libtool \ + distclean-recursive distclean-tags distdir dvi dvi-am html \ + html-am info info-am install install-am install-data \ + install-data-am install-exec install-exec-am install-info \ + install-info-am install-man install-strip installcheck \ + installcheck-am installdirs installdirs-am maintainer-clean \ + maintainer-clean-generic maintainer-clean-recursive \ + mostlyclean mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool mostlyclean-recursive pdf pdf-am ps ps-am \ + tags tags-recursive uninstall uninstall-am uninstall-info-am -#if USE_X11 -#libmisc_la_SOURCES += bitmap.c -#endif # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: diff --git a/src/misc/bitmap/Makefile.am b/src/misc/bitmap/Makefile.am new file mode 100644 index 0000000..1d6c532 --- /dev/null +++ b/src/misc/bitmap/Makefile.am @@ -0,0 +1,12 @@ +#!/bin/bash + +EXTRA_DIST = intern_bitmap.h + +noinst_LTLIBRARIES = libbitmap.la + +AM_CFLAGS= @NEUROFLAGS@ + +libbitmap_la_SOURCES = \ + core.c \ + io.c \ + process.c diff --git a/src/misc/Makefile.in b/src/misc/bitmap/Makefile.in similarity index 93% copy from src/misc/Makefile.in copy to src/misc/bitmap/Makefile.in index 67f9994..8fbc4c2 100644 --- a/src/misc/Makefile.in +++ b/src/misc/bitmap/Makefile.in @@ -16,7 +16,7 @@ #!/bin/bash -SOURCES = $(libmisc_la_SOURCES) +SOURCES = $(libbitmap_la_SOURCES) srcdir = @srcdir@ top_srcdir = @top_srcdir@ @@ -24,7 +24,7 @@ VPATH = @srcdir@ pkgdatadir = $(datadir)/@PACKAGE@ pkglibdir = $(libdir)/@PACKAGE@ pkgincludedir = $(includedir)/@PACKAGE@ -top_builddir = ../.. +top_builddir = ../../.. am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd INSTALL = @INSTALL@ install_sh_DATA = $(install_sh) -c -m 644 @@ -40,7 +40,7 @@ PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ -subdir = src/misc +subdir = src/misc/bitmap DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/configure.ac @@ -50,9 +50,9 @@ mkinstalldirs = $(install_sh) -d CONFIG_HEADER = $(top_builddir)/include/neuro/config.h CONFIG_CLEAN_FILES = LTLIBRARIES = $(noinst_LTLIBRARIES) -libmisc_la_LIBADD = -am_libmisc_la_OBJECTS = other.lo arg.lo bitmap.lo -libmisc_la_OBJECTS = $(am_libmisc_la_OBJECTS) +libbitmap_la_LIBADD = +am_libbitmap_la_OBJECTS = core.lo io.lo process.lo +libbitmap_la_OBJECTS = $(am_libbitmap_la_OBJECTS) DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)/include/neuro depcomp = $(SHELL) $(top_srcdir)/depcomp am__depfiles_maybe = depfiles @@ -64,8 +64,8 @@ LTCOMPILE = $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) \ CCLD = $(CC) LINK = $(LIBTOOL) --tag=CC --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(AM_LDFLAGS) $(LDFLAGS) -o $@ -SOURCES = $(libmisc_la_SOURCES) -DIST_SOURCES = $(libmisc_la_SOURCES) +SOURCES = $(libbitmap_la_SOURCES) +DIST_SOURCES = $(libbitmap_la_SOURCES) ETAGS = etags CTAGS = ctags DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) @@ -197,12 +197,13 @@ sharedstatedir = @sharedstatedir@ subdirs = @subdirs@ sysconfdir = @sysconfdir@ target_alias = @target_alias@ -noinst_LTLIBRARIES = libmisc.la +EXTRA_DIST = intern_bitmap.h +noinst_LTLIBRARIES = libbitmap.la AM_CFLAGS = @NEUROFLAGS@ -libmisc_la_SOURCES = \ - other.c \ - arg.c \ - bitmap.c +libbitmap_la_SOURCES = \ + core.c \ + io.c \ + process.c all: all-am @@ -217,9 +218,9 @@ $(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) exit 1;; \ esac; \ done; \ - echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/misc/Makefile'; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/misc/bitmap/Makefile'; \ cd $(top_srcdir) && \ - $(AUTOMAKE) --gnu src/misc/Makefile + $(AUTOMAKE) --gnu src/misc/bitmap/Makefile .PRECIOUS: Makefile Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status @case '$?' in \ @@ -246,8 +247,8 @@ clean-noinstLTLIBRARIES: echo "rm -f \"$${dir}/so_locations\""; \ rm -f "$${dir}/so_locations"; \ done -libmisc.la: $(libmisc_la_OBJECTS) $(libmisc_la_DEPENDENCIES) - $(LINK) $(libmisc_la_LDFLAGS) $(libmisc_la_OBJECTS) $(libmisc_la_LIBADD) $(LIBS) +libbitmap.la: $(libbitmap_la_OBJECTS) $(libbitmap_la_DEPENDENCIES) + $(LINK) $(libbitmap_la_LDFLAGS) $(libbitmap_la_OBJECTS) $(libbitmap_la_LIBADD) $(LIBS) mostlyclean-compile: -rm -f *.$(OBJEXT) @@ -255,9 +256,9 @@ mostlyclean-compile: distclean-compile: -rm -f *.tab.c -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/arg.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bitmap.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/other.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/core.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/io.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/process.Plo@am__quote@ .c.o: @am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \ @@ -456,12 +457,6 @@ uninstall-am: uninstall-info-am pdf pdf-am ps ps-am tags uninstall uninstall-am \ uninstall-info-am - -#chgen.c - -#if USE_X11 -#libmisc_la_SOURCES += bitmap.c -#endif # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: diff --git a/src/misc/bitmap/core.c b/src/misc/bitmap/core.c new file mode 100644 index 0000000..e9258c3 --- /dev/null +++ b/src/misc/bitmap/core.c @@ -0,0 +1,143 @@ + +/* + * libneuro, a light weight abstraction of high or lower libraries + * and toolkit for applications. + * Copyright (C) 2005-2006 Nicholas Niro, Robert Lemay + * + * 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. + * + * 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 St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* core.c + * Module : Bitmap_ + * + * This module actually is a driver to load + * bitmap file types to memory. + */ + +/*-------------------- Extern Headers Including --------------------*/ +#include +#include +#include +#include + +/*-------------------- Local Headers Including ---------------------*/ +#include +#include +#include + +#include /* Neuro_PutPixel */ + +/*-------------------- Main Module Header --------------------------*/ +#include "intern_bitmap.h" + +/*-------------------- Other ----------------------------*/ + +NEURO_MODULE_CHANNEL("bitmap/core"); + +/*-------------------- Global Variables ----------------------------*/ + +/*-------------------- Static Variables ----------------------------*/ + +/*-------------------- Static Prototypes ---------------------------*/ + +/*-------------------- Static Functions ----------------------------*/ + +/*-------------------- Global Functions ----------------------------*/ + +v_object * +Bitmap_LoadBMP(const char *bitmap) +{ + BMP_CTX *ctx = NULL; + int _err = 0; + + ctx = Bitmap_CreateCTX(bitmap); + + if (ctx == NULL) + { + NEURO_WARN("Context creation failed", NULL); + return NULL; + } + + while (1 != 2) + { + _err = Bitmap_Poll(ctx); + + if (_err == 100) + break; + + if (_err < 0) + { + NEURO_WARN("Poll failed...", NULL); + return NULL; + } + + /* printf("loading progress : %d\n", _err); */ + } + + return Bitmap_DestroyCTX(ctx); +} + +/*-------------------- Poll ----------------------------------------*/ + +/* returns a percentage of progress */ +i8 +Bitmap_Poll(BMP_CTX *ctx) +{ + return Bitmap_ProcessGradual(ctx, ctx->cut_size); +} + +/*-------------------- Constructor Destructor ----------------------*/ + +BMP_CTX * +Bitmap_CreateCTX(const char *path) +{ + BMP_CTX *output; + + output = calloc(1, sizeof(BMP_CTX)); + + if (output == NULL) + return NULL; +#if USE_ZLIB 1 + output->f_bitmap = gzopen(path, "r"); /* can also be used for non compressed files */ +#else /* NOT USE_ZLIB */ + output->f_bitmap = fopen(path, "r"); +#endif /* NOT USE_ZLIB */ + + if (output->f_bitmap == NULL) + { + free(output); + return NULL; + } + + return output; +} + +v_object * +Bitmap_DestroyCTX(BMP_CTX *ctx) +{ + v_object *output = NULL; + + if (ctx == NULL) + return NULL; + + /* loading the image is done so we unlock */ + Neuro_UnlockVObject(ctx->output); + + output = ctx->output; + + free(ctx); + + return output; +} diff --git a/src/misc/bitmap/intern_bitmap.h b/src/misc/bitmap/intern_bitmap.h new file mode 100644 index 0000000..f7d7951 --- /dev/null +++ b/src/misc/bitmap/intern_bitmap.h @@ -0,0 +1,108 @@ +/* intern_bitmap.h */ + +#ifndef __INTERN_BITMAP_H +#define __INTERN_BITMAP_H + +#include + +#include + +#include +#include + +#if USE_ZLIB 1 +/* this is used to open the bitmaps, + * the beauty of zlib is it works + * for compressed and uncompressed + * transparently, meaning no extra code + * for both! + */ +#include +typedef gzFile nFILE; +#else /* NOT USE_ZLIB */ +typedef FILE nFILE; +#endif /* USE_ZLIB */ + +typedef struct BITMAP_HEADER +{ + u16 type __attribute__((packed)); /* Magic identifier */ + u32 size __attribute__((packed)); /* File size in bytes */ + u16 reserved1, reserved2; /* reserved */ + u32 offset __attribute__((packed)); /* Offset to image data, bytes */ +}BITMAP_HEADER; + +typedef struct BITMAP_INFOHEADER +{ + u32 size; /* Header size in bytes */ + i32 width, height; /* Width and height of image */ + u16 planes; /* Number of colour planes */ + u16 bits; /* Bits per pixel */ + u32 compression; /* Compression type */ + u32 imagesize; /* Image size in bytes */ + i32 xresolution, yresolution; /* Pixels per meter */ + u32 ncolors; /* Number of colours */ + u32 importantcolours; /* Important colours */ +}BITMAP_INFOHEADER; + +typedef struct BITMAP_HDATA +{ + BITMAP_HEADER header __attribute__((packed)); + BITMAP_INFOHEADER infoheader __attribute__((packed)); +}BITMAP_HDATA; + +struct BMP_CTX +{ + nFILE *f_bitmap; + + /* major (buffers) */ + EBUF *bmap_colors; /* the colors */ + u8 *buf; /* the buffer that will contain the content of the file */ + + /* minor (mostly pointers and temporary variables) */ + i32 i; /* incremental variable */ + u32 x, y; + + u32 psize; /* the full size of the pixels data */ + BITMAP_HDATA *bmap; /* this is how we will get informations about the bitmap */ + int aux_var; /* auxiliary variable that can be used by external functions */ + char *aux_buf; /* same as aux_var but a buffer */ + u32 wmult; + u32 DATA; + i32 advance; + u32 row_amount; /* processing of the current row */ + v_object *output; /* the image into which we will load the bitmap */ + u32 cut_size; /* amount of bytes to load per cycles */ +}; + +typedef struct BITMAP_COLOR +{ + u8 r, g, b /*, a*/ ; /* red green blue */ +}BITMAP_COLOR; + +typedef struct BITMAP_MAP +{ + BITMAP_COLOR *color; +}BITMAP_MAP; + +/* io.c */ + +extern int fpdata8(nFILE *input, u8 *output); +extern int fpdata16(nFILE *input, u16 *output); +extern int fpdata32(nFILE *input, u32 *output); + + +/* process.c */ + +extern i8 Bitmap_ProcessGradual(BMP_CTX *ctx, u32 loops); + +/* core.c */ + +extern v_object *Bitmap_LoadBMP(const char *bitmap); + +extern i8 Bitmap_Poll(BMP_CTX *ctx); + +extern BMP_CTX *Bitmap_CreateCTX(const char *path); + +extern v_object *Bitmap_DestroyCTX(BMP_CTX *ctx); + +#endif /* NOT __INTERN_BITMAP_H */ diff --git a/src/misc/bitmap/io.c b/src/misc/bitmap/io.c new file mode 100644 index 0000000..d708af7 --- /dev/null +++ b/src/misc/bitmap/io.c @@ -0,0 +1,156 @@ + +/* + * libneuro, a light weight abstraction of high or lower libraries + * and toolkit for applications. + * Copyright (C) 2005-2006 Nicholas Niro, Robert Lemay + * + * 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. + * + * 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 St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* io.c + * + * Basic input and output functions. + */ + +/*-------------------- Extern Headers Including --------------------*/ + +#include +#include + +/*-------------------- Local Headers Including ---------------------*/ +#include + +/*-------------------- Main Module Header --------------------------*/ +#include "intern_bitmap.h" + +/*-------------------- Other ----------------------------*/ + +NEURO_MODULE_CHANNEL("bitmap/io"); + +/*-------------------- Global Variables ----------------------------*/ + +/*-------------------- Static Variables ----------------------------*/ + +/*-------------------- Static Prototypes ---------------------------*/ + +/*-------------------- Static Functions ----------------------------*/ + +/*-------------------- Global Functions ----------------------------*/ + +/* returns 0 on success and puts the data in *output + * when 1 on error don't touch output + */ +int +fpdata8(nFILE *input, u8 *output) +{ + if (input == NULL || output == NULL) + { + NEURO_WARN("Arguments are NULL", NULL); + return 1; + } + +#if USE_ZLIB 1 + *output = gzgetc(input); +#else /* NOT USE_ZLIB */ + *output = fgetc(input); +#endif /* NOT USE_ZLIB */ + + + return 0; +} + +/* returns 0 on success and puts the data in *output + * when 1 on error don't touch output + */ +int +fpdata16(nFILE *input, u16 *output) +{ + u8 feed[2]; + u16 *buf; + + if (input == NULL || output == NULL) + { + NEURO_WARN("Arguments are NULL", NULL); + return 1; + } + + if (IsLittleEndian()) + { +#if USE_ZLIB 1 + feed[0] = gzgetc(input); + feed[1] = gzgetc(input); +#else /* NOT USE_ZLIB */ + feed[0] = fgetc(input); + feed[1] = fgetc(input); +#endif /* NOT USE_ZLIB */ + } + else + { + feed[1] = gzgetc(input); + feed[0] = gzgetc(input); + } + + buf = (u16*)&feed; + + *output = *buf; + + return 0; +} + +/* returns 0 on success and puts the data in *output + * when 1 on error don't touch output + */ +int +fpdata32(nFILE *input, u32 *output) +{ + /* register int feed; */ + u8 feed[4]; + u32 *buf; + + + if (input == NULL || output == NULL) + { + NEURO_WARN("Arguments are NULL", NULL); + return 1; + } + + if (IsLittleEndian()) + { +#if USE_ZLIB 1 + feed[0] = gzgetc(input); + feed[1] = gzgetc(input); + feed[2] = gzgetc(input); + feed[3] = gzgetc(input); +#else /* NOT USE_ZLIB */ + feed[0] = fgetc(input); + feed[1] = fgetc(input); + feed[2] = fgetc(input); + feed[3] = fgetc(input); +#endif /* NOT USE_ZLIB */ + } + else + { + feed[3] = gzgetc(input); + feed[2] = gzgetc(input); + feed[1] = gzgetc(input); + feed[0] = gzgetc(input); + } + + buf = (u32*)&feed; + + *output = *buf; + + return 0; +} diff --git a/src/misc/bitmap.c b/src/misc/bitmap/process.c similarity index 56% rename from src/misc/bitmap.c rename to src/misc/bitmap/process.c index 7aec534..2eed7af 100644 --- a/src/misc/bitmap.c +++ b/src/misc/bitmap/process.c @@ -19,114 +19,39 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -/* bitmap.c +/* process.c * Module : Bitmap * - * bitmap process module + * Code to process the bitmap data. */ -/* the package's main config file */ -#include - /*-------------------- Extern Headers Including --------------------*/ #include #include #include #include -#if USE_ZLIB 1 -/* this is used to open the bitmaps, - * the beauty of this is it works - * for compressed and uncompressed - * transparently, meaning no extra code - * for both! - */ -#include -typedef gzFile nFILE; -#else /* NOT USE_ZLIB */ -typedef FILE nFILE; -#endif /* USE_ZLIB */ - /*-------------------- Local Headers Including ---------------------*/ #include #include #include -#include /* Lib_GetDefaultDepth() */ #include /* Neuro_PutPixel */ /*-------------------- Main Module Header --------------------------*/ -#include +#include "intern_bitmap.h" /*-------------------- Other ----------------------------*/ -NEURO_MODULE_CHANNEL("bitmap"); - -typedef struct BITMAP_HEADER -{ - u16 type __attribute__((packed)); /* Magic identifier */ - u32 size __attribute__((packed)); /* File size in bytes */ - u16 reserved1, reserved2; /* reserved */ - u32 offset __attribute__((packed)); /* Offset to image data, bytes */ -}BITMAP_HEADER; - -typedef struct BITMAP_INFOHEADER -{ - u32 size; /* Header size in bytes */ - i32 width, height; /* Width and height of image */ - u16 planes; /* Number of colour planes */ - u16 bits; /* Bits per pixel */ - u32 compression; /* Compression type */ - u32 imagesize; /* Image size in bytes */ - i32 xresolution, yresolution; /* Pixels per meter */ - u32 ncolors; /* Number of colours */ - u32 importantcolours; /* Important colours */ -}BITMAP_INFOHEADER; - -typedef struct BITMAP_HDATA -{ - BITMAP_HEADER header __attribute__((packed)); - BITMAP_INFOHEADER infoheader __attribute__((packed)); -}BITMAP_HDATA; - -typedef struct BITMAP_COLOR -{ - u8 r, g, b /*, a*/ ; /* red green blue */ -}BITMAP_COLOR; - -typedef struct BITMAP_MAP -{ - BITMAP_COLOR *color; -}BITMAP_MAP; - -struct BMP_CTX -{ - nFILE *f_bitmap; - - /* major (buffers) */ - EBUF *bmap_colors; /* the colors */ - u8 *buf; /* the buffer that will contain the content of the file */ - - /* minor (mostly pointers and temporary variables) */ - i32 i; /* incremental variable */ - u32 skip_i, x, y; - - u32 psize; /* the full size of the pixels data */ - u8 *palette; /* the pointer to the palette if theres one */ - BITMAP_HDATA *bmap; /* this is how we will get informations about the bitmap */ - int aux_var; /* auxiliary variable that can be used by external functions */ - char *aux_buf; /* same as aux_var but a buffer */ - double msize; - double calc; - double tmp; - u32 wmult; - double pixellen; - u32 increm; - u8 DATA; - v_object *output; /* the image into which we will load the bitmap */ - u32 cut_size; /* amount of bytes to load per cycles */ -}; +NEURO_MODULE_CHANNEL("bitmap/process"); +/* this macro is used to offset the actual workable value + * of the bitmap's width and height values. + * + * A value of say 200 in width and height would actually + * yield in the values of 0 to 199. + */ +#define SIZE_OFFSET -1 /*-------------------- Global Variables ----------------------------*/ @@ -135,152 +60,9 @@ struct BMP_CTX /*-------------------- Static Prototypes ---------------------------*/ static void print_bitmap_infos(BITMAP_HDATA *bmap) __attribute__((unused)); -static int fpdata8(nFILE *input, u8 *output) __attribute__((unused)); -static int fpdata16(nFILE *input, u16 *output) __attribute__((unused)); -static int fpdata32(nFILE *input, u32 *output) __attribute__((unused)); - /*-------------------- Static Functions ----------------------------*/ -static void -clean_bmap_color(void *eng) -{ - BITMAP_COLOR *buf; - - buf = (BITMAP_COLOR*)eng; -} - - -/* returns 0 on success and puts the data in *output - * 1 on error dont touch output - */ -static int -fpdata8(nFILE *input, u8 *output) -{ - if (input == NULL || output == NULL) - return 1; -#if USE_ZLIB 1 - *output = gzgetc(input); -#else /* NOT USE_ZLIB */ - *output = fgetc(input); -#endif /* NOT USE_ZLIB */ - - - return 0; -} - -/* returns 0 on success and puts the data in *output - * 1 on error dont touch output - */ -static int -fpdata16(nFILE *input, u16 *output) -{ - u8 feed[2]; - u16 *buf; - - if (input == NULL || output == NULL) - return 1; - - if (IsLittleEndian()) - { -#if USE_ZLIB 1 - feed[0] = gzgetc(input); - feed[1] = gzgetc(input); -#else /* NOT USE_ZLIB */ - feed[0] = fgetc(input); - feed[1] = fgetc(input); -#endif /* NOT USE_ZLIB */ - } - else - { - feed[1] = gzgetc(input); - feed[0] = gzgetc(input); - } - - buf = (u16*)&feed; - - *output = *buf; - - return 0; -} - -/* returns 0 on success and puts the data in *output - * 1 on error dont touch output - */ -static int -fpdata32(nFILE *input, u32 *output) -{ - /* register int feed; */ - u8 feed[4]; - u32 *buf; - - - if (input == NULL || output == NULL) - return 1; - - if (IsLittleEndian()) - { -#if USE_ZLIB 1 - feed[0] = gzgetc(input); - feed[1] = gzgetc(input); - feed[2] = gzgetc(input); - feed[3] = gzgetc(input); -#else /* NOT USE_ZLIB */ - feed[0] = fgetc(input); - feed[1] = fgetc(input); - feed[2] = fgetc(input); - feed[3] = fgetc(input); -#endif /* NOT USE_ZLIB */ - } - else - { - feed[3] = gzgetc(input); - feed[2] = gzgetc(input); - feed[1] = gzgetc(input); - feed[0] = gzgetc(input); - } - - buf = (u32*)&feed; - - *output = *buf; - - return 0; -} - -static BITMAP_HDATA * -parse_bitmap_header(nFILE *input) -{ - BITMAP_HDATA *buf; - BITMAP_INFOHEADER *tmp; - - if (input == NULL) - return NULL; - - buf = calloc(1, sizeof(BITMAP_HDATA)); - - tmp = &buf->infoheader; - - fpdata16(input, &buf->header.type); - fpdata32(input, &buf->header.size); - fpdata16(input, &buf->header.reserved1); - fpdata16(input, &buf->header.reserved2); - fpdata32(input, &buf->header.offset); - - fpdata32(input, &tmp->size); - fpdata32(input, (u32*)&tmp->width); - fpdata32(input, (u32*)&tmp->height); - fpdata16(input, &tmp->planes); - fpdata16(input, &tmp->bits); - fpdata32(input, &tmp->compression); - fpdata32(input, &tmp->imagesize); - fpdata32(input, (u32*)&tmp->xresolution); - fpdata32(input, (u32*)&tmp->yresolution); - fpdata32(input, &tmp->ncolors); - fpdata32(input, &tmp->importantcolours); - - return buf; -} - /* the magic number will probably not show correctly if big endian */ static void print_bitmap_infos(BITMAP_HDATA *bmap) @@ -304,60 +86,23 @@ print_bitmap_infos(BITMAP_HDATA *bmap) bmap->infoheader.importantcolours); } - -static void -process_palette(nFILE *input, BITMAP_HDATA *bmap, EBUF *bcolors) +static void +clean_bmap_color(void *eng) { - u32 i = 0; BITMAP_COLOR *buf; - while (i < bmap->infoheader.ncolors) - { - Neuro_AllocEBuf(bcolors, sizeof(BITMAP_COLOR*), sizeof(BITMAP_COLOR)); - - buf = Neuro_GiveCurEBuf(bcolors); - - /*buf->r = palette[(i * 4) + 2]; - buf->g = palette[(i * 4) + 1]; - buf->b = palette[(i * 4)]; - */ - - /* - fpdata8(input, &buf->b); - fpdata8(input, &buf->g); - fpdata8(input, &buf->r); - fpdata8(input, &buf->a); - */ -#if USE_ZLIB 1 - buf->b = gzgetc(input); - buf->g = gzgetc(input); - buf->r = gzgetc(input); - - /* I leave this just in case */ - /* buf->a = fgetc(input); */ - - /* skip the alpha color */ - gzgetc(input); -#else /* NOT USE_ZLIB */ - buf->b = fgetc(input); - buf->g = fgetc(input); - buf->r = fgetc(input); - - /* I leave this just in case */ - /* buf->a = fgetc(input); */ - - /* skip the alpha color */ - fgetc(input); -#endif /* NOT USE_ZLIB */ - i++; - } + buf = (BITMAP_COLOR*)eng; } -/* input the bits per pixel of the image +/* This function processes each bytes of the inherent bitmap + * data pixels. It supports 4 bits per pixels types : + * 1, 4, 8 and 24. + * + * input the bits per pixel of the image * input a 1 byte of data to process */ static void -process_bitmap(BITMAP_HDATA *bmap, v_object *image, u8 *palette, u8 *data, EBUF *bcolors, u32 *x, u32 *y, int *aux, char **buf) +process_bitmap(BITMAP_HDATA *bmap, v_object *image, u8 *data, EBUF *bcolors, u32 *x, u32 *y, int *aux, char **buf) { /* we will call functions depending on the bpp of the image */ @@ -427,6 +172,9 @@ process_bitmap(BITMAP_HDATA *bmap, v_object *image, u8 *palette, u8 *data, EBUF { BITMAP_COLOR *cbuf = NULL; + if (*y >= bmap->infoheader.height) + break; + temp = *data & values[i]; @@ -435,16 +183,15 @@ process_bitmap(BITMAP_HDATA *bmap, v_object *image, u8 *palette, u8 *data, EBUF cbuf = Neuro_GiveEBuf(bcolors, temp); - if (IsLittleEndian()) - Neuro_PutPixel(image, *x, (bmap->infoheader.height - 1) - *y, Neuro_MapRGB(cbuf->r, cbuf->g, cbuf->b)); - else - Neuro_PutPixel(image, *x, (bmap->infoheader.height - 1) - *y, Neuro_MapRGB(cbuf->b, cbuf->g, cbuf->r)); + Neuro_PutPixel(image, *x, + (bmap->infoheader.height + SIZE_OFFSET) - *y, + Neuro_MapRGB(cbuf->r, cbuf->g, cbuf->b)); *x = *x + 1; i++; } - if (*x > bmap->infoheader.width - 1) + if (*x > bmap->infoheader.width + SIZE_OFFSET) { *x = 0; *y = *y + 1; @@ -456,9 +203,6 @@ process_bitmap(BITMAP_HDATA *bmap, v_object *image, u8 *palette, u8 *data, EBUF { /* will do a loop to get each 2 pixels from the data */ u8 temp; - /* double calc = 0; */ - - /* u8 r, g, b; */ const u8 values[2] = { 0xF0, @@ -495,6 +239,9 @@ process_bitmap(BITMAP_HDATA *bmap, v_object *image, u8 *palette, u8 *data, EBUF while (i < max) { BITMAP_COLOR *cbuf = NULL; + + if (*y >= bmap->infoheader.height) + break; temp = *data & values[i]; if (IsLittleEndian()) @@ -510,17 +257,14 @@ process_bitmap(BITMAP_HDATA *bmap, v_object *image, u8 *palette, u8 *data, EBUF cbuf = Neuro_GiveEBuf(bcolors, temp); - if (IsLittleEndian()) - Neuro_PutPixel(image, *x, (bmap->infoheader.height - 1) - *y, Neuro_MapRGB(cbuf->r, cbuf->g, cbuf->b)); - else - Neuro_PutPixel(image, *x, (bmap->infoheader.height - 1) - *y, Neuro_MapRGB(cbuf->b, cbuf->g, cbuf->r)); - + Neuro_PutPixel(image, *x, (bmap->infoheader.height + SIZE_OFFSET) - *y, + Neuro_MapRGB(cbuf->r, cbuf->g, cbuf->b)); *x = *x + 1; i++; } - if (*x > bmap->infoheader.width - 1) + if (*x > bmap->infoheader.width + SIZE_OFFSET) { *x = 0; *y = *y + 1; @@ -569,22 +313,23 @@ process_bitmap(BITMAP_HDATA *bmap, v_object *image, u8 *palette, u8 *data, EBUF { BITMAP_COLOR *cbuf = NULL; temp = *data; - + + if (*y >= bmap->infoheader.height) + break; cbuf = Neuro_GiveEBuf(bcolors, temp); - if (IsLittleEndian()) - Neuro_PutPixel(image, *x, (bmap->infoheader.height - 1) - *y, Neuro_MapRGB(cbuf->r, cbuf->g, cbuf->b)); - else - Neuro_PutPixel(image, *x, (bmap->infoheader.height - 1) - *y, Neuro_MapRGB(cbuf->b, cbuf->g, cbuf->r)); + Neuro_PutPixel(image, *x, (bmap->infoheader.height + SIZE_OFFSET) - *y, + Neuro_MapRGB(cbuf->r, cbuf->g, cbuf->b)); *x = *x + 1; i++; } - if (*x > bmap->infoheader.width - 1) + if (*x > bmap->infoheader.width + SIZE_OFFSET) { *x = 0; + *y = *y + 1; } @@ -620,23 +365,22 @@ process_bitmap(BITMAP_HDATA *bmap, v_object *image, u8 *palette, u8 *data, EBUF { *aux = 0; - if (bmap->infoheader.height == *y) + if (bmap->infoheader.height >= *y) { NEURO_ERROR("attempted to draw an invalid location", NULL); return; } - if (IsLittleEndian()) - Neuro_PutPixel(image, *x, (bmap->infoheader.height - 1) - *y, Neuro_MapRGB((*buf)[2], (*buf)[1], (*buf)[0])); - else - Neuro_PutPixel(image, *x, (bmap->infoheader.height - 1) - *y, Neuro_MapRGB((*buf)[0], (*buf)[1], (*buf)[2])); + Neuro_PutPixel(image, *x, (bmap->infoheader.height + SIZE_OFFSET) - *y, + Neuro_MapRGB((*buf)[2], (*buf)[1], (*buf)[0])); *x = *x + 1; } - if (*x > bmap->infoheader.width - 1) + if (*x > bmap->infoheader.width + SIZE_OFFSET) { *x = 0; + *y = *y + 1; } } @@ -659,13 +403,99 @@ process_bitmap(BITMAP_HDATA *bmap, v_object *image, u8 *palette, u8 *data, EBUF } } +static BITMAP_HDATA * +parse_bitmap_header(nFILE *input) +{ + BITMAP_HDATA *buf; + BITMAP_INFOHEADER *tmp; + + if (input == NULL) + return NULL; + + buf = calloc(1, sizeof(BITMAP_HDATA)); + + tmp = &buf->infoheader; + + fpdata16(input, &buf->header.type); + fpdata32(input, &buf->header.size); + fpdata16(input, &buf->header.reserved1); + fpdata16(input, &buf->header.reserved2); + fpdata32(input, &buf->header.offset); + + fpdata32(input, &tmp->size); + fpdata32(input, (u32*)&tmp->width); + fpdata32(input, (u32*)&tmp->height); + + fpdata16(input, &tmp->planes); + fpdata16(input, &tmp->bits); + fpdata32(input, &tmp->compression); + fpdata32(input, &tmp->imagesize); + fpdata32(input, (u32*)&tmp->xresolution); + fpdata32(input, (u32*)&tmp->yresolution); + fpdata32(input, &tmp->ncolors); + fpdata32(input, &tmp->importantcolours); + + return buf; +} + +void +process_palette(nFILE *input, BITMAP_HDATA *bmap, EBUF *bcolors) +{ + u32 i = 0; + BITMAP_COLOR *buf; + + while (i < bmap->infoheader.ncolors) + { + Neuro_AllocEBuf(bcolors, sizeof(BITMAP_COLOR*), sizeof(BITMAP_COLOR)); + + buf = Neuro_GiveCurEBuf(bcolors); + + /*buf->r = palette[(i * 4) + 2]; + buf->g = palette[(i * 4) + 1]; + buf->b = palette[(i * 4)]; + */ + + /* + fpdata8(input, &buf->b); + fpdata8(input, &buf->g); + fpdata8(input, &buf->r); + fpdata8(input, &buf->a); + */ +#if USE_ZLIB 1 + buf->b = gzgetc(input); + buf->g = gzgetc(input); + buf->r = gzgetc(input); + + /* I leave this just in case */ + /* buf->a = fgetc(input); */ + + /* skip the alpha color */ + gzgetc(input); +#else /* NOT USE_ZLIB */ + buf->b = fgetc(input); + buf->g = fgetc(input); + buf->r = fgetc(input); + + /* I leave this just in case */ + /* buf->a = fgetc(input); */ + + /* skip the alpha color */ + fgetc(input); +#endif /* NOT USE_ZLIB */ + i++; + } +} + + +/*-------------------- Global Functions ----------------------------*/ + /* ctx being the bitmap loading context * and loops being how many times the * external function wants this function * to load bytes from the image file. */ -static i8 -processGradual_BMP(BMP_CTX *ctx, u32 loops) +i8 +Bitmap_ProcessGradual(BMP_CTX *ctx, u32 loops) { if (ctx == NULL) { @@ -711,7 +541,7 @@ processGradual_BMP(BMP_CTX *ctx, u32 loops) Neuro_SetcallbEBuf(ctx->bmap_colors, &clean_bmap_color); - /* print_bitmap_infos(bmap); */ + /* print_bitmap_infos(ctx->bmap); */ /* we set the variable psize to the size that * the image data is minus the actual header size. @@ -735,10 +565,9 @@ processGradual_BMP(BMP_CTX *ctx, u32 loops) * representation of the image. */ { - - /* Debug_Val(0, "image creation -- depth %d\n", ctx->bmap->infoheader.bits); */ - /*ctx->output = Neuro_CreateVObject(0, ctx->bmap->infoheader.width, ctx->bmap->infoheader.height, ctx->bmap->infoheader.bits, rmask, gmask, bmask, amask);*/ - ctx->output = Neuro_CreateVObject(0, ctx->bmap->infoheader.width, ctx->bmap->infoheader.height, ctx->bmap->infoheader.bits, 0, 0, 0, 0); + ctx->output = Neuro_CreateVObject(0, ctx->bmap->infoheader.width, + ctx->bmap->infoheader.height, + ctx->bmap->infoheader.bits, 0, 0, 0, 0); if (ctx->output == NULL) @@ -748,11 +577,6 @@ processGradual_BMP(BMP_CTX *ctx, u32 loops) } } - /* semi static values to skip bytes that form 32 bit chunks in the data */ - - ctx->pixellen = (8 / (double)ctx->bmap->infoheader.bits); - ctx->msize = ctx->pixellen * 4; - /* we calculate the number of bytes there is per rows * this is mainly so we can know how much "alignment" * bytes there is (which need to be skipped) @@ -765,33 +589,25 @@ processGradual_BMP(BMP_CTX *ctx, u32 loops) ctx->wmult = ctx->wmult * ctx->bmap->infoheader.width; } + ctx->row_amount = ctx->wmult; - ctx->increm = (u32)ctx->pixellen; - - if (ctx->increm == 0) - ctx->increm++; - - ctx->x = (u32)(ctx->bmap->infoheader.width / ctx->msize); - ctx->tmp = ctx->msize * ctx->x; - ctx->tmp = (double)ctx->bmap->infoheader.width - ctx->tmp; - ctx->tmp = ctx->tmp - 0.000001; /* to avoid bugs */ - - ctx->x = 0; + /* we advance up to the point where the bitmap's data are. */ #if USE_ZLIB 1 gzseek(ctx->f_bitmap, ctx->bmap->header.offset, SEEK_SET); #else /* NOT USE_ZLIB */ fseek(ctx->f_bitmap, ctx->bmap->header.offset, SEEK_SET); #endif /* NOT USE_ZLIB */ - NEURO_WARN("Bitmap size %d", ctx->psize); - Debug_Val(0, "Bitmap size %d\n", ctx->psize); + NEURO_TRACE("Bitmap size %d", ctx->psize); + /* we calculate the chunk of data that will be loaded for each + * cycles or polls. + */ ctx->cut_size = ctx->psize / 30; - loops = ctx->cut_size; /* we lock the surface */ - Lib_LockVObject(ctx->output); + Neuro_LockVObject(ctx->output); } @@ -801,62 +617,71 @@ processGradual_BMP(BMP_CTX *ctx, u32 loops) { i32 initial = ctx->i; - /* while (ctx->i < ctx->psize) */ while (ctx->i < (initial + loops)) { + u8 *data; + + /* we check to see if we went past the size of the data */ if (ctx->i > ctx->psize) break; - if (ctx->tmp > 0) + + /* we fetch 32 bits from the file stream */ + if (ctx->advance == 0) { - /* skip bytes that are inside the bitmap for - * filling purpose. (the data is purposely filled - * with 0 bits so the data is 32bits aligned) + /* the algorithm now fetches 32 bits instead of + * the old 8 bits as it was before. + * + * This supplements the huge amount of code that + * was necessary in order to align itself to the + * data which was 32 bits aligned. */ - if (ctx->skip_i >= ctx->wmult) - { - ctx->calc = ctx->tmp / ctx->pixellen; - ctx->skip_i = (u32)ctx->calc; - if (ctx->skip_i < ctx->calc) - { - ctx->skip_i++; - } - ctx->skip_i = (4 - ctx->skip_i); - ctx->i += ctx->skip_i; + fpdata32(ctx->f_bitmap, &ctx->DATA); -#if USE_ZLIB 1 - gzseek(ctx->f_bitmap, ctx->bmap->header.offset + ctx->i, SEEK_SET); -#else /* NOT USE_ZLIB */ - fseek(ctx->f_bitmap, ctx->bmap->header.offset + ctx->i, SEEK_SET); -#endif /* NOT USE_ZLIB */ - - /* - printf("skipping %d bytes wmult %d width %d tmp %f plen %f calc %f\n", - skip_i, - wmult, - bmap->infoheader.width, - tmp, - pixellen, calc); - */ - - ctx->skip_i = 0; - } - - ctx->skip_i += ctx->increm; + /* we fetch 4 bytes of data from the bitmap file + * which will be processed one after the other. + * + * This variable is used to know which + * byte we are processing currently. + */ + ctx->advance = 4; + } - if (ctx->i >= ctx->psize) - break; + /* since the function process_bitmap requires + * a single byte and our ctx->DATA variable is an integer, + * we use the variable data to permit us the ease of pushing + * only a single byte to the function. + */ + data = (u8*)&ctx->DATA; + + + if (ctx->row_amount > 0) + { + /* we push the 8 bits with various other + * variables to the bits processor. + * + */ + process_bitmap(ctx->bmap, ctx->output, &data[4 - ctx->advance], + ctx->bmap_colors, &ctx->x, &ctx->y, + &ctx->aux_var, &ctx->aux_buf); + + ctx->row_amount--; } + else + { + ctx->row_amount = ctx->wmult; - /* we fetch 8 bits from the file stream */ - fpdata8(ctx->f_bitmap, &ctx->DATA); + /* a new row started and we got fresh data + * for the next row so we handle them. + */ + if (ctx->advance == 4) + continue; - /* we push the 8 bits along with various other - * variables to the bits processor. - */ - - process_bitmap(ctx->bmap, ctx->output, ctx->palette, &ctx->DATA, - ctx->bmap_colors, &ctx->x, &ctx->y, &ctx->aux_var, &ctx->aux_buf); + /* we flush the remaining bytes if any */ + ctx->advance = 1; + } + + ctx->advance--; ctx->i++; @@ -889,10 +714,6 @@ processGradual_BMP(BMP_CTX *ctx, u32 loops) return 100; } - /*Debug_Val(0, "((%d * 100) / %d) == %d\n", - ctx->i, ctx->psize, - (i8)((u32)((ctx->i * 100) / ctx->psize)));*/ - /* we return the percentage of the file that * is currently loaded. */ @@ -904,90 +725,4 @@ processGradual_BMP(BMP_CTX *ctx, u32 loops) return -1; } -/*-------------------- Global Functions ----------------------------*/ - -v_object * -readBitmapFile(const char *bitmap) -{ - BMP_CTX *ctx = NULL; - int _err = 0; - - ctx = Bitmap_CreateCTX(bitmap); - if (ctx == NULL) - { - NEURO_WARN("Context creation failed", NULL); - return NULL; - } - - while (1 != 2) - { - _err = Bitmap_Poll(ctx); - - if (_err == 100) - break; - - if (_err < 0) - { - NEURO_WARN("Poll failed...", NULL); - return NULL; - } - - /* printf("loading progress : %d\n", _err); */ - } - - return Bitmap_DestroyCTX(ctx); -} - -/*-------------------- Poll ----------------------------------------*/ - -/* returns a percentage of progress */ -i8 -Bitmap_Poll(BMP_CTX *ctx) -{ - return processGradual_BMP(ctx, ctx->cut_size); -} - -/*-------------------- Constructor Destructor ----------------------*/ - -BMP_CTX * -Bitmap_CreateCTX(const char *path) -{ - BMP_CTX *output; - - output = calloc(1, sizeof(BMP_CTX)); - - if (output == NULL) - return NULL; -#if USE_ZLIB 1 - output->f_bitmap = gzopen(path, "r"); /* can also be used for non compressed files */ -#else /* NOT USE_ZLIB */ - output->f_bitmap = fopen(path, "r"); -#endif /* NOT USE_ZLIB */ - - if (output->f_bitmap == NULL) - { - free(output); - return NULL; - } - - return output; -} - -v_object * -Bitmap_DestroyCTX(BMP_CTX *ctx) -{ - v_object *output = NULL; - - if (ctx == NULL) - return NULL; - - /* loading the image is done so we unlock */ - Lib_UnlockVObject(ctx->output); - - output = ctx->output; - - free(ctx); - - return output; -} diff --git a/version.mk b/version.mk index 0393e7b..ff78988 100644 --- a/version.mk +++ b/version.mk @@ -1,6 +1,6 @@ MAJOR=0 MINOR=49 -MICRO=35 +MICRO=36 INTERFACE=3 -REVISION=9 +REVISION=10 BINARY=3 -- 2.11.4.GIT