Ejemplo n.º 1
0
const uint16_t* CLAVPixFmtConverter::GetRandomDitherCoeffs(int height, int coeffs, int bits, int line)
{
  if (m_pSettings->GetDitherMode() != LAVDither_Random)
    return nullptr;

  int totalWidth = 8 * coeffs;
  if (!m_pRandomDithers || totalWidth > m_ditherWidth || height > m_ditherHeight || bits != m_ditherBits) {
    if (m_pRandomDithers)
      _aligned_free(m_pRandomDithers);
    m_pRandomDithers = nullptr;
    m_ditherWidth = totalWidth;
    m_ditherHeight = height;
    m_ditherBits = bits;
    m_pRandomDithers = (uint16_t *)_aligned_malloc(m_ditherWidth * m_ditherHeight * 2, 16);

#ifdef DEBUG
    LARGE_INTEGER frequency, start, end;
    QueryPerformanceFrequency(&frequency);
    QueryPerformanceCounter(&start);
    DbgLog((LOG_TRACE, 10, L"Creating dither matrix"));
#endif

    // Seed random number generator
    time_t seed = time(nullptr);
    seed >>= 1;
    srand_sse((unsigned int)seed);

    bits = (1 << bits);
    for (int i = 0; i < m_ditherHeight; i++) {
      uint16_t *ditherline = m_pRandomDithers + (m_ditherWidth * i);
      for (int j = 0; j < m_ditherWidth; j += 4) {
        int rnds[4];
        rand_sse(rnds);
        ditherline[j+0] = rnds[0] % bits;
        ditherline[j+1] = rnds[1] % bits;
        ditherline[j+2] = rnds[2] % bits;
        ditherline[j+3] = rnds[3] % bits;
      }
    }
#ifdef DEBUG
    QueryPerformanceCounter(&end);
    double diff = (end.QuadPart - start.QuadPart) * 1000.0 / frequency.QuadPart;
    DbgLog((LOG_TRACE, 10, L"Finished creating dither matrix (took %2.3fms)", diff));
#endif

  }

  if (line < 0 || line >= m_ditherHeight)
    line = rand() % m_ditherHeight;

  return &m_pRandomDithers[line * m_ditherWidth];
}
Ejemplo n.º 2
0
short rand_sse()
{
	unsigned int result[4];
	rand_sse(result);
	return (short)*result;
}