mirror of
				https://github.com/webmproject/libwebp.git
				synced 2025-10-31 10:25:46 +01:00 
			
		
		
		
	further speed-up/cleanup of RecordCoeffs() and GetResidualCost()
(note: Incorporated the cost of bin #1 into the LevelCost[]) Change-Id: I6408b2a822efdb97ad6a3a21d380bc7b0da9c715
This commit is contained in:
		| @@ -359,7 +359,7 @@ void VP8CalculateLevelCosts(VP8Proba* const proba) { | |||||||
|       for(ctx = 0; ctx < NUM_CTX; ++ctx) { |       for(ctx = 0; ctx < NUM_CTX; ++ctx) { | ||||||
|         const uint8_t* const p = proba->coeffs_[ctype][band][ctx]; |         const uint8_t* const p = proba->coeffs_[ctype][band][ctx]; | ||||||
|         uint16_t* const table = proba->level_cost_[ctype][band][ctx]; |         uint16_t* const table = proba->level_cost_[ctype][band][ctx]; | ||||||
|         const int cost_base = VP8BitCost(1, p[1]); |         const int cost_base = VP8BitCost(0, p[0]) + VP8BitCost(1, p[1]); | ||||||
|         int v; |         int v; | ||||||
|         table[0] = VP8BitCost(0, p[1]); |         table[0] = VP8BitCost(0, p[1]); | ||||||
|         for (v = 1; v <= MAX_VARIABLE_LEVEL; ++v) { |         for (v = 1; v <= MAX_VARIABLE_LEVEL; ++v) { | ||||||
|   | |||||||
| @@ -146,16 +146,18 @@ static int Record(int bit, uint64_t* const stats) { | |||||||
| static int RecordCoeffs(int ctx, VP8Residual* res) { | static int RecordCoeffs(int ctx, VP8Residual* res) { | ||||||
|   int n = res->first; |   int n = res->first; | ||||||
|   uint64_t (*s)[2] = res->stats[VP8EncBands[n]][ctx]; |   uint64_t (*s)[2] = res->stats[VP8EncBands[n]][ctx]; | ||||||
|   if (!Record(res->last >= 0, s[0])) { |   if (res->last  < 0) { | ||||||
|  |     Record(0, s[0]); | ||||||
|     return 0; |     return 0; | ||||||
|   } |   } | ||||||
|  |   while (n <= res->last) { | ||||||
|   while (1) { |     int v; | ||||||
|     int v = res->coeffs[n++]; |     Record(1, s[0]); | ||||||
|     if (!Record(v != 0, s[1])) { |     while ((v = res->coeffs[n++]) == 0) { | ||||||
|  |       Record(0, s[1]); | ||||||
|       s = res->stats[VP8EncBands[n]][0];       |       s = res->stats[VP8EncBands[n]][0];       | ||||||
|       continue; |  | ||||||
|     } |     } | ||||||
|  |     Record(1, s[1]); | ||||||
|     if (!Record(2u < (unsigned int)(v + 1), s[2])) {  // v = -1 or 1 |     if (!Record(2u < (unsigned int)(v + 1), s[2])) {  // v = -1 or 1 | ||||||
|       s = res->stats[VP8EncBands[n]][1]; |       s = res->stats[VP8EncBands[n]][1]; | ||||||
|     } else { |     } else { | ||||||
| @@ -187,10 +189,9 @@ static int RecordCoeffs(int ctx, VP8Residual* res) { | |||||||
| #endif | #endif | ||||||
|       s = res->stats[VP8EncBands[n]][2]; |       s = res->stats[VP8EncBands[n]][2]; | ||||||
|     } |     } | ||||||
|     if (n == 16 || !Record(n <= res->last, s[0])) { |  | ||||||
|       return 1; |  | ||||||
|     } |  | ||||||
|   } |   } | ||||||
|  |   if (n < 16) Record(0, s[0]); | ||||||
|  |   return 1; | ||||||
| } | } | ||||||
|  |  | ||||||
| // Collect statistics and deduce probabilities for next coding pass. | // Collect statistics and deduce probabilities for next coding pass. | ||||||
| @@ -260,13 +261,12 @@ static void SetResidualCoeffs(const int16_t* const coeffs, | |||||||
|  |  | ||||||
| static int GetResidualCost(int ctx, const VP8Residual* const res) { | static int GetResidualCost(int ctx, const VP8Residual* const res) { | ||||||
|   int n = res->first; |   int n = res->first; | ||||||
|   const uint8_t* p = res->prob[VP8EncBands[n]][ctx]; |   int p0 = res->prob[VP8EncBands[n]][ctx][0]; | ||||||
|   const uint16_t *t = res->cost[VP8EncBands[n]][ctx]; |   const uint16_t *t = res->cost[VP8EncBands[n]][ctx]; | ||||||
|   int last_p0 = p[0]; |  | ||||||
|   int cost; |   int cost; | ||||||
|  |  | ||||||
|   if (res->last < 0) { |   if (res->last < 0) { | ||||||
|     return VP8BitCost(0, last_p0); |     return VP8BitCost(0, p0); | ||||||
|   } |   } | ||||||
|   cost = 0; |   cost = 0; | ||||||
|   while (n <= res->last) { |   while (n <= res->last) { | ||||||
| @@ -275,23 +275,20 @@ static int GetResidualCost(int ctx, const VP8Residual* const res) { | |||||||
|     ++n; |     ++n; | ||||||
|     if (v == 0) { |     if (v == 0) { | ||||||
|       cost += VP8LevelCost(t, 0); |       cost += VP8LevelCost(t, 0); | ||||||
|       p = res->prob[b][0]; |  | ||||||
|       t = res->cost[b][0]; |       t = res->cost[b][0]; | ||||||
|       continue; |       continue; | ||||||
|     } |     } | ||||||
|     cost += VP8BitCost(1, last_p0); |  | ||||||
|     if (2u >= (unsigned int)(v + 1)) {   // v = -1 or 1 |     if (2u >= (unsigned int)(v + 1)) {   // v = -1 or 1 | ||||||
|       cost += VP8LevelCost(t, 1); |       cost += VP8LevelCost(t, 1); | ||||||
|       p = res->prob[b][1]; |       p0 = res->prob[b][1][0]; | ||||||
|       t = res->cost[b][1]; |       t = res->cost[b][1]; | ||||||
|     } else { |     } else { | ||||||
|       cost += VP8LevelCost(t, abs(v)); |       cost += VP8LevelCost(t, abs(v)); | ||||||
|       p = res->prob[b][2]; |       p0 = res->prob[b][2][0]; | ||||||
|       t = res->cost[b][2]; |       t = res->cost[b][2]; | ||||||
|     } |     } | ||||||
|     last_p0 = p[0]; |  | ||||||
|   } |   } | ||||||
|   if (n < 16) cost += VP8BitCost(0, last_p0); |   if (n < 16) cost += VP8BitCost(0, p0); | ||||||
|   return cost; |   return cost; | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user