static gboolean parse_sprite_trajectory (GstBitReader * br, GstMpeg4SpriteTrajectory * sprite_traj, guint no_of_sprite_warping_points) { guint i, length; for (i = 0; i < no_of_sprite_warping_points; i++) { if (!decode_vlc (br, &length, mpeg4_dmv_size_vlc_table, G_N_ELEMENTS (mpeg4_dmv_size_vlc_table))) goto failed; if (length) READ_UINT16 (br, sprite_traj->vop_ref_points[i], length); CHECK_MARKER (br); if (!decode_vlc (br, &length, mpeg4_dmv_size_vlc_table, G_N_ELEMENTS (mpeg4_dmv_size_vlc_table))) goto failed; if (length) READ_UINT16 (br, sprite_traj->sprite_ref_points[i], length); CHECK_MARKER (br); } return TRUE; failed: GST_WARNING ("Could not parse the sprite trajectory"); return FALSE; }
void OSystem_Android::disableCursorPalette(bool disable) { ENTER("%d", disable); // when disabling the cursor palette, and we're running a clut8 game, // it expects the game palette to be used for the cursor if (disable && _game_texture->hasPalette()) { const byte *src = _game_texture->palette_const(); byte *dst = _mouse_texture_palette->palette(); const Graphics::PixelFormat &pf_src = _game_texture->getPalettePixelFormat(); const Graphics::PixelFormat &pf_dst = _mouse_texture_palette->getPalettePixelFormat(); uint8 r, g, b; for (uint i = 0; i < 256; ++i, src += 2, dst += 2) { pf_src.colorToRGB(READ_UINT16(src), r, g, b); WRITE_UINT16(dst, pf_dst.RGBToColor(r, g, b)); } byte *p = _mouse_texture_palette->palette() + _mouse_keycolor * 2; WRITE_UINT16(p, READ_UINT16(p) & ~1); } _use_mouse_palette = !disable; }
gboolean mpeg_util_parse_sequence_hdr (MPEGSeqHdr * hdr, GstBuffer * buffer) { GstBitReader reader = GST_BIT_READER_INIT_FROM_BUFFER (buffer); guint8 dar_idx, par_idx; guint8 load_intra_flag, load_non_intra_flag; /* skip sync word */ if (!gst_bit_reader_skip (&reader, 8 * 4)) return FALSE; /* resolution */ READ_UINT16 (&reader, hdr->width, 12); READ_UINT16 (&reader, hdr->height, 12); /* aspect ratio */ READ_UINT8 (&reader, dar_idx, 4); set_par_from_dar (hdr, dar_idx); /* framerate */ READ_UINT8 (&reader, par_idx, 4); set_fps_from_code (hdr, par_idx); /* bitrate */ READ_UINT32 (&reader, hdr->bitrate, 18); if (!gst_bit_reader_skip (&reader, 1)) return FALSE; /* VBV buffer size */ READ_UINT16 (&reader, hdr->vbv_buffer, 10); /* constrained parameters flag */ READ_UINT8 (&reader, hdr->constrained_parameters_flag, 1); /* intra quantizer matrix */ READ_UINT8 (&reader, load_intra_flag, 1); if (load_intra_flag) { gint i; for (i = 0; i < 64; i++) READ_UINT8 (&reader, hdr->intra_quantizer_matrix[mpeg_zigzag_8x8[i]], 8); } else memcpy (hdr->intra_quantizer_matrix, default_intra_quantizer_matrix, 64); /* non intra quantizer matrix */ READ_UINT8 (&reader, load_non_intra_flag, 1); if (load_non_intra_flag) { gint i; for (i = 0; i < 64; i++) READ_UINT8 (&reader, hdr->non_intra_quantizer_matrix[mpeg_zigzag_8x8[i]], 8); } else memset (hdr->non_intra_quantizer_matrix, 16, 64); return TRUE; error: GST_WARNING ("error parsing \"Sequence Header\""); return FALSE; }
void Transport::nfcGetRecordInfo(size_t recordNumber, uint16_t* pType, uint16_t* info, size_t infoCount) { uint8_t out[2]; uint8_t in[2+2*infoCount]; WRITE_UINT16(&out[0], recordNumber); command(Transport::NFC_GET_RECORD_INFO, out, sizeof(out), in, sizeof(in)); READ_UINT16(&in[0], *pType); for(int i = 0; i < infoCount; i++) { READ_UINT16(&in[2+2*i], info[i]); } }
void Surface::scaleTransparentCopy(const Common::Rect &srcRect, const Common::Rect &dstRect) const { // I'm doing simple linear scaling here // dstRect(x, y) = srcRect(x * srcW / dstW, y * srcH / dstH); Graphics::Surface *screen = ((PegasusEngine *)g_engine)->_gfx->getCurSurface(); int srcW = srcRect.width(); int srcH = srcRect.height(); int dstW = dstRect.width(); int dstH = dstRect.height(); for (int y = 0; y < dstH; y++) { for (int x = 0; x < dstW; x++) { if (g_system->getScreenFormat().bytesPerPixel == 2) { uint16 color = READ_UINT16((byte *)_surface->getBasePtr( x * srcW / dstW + srcRect.left, y * srcH / dstH + srcRect.top)); if (!isTransparent(color)) WRITE_UINT16((byte *)screen->getBasePtr(x + dstRect.left, y + dstRect.top), color); } else if (g_system->getScreenFormat().bytesPerPixel == 4) { uint32 color = READ_UINT32((byte *)_surface->getBasePtr( x * srcW / dstW + srcRect.left, y * srcH / dstH + srcRect.top)); if (!isTransparent(color)) WRITE_UINT32((byte *)screen->getBasePtr(x + dstRect.left, y + dstRect.top), color); } } } }
void Surface::copyToCurrentPortTransparentGlow(const Common::Rect &srcRect, const Common::Rect &dstRect) const { // This is the same as copyToCurrentPortTransparent(), but turns the red value of each // pixel all the way up. Graphics::Surface *screen = ((PegasusEngine *)g_engine)->_gfx->getCurSurface(); byte *src = (byte *)_surface->getBasePtr(srcRect.left, srcRect.top); byte *dst = (byte *)screen->getBasePtr(dstRect.left, dstRect.top); int lineSize = srcRect.width() * _surface->format.bytesPerPixel; for (int y = 0; y < srcRect.height(); y++) { for (int x = 0; x < srcRect.width(); x++) { if (g_system->getScreenFormat().bytesPerPixel == 2) { uint16 color = READ_UINT16(src); if (!isTransparent(color)) WRITE_UINT16(dst, getGlowColor(color)); } else if (g_system->getScreenFormat().bytesPerPixel == 4) { uint32 color = READ_UINT32(src); if (!isTransparent(color)) WRITE_UINT32(dst, getGlowColor(color)); } src += g_system->getScreenFormat().bytesPerPixel; dst += g_system->getScreenFormat().bytesPerPixel; } src += _surface->pitch - lineSize; dst += screen->pitch - lineSize; } }
void Surface::copyToCurrentPortMasked(const Common::Rect &srcRect, const Common::Rect &dstRect, const Surface *mask) const { Graphics::Surface *screen = ((PegasusEngine *)g_engine)->_gfx->getCurSurface(); byte *src = (byte *)_surface->getBasePtr(srcRect.left, srcRect.top); byte *dst = (byte *)screen->getBasePtr(dstRect.left, dstRect.top); int lineSize = srcRect.width() * _surface->format.bytesPerPixel; for (int y = 0; y < srcRect.height(); y++) { byte *maskSrc = (byte *)mask->getSurface()->getBasePtr(0, y); for (int x = 0; x < srcRect.width(); x++) { if (g_system->getScreenFormat().bytesPerPixel == 2) { uint16 color = READ_UINT16(maskSrc); if (!isTransparent(color)) memcpy(dst, src, 2); } else if (g_system->getScreenFormat().bytesPerPixel == 4) { uint32 color = READ_UINT32(maskSrc); if (!isTransparent(color)) memcpy(dst, src, 4); } src += g_system->getScreenFormat().bytesPerPixel; maskSrc += g_system->getScreenFormat().bytesPerPixel; dst += g_system->getScreenFormat().bytesPerPixel; } src += _surface->pitch - lineSize; dst += screen->pitch - lineSize; } }
void hwTimer32ClearEvent(soc_timer32_num_t timer_num) { unsigned int module = timer32_module(timer_num); unsigned int timer = timer32_in_module(timer_num); #ifdef B4860_FAMILY uint16_t reg; #endif #ifdef HW_TIMER_ERROR_CHECKING if (timer_num >= NUM_OF_HW_TIMERS_32b) { #ifdef HW_TIMER_ERROR_ASSERT OS_ASSERT; #endif /* HW_TIMER_ERROR_ASSERT */ return; } #endif /* HW_TIMER_ERROR_CHECKING */ #ifdef B4860_FAMILY CLEAR_UINT16(soc_timer32_module[module].tmr[timer].tmr_sctl, TMR32_SCTL_TCF); DBAR_SCFG(); READ_UINT16(reg, soc_timer32_module[module].tmr[timer].tmr_sctl); #else CLEAR_UINT32(soc_timer32_module[module].tmr[timer].tmr_sctl, TMR32_SCTL_TCF); #endif //B4860_FAMILY }
void Surface::scaleTransparentCopyGlow(const Common::Rect &srcRect, const Common::Rect &dstRect) const { // This is the same as scaleTransparentCopy(), but turns the red value of each // pixel all the way up. Graphics::Surface *screen = ((PegasusEngine *)g_engine)->_gfx->getCurSurface(); int srcW = srcRect.width(); int srcH = srcRect.height(); int dstW = dstRect.width(); int dstH = dstRect.height(); for (int y = 0; y < dstH; y++) { for (int x = 0; x < dstW; x++) { if (g_system->getScreenFormat().bytesPerPixel == 2) { uint16 color = READ_UINT16((byte *)_surface->getBasePtr( x * srcW / dstW + srcRect.left, y * srcH / dstH + srcRect.top)); if (!isTransparent(color)) WRITE_UINT16((byte *)screen->getBasePtr(x + dstRect.left, y + dstRect.top), getGlowColor(color)); } else if (g_system->getScreenFormat().bytesPerPixel == 4) { uint32 color = READ_UINT32((byte *)_surface->getBasePtr( x * srcW / dstW + srcRect.left, y * srcH / dstH + srcRect.top)); if (!isTransparent(color)) WRITE_UINT32((byte *)screen->getBasePtr(x + dstRect.left, y + dstRect.top), getGlowColor(color)); } } } }
void CloudIcon::makeAlphaIcon(const Graphics::Surface &icon, float alpha) { _alphaIcon.copyFrom(icon); byte *pixels = (byte *)_alphaIcon.getPixels(); for (int y = 0; y < _alphaIcon.h; y++) { byte *row = pixels + y * _alphaIcon.pitch; for (int x = 0; x < _alphaIcon.w; x++) { uint32 srcColor; if (_alphaIcon.format.bytesPerPixel == 2) srcColor = READ_UINT16(row); else if (_alphaIcon.format.bytesPerPixel == 3) srcColor = READ_UINT24(row); else srcColor = READ_UINT32(row); // Update color's alpha byte r, g, b, a; _alphaIcon.format.colorToARGB(srcColor, a, r, g, b); a = (byte)(a * alpha); uint32 color = _alphaIcon.format.ARGBToColor(a, r, g, b); if (_alphaIcon.format.bytesPerPixel == 2) *((uint16 *)row) = color; else *((uint32 *)row) = color; row += _alphaIcon.format.bytesPerPixel; } } }
/* Used by client_x11.c, for parsing xauth */ int parse_uint16(struct simple_buffer *buffer, uint32_t *result) { if (LEFT < 2) return 0; *result = READ_UINT16(HERE); ADVANCE(2); return 1; }
void FlicDecoder::FlicVideoTrack::decodeDeltaFLC(uint8 *data) { uint16 linesInChunk = READ_LE_UINT16(data); data += 2; uint16 currentLine = 0; uint16 packetCount = 0; while (linesInChunk--) { uint16 opcode; // First process all the opcodes. do { opcode = READ_LE_UINT16(data); data += 2; switch ((opcode >> 14) & 3) { case OP_PACKETCOUNT: packetCount = opcode; break; case OP_UNDEFINED: break; case OP_LASTPIXEL: *((byte *)_surface->getBasePtr(getWidth() - 1, currentLine)) = (opcode & 0xFF); _dirtyRects.push_back(Common::Rect(getWidth() - 1, currentLine, getWidth(), currentLine + 1)); break; case OP_LINESKIPCOUNT: currentLine += -(int16)opcode; break; } } while (((opcode >> 14) & 3) != OP_PACKETCOUNT); uint16 column = 0; // Now interpret the RLE data while (packetCount--) { column += *data++; int rleCount = (int8)*data++; if (rleCount > 0) { memcpy((byte *)_surface->getBasePtr(column, currentLine), data, rleCount * 2); data += rleCount * 2; _dirtyRects.push_back(Common::Rect(column, currentLine, column + rleCount * 2, currentLine + 1)); } else if (rleCount < 0) { rleCount = -rleCount; uint16 dataWord = READ_UINT16(data); data += 2; for (int i = 0; i < rleCount; ++i) { WRITE_UINT16((byte *)_surface->getBasePtr(column + i * 2, currentLine), dataWord); } _dirtyRects.push_back(Common::Rect(column, currentLine, column + rleCount * 2, currentLine + 1)); } else { // End of cutscene ? return; } column += rleCount * 2; } currentLine++; } }
void OSystem_Android::setCursorPaletteInternal(const byte *colors, uint start, uint num) { const Graphics::PixelFormat &pf = _mouse_texture_palette->getPalettePixelFormat(); byte *p = _mouse_texture_palette->palette() + start * 2; for (uint i = 0; i < num; ++i, colors += 3, p += 2) WRITE_UINT16(p, pf.RGBToColor(colors[0], colors[1], colors[2])); p = _mouse_texture_palette->palette() + _mouse_keycolor * 2; WRITE_UINT16(p, READ_UINT16(p) & ~1); }
void Transport::nfcDecodePrefix(uint8_t prefix, char* data, size_t* pDataLength) { uint8_t out[] = { prefix }; uint8_t in[2 + 36]; //max prefix length is 36 command(Transport::NFC_DECODE_PREFIX, out, sizeof(out), in, sizeof(in)); size_t length; READ_UINT16(&in[0], length); if(length < *pDataLength) { *pDataLength = length; } memcpy(data, &in[2], *pDataLength); }
void TinyGLBlit(byte *dst, byte *src, int x, int y, int width, int height, bool trans) { int srcPitch = width * 2; int dstPitch = 640 * 2; int srcX, srcY; int l, r; if (x > 639 || y > 479) return; if (x < 0) { srcX = -x; x = 0; } else { srcX = 0; } if (y < 0) { srcY = -y; y = 0; } else { srcY = 0; } if (x + width > 640) width -= (x + width) - 640; if (y + height > 480) height -= (y + height) - 480; dst += (x + (y * 640)) * 2; src += (srcX + (srcY * width)) * 2; int copyWidth = width * 2; if (!trans) { for (l = 0; l < height; l++) { memcpy(dst, src, copyWidth); dst += dstPitch; src += srcPitch; } } else { for (l = 0; l < height; l++) { for (r = 0; r < copyWidth; r += 2) { uint16 pixel = READ_UINT16(src + r); if (pixel != 0xf81f) WRITE_UINT16(dst + r, pixel); } dst += dstPitch; src += srcPitch; } } }
void SaveLoadManager::convertThumb16To8(Graphics::Surface *thumb16, Graphics::Surface *thumb8) { thumb8->create(thumb16->w, thumb16->h, Graphics::PixelFormat::createFormatCLUT8()); Graphics::PixelFormat pixelFormat16(2, 5, 6, 5, 0, 11, 5, 0, 0); byte paletteR[PALETTE_SIZE]; byte paletteG[PALETTE_SIZE]; byte paletteB[PALETTE_SIZE]; for (int palIndex = 0; palIndex < PALETTE_SIZE; ++palIndex) { uint16 p = READ_UINT16(&_vm->_graphicsMan->_palettePixels[palIndex * 2]); pixelFormat16.colorToRGB(p, paletteR[palIndex], paletteG[palIndex], paletteB[palIndex]); } const uint16 *srcP = (const uint16 *)thumb16->getPixels(); byte *destP = (byte *)thumb8->getPixels(); for (int yp = 0; yp < thumb16->h; ++yp) { const uint16 *lineSrcP = srcP; byte *lineDestP = destP; for (int xp = 0; xp < thumb16->w; ++xp) { byte r, g, b; pixelFormat16.colorToRGB(*lineSrcP++, r, g, b); // Do like in the original and show thumbnail as a grayscale picture int lum = (r * 21 + g * 72 + b * 7) / 100; r = g = b = lum; // Scan the palette for the closest match int difference = 99999, foundIndex = 0; for (int palIndex = 0; palIndex < PALETTE_SIZE; ++palIndex) { byte rCurrent = paletteR[palIndex]; byte gCurrent = paletteG[palIndex]; byte bCurrent = paletteB[palIndex]; int diff = ABS((int)r - (int)rCurrent) + ABS((int)g - (int)gCurrent) + ABS((int)b - (int)bCurrent); if (diff < difference) { difference = diff; foundIndex = palIndex; } } *lineDestP++ = foundIndex; } // Move to the start of the next line srcP += thumb16->w; destP += thumb16->w; } }
void OSystem_Android::grabPalette(byte *colors, uint start, uint num) { ENTER("%p, %u, %u", colors, start, num); #ifdef USE_RGB_COLOR assert(_game_texture->hasPalette()); #endif GLTHREADCHECK; const Graphics::PixelFormat &pf = _game_texture->getPalettePixelFormat(); const byte *p = _game_texture->palette_const() + start * 2; for (uint i = 0; i < num; ++i, colors += 3, p += 2) pf.colorToRGB(READ_UINT16(p), colors[0], colors[1], colors[2]); }
gboolean mpeg_util_parse_sequence_extension (MPEGSeqExtHdr * hdr, GstBuffer * buffer) { GstBitReader reader = GST_BIT_READER_INIT_FROM_BUFFER (buffer);; /* skip sync word */ if (!gst_bit_reader_skip (&reader, 8 * 4)) return FALSE; /* skip extension code */ if (!gst_bit_reader_skip (&reader, 4)) return FALSE; /* skip profile and level escape bit */ if (!gst_bit_reader_skip (&reader, 1)) return FALSE; READ_UINT8 (&reader, hdr->profile, 3); READ_UINT8 (&reader, hdr->level, 4); /* progressive */ READ_UINT8 (&reader, hdr->progressive, 1); /* chroma format */ READ_UINT8 (&reader, hdr->chroma_format, 2); /* resolution extension */ READ_UINT8 (&reader, hdr->horiz_size_ext, 2); READ_UINT8 (&reader, hdr->vert_size_ext, 2); READ_UINT16 (&reader, hdr->bitrate_ext, 12); /* skip to framerate extension */ if (!gst_bit_reader_skip (&reader, 9)) return FALSE; /* framerate extension */ READ_UINT8 (&reader, hdr->fps_n_ext, 2); READ_UINT8 (&reader, hdr->fps_d_ext, 2); return TRUE; error: GST_WARNING ("error parsing \"Sequence Extension\""); return FALSE; }
int sexp_iterator_get_uint32(struct sexp_iterator *iterator, uint32_t *x) { if (iterator->type == SEXP_ATOM && !iterator->display && iterator->atom_length && iterator->atom[0] < 0x80) { size_t length = iterator->atom_length; const uint8_t *p = iterator->atom; /* Skip leading zeros. */ while(length && !*p) { length--; p++; } switch(length) { case 0: *x = 0; break; case 1: *x = p[0]; break; case 2: *x = READ_UINT16(p); break; case 3: *x = READ_UINT24(p); break; case 4: *x = READ_UINT32(p); break; default: return 0; } return sexp_iterator_next(iterator); } return 0; }
void drawCharIntern(byte *ptr, uint pitch, const bitmap_t *src, int h, int minX, int maxX, const PixelType color) { const bitmap_t maxXMask = ~((1 << (16-maxX)) - 1); while (h-- > 0) { bitmap_t buffer = READ_UINT16(src); src++; buffer &= maxXMask; buffer <<= minX; PixelType *tmp = (PixelType *)ptr; while (buffer != 0) { if ((buffer & 0x8000) != 0) *tmp = color; tmp++; buffer <<= 1; } ptr += pitch; } }
bool SaveConverter::swapDataEndian(byte *data, const byte *sizes, uint32 count) { if (!data || !sizes || (count == 0)) return false; while (count-- > 0) { if (*sizes == 3) // 32bit value (3 additional bytes) WRITE_UINT32(data, SWAP_BYTES_32(READ_UINT32(data))); else if (*sizes == 1) // 16bit value (1 additional byte) WRITE_UINT16(data, SWAP_BYTES_16(READ_UINT16(data))); else if (*sizes != 0) // else, it has to be an 8bit value return false; count -= *sizes; data += *sizes + 1; sizes += *sizes + 1; } return true; }
static void uncompressPlane(const byte *plane, byte *outptr, int length) { while (length != 0) { int wordlen; signed char x = *plane++; if (x >= 0) { wordlen = MIN<int>(x + 1, length); uint16 w = READ_UINT16(plane); plane += 2; for (int i = 0; i < wordlen; ++i) { WRITE_UINT16(outptr, w); outptr += 2; } } else { wordlen = MIN<int>(-x, length); memcpy(outptr, plane, wordlen * 2); outptr += wordlen * 2; plane += wordlen * 2; } length -= wordlen; } }
/** * Copies the current screen contents to a new surface, using RGB565 format. * WARNING: surf->free() must be called by the user to avoid leaking. * * @param surf the surface to store the data in it */ static bool grabScreen565(Graphics::Surface *surf) { Graphics::Surface *screen = g_system->lockScreen(); if (!screen) return false; assert(screen->format.bytesPerPixel == 1 || screen->format.bytesPerPixel == 2); assert(screen->getPixels() != 0); Graphics::PixelFormat screenFormat = g_system->getScreenFormat(); surf->create(screen->w, screen->h, Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0)); byte *palette = 0; if (screenFormat.bytesPerPixel == 1) { palette = new byte[256 * 3]; assert(palette); g_system->getPaletteManager()->grabPalette(palette, 0, 256); } for (uint y = 0; y < screen->h; ++y) { for (uint x = 0; x < screen->w; ++x) { byte r = 0, g = 0, b = 0; if (screenFormat.bytesPerPixel == 1) { uint8 pixel = *(uint8 *)screen->getBasePtr(x, y); r = palette[pixel * 3 + 0]; g = palette[pixel * 3 + 1]; b = palette[pixel * 3 + 2]; } else if (screenFormat.bytesPerPixel == 2) { uint16 col = READ_UINT16(screen->getBasePtr(x, y)); screenFormat.colorToRGB(col, r, g, b); } *((uint16 *)surf->getBasePtr(x, y)) = Graphics::RGBToColor<Graphics::ColorMasks<565> >(r, g, b); } } delete[] palette; g_system->unlockScreen(); return true; }
Uint32 dw_getPixel(SDL_Surface *s, Uint16 x, Uint16 y) { assert(s); assert(x < s->w && y < s->h); Uint32 bpp = s->format->BytesPerPixel; Uint8 *p = (Uint8 *)s->pixels + (y * s->pitch) + (x * bpp); Uint32 pix; switch (bpp) { case 1: // b/w return *p; case 2: // 16 bit per pixel return READ_UINT16(p); case 3: pix = p[0] << 24 | p[1] << 16 | p[0] << 0; return READ_UINT32(&pix); case 4: return READ_UINT32(p); default: // !?!? return 0; } }
void vs_fill_borders_RGB555 (const VSImage * dest, const uint8_t * val) { int i; int top = dest->border_top, bottom = dest->border_bottom; int left = dest->border_left, right = dest->border_right; int width = dest->width; int height = dest->height; int real_width = dest->real_width; gsize stride = dest->stride; int tmp, tmp2; uint8_t *data; uint16_t v = READ_UINT16 (val); data = dest->real_pixels; for (i = 0; i < top; i++) { video_scale_orc_splat_u16 ((uint16_t *) data, v, real_width); data += stride; } if (left || right) { tmp = height; tmp2 = (left + width) * 2; for (i = 0; i < tmp; i++) { video_scale_orc_splat_u16 ((uint16_t *) data, v, left); video_scale_orc_splat_u16 ((uint16_t *) (data + tmp2), v, right); data += stride; } } else { data += stride * height; } for (i = 0; i < bottom; i++) { video_scale_orc_splat_u16 ((uint16_t *) data, v, real_width); data += stride; } }
void ScreenFader::setFaderValue(const int32 value) { if (value != getFaderValue()) { Fader::setFaderValue(value); if (_screen->getPixels()) { // The original game does a gamma fade here using the Mac API. In order to do // that, it would require an immense amount of CPU processing. This does a // linear fade instead, which looks fairly well, IMO. Graphics::Surface *screen = g_system->lockScreen(); for (uint y = 0; y < _screen->h; y++) { for (uint x = 0; x < _screen->w; x++) { if (_screen->format.bytesPerPixel == 2) WRITE_UINT16(screen->getBasePtr(x, y), fadePixel(READ_UINT16(_screen->getBasePtr(x, y)), value)); else WRITE_UINT32(screen->getBasePtr(x, y), fadePixel(READ_UINT32(_screen->getBasePtr(x, y)), value)); } } g_system->unlockScreen(); g_system->updateScreen(); } } }
void *OSystem_Android::audioThreadFunc(void *arg) { JNI::attachThread(); OSystem_Android *system = (OSystem_Android *)arg; Audio::MixerImpl *mixer = system->_mixer; uint buf_size = system->_audio_buffer_size; JNIEnv *env = JNI::getEnv(); jbyteArray bufa = env->NewByteArray(buf_size); bool paused = true; byte *buf; int offset, left, written; int samples, i; struct timespec tv_delay; tv_delay.tv_sec = 0; tv_delay.tv_nsec = 20 * 1000 * 1000; uint msecs_full = buf_size * 1000 / (mixer->getOutputRate() * 2 * 2); struct timespec tv_full; tv_full.tv_sec = 0; tv_full.tv_nsec = msecs_full * 1000 * 1000; bool silence; uint silence_count = 33; while (!system->_audio_thread_exit) { if (JNI::pause) { JNI::setAudioStop(); paused = true; silence_count = 33; LOGD("audio thread going to sleep"); sem_wait(&JNI::pause_sem); LOGD("audio thread woke up"); } buf = (byte *)env->GetPrimitiveArrayCritical(bufa, 0); assert(buf); samples = mixer->mixCallback(buf, buf_size); silence = samples < 1; // looks stupid, and it is, but currently there's no way to detect // silence-only buffers from the mixer if (!silence) { silence = true; for (i = 0; i < samples; i += 2) // SID streams constant crap if (READ_UINT16(buf + i) > 32) { silence = false; break; } } env->ReleasePrimitiveArrayCritical(bufa, buf, 0); if (silence) { if (!paused) silence_count++; // only pause after a while to prevent toggle mania if (silence_count > 32) { if (!paused) { LOGD("AudioTrack pause"); JNI::setAudioPause(); paused = true; } nanosleep(&tv_full, 0); continue; } } if (paused) { LOGD("AudioTrack play"); JNI::setAudioPlay(); paused = false; silence_count = 0; } offset = 0; left = buf_size; written = 0; while (left > 0) { written = JNI::writeAudio(env, bufa, offset, left); if (written < 0) { LOGE("AudioTrack error: %d", written); break; } // buffer full if (written < left) nanosleep(&tv_delay, 0); offset += written; left -= written; } if (written < 0) break; // prepare the next buffer, and run into the blocking AudioTrack.write } JNI::setAudioStop(); env->DeleteLocalRef(bufa); JNI::detachThread(); return 0; }
static char * _verify_nettle_rsa(sldns_buffer* buf, unsigned int digest_size, char* sigblock, unsigned int sigblock_len, uint8_t* key, unsigned int keylen) { uint16_t exp_len = 0; size_t exp_offset = 0, mod_offset = 0; struct rsa_public_key pubkey; mpz_t signature; int res = 0; /* RSA pubkey parsing as per RFC 3110 sec. 2 */ if( keylen <= 1) { return "null RSA key"; } if (key[0] != 0) { /* 1-byte length */ exp_len = key[0]; exp_offset = 1; } else { /* 1-byte NUL + 2-bytes exponent length */ if (keylen < 3) { return "incorrect RSA key length"; } exp_len = READ_UINT16(key+1); if (exp_len == 0) return "null RSA exponent length"; exp_offset = 3; } /* Check that we are not over-running input length */ if (keylen < exp_offset + exp_len + 1) { return "RSA key content shorter than expected"; } mod_offset = exp_offset + exp_len; nettle_rsa_public_key_init(&pubkey); pubkey.size = keylen - mod_offset; nettle_mpz_set_str_256_u(pubkey.e, exp_len, &key[exp_offset]); nettle_mpz_set_str_256_u(pubkey.n, pubkey.size, &key[mod_offset]); /* Digest content of "buf" and verify its RSA signature in "sigblock"*/ nettle_mpz_init_set_str_256_u(signature, sigblock_len, (uint8_t*)sigblock); switch (digest_size) { case SHA1_DIGEST_SIZE: { uint8_t digest[SHA1_DIGEST_SIZE]; res = _digest_nettle(SHA1_DIGEST_SIZE, (unsigned char*)sldns_buffer_begin(buf), (unsigned int)sldns_buffer_limit(buf), (unsigned char*)digest); res &= rsa_sha1_verify_digest(&pubkey, digest, signature); break; } case SHA256_DIGEST_SIZE: { uint8_t digest[SHA256_DIGEST_SIZE]; res = _digest_nettle(SHA256_DIGEST_SIZE, (unsigned char*)sldns_buffer_begin(buf), (unsigned int)sldns_buffer_limit(buf), (unsigned char*)digest); res &= rsa_sha256_verify_digest(&pubkey, digest, signature); break; } case SHA512_DIGEST_SIZE: { uint8_t digest[SHA512_DIGEST_SIZE]; res = _digest_nettle(SHA512_DIGEST_SIZE, (unsigned char*)sldns_buffer_begin(buf), (unsigned int)sldns_buffer_limit(buf), (unsigned char*)digest); res &= rsa_sha512_verify_digest(&pubkey, digest, signature); break; } default: break; } /* Clear and return */ nettle_rsa_public_key_clear(&pubkey); mpz_clear(signature); if (!res) { return "RSA signature verification failed"; } else { return NULL; } }
void Transport::nfcGetMessageInfo(size_t* pRecordCount) { uint8_t in[2]; command(Transport::NFC_GET_MESSAGE_INFO, NULL, 0, in, sizeof(in)); READ_UINT16(&in[0], *pRecordCount); }
void OSystem_Android::setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale, const Graphics::PixelFormat *format) { ENTER("%p, %u, %u, %d, %d, %u, %d, %p", buf, w, h, hotspotX, hotspotY, keycolor, dontScale, format); GLTHREADCHECK; #ifdef USE_RGB_COLOR if (format && format->bytesPerPixel > 1) { if (_mouse_texture != _mouse_texture_rgb) { LOGD("switching to rgb mouse cursor"); assert(!_mouse_texture_rgb); _mouse_texture_rgb = new GLES5551Texture(); _mouse_texture_rgb->setLinearFilter(_graphicsMode == 1); } _mouse_texture = _mouse_texture_rgb; } else { if (_mouse_texture != _mouse_texture_palette) LOGD("switching to paletted mouse cursor"); _mouse_texture = _mouse_texture_palette; delete _mouse_texture_rgb; _mouse_texture_rgb = 0; } #endif _mouse_texture->allocBuffer(w, h); if (_mouse_texture == _mouse_texture_palette) { assert(keycolor < 256); byte *p = _mouse_texture_palette->palette() + _mouse_keycolor * 2; WRITE_UINT16(p, READ_UINT16(p) | 1); _mouse_keycolor = keycolor; p = _mouse_texture_palette->palette() + _mouse_keycolor * 2; WRITE_UINT16(p, READ_UINT16(p) & ~1); } if (w == 0 || h == 0) return; if (_mouse_texture == _mouse_texture_palette) { _mouse_texture->updateBuffer(0, 0, w, h, buf, w); } else { uint16 pitch = _mouse_texture->pitch(); byte *tmp = new byte[pitch * h]; // meh, a 16bit cursor without alpha bits... this is so silly if (!crossBlit(tmp, (const byte *)buf, pitch, w * 2, w, h, _mouse_texture->getPixelFormat(), *format)) { LOGE("crossblit failed"); delete[] tmp; _mouse_texture->allocBuffer(0, 0); return; } const uint16 *s = (const uint16 *)buf; uint16 *d = (uint16 *)tmp; for (uint16 y = 0; y < h; ++y, d += pitch / 2 - w) for (uint16 x = 0; x < w; ++x, d++) if (*s++ == (keycolor & 0xffff)) *d = 0; _mouse_texture->updateBuffer(0, 0, w, h, tmp, pitch); delete[] tmp; } _mouse_hotspot = Common::Point(hotspotX, hotspotY); // TODO: Adapt to the new "do not scale" cursor logic. _mouse_targetscale = 1; }