| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008-2009 Torch Mobile, Inc. | |
| 3 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. | 2 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. |
| 4 * | 3 * |
| 5 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
| 6 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
| 7 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
| 8 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
| 9 * | 8 * |
| 10 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
| 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 return 0; | 131 return 0; |
| 133 // FIXME: Use the dimension of the requested frame. | 132 // FIXME: Use the dimension of the requested frame. |
| 134 return m_size.area() * sizeof(ImageFrame::PixelData); | 133 return m_size.area() * sizeof(ImageFrame::PixelData); |
| 135 } | 134 } |
| 136 | 135 |
| 137 void ImageDecoder::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const | 136 void ImageDecoder::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const |
| 138 { | 137 { |
| 139 MemoryClassInfo info(memoryObjectInfo, this, PlatformMemoryTypes::Image); | 138 MemoryClassInfo info(memoryObjectInfo, this, PlatformMemoryTypes::Image); |
| 140 info.addMember(m_data, "data"); | 139 info.addMember(m_data, "data"); |
| 141 info.addMember(m_frameBufferCache, "frameBufferCache"); | 140 info.addMember(m_frameBufferCache, "frameBufferCache"); |
| 142 info.addMember(m_scaledColumns, "scaledColumns"); | |
| 143 info.addMember(m_scaledRows, "scaledRows"); | |
| 144 } | |
| 145 | |
| 146 // FIXME: don't add any more code below this line: the code below is related to | |
| 147 // ENABLE(IMAGE_DECODER_DOWN_SAMPLING), a feature chrome does not use, and does | |
| 148 // test, and does not need. It is therefore earmarked for removal. | |
| 149 | |
| 150 enum MatchType { | |
| 151 Exact, | |
| 152 UpperBound, | |
| 153 LowerBound | |
| 154 }; | |
| 155 | |
| 156 inline void fillScaledValues(Vector<int>& scaledValues, double scaleRate, int le
ngth) | |
| 157 { | |
| 158 double inflateRate = 1. / scaleRate; | |
| 159 scaledValues.reserveCapacity(static_cast<int>(length * scaleRate + 0.5)); | |
| 160 for (int scaledIndex = 0; ; ++scaledIndex) { | |
| 161 int index = static_cast<int>(scaledIndex * inflateRate + 0.5); | |
| 162 if (index >= length) | |
| 163 break; | |
| 164 scaledValues.append(index); | |
| 165 } | |
| 166 } | |
| 167 | |
| 168 template <MatchType type> static int getScaledValue(const Vector<int>& scaledVal
ues, int valueToMatch, int searchStart) | |
| 169 { | |
| 170 if (scaledValues.isEmpty()) | |
| 171 return valueToMatch; | |
| 172 | |
| 173 const int* dataStart = scaledValues.data(); | |
| 174 const int* dataEnd = dataStart + scaledValues.size(); | |
| 175 const int* matched = std::lower_bound(dataStart + searchStart, dataEnd, valu
eToMatch); | |
| 176 switch (type) { | |
| 177 case Exact: | |
| 178 return matched != dataEnd && *matched == valueToMatch ? matched - dataSt
art : -1; | |
| 179 case LowerBound: | |
| 180 return matched != dataEnd && *matched == valueToMatch ? matched - dataSt
art : matched - dataStart - 1; | |
| 181 case UpperBound: | |
| 182 default: | |
| 183 return matched != dataEnd ? matched - dataStart : -1; | |
| 184 } | |
| 185 } | |
| 186 | |
| 187 void ImageDecoder::prepareScaleDataIfNecessary() | |
| 188 { | |
| 189 m_scaled = false; | |
| 190 m_scaledColumns.clear(); | |
| 191 m_scaledRows.clear(); | |
| 192 | |
| 193 int width = size().width(); | |
| 194 int height = size().height(); | |
| 195 int numPixels = height * width; | |
| 196 if (m_maxNumPixels <= 0 || numPixels <= m_maxNumPixels) | |
| 197 return; | |
| 198 | |
| 199 m_scaled = true; | |
| 200 double scale = sqrt(m_maxNumPixels / (double)numPixels); | |
| 201 fillScaledValues(m_scaledColumns, scale, width); | |
| 202 fillScaledValues(m_scaledRows, scale, height); | |
| 203 } | |
| 204 | |
| 205 int ImageDecoder::upperBoundScaledX(int origX, int searchStart) | |
| 206 { | |
| 207 return getScaledValue<UpperBound>(m_scaledColumns, origX, searchStart); | |
| 208 } | |
| 209 | |
| 210 int ImageDecoder::lowerBoundScaledX(int origX, int searchStart) | |
| 211 { | |
| 212 return getScaledValue<LowerBound>(m_scaledColumns, origX, searchStart); | |
| 213 } | |
| 214 | |
| 215 int ImageDecoder::upperBoundScaledY(int origY, int searchStart) | |
| 216 { | |
| 217 return getScaledValue<UpperBound>(m_scaledRows, origY, searchStart); | |
| 218 } | |
| 219 | |
| 220 int ImageDecoder::lowerBoundScaledY(int origY, int searchStart) | |
| 221 { | |
| 222 return getScaledValue<LowerBound>(m_scaledRows, origY, searchStart); | |
| 223 } | |
| 224 | |
| 225 int ImageDecoder::scaledY(int origY, int searchStart) | |
| 226 { | |
| 227 return getScaledValue<Exact>(m_scaledRows, origY, searchStart); | |
| 228 } | 141 } |
| 229 | 142 |
| 230 } // namespace WebCore | 143 } // namespace WebCore |
| OLD | NEW |