aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudvig Strigeus2001-12-11 13:34:15 +0000
committerLudvig Strigeus2001-12-11 13:34:15 +0000
commit083d9204c3ea52baac23a11ee0445a186e1cbe95 (patch)
treea9223f2b6fab30720d83c79bd91e07b560626364
parenta117505403bf1c7bd2ac206d74f423c42bb953e5 (diff)
downloadscummvm-rg350-083d9204c3ea52baac23a11ee0445a186e1cbe95.tar.gz
scummvm-rg350-083d9204c3ea52baac23a11ee0445a186e1cbe95.tar.bz2
scummvm-rg350-083d9204c3ea52baac23a11ee0445a186e1cbe95.zip
converted internal representation of palette from 6-bit to 8-bit
yazoo implemented remapActor svn-id: r3526
-rw-r--r--actor.cpp55
-rw-r--r--gfx.cpp80
-rw-r--r--resource.cpp12
-rw-r--r--saveload.cpp4
-rw-r--r--script.cpp4
-rw-r--r--scumm.h15
-rw-r--r--sdl.cpp6
-rw-r--r--wince/pocketpc.cpp2
-rw-r--r--windows.cpp6
9 files changed, 114 insertions, 70 deletions
diff --git a/actor.cpp b/actor.cpp
index 3862bfd60a..4df88b14ef 100644
--- a/actor.cpp
+++ b/actor.cpp
@@ -1045,6 +1045,57 @@ bool Scumm::isCostumeInUse(int cost) {
return false;
}
-void Scumm::remapActor(Actor *a, int b, int c, int d, int e) {
- warning("stub remapActor(%d,%d,%d,%d,%d)", a->number, b, c, d, e);
+void Scumm::remapActor(Actor *a, int r_fact, int g_fact, int b_fact, int threshold) {
+ byte *akos, *rgbs,*akpl;
+ int akpl_size, i;
+ int r,g,b;
+ byte akpl_color;
+
+ if (a->room != _currentRoom) {
+ warning("Remap actor %d not in current room",a->number);
+ return;
+ }
+
+ if (a->costume < 1 || a->costume >= _numCostumes-1){
+ warning("Remap actor %d invalid costume",a->number,a->costume);
+ return;
+ }
+
+ akos = getResourceAddress(rtCostume, a->costume);
+ akpl = findResource(MKID('AKPL'), akos);
+
+ //get num palette entries
+ akpl_size=RES_SIZE(akpl) - 8;
+
+ //skip resource header
+ akpl = RES_DATA(akpl);
+
+ rgbs = findResource(MKID('RGBS'), akos);
+
+ if (!rgbs) {
+ warning("Can't remap actor %d costume %d doesn't contain an RGB block",a->number,a->costume);
+ return;
+ }
+ // skip resource header
+ rgbs = RES_DATA(rgbs);
+
+ for(i=0; i<akpl_size; i++) {
+ r=*rgbs++;
+ g=*rgbs++;
+ b=*rgbs++;
+
+ akpl_color=*akpl++;
+
+ // allow remap of generic palette entry?
+ if (!a->unk1 || akpl_color>=16) {
+ if (r_fact!=256) r = (r*r_fact) >> 8;
+ if (r_fact!=256) g = (g*g_fact) >> 8;
+ if (r_fact!=256) b = (b*b_fact) >> 8;
+ a->palette[i]=remapPaletteColor(r,g,b,threshold);
+ }
+ }
+}
+
+void Scumm::setupShadowPalette(int slot,int rfact,int gfact,int bfact,int from,int to) {
+ warning("stub setupShadowPalette(%d,%d,%d,%d,%d,%d)", slot,rfact,gfact,bfact,from,to);
}
diff --git a/gfx.cpp b/gfx.cpp
index 54b6c19b27..ab24c92081 100644
--- a/gfx.cpp
+++ b/gfx.cpp
@@ -343,24 +343,14 @@ void Scumm::setPaletteFromPtr(byte *ptr) {
g = *ptr++;
b = *ptr++;
if (i<=15 || r<252 || g<252 || b<252) {
- *dest++ = r>>2;
- *dest++ = g>>2;
- *dest++ = b>>2;
+ *dest++ = r;
+ *dest++ = g;
+ *dest++ = b;
} else {
dest += 3;
}
}
-#if 0
- if (_videoMode==0xE) {
- epal = getResourceAddress(rtRoom, _roomResource) + _EPAL_offs + 8;
- for (i=0; i<256; i++,epal++) {
- _currentPalette[i] = *epal&0xF;
- _currentPalette[i+256] = *epal>>4;
- }
- }
-#endif
-
setDirtyColors(0, numcolor-1);
}
@@ -1689,9 +1679,9 @@ void Gdi::resetBackground(byte top, byte bottom, int strip) {
}
void Scumm::setPalColor(int index, int r, int g, int b) {
- _currentPalette[index*3+0] = r>>2;
- _currentPalette[index*3+1] = g>>2;
- _currentPalette[index*3+2] = b>>2;
+ _currentPalette[index*3+0] = r;
+ _currentPalette[index*3+1] = g;
+ _currentPalette[index*3+2] = b;
setDirtyColors(index,index);
}
@@ -1796,7 +1786,7 @@ byte *Scumm::getPalettePtr() {
void Scumm::darkenPalette(int a, int b, int c, int d, int e) {
byte *cptr, *cur;
int num;
- byte color;
+ int color;
cptr = getPalettePtr();
cptr += 8 + a*3;
@@ -1805,28 +1795,22 @@ void Scumm::darkenPalette(int a, int b, int c, int d, int e) {
num = b - a + 1;
do {
- if (c != 0xFF) {
- color = *cptr++ * (c>>2) / 0xFF;
- } else {
- color = *cptr++ >> 2;
- }
- if(color>63) color = 63;
+ color = *cptr++;
+ if (c != 0xFF)
+ color = color * c / 0xFF;
+ if(color>255) color = 255;
*cur++=color;
- if (d != 0xFF) {
- color = *cptr++ * (d>>2) / 0xFF;
- } else {
- color = *cptr++ >> 2;
- }
- if(color>63) color = 63;
+ color = *cptr++;
+ if (d != 0xFF)
+ color = color * d / 0xFF;
+ if(color>255) color = 255;
*cur++=color;
- if (e != 0xFF) {
- color = *cptr++ * (e>>2) / 0xFF;
- } else {
- color = *cptr++ >> 2;
- }
- if(color>63) color = 63;
+ color = *cptr++;
+ if (e != 0xFF)
+ color = color * e / 0xFF;
+ if(color>255) color = 255;
*cur++=color;
} while (--num);
}
@@ -1951,12 +1935,16 @@ void Scumm::decompressDefaultCursor(int index) {
}
-int Scumm::remapPaletteColor(byte r, byte g, byte b, uint threshold) {
+int Scumm::remapPaletteColor(int r, int g, int b, uint threshold) {
int i;
- byte ar,ag,ab;
+ int ar,ag,ab;
uint sum,j,bestsum,bestitem;
byte *pal = _currentPalette;
+ if (r>255) r=255;
+ if (g>255) g=255;
+ if (b>255) b=255;
+
bestsum = (uint)-1;
r &= ~3;
@@ -1970,12 +1958,12 @@ int Scumm::remapPaletteColor(byte r, byte g, byte b, uint threshold) {
if (ar==r && ag==g && ab==b)
return i;
- j=abs(ar-r)*3;
- sum = j*j;
- j=abs(ag-g)*6;
- sum += j*j;
- j=abs(ab-b)*2;
- sum += j*j;
+ j=abs(ar-r);
+ sum = j*j*3;
+ j=abs(ag-g);
+ sum += j*j*6;
+ j=abs(ab-b);
+ sum += j*j*2;
if (sum < bestsum) {
bestsum = sum;
@@ -1983,7 +1971,7 @@ int Scumm::remapPaletteColor(byte r, byte g, byte b, uint threshold) {
}
}
- if (threshold != -1 && bestsum > threshold*threshold*(2+3+6)) {
+ if (threshold != (uint)-1 && bestsum > threshold*threshold*(2+3+6)) {
pal = _currentPalette + (256-2)*3;
for(i=254; i>48; i--,pal-=3) {
if (pal[0]>=252 && pal[1]>=252 && pal[2]>=252) {
@@ -1996,10 +1984,6 @@ int Scumm::remapPaletteColor(byte r, byte g, byte b, uint threshold) {
return bestitem;
}
-void Scumm::setupShadowPalette(int slot,int rfact,int gfact,int bfact,int from,int to) {
-
-}
-
void Scumm::drawBomp(BompDrawData *bd) {
byte *dest = bd->out + bd->y * bd->outwidth, *src;
int h = bd->srcheight;
diff --git a/resource.cpp b/resource.cpp
index 40cf7ac5f7..25c87e2a5a 100644
--- a/resource.cpp
+++ b/resource.cpp
@@ -537,7 +537,7 @@ byte *Scumm::getResourceAddress(int type, int index) {
setResourceCounter(type, index, 1);
- return ptr + sizeof(ResHeader);
+ return ptr + sizeof(MemBlkHeader);
}
byte *Scumm::getStringAddress(int i) {
@@ -575,7 +575,7 @@ byte *Scumm::createResource(int type, int index, uint32 size) {
CHECK_HEAP
- ptr = (byte*)alloc(size + sizeof(ResHeader) + SAFETY_AREA);
+ ptr = (byte*)alloc(size + sizeof(MemBlkHeader) + SAFETY_AREA);
if (ptr==NULL) {
error("Out of memory while allocating %d", size);
}
@@ -583,9 +583,9 @@ byte *Scumm::createResource(int type, int index, uint32 size) {
_allocatedSize += size;
res.address[type][index] = ptr;
- ((ResHeader*)ptr)->size = size;
+ ((MemBlkHeader*)ptr)->size = size;
setResourceCounter(type, index, 1);
- return ptr + sizeof(ResHeader); /* skip header */
+ return ptr + sizeof(MemBlkHeader); /* skip header */
}
void Scumm::validateResource(const char *str, int type, int index) {
@@ -606,7 +606,7 @@ void Scumm::nukeResource(int type, int index) {
if ((ptr = res.address[type][index]) != NULL) {
res.address[type][index] = 0;
res.flags[type][index] = 0;
- _allocatedSize -= ((ResHeader*)ptr)->size;
+ _allocatedSize -= ((MemBlkHeader*)ptr)->size;
free(ptr);
}
}
@@ -823,7 +823,7 @@ void Scumm::resourceStats() {
for(j=res.num[i]; --j>=0;) {
flag = res.flags[i][j];
if (flag&0x80 && res.address[i][j]) {
- lockedSize += ((ResHeader*)res.address[i][j])->size;
+ lockedSize += ((MemBlkHeader*)res.address[i][j])->size;
lockedNum++;
}
}
diff --git a/saveload.cpp b/saveload.cpp
index 5b6ff31caf..9625dd886d 100644
--- a/saveload.cpp
+++ b/saveload.cpp
@@ -520,10 +520,10 @@ void Scumm::saveLoadResource(Serializer *ser, int type, int index) {
return;
}
- size = ((ResHeader*)ptr)->size;
+ size = ((MemBlkHeader*)ptr)->size;
ser->saveUint32(size);
- ser->saveLoadBytes(ptr+sizeof(ResHeader),size);
+ ser->saveLoadBytes(ptr+sizeof(MemBlkHeader),size);
if (type==rtInventory) {
ser->saveWord(_inventory[index]);
diff --git a/script.cpp b/script.cpp
index 193abe5635..8279629fde 100644
--- a/script.cpp
+++ b/script.cpp
@@ -266,7 +266,7 @@ void Scumm::executeScript() {
}
byte Scumm::fetchScriptByte() {
- if (*_lastCodePtr + sizeof(ResHeader) != _scriptOrgPointer) {
+ if (*_lastCodePtr + sizeof(MemBlkHeader) != _scriptOrgPointer) {
uint32 oldoffs = _scriptPointer - _scriptOrgPointer;
getScriptBaseAddress();
_scriptPointer = _scriptOrgPointer + oldoffs;
@@ -276,7 +276,7 @@ byte Scumm::fetchScriptByte() {
int Scumm::fetchScriptWord() {
int a;
- if (*_lastCodePtr + sizeof(ResHeader) != _scriptOrgPointer) {
+ if (*_lastCodePtr + sizeof(MemBlkHeader) != _scriptOrgPointer) {
uint32 oldoffs = _scriptPointer - _scriptOrgPointer;
getScriptBaseAddress();
_scriptPointer = _scriptOrgPointer + oldoffs;
diff --git a/scumm.h b/scumm.h
index 3db8a26d8a..7b6b0e72d4 100644
--- a/scumm.h
+++ b/scumm.h
@@ -49,6 +49,11 @@ struct Point {
int x,y;
};
+struct MemBlkHeader {
+ uint32 size;
+};
+
+
#pragma START_PACK_STRUCTS
#define SIZEOF_BOX 20
@@ -62,10 +67,14 @@ struct Box { /* file format */
uint16 scale;
} GCC_PACK;
-struct ResHeader {
- uint32 size;
+struct ResHdr {
+ uint32 tag, size;
} GCC_PACK;
+#define RES_DATA(x) (((byte*)x) + sizeof(ResHdr))
+#define RES_SIZE(x) ( READ_BE_UINT32(&((ResHdr*)x)->size) )
+
+
struct RoomHeader {
uint32 tag, size;
#ifdef FULL_THROTTLE
@@ -1960,7 +1969,7 @@ struct Scumm {
void runTalkScript(int frame);
- int remapPaletteColor(byte r, byte g, byte b, uint threshold);
+ int remapPaletteColor(int r, int g, int b, uint threshold);
void remapActor(Actor *a, int b, int c, int d, int e);
byte *findResourceData(uint32 tag, byte *ptr);
diff --git a/sdl.cpp b/sdl.cpp
index cd41bb1d08..8d4821118f 100644
--- a/sdl.cpp
+++ b/sdl.cpp
@@ -50,9 +50,9 @@ void updatePalette(Scumm *s) {
data += first*3;
for (i=0; i<num; i++,data+=3) {
- colors[i].r = data[0]<<2;
- colors[i].g = data[1]<<2;
- colors[i].b = data[2]<<2;
+ colors[i].r = data[0];
+ colors[i].g = data[1];
+ colors[i].b = data[2];
colors[i].unused = 0;
}
diff --git a/wince/pocketpc.cpp b/wince/pocketpc.cpp
index f0029975f6..bf367e0822 100644
--- a/wince/pocketpc.cpp
+++ b/wince/pocketpc.cpp
@@ -241,7 +241,7 @@ void WndMan::setPalette(byte *ctab, int first, int num) {
int i;
for (i=0; i<256; i++)
- SetPalEntry(i, ctab[i*3+0]<<2, ctab[i*3+1]<<2, ctab[i*3+2]<<2);
+ SetPalEntry(i, ctab[i*3+0], ctab[i*3+1], ctab[i*3+2]);
}
diff --git a/windows.cpp b/windows.cpp
index e764e722a4..1199b675bc 100644
--- a/windows.cpp
+++ b/windows.cpp
@@ -331,9 +331,9 @@ void WndMan::setPalette(byte *ctab, int first, int num) {
#if 1
for (i=0; i<256; i++) {
- dib.pal[i].rgbRed = ctab[i*3+0]<<2;
- dib.pal[i].rgbGreen = ctab[i*3+1]<<2;
- dib.pal[i].rgbBlue = ctab[i*3+2]<<2;
+ dib.pal[i].rgbRed = ctab[i*3+0];
+ dib.pal[i].rgbGreen = ctab[i*3+1];
+ dib.pal[i].rgbBlue = ctab[i*3+2];
}
#else
for (i=0; i<256; i++) {