File indexing completed on 2024-12-22 04:10:29
0001 /* 0002 * SPDX-FileCopyrightText: 2010 Dmitry Kazakov <dimula73@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "kis_abstract_compression.h" 0008 0009 KisAbstractCompression::KisAbstractCompression() 0010 { 0011 } 0012 0013 KisAbstractCompression::~KisAbstractCompression() 0014 { 0015 } 0016 0017 void KisAbstractCompression::adjustForDataSize(qint32 dataSize) 0018 { 0019 Q_UNUSED(dataSize); 0020 } 0021 0022 void KisAbstractCompression::linearizeColors(quint8 *input, quint8 *output, 0023 qint32 dataSize, qint32 pixelSize) 0024 { 0025 quint8 *outputByte = output; 0026 quint8 *lastByte = input + dataSize -1; 0027 0028 for(qint32 i = 0; i < pixelSize; i++) { 0029 quint8 *inputByte = input + i; 0030 while (inputByte <= lastByte) { 0031 *outputByte = *inputByte; 0032 outputByte++; 0033 inputByte+=pixelSize; 0034 } 0035 } 0036 } 0037 0038 void KisAbstractCompression::delinearizeColors(quint8 *input, quint8 *output, 0039 qint32 dataSize, qint32 pixelSize) 0040 { 0041 /** 0042 * In the beginning, i wrote "delinearization" in a way, 0043 * that looks like a "linearization", but it turned to be quite 0044 * inefficient. It seems like reading from random positions is 0045 * much faster than writing to random areas. So this version is 0046 * 13% faster. 0047 */ 0048 0049 quint8 *outputByte = output; 0050 quint8 *lastByte = output + dataSize -1; 0051 0052 qint32 strideSize = dataSize / pixelSize; 0053 quint8 *startByte = input; 0054 0055 while (outputByte <= lastByte) { 0056 quint8 *inputByte = startByte; 0057 0058 for(qint32 i = 0; i < pixelSize; i++) { 0059 *outputByte = *inputByte; 0060 outputByte++; 0061 inputByte += strideSize; 0062 } 0063 0064 startByte++; 0065 } 0066 }