bool CGondolierSlider::SignalObject(CSignalObject *msg) { _arrayIndex = CLIP(_arrayIndex, 0, 10); _sliderRect1 = _sliderRect2; _sliderRect1.translate(_bounds.left, _bounds.top); _sliderRect1.translate(0, ARRAY[_arrayIndex]); loadFrame(_arrayIndex); CSignalObject signalMsg; signalMsg._numValue = 10 - _arrayIndex; signalMsg._strValue = _fieldFC ? "Fly" : "Tos"; signalMsg.execute(_string3); return true; }
int HSV::hsv_to_yuv(int &y, int &u, int &v, float h, float s, float va, int max) { float r, g, b; int r_i, g_i, b_i; HSV::hsv_to_rgb(r, g, b, h, s, va); r = r * max + 0.5; g = g * max + 0.5; b = b * max + 0.5; r_i = (int)CLIP(r, 0, max); g_i = (int)CLIP(g, 0, max); b_i = (int)CLIP(b, 0, max); int y2, u2, v2; if(max == 0xffff) yuv_static.rgb_to_yuv_16(r_i, g_i, b_i, y2, u2, v2); else yuv_static.rgb_to_yuv_8(r_i, g_i, b_i, y2, u2, v2); y = y2; u = u2; v = v2; return 0; }
float setMaxFreq ( t_CKFLOAT p ) { const float nyquist = srate / 2; if (p == 0) p = nyquist; float max = CLIP(p, minfreq, nyquist); if (max != maxfreq) { maxfreq = max; spectdelay->set_delay_freqrange(minfreq, maxfreq); spectdelay->set_freqrange(minfreq, maxfreq); } return max; }
void MidiPlayer::setVolume(int volume) { volume = CLIP(volume, 0, 255); if (_masterVolume == volume) return; Common::StackLock lock(_mutex); _masterVolume = volume; for (int i = 0; i < kNumChannels; ++i) { if (_channelsTable[i]) { _channelsTable[i]->volume(_channelsVolume[i] * _masterVolume / 255); } } }
void GfxPalette::copySysPaletteToScreen() { // just copy palette to system byte bpal[3 * 256]; // Get current palette, update it and put back g_system->getPaletteManager()->grabPalette(bpal, 0, 256); for (int16 i = 0; i < 256; i++) { if (colorIsFromMacClut(i)) { // If we've got a Mac CLUT, override the SCI palette with its non-black colors bpal[i * 3 ] = convertMacGammaToSCIGamma(_macClut[i * 3 ]); bpal[i * 3 + 1] = convertMacGammaToSCIGamma(_macClut[i * 3 + 1]); bpal[i * 3 + 2] = convertMacGammaToSCIGamma(_macClut[i * 3 + 2]); } else if (_sysPalette.colors[i].used != 0) { // Otherwise, copy to the screen bpal[i * 3 ] = CLIP(_sysPalette.colors[i].r * _sysPalette.intensity[i] / 100, 0, 255); bpal[i * 3 + 1] = CLIP(_sysPalette.colors[i].g * _sysPalette.intensity[i] / 100, 0, 255); bpal[i * 3 + 2] = CLIP(_sysPalette.colors[i].b * _sysPalette.intensity[i] / 100, 0, 255); } } g_system->getPaletteManager()->setPalette(bpal, 0, 256); }
bool TheoraDecoder::VorbisAudioTrack::decodeSamples() { float **pcm; // if there's pending, decoded audio, grab it int ret = vorbis_synthesis_pcmout(&_vorbisDSP, &pcm); if (ret > 0) { if (!_audioBuffer) { _audioBuffer = (ogg_int16_t *)malloc(AUDIOFD_FRAGSIZE * sizeof(ogg_int16_t)); assert(_audioBuffer); } int channels = _audStream->isStereo() ? 2 : 1; int count = _audioBufferFill / 2; int maxsamples = ((AUDIOFD_FRAGSIZE - _audioBufferFill) / channels) >> 1; int i; for (i = 0; i < ret && i < maxsamples; i++) { for (int j = 0; j < channels; j++) { int val = CLIP((int)rint(pcm[j][i] * 32767.f), -32768, 32767); _audioBuffer[count++] = val; } } vorbis_synthesis_read(&_vorbisDSP, i); _audioBufferFill += (i * channels) << 1; if (_audioBufferFill == AUDIOFD_FRAGSIZE) { byte flags = Audio::FLAG_16BITS; if (_audStream->isStereo()) flags |= Audio::FLAG_STEREO; #ifdef SCUMM_LITTLE_ENDIAN flags |= Audio::FLAG_LITTLE_ENDIAN; #endif _audStream->queueBuffer((byte *)_audioBuffer, AUDIOFD_FRAGSIZE, DisposeAfterUse::YES, flags); // The audio mixer is now responsible for the old audio buffer. // We need to create a new one. _audioBuffer = 0; _audioBufferFill = 0; } return true; } return false; }
mlib_status mlib_ImageAffine_s16_3ch_nn( mlib_affine_param *param) { DECLAREVAR_NN(); DTYPE *dstLineEnd; for (j = yStart; j <= yFinish; j++) { mlib_s32 pix0, pix1, pix2; CLIP(3); dstLineEnd = (DTYPE *) dstData + 3 * xRight; ySrc = MLIB_POINTER_SHIFT(Y); Y += dY; xSrc = X >> MLIB_SHIFT; X += dX; srcPixelPtr = MLIB_POINTER_GET(lineAddr, ySrc) + 3 * xSrc; pix0 = srcPixelPtr[0]; pix1 = srcPixelPtr[1]; pix2 = srcPixelPtr[2]; ySrc = MLIB_POINTER_SHIFT(Y); Y += dY; xSrc = X >> MLIB_SHIFT; X += dX; #ifdef __SUNPRO_C #pragma pipeloop(0) #endif /* __SUNPRO_C */ for (; dstPixelPtr < dstLineEnd; dstPixelPtr += 3) { srcPixelPtr = MLIB_POINTER_GET(lineAddr, ySrc) + 3 * xSrc; ySrc = MLIB_POINTER_SHIFT(Y); Y += dY; xSrc = X >> MLIB_SHIFT; X += dX; dstPixelPtr[0] = pix0; dstPixelPtr[1] = pix1; dstPixelPtr[2] = pix2; pix0 = srcPixelPtr[0]; pix1 = srcPixelPtr[1]; pix2 = srcPixelPtr[2]; } dstPixelPtr[0] = pix0; dstPixelPtr[1] = pix1; dstPixelPtr[2] = pix2; } return (MLIB_SUCCESS); }
void MusicPlayer::setVolume(int volume) { Common::StackLock lock(_mutex); volume = CLIP(volume, 0, 255); if (_masterVolume == volume) return; _masterVolume = volume; for (int i = 0; i < 16; ++i) { if (_channel[i]) { setChannelVolume(i); } } }
void ConsoleWindow::highlightClip(uint32 &x, uint32 &y) const { y = CLIP<uint32>(y, 0, _lines.size()); uint32 minX, maxX; if (y == 0) { minX = _prompt->get().size(); maxX = _prompt->get().size() + _input->get().size(); } else { minX = 0; maxX = _lines[_lines.size() - y]->get().size(); } x = CLIP(x, minX, maxX); }
/* * accumulate a blockquote. * * one sick horrible thing about blockquotes is that even though * it just takes ^> to start a quote, following lines, if quoted, * assume that the prefix is ``> ''. This means that code needs * to be indented *5* spaces from the leading '>', but *4* spaces * from the start of the line. This does not appear to be * documented in the reference implementation, but it's the * way the markdown sample web form at Daring Fireball works. */ static Line * quoteblock(Paragraph *p, DWORD flags) { Line *t, *q; int qp; for ( t = p->text; t ; t = q ) { if ( isquote(t) ) { /* clip leading spaces */ for (qp = 0; T(t->text)[qp] != '>'; qp ++) /* assert: the first nonblank character on this line * will be a > */; /* clip '>' */ qp++; /* clip next space, if any */ if ( T(t->text)[qp] == ' ' ) qp++; CLIP(t->text, 0, qp); UNCHECK(t); t->dle = mkd_firstnonblank(t); } q = skipempty(t->next); if ( (q == 0) || ((q != t->next) && (!isquote(q) || isdivmarker(q,1,flags))) ) { ___mkd_freeLineRange(t, q); t = q; break; } } if ( isdivmarker(p->text,0,flags) ) { char *prefix = "class"; int i; q = p->text; p->text = p->text->next; if ( (i = szmarkerclass(1+T(q->text))) == 3 ) /* and this would be an "%id:" prefix */ prefix="id"; if ( p->ident = malloc(4+strlen(prefix)+S(q->text)) ) sprintf(p->ident, "%s=\"%.*s\"", prefix, S(q->text)-(i+2), T(q->text)+(i+1) ); ___mkd_freeLine(q); } return t; }
bool CGondolierSlider::SignalObject(CSignalObject *msg) { _sliderIndex = CLIP(_sliderIndex, 0, 10); _thumbRect = _defaultThumbRect; _thumbRect.translate(_bounds.left, _bounds.top); _thumbRect.translate(0, Y_OFFSETS[_sliderIndex]); loadFrame(_sliderIndex); CSignalObject signalMsg; signalMsg._numValue = 10 - _sliderIndex; signalMsg._strValue = _sliderNum ? "Fly" : "Tos"; signalMsg.execute(_signalTarget); return true; }
void process (struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, void *ivoid, void *ovoid, const dt_iop_roi_t *roi_in, const dt_iop_roi_t *roi_out) { dt_iop_relight_data_t *data = (dt_iop_relight_data_t *)piece->data; const int ch = piece->colors; // Precalculate parameters for gauss function const float a = 1.0; // Height of top const float b = -1.0+(data->center*2); // Center of top const float c = (data->width/10.0)/2.0; // Width #ifdef _OPENMP #pragma omp parallel for default(none) shared(roi_out, ivoid, ovoid, data) schedule(static) #endif for(int k=0; k<roi_out->height; k++) { float *in = ((float *)ivoid) + ch*k*roi_out->width; float *out = ((float *)ovoid) + ch*k*roi_out->width; for(int j=0; j<roi_out->width; j++,in+=ch,out+=ch) { const float lightness = in[0]/100.0; const float x = -1.0+(lightness*2.0); float gauss = GAUSS(a,b,c,x); if(isnan(gauss) || isinf(gauss)) gauss = 0.0; float relight = 1.0 / exp2f ( -data->ev * CLIP(gauss)); if(isnan(relight) || isinf(relight)) relight = 1.0; out[0] = 100.0*CLIP (lightness*relight); out[1] = in[1]; out[2] = in[2]; } } }
/*jpeg decoding 420 planar to 422 * args: * out: pointer to data output of idct (macroblocks yyyy u v) * pic: pointer to picture buffer (yuyv) * stride: picture stride */ static void yuv420pto422(int * out,uint8_t *pic,int stride) { int j, k; uint8_t *pic0, *pic1; int *outy, *outu, *outv; int outy1 = 0; int outy2 = 8; //yyyyuv pic0 = pic; pic1 = pic + stride; outy = out; outu = out + 64 * 4; outv = out + 64 * 5; for (j = 0; j < 8; j++) { for (k = 0; k < 8; k++) { if( k == 4) { outy1 += 56; outy2 += 56; } *pic0++ = CLIP(outy[outy1]); //y1 line 1 *pic0++ = CLIP(128 + *outu); //u line 1-2 *pic0++ = CLIP(outy[outy1+1]); //y2 line 1 *pic0++ = CLIP(128 + *outv); //v line 1-2 *pic1++ = CLIP(outy[outy2]); //y1 line 2 *pic1++ = CLIP(128 + *outu); //u line 1-2 *pic1++ = CLIP(outy[outy2+1]); //y2 line 2 *pic1++ = CLIP(128 + *outv); //v line 1-2 outy1 +=2; outy2 += 2; outu++; outv++; } if(j==3) { outy = out + 128; } else { outy += 16; } outy1 = 0; outy2 = 8; pic0 += 2 * (stride -16); pic1 += 2 * (stride -16); } }
int pcmfile_seek_samples(PcmFile *pf, int64_t offset, int whence) { int64_t byte_offset; uint64_t newpos, fpos, dst, dsz; if(pf == NULL || pf->io.fp == NULL) return -1; if(pf->block_align <= 0) return -1; if(pf->filepos < pf->data_start) return -1; if(pf->data_size == 0) return 0; fpos = pf->filepos; dst = pf->data_start; dsz = pf->data_size; byte_offset = offset; byte_offset *= pf->block_align; // calculate new destination within file switch(whence) { case PCM_SEEK_SET: newpos = dst + CLIP(byte_offset, 0, (int64_t)dsz); break; case PCM_SEEK_CUR: newpos = fpos - MIN(-byte_offset, (int64_t)(fpos - dst)); newpos = MIN(newpos, dst + dsz); break; case PCM_SEEK_END: newpos = dst + dsz - CLIP(byte_offset, 0, (int64_t)dsz); break; default: return -1; } // seek to the destination point if(pcmfile_seek_set(pf, newpos)) return -1; return 0; }
t_jit_err jit_gl_videoplane_draw(t_jit_gl_videoplane *x) { t_jit_err result = JIT_ERR_NONE; GLenum prim; CLIP (x->nudge,0.,0.5); prim = (x->gridmode) ? GL_TRIANGLE_STRIP : GL_QUAD_STRIP; if (x->recalc) { jit_gl_videoplane_recalc(x); if (x->displaylist) { t_jit_gl_context ctx; // cache/restore context in case in capture mode ctx = jit_gl_get_context(); jit_ob3d_set_context(x); if (x->dlref) { glDeleteLists(x->dlref,1); x->dlref = 0; } if (x->dlref=glGenLists(1)) { glNewList(x->dlref, GL_COMPILE); if (x->chunk&&x->chunk->m_vertex) draw_grid(x,x->chunk->m_vertex, prim); glEndList(); } jit_gl_set_context(ctx); } x->recalc = 0; } // draw our chunk of OpenGL geometry. if (x->chunk&&x->chunk->m_vertex) { if (!jit_attr_getlong(x,gensym("matrixoutput"))) { if (x->displaylist&&x->dlref) glCallList(x->dlref); else draw_grid(x,x->chunk->m_vertex, prim); } else{ color_surface(x); result = jit_ob3d_draw_chunk(x->ob3d, x->chunk); //output matrix } } return result; }
static Line * headerblock(Paragraph *pp, int htyp) { Line *ret = 0; Line *p = pp->text; int i, j; switch (htyp) { case SETEXT: /* p->text is header, p->next->text is -'s or ='s */ pp->hnumber = (T(p->next->text)[0] == '=') ? 1 : 2; ret = p->next->next; ___mkd_freeLine(p->next); p->next = 0; break; case ETX: /* p->text is ###header###, so we need to trim off * the leading and trailing `#`'s */ for (i=0; (T(p->text)[i] == T(p->text)[0]) && (i < S(p->text)-1) && (i < 6); i++) ; pp->hnumber = i; while ( (i < S(p->text)) && isspace(T(p->text)[i]) ) ++i; CLIP(p->text, 0, i); UNCHECK(p); for (j=S(p->text); (j > 1) && (T(p->text)[j-1] == '#'); --j) ; while ( j && isspace(T(p->text)[j-1]) ) --j; S(p->text) = j; ret = p->next; p->next = 0; break; } return ret; }
static void PaConvert_Float32_Int16_Clip( float *sourceBuffer, int sourceStride, short *targetBuffer, int targetStride, int numSamples ) { int i; for( i=0; i<numSamples; i++ ) { long samp = (long) (*sourceBuffer * (32767.0f)); CLIP( samp, -0x8000, 0x7FFF ); *targetBuffer = (short) samp; sourceBuffer += sourceStride; targetBuffer += targetStride; } }
int sushi_update_pos(struct sushi_game *sg) { int i; /* 寿司を1つ進める */ #define CLIP(a, b) ( ((a) % (b) < 0) ? (((a) % (b)) + (b)) : ((a) % (b)) ) for(i = sg->sushi_len; i > 0; i--) { sg->sushi_pos[i] = sg->sushi_pos[i-1]; } switch(sg->dir) { case SUSHI_RIGHT: sg->sushi_pos[0].x = CLIP(sg->sushi_pos[0].x+1, sg->width); break; case SUSHI_LEFT: sg->sushi_pos[0].x = CLIP(sg->sushi_pos[0].x-1, sg->width); break; case SUSHI_DOWN: sg->sushi_pos[0].y = CLIP(sg->sushi_pos[0].y+1, sg->height); break; case SUSHI_UP: sg->sushi_pos[0].y = CLIP(sg->sushi_pos[0].y-1, sg->height); break; default: break; } #undef CLIP /* 自分との当たり判定 */ for(i = 1; i < sg->sushi_len; i++) { if(sg->sushi_pos[0].x == sg->sushi_pos[i].x && sg->sushi_pos[0].y == sg->sushi_pos[i].y) { return SUSHI_GAME_OVER; } } /* 魚とのあたり判定 */ for(i = 0; i < sg->fish_cnt; i++) { if(sg->sushi_pos[0].x == sg->fish_pos[i].x && sg->sushi_pos[0].y == sg->fish_pos[i].y) { /* 当たった */ sg->sushi_len = (sg->sushi_len < sg->sushi_max) ? sg->sushi_len+1 : sg->sushi_len; sg->fish_cnt = (sg->fish_cnt > 0) ? sg->fish_cnt-1 : sg->fish_cnt; memcpy(&sg->fish_pos[i], &sg->fish_pos[sg->fish_cnt], sizeof(struct sushi_pos)); } } return SUSHI_SUCCESS; }
/** * Delays the game for the specified number of frames, if necessary, from the * previous time the delay method was called */ void EventsClass::delay(int numFrames) { while (_frameNumber < (_prevDelayFrame + numFrames)) { uint32 delayAmount = CLIP(_priorFrameTime + GAME_SCRIPT_TIME - g_system->getMillis(), (uint32)0, (uint32)GAME_FRAME_TIME); if (delayAmount > 0) g_system->delayMillis(delayAmount); ++_frameNumber; _priorFrameTime = g_system->getMillis(); } GLOBALS._screenSurface.copyToScreen(); _prevDelayFrame = _frameNumber; _priorFrameTime = g_system->getMillis(); }
static void PaConvert_Float32_Int8_Clip( float *sourceBuffer, int sourceStride, char *targetBuffer, int targetStride, int numSamples ) { int i; for( i=0; i<numSamples; i++ ) { long samp = (long) (*sourceBuffer * 127.0f); CLIP( samp, -0x80, 0x7F ); *targetBuffer = (char) samp; sourceBuffer += sourceStride; targetBuffer += targetStride; } }
void Cursor::updateFadeLevel() { if (_fading) { if (_fadeLevelIncreasing) { _fadeLevel += 0.001f * StarkGlobal->getMillisecondsPerGameloop(); } else { _fadeLevel -= 0.001f * StarkGlobal->getMillisecondsPerGameloop(); } if (ABS(_fadeLevel) >= _fadeValueMax) { _fadeLevelIncreasing = !_fadeLevelIncreasing; _fadeLevel = CLIP(_fadeLevel, -_fadeValueMax, _fadeValueMax); } } else { _fadeLevel = 0; } }
/** * Delays the game for the specified number of frames, if necessary, from the * previous time the delay method was called */ void EventsClass::delay(int numFrames) { while (_frameNumber < (_prevDelayFrame + numFrames)) { uint32 delayAmount = CLIP(_priorFrameTime + GAME_FRAME_TIME - g_system->getMillis(), (uint32)0, (uint32)GAME_FRAME_TIME); if (delayAmount > 0) g_system->delayMillis(delayAmount); ++_frameNumber; _priorFrameTime = g_system->getMillis(); } g_system->updateScreen(); _prevDelayFrame = _frameNumber; _priorFrameTime = g_system->getMillis(); }
/** * \brief Get scaled QP used in quantization * */ int32_t kvz_get_scaled_qp(int8_t type, int8_t qp, int8_t qp_offset) { int32_t qp_scaled = 0; if(type == 0) { qp_scaled = qp + qp_offset; } else { qp_scaled = CLIP(-qp_offset, 57, qp); if(qp_scaled < 0) { qp_scaled = qp_scaled + qp_offset; } else { qp_scaled = kvz_g_chroma_scale[qp_scaled] + qp_offset; } } return qp_scaled; }
void WidgetScrollbar::setLength(float percent) { _full = percent >= 1.0f; // Calculate the actual length, at 2 pixel intervals _length = ceilf(MAX(_range * CLIP(percent, 0.0f, 1.0f), 10.0f)); if ((((int) _length) % 2) == 1) _length += 1.0f; if (_length > _range) _length = _range; _scrollbar.setLength(_length); setState(_state); }
void fillAudioBuffer(void *udata, Uint8 *stream, int len) { int bufvalid_bytes = min(len, sizeof(sound_buffer)); int bufvalid_samples = bufvalid_bytes / sizeof(int16_t); // Mix in the music SDL_mutexP(::opl.mutex); if (::opl.cur_song) { ::opl.sh->buf = (uint8_t *)sound_buffer; int opl_samples = bufvalid_samples; do { while (::opl.delay_remaining == 0) { // No more delay, process song data until next delay ::opl.chip->WriteReg(::opl.cur_song[::opl.song_pos], ::opl.cur_song[::opl.song_pos + 1]); ::opl.delay_remaining = ::opl.cur_song[::opl.song_pos + 2] | (::opl.cur_song[::opl.song_pos + 3] << 8); ::opl.delay_remaining = ::opl.delay_remaining * (48000/512) / 560; ::opl.song_pos += 4; if (::opl.song_pos >= ::opl.song_len) ::opl.song_pos = 0; // loop } ::opl.chip->Generate(::opl.sh, min(512, bufvalid_samples)); opl_samples -= 512; ::opl.sh->buf += 512 * sizeof(int16_t); ::opl.delay_remaining--; } while (opl_samples >= 512); } else { // No music memset(sound_buffer, 0, bufvalid_bytes); } SDL_mutexV(::opl.mutex); // Play the next bit of the sound effect if needed if (::sound.len > 0) { // Take U8 sound at any rate, convert to S16 48kHz and mix with music double ratio = sound.samplerate / 48000.0; for (int i = 0; i < bufvalid_samples; i++) { int j = ::sound.pos + (int)(i * ratio); if (j >= ::sound.len) break; int32_t a = 32768 + sound_buffer[i]; int32_t b = 32768 + (::sound.data[j] - 127) * (254/2); sound_buffer[i] = CLIP(-32768 + 2 * (a + b) - (a * b) / 32768 - 65536); } ::sound.pos += bufvalid_samples * ratio; // TODO: might drop a sample or two... if (::sound.pos >= ::sound.len) ::sound.len = 0; // end of sound } SDL_MixAudio(stream, (Uint8 *)sound_buffer, bufvalid_bytes, SDL_MIX_MAXVOLUME); return; }
void *max_jit_unpack_new(t_symbol *s, long argc, t_atom *argv) { t_max_jit_unpack *x; void *o,*m,*p,*mop; t_jit_matrix_info info; long i; if (x=(t_max_jit_unpack *)max_jit_obex_new(max_jit_unpack_class,gensym("jit_unpack"))) { if (o=jit_object_new(gensym("jit_unpack"))) { max_jit_obex_jitob_set(x,o); max_jit_obex_dumpout_set(x,outlet_new(x,NULL)); max_jit_mop_setup(x); max_jit_mop_inputs(x); if (argc&&(i=jit_atom_getlong(argv))) { CLIP(i,1,JIT_MATRIX_MAX_PLANECOUNT); } else { i=4; } x->outlets = i; max_jit_mop_variable_addoutputs(x,i); while (i) { p=max_jit_mop_getoutput(x,i); jit_attr_setlong(p,gensym("minplanecount"),1); jit_attr_setlong(p,gensym("maxplanecount"),1); i--; } max_jit_mop_outputs(x); max_jit_mop_matrix_args(x,argc,argv); //set adapt true if only plane argument(should come after matrix_args call) if ((max_jit_attr_args_offset(argc,argv)<=1) && (mop=max_jit_obex_adornment_get(x,_jit_sym_jit_mop))) { jit_attr_setlong(mop,_jit_sym_adapt,1); } max_jit_attr_args(x,argc,argv); } else { jit_object_error((t_object *)x,"jit.unpack: could not allocate object"); freeobject(x); x = NULL; } } return (x); }
void WidgetScrollbar::setState(float state) { _state = CLIP(state, 0.0f, 1.0f); float span = _range - _length; // Space to scroll in float pos = _state * span; // Offset within that space float x, y, z; getPosition(x, y, z); if (_type == Scrollbar::kTypeVertical) y += span - pos; else if (_type == Scrollbar::kTypeHorizontal) x += pos; _scrollbar.setPosition(x, y, z); }
static int centered(Line *first, Line *last) { if ( first&&last ) { int len = S(last->text); if ( (len > 2) && (strncmp(T(first->text), "->", 2) == 0) && (strncmp(T(last->text)+len-2, "<-", 2) == 0) ) { CLIP(first->text, 0, 2); S(last->text) -= 2; return CENTER; } } return 0; }
void UserInterface::changeScrollBar() { Common::Array<int> &inventoryList = _vm->_game->_objects._inventoryList; ScreenObjects &screenObjects = _vm->_game->_screenObjects; if (screenObjects._inputMode != kInputBuildingSentences) return; switch (_scrollbarStrokeType) { case SCROLLBAR_UP: // Scroll up if (_inventoryTopIndex > 0 && inventoryList.size() > 0) { --_inventoryTopIndex; _inventoryChanged = true; } break; case SCROLLBAR_DOWN: // Scroll down if (_inventoryTopIndex < ((int)inventoryList.size() - 1) && inventoryList.size() > 1) { ++_inventoryTopIndex; _inventoryChanged = true; } break; case SCROLLBAR_ELEVATOR: { // Inventory slider int newIndex = CLIP((int)_vm->_events->currentPos().y - 170, 0, 17) * inventoryList.size() / 10; if (newIndex >= (int)inventoryList.size()) newIndex = inventoryList.size() - 1; if (inventoryList.size() > 0) { _inventoryChanged = newIndex != _inventoryTopIndex; _inventoryTopIndex = newIndex; } break; } default: break; } if (_inventoryChanged) { int dummy; updateSelection(CAT_INV_LIST, 0, &dummy); } }
/** * \brief RDO function to calculate cost for intra * \returns cost to code pred block ** Only for luma */ uint32_t kvz_rdo_cost_intra(encoder_state_t * const state, kvz_pixel *pred, kvz_pixel *orig_block, int width, int8_t mode, int tr_depth) { const encoder_control_t * const encoder = state->encoder_control; coeff_t pre_quant_coeff[LCU_WIDTH*LCU_WIDTH>>2]; int16_t block[LCU_WIDTH*LCU_WIDTH>>2]; int16_t temp_block[LCU_WIDTH*LCU_WIDTH>>2]; coeff_t temp_coeff[LCU_WIDTH*LCU_WIDTH>>2]; int8_t luma_scan_mode = SCAN_DIAG; int i = 0,x,y; for (y = 0; y < width; y++) { for (x = 0; x < width; x++) { block[i++] = orig_block[x + y*width]- pred[x + y*width]; } } // Scan mode is diagonal, except for 4x4 and 8x8, where: // - angular 6-14 = vertical // - angular 22-30 = horizontal if (width <= 8) { if (mode >= 6 && mode <= 14) { luma_scan_mode = SCAN_VER; } else if (mode >= 22 && mode <= 30) { luma_scan_mode = SCAN_HOR; } } kvz_transform2d(encoder, block,pre_quant_coeff,width,0); if(encoder->rdoq_enable) { kvz_rdoq(state, pre_quant_coeff, temp_coeff, width, width, 0, luma_scan_mode, CU_INTRA, tr_depth); } else { kvz_quant(state, pre_quant_coeff, temp_coeff, width, width, 0, luma_scan_mode, CU_INTRA); } kvz_dequant(state, temp_coeff, pre_quant_coeff, width, width, 0, CU_INTRA); kvz_itransform2d(encoder, temp_block,pre_quant_coeff,width,0); unsigned ssd = 0; // SSD between original and reconstructed for (i = 0; i < width*width; i++) { //int diff = temp_block[i]-block[i]; int diff = orig_block[i] - CLIP(0, PIXEL_MAX, pred[i] + temp_block[i]); ssd += diff*diff; } double coeff_bits = kvz_get_coeff_cost(state, temp_coeff, width, 0, luma_scan_mode); return (uint32_t)(0.5 + ssd + coeff_bits * state->global->cur_lambda_cost); }