/* ************* */ /* bumper_cgx8.e */ /* ************* */ /* WBBump - Bumpmapping on the Workbench! Copyright (C) 1999 Thomas Jensen - dm98411@edb.tietgen.dk This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ OPT MODULE OPT PREPROCESS MODULE 'intuition/intuition', 'intuition/screens', 'intuition/intuitionbase', 'graphics/gfx', 'graphics/rastport' MODULE '*bumper', '*prefs', '*hmap2lut', '*brighttable', '*chunkyimage', '*errors', '*pluginmanager' EXPORT OBJECT bumper_cgx8 OF bumper PRIVATE outbuf : PTR TO cimg btab : PTR TO CHAR ENDOBJECT /* constructor */ PROC bumper_cgx8(p:PTR TO prefs, plist) OF bumper_cgx8 HANDLE /* call super constructor */ self.bumper(p, plist) /* allocate the brightness table */ /* really a distance table */ self.btab := get_brighttable() EXCEPT DO IF exception self.freeall() ENDIF ReThrow() ENDPROC PROC make_backup(s:PTR TO screen, px, py) OF bumper_cgx8 HANDLE DEF ix, iy, i, sum, bmadr:PTR TO CHAR /* allocate color usage array */ self.cusage := NewR(256) /* allocate backup bitmap */ NEW self.backup.alloc(self.width, self.height, CIMGTYP_8BIT) self.backup.read_full(s.rastport, px, py) /* the output buffer must also contain the original image */ /* this is because the bumpmapper will write if there's a change */ NEW self.outbuf.alloc(self.width, self.height, CIMGTYP_8BIT) self.outbuf.read_full(s.rastport, px, py) /* self.backup.lock([CIMGTAG_LOCK_BUF, {bmadr}, NIL]) sum := 0 FOR i := 0 TO self.backup.width * self.backup.height DO sum := sum + bmadr[i] WriteF('backup sum: \d, avg: \d\n', sum, Div(sum, self.backup.width * self.backup.height)) self.outbuf.lock([CIMGTAG_LOCK_BUF, {bmadr}, NIL]) sum := 0 FOR i := 0 TO self.outbuf.width * self.outbuf.height DO sum := sum + bmadr[i] WriteF('outbuf sum: \d, avg: \d\n', sum, Div(sum, self.outbuf.width * self.outbuf.height)) */ /* make color usage array */ self.backup.lock([CIMGTAG_LOCK_BUF, {bmadr}, NIL]) i := 0 FOR iy := 0 TO self.height-1 FOR ix := 0 TO self.width-1 self.cusage[bmadr[i]] := -1 i++ ENDFOR ENDFOR EXCEPT DO self.backup.unlock() ReThrow() ENDPROC PROC freeall() OF bumper_cgx8 END self.outbuf END self.backup self.outbuf := NIL self.backup := NIL SUPER self.freeall() ENDPROC PROC end() OF bumper_cgx8 self.freeall() SUPER self.end() ENDPROC PROC update() OF bumper_cgx8 HANDLE DEF inbuf=NIL, outbuf=NIL, bumpbuf=NIL, lightx, lighty, lmap=NIL:PTR TO CHAR, i, sum=0 /* is an update needed? */ IF self.needUpdate() = FALSE Delay(1) Raise("skip") ENDIF /* position of light*/ lightx, lighty := self.getLightSourcePos() /* lock bitmaps to do direct draw */ IF self.backup.lock([CIMGTAG_LOCK_BUF, {inbuf}, NIL]) = FALSE THEN Raise(ERR_LOCKCIMG) IF self.outbuf.lock([CIMGTAG_LOCK_BUF, {outbuf}, NIL]) = FALSE THEN Raise(ERR_LOCKCIMG) bumpbuf := self.plugins.doUpdate() IF bumpbuf /* allocate a temporary chunky buffer */ lmap := NewR(self.width * self.height) /* heightmap to colormap conversion (hmap2lut.asm) */ /* WriteF('\d,\d,\d,\d,\d,\d,\d,\d,\d,\d\n', inbuf, self.blut, self.levels_bit, self.btab, bumpbuf, outbuf, self.width, self.height, lightx, lighty) sum := 0 FOR i := 0 TO self.width * self.height DO sum := sum + inbuf[i] WriteF('inbuf sum: \d, avg: \d\n', sum, Div(sum, self.width * self.height)) */ hmap2lut(inbuf, self.blut, self.levels_bit, self.btab, bumpbuf, outbuf, self.width, self.height, lightx, lighty) /* sum := 0 FOR i := 0 TO self.width * self.height DO sum := sum + outbuf[i] WriteF('outbuf sum: \d, avg: \d\n', sum, Div(sum, self.width * self.height)) */ /* blit the resulting image to the window */ self.outbuf.write_full(self.win.rport, 0, 0, [CIMG_WRITE_ASYNC, TRUE, CIMG_WRITE_LPB, 10, NIL]) ENDIF EXCEPT DO self.backup.unlock() self.outbuf.unlock() /* free stuff */ IF lmap THEN Dispose(lmap) IF exception <> "skip" THEN ReThrow() ENDPROC