bool Console::cmdShowSprite(int argc, const char **argv) { View *view = _vm->_viewManager->getView(VIEWID_SCENE); if (view == NULL) DebugPrintf("The scene view isn't currently active\n"); else if (argc < 2) DebugPrintf("Usage: %s resource_name\n", argv[0]); else { char resourceName[20]; strncpy(resourceName, argv[1], 15); resourceName[15] = '\0'; if (!strchr(resourceName, '.')) strcat(resourceName, ".SS"); _vm->_viewManager->moveToFront(view); Common::SeekableReadStream *data = _vm->res()->get(resourceName); SpriteAsset *asset = new SpriteAsset(_vm, data, data->size(), resourceName); _vm->res()->toss(resourceName); RGBList *palData = new RGBList(asset->getColorCount(), asset->getPalette(), true); _vm->_palette->addRange(palData); // Get the scene background surface M4Surface *bg = _vm->_scene->getBackgroundSurface(); // Write the sprite onto the screen int x = 0, y = 0, yMax = 0; for (int index = 0; index < asset->getCount(); index++) { M4Sprite *spr = asset->getFrame(index); spr->translate(palData); // sprite pixel translation if ((x + spr->width() >= bg->width()) && (yMax != 0)) { x = 0; y += yMax; yMax = 0; } if (y >= bg->height()) break; // FIXME: We assume that the transparent color is the color of the top left pixel byte *transparentColor = (byte *)spr->pixels; spr->copyTo(bg, x, y, (int)*transparentColor); x += spr->width(); yMax = MAX(yMax, spr->height()); } view->restore(0, 0, view->width(), view->height()); return false; } return true; }
M4Surface *OrionMenuView::createThumbnail() { M4Surface srcSurface(_vm->_screen->width(), _vm->_screen->height()); M4Surface *result = new M4Surface(_vm->_screen->width() / 3, _vm->_screen->height() / 3); // Translate the scene data _vm->_scene->onRefresh(NULL, &srcSurface); byte *srcP = (byte *)srcSurface.pixels; byte *destP = (byte *)result->pixels; for (int yCtr = 0; yCtr < _vm->_scene->height() / 3; ++yCtr, srcP += g_system->getWidth() * 3) { byte *src0P = srcP; byte *src1P = srcP + _vm->_screen->width(); byte *src2P = src1P + _vm->_screen->width(); for (int xCtr = 0; xCtr < result->width(); ++xCtr) { *destP = (byte)((uint32)(( *src0P + *(src0P + 1) + *(src0P + 2) + *src1P + *(src1P + 1) + *(src1P + 2) + *src2P + *(src2P + 1) + *(src2P + 2)) / 9)); if (*destP == 0) *destP = 21; ++destP; src0P += 3; src1P += 3; src2P += 3; } } // Translate the game interface view - since it's using standard colors that can't be // averaged, simply take the top left pixel of every 3x3 pixel block _vm->_interfaceView->onRefresh(NULL, &srcSurface); destP = (byte *)result->pixels + (_vm->_screen->width() / 3) * (_vm->_interfaceView->bounds().top / 3); int yStart = _vm->_interfaceView->bounds().top; int yEnd = MIN(_vm->_screen->height() - 1, (int) _vm->_interfaceView->bounds().bottom - 1); for (int yCtr = yStart; yCtr <= yEnd; yCtr += 3) { srcP = (byte *)srcSurface.pixels + (yCtr * _vm->_screen->width()); for (int xCtr = 0; xCtr < result->width(); ++xCtr, srcP += 3) *destP++ = *srcP; } return result; }
void MadsAnimation::load1(int frameNumber) { if (_skipLoad) return; Common::Point pt; int listIndex = _spriteListIndexes[_spriteListIndex]; SpriteAsset &spriteSet = _view->_spriteSlots.getSprite(listIndex); if (_unkIndex < 0) { M4Surface *frame = spriteSet.getFrame(0); pt.x = frame->bounds().left; pt.y = frame->bounds().top; } else { pt.x = _unkList[_unkIndex].x; pt.y = _unkList[_unkIndex].y; _unkIndex = 1 - _unkIndex; } if (proc1(spriteSet, pt, frameNumber)) error("proc1 failure"); }
void MadsSpriteSlots::drawForeground(M4Surface *viewport) { DepthList depthList; // Get a list of sprite object depths for active objects for (int i = 0; i < startIndex; ++i) { if (_entries[i].spriteType >= SPRITE_ZERO) { DepthEntry rec(16 - _entries[i].depth, i); depthList.push_back(rec); } } // Sort the list in order of the depth Common::sort(depthList.begin(), depthList.end(), sortHelper); // Loop through each of the objects DepthList::iterator i; for (i = depthList.begin(); i != depthList.end(); ++i) { DepthEntry &de = *i; MadsSpriteSlot &slot = _entries[de.index]; assert(slot.spriteListIndex < (int)_sprites.size()); SpriteAsset &spriteSet = *_sprites[slot.spriteListIndex]; // Get the sprite frame int frameNumber = slot.frameNumber & 0x7fff; bool flipped = (slot.frameNumber & 0x8000) != 0; M4Sprite *sprite = spriteSet.getFrame(frameNumber - 1); M4Surface *spr = sprite; if (flipped) { // Create a flipped copy of the sprite temporarily spr = sprite->flipHorizontal(); } if ((slot.scale < 100) && (slot.scale != -1)) { // Minimalised drawing viewport->copyFrom(spr, slot.xp, slot.yp, slot.depth, _owner._depthSurface, slot.scale, sprite->getTransparencyIndex()); } else { int xp, yp; if (slot.scale == -1) { xp = slot.xp - _owner._posAdjust.x; yp = slot.yp - _owner._posAdjust.y; } else { xp = slot.xp - (spr->width() / 2) - _owner._posAdjust.x; yp = slot.yp - spr->height() - _owner._posAdjust.y + 1; } if (slot.depth > 1) { // Draw the frame with depth processing viewport->copyFrom(spr, xp, yp, slot.depth, _owner._depthSurface, 100, sprite->getTransparencyIndex()); } else { // No depth, so simply draw the image spr->copyTo(viewport, xp, yp, sprite->getTransparencyIndex()); } } // Free sprite if it was a flipped one if (flipped) delete spr; } }