Lines Matching refs:manager
202 static void CostIntervalAddToFreeList(CostManager* const manager, in CostIntervalAddToFreeList() argument
204 interval->next_ = manager->free_intervals_; in CostIntervalAddToFreeList()
205 manager->free_intervals_ = interval; in CostIntervalAddToFreeList()
208 static int CostIntervalIsInFreeList(const CostManager* const manager, in CostIntervalIsInFreeList() argument
210 return (interval >= &manager->intervals_[0] && in CostIntervalIsInFreeList()
211 interval <= &manager->intervals_[COST_MANAGER_MAX_FREE_LIST - 1]); in CostIntervalIsInFreeList()
214 static void CostManagerInitFreeList(CostManager* const manager) { in CostManagerInitFreeList() argument
216 manager->free_intervals_ = NULL; in CostManagerInitFreeList()
218 CostIntervalAddToFreeList(manager, &manager->intervals_[i]); in CostManagerInitFreeList()
222 static void DeleteIntervalList(CostManager* const manager, in DeleteIntervalList() argument
226 if (!CostIntervalIsInFreeList(manager, interval)) { in DeleteIntervalList()
233 static void CostManagerClear(CostManager* const manager) { in CostManagerClear() argument
234 if (manager == NULL) return; in CostManagerClear()
236 WebPSafeFree(manager->costs_); in CostManagerClear()
237 WebPSafeFree(manager->cache_intervals_); in CostManagerClear()
240 DeleteIntervalList(manager, manager->head_); in CostManagerClear()
241 manager->head_ = NULL; in CostManagerClear()
242 DeleteIntervalList(manager, manager->recycled_intervals_); in CostManagerClear()
243 manager->recycled_intervals_ = NULL; in CostManagerClear()
246 memset(manager, 0, sizeof(*manager)); in CostManagerClear()
247 CostManagerInitFreeList(manager); in CostManagerClear()
250 static int CostManagerInit(CostManager* const manager, in CostManagerInit() argument
256 manager->costs_ = NULL; in CostManagerInit()
257 manager->cache_intervals_ = NULL; in CostManagerInit()
258 manager->head_ = NULL; in CostManagerInit()
259 manager->recycled_intervals_ = NULL; in CostManagerInit()
260 manager->count_ = 0; in CostManagerInit()
261 manager->dist_array_ = dist_array; in CostManagerInit()
262 CostManagerInitFreeList(manager); in CostManagerInit()
265 manager->cache_intervals_size_ = 1; in CostManagerInit()
266 manager->cost_cache_[0] = GetLengthCost(cost_model, 0); in CostManagerInit()
268 manager->cost_cache_[i] = GetLengthCost(cost_model, i); in CostManagerInit()
270 if (manager->cost_cache_[i] != manager->cost_cache_[i - 1]) { in CostManagerInit()
271 ++manager->cache_intervals_size_; in CostManagerInit()
279 assert(manager->cache_intervals_size_ <= MAX_LENGTH); in CostManagerInit()
280 manager->cache_intervals_ = (CostCacheInterval*)WebPSafeMalloc( in CostManagerInit()
281 manager->cache_intervals_size_, sizeof(*manager->cache_intervals_)); in CostManagerInit()
282 if (manager->cache_intervals_ == NULL) { in CostManagerInit()
283 CostManagerClear(manager); in CostManagerInit()
289 CostCacheInterval* cur = manager->cache_intervals_; in CostManagerInit()
295 cur->cost_ = manager->cost_cache_[0]; in CostManagerInit()
297 const double cost_val = manager->cost_cache_[i]; in CostManagerInit()
308 manager->costs_ = (float*)WebPSafeMalloc(pix_count, sizeof(*manager->costs_)); in CostManagerInit()
309 if (manager->costs_ == NULL) { in CostManagerInit()
310 CostManagerClear(manager); in CostManagerInit()
314 for (i = 0; i < pix_count; ++i) manager->costs_[i] = 1e38f; in CostManagerInit()
321 static WEBP_INLINE void UpdateCost(CostManager* const manager, int i, in UpdateCost() argument
326 if (manager->costs_[i] > cost) { in UpdateCost()
327 manager->costs_[i] = cost; in UpdateCost()
328 manager->dist_array_[i] = k + 1; in UpdateCost()
334 static WEBP_INLINE void UpdateCostPerInterval(CostManager* const manager, in UpdateCostPerInterval() argument
338 for (i = start; i < end; ++i) UpdateCost(manager, i, position, cost); in UpdateCostPerInterval()
342 static WEBP_INLINE void ConnectIntervals(CostManager* const manager, in ConnectIntervals() argument
348 manager->head_ = next; in ConnectIntervals()
355 static WEBP_INLINE void PopInterval(CostManager* const manager, in PopInterval() argument
359 ConnectIntervals(manager, interval->previous_, interval->next_); in PopInterval()
360 if (CostIntervalIsInFreeList(manager, interval)) { in PopInterval()
361 CostIntervalAddToFreeList(manager, interval); in PopInterval()
363 interval->next_ = manager->recycled_intervals_; in PopInterval()
364 manager->recycled_intervals_ = interval; in PopInterval()
366 --manager->count_; in PopInterval()
367 assert(manager->count_ >= 0); in PopInterval()
374 static WEBP_INLINE void UpdateCostAtIndex(CostManager* const manager, int i, in UpdateCostAtIndex() argument
376 CostInterval* current = manager->head_; in UpdateCostAtIndex()
383 PopInterval(manager, current); in UpdateCostAtIndex()
386 UpdateCost(manager, i, current->index_, current->cost_); in UpdateCostAtIndex()
395 static WEBP_INLINE void PositionOrphanInterval(CostManager* const manager, in PositionOrphanInterval() argument
400 if (previous == NULL) previous = manager->head_; in PositionOrphanInterval()
410 ConnectIntervals(manager, current, previous->next_); in PositionOrphanInterval()
412 ConnectIntervals(manager, current, manager->head_); in PositionOrphanInterval()
414 ConnectIntervals(manager, previous, current); in PositionOrphanInterval()
419 static WEBP_INLINE void InsertInterval(CostManager* const manager, in InsertInterval() argument
426 if (manager->count_ >= COST_CACHE_INTERVAL_SIZE_MAX) { in InsertInterval()
428 UpdateCostPerInterval(manager, start, end, position, cost); in InsertInterval()
431 if (manager->free_intervals_ != NULL) { in InsertInterval()
432 interval_new = manager->free_intervals_; in InsertInterval()
433 manager->free_intervals_ = interval_new->next_; in InsertInterval()
434 } else if (manager->recycled_intervals_ != NULL) { in InsertInterval()
435 interval_new = manager->recycled_intervals_; in InsertInterval()
436 manager->recycled_intervals_ = interval_new->next_; in InsertInterval()
441 UpdateCostPerInterval(manager, start, end, position, cost); in InsertInterval()
450 PositionOrphanInterval(manager, interval_new, interval_in); in InsertInterval()
452 ++manager->count_; in InsertInterval()
459 static WEBP_INLINE void PushInterval(CostManager* const manager, in PushInterval() argument
463 CostInterval* interval = manager->head_; in PushInterval()
466 manager->cache_intervals_; in PushInterval()
477 cost_tmp = (float)(distance_cost + manager->cost_cache_[k]); in PushInterval()
479 if (manager->costs_[j] > cost_tmp) { in PushInterval()
480 manager->costs_[j] = cost_tmp; in PushInterval()
481 manager->dist_array_[j] = k + 1; in PushInterval()
487 for (i = 0; i < manager->cache_intervals_size_ && in PushInterval()
513 InsertInterval(manager, interval, cost, position, start, in PushInterval()
527 PopInterval(manager, interval); in PushInterval()
545 InsertInterval(manager, interval, interval->cost_, interval->index_, in PushInterval()
559 InsertInterval(manager, interval, cost, position, start, end); in PushInterval()