Changeset 494 for GraphicTest/Packages/bgrabitmap/bgracolorint.pas
- Timestamp:
- Dec 22, 2016, 8:49:19 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GraphicTest/Packages/bgrabitmap/bgracolorint.pas
r472 r494 26 26 operator *(const color1,color2: TColorInt65536): TColorInt65536; 27 27 operator *(const color1: TColorInt65536; factor65536: integer): TColorInt65536; 28 function ColorIntToBGRA(const AColor: TColorInt65536 ): TBGRAPixel;29 function BGRAToColorInt(const AColor: TBGRAPixel ): TColorInt65536;28 function ColorIntToBGRA(const AColor: TColorInt65536; AGammaCompression: boolean = false): TBGRAPixel; 29 function BGRAToColorInt(const AColor: TBGRAPixel; AGammaExpansion: boolean = false): TColorInt65536; 30 30 function BGRAToColorIntMultiply(const color1: TBGRAPixel; const color2: TColorInt65536): TColorInt65536; 31 31 … … 184 184 {$endif} 185 185 186 function BGRAToColorInt(const AColor: TBGRAPixel): TColorInt65536; 187 begin 188 result.r := AColor.red shl 8 + AColor.red + (AColor.red shr 7); 189 result.g := AColor.green shl 8 + AColor.green + (AColor.green shr 7); 190 result.b := AColor.blue shl 8 + AColor.blue + (AColor.blue shr 7); 186 function BGRAToColorInt(const AColor: TBGRAPixel; AGammaExpansion: boolean): TColorInt65536; 187 begin 188 if AGammaExpansion then 189 begin 190 result.r := GammaExpansionTab[AColor.red] + (AColor.red shr 7); 191 result.g := GammaExpansionTab[AColor.green] + (AColor.green shr 7); 192 result.b := GammaExpansionTab[AColor.blue] + (AColor.blue shr 7); 193 end else 194 begin 195 result.r := AColor.red shl 8 + AColor.red + (AColor.red shr 7); 196 result.g := AColor.green shl 8 + AColor.green + (AColor.green shr 7); 197 result.b := AColor.blue shl 8 + AColor.blue + (AColor.blue shr 7); 198 end; 191 199 result.a := AColor.alpha shl 8 + AColor.alpha+ (AColor.alpha shr 7); 192 200 end; … … 203 211 mov ecx, [Color1] 204 212 205 movzx eax, cl //b 213 mov eax, ecx 214 shr eax, TBGRAPixel_RedShift 215 and eax, 255 216 mov edx, eax 217 shr edx, 7 218 add eax, edx 219 imul [esi] 220 shl edx, 24 221 shr eax, 8 222 or edx, eax 223 mov [ebx], edx 224 225 mov eax, ecx 226 shr eax, TBGRAPixel_GreenShift 227 and eax, 255 228 mov edx, eax 229 shr edx, 7 230 add eax, edx 231 imul [esi+4] 232 shl edx, 24 233 shr eax, 8 234 or edx, eax 235 mov [ebx+4], edx 236 237 mov eax, ecx 238 shr eax, TBGRAPixel_BlueShift 239 and eax, 255 206 240 mov edx, eax 207 241 shr edx, 7 … … 212 246 or edx, eax 213 247 mov [ebx+8], edx 214 shr ecx, 8 215 216 movzx eax, cl //g 217 mov edx, eax 218 shr edx, 7 219 add eax, edx 220 imul [esi+4] 221 shl edx, 24 222 shr eax, 8 223 or edx, eax 224 mov [ebx+4], edx 225 shr ecx, 8 226 227 movzx eax, cl //r 228 mov edx, eax 229 shr edx, 7 230 add eax, edx 231 imul [esi] 232 shl edx, 24 233 shr eax, 8 234 or edx, eax 235 mov [ebx], edx 236 shr ecx, 8 237 238 movzx eax, cl //a 248 249 mov eax, ecx 250 shr eax, TBGRAPixel_AlphaShift 251 and eax, 255 239 252 mov edx, eax 240 253 shr edx, 7 … … 258 271 {$ENDIF} 259 272 260 function ColorIntToBGRA(const AColor: TColorInt65536 ): TBGRAPixel;273 function ColorIntToBGRA(const AColor: TColorInt65536; AGammaCompression: boolean): TBGRAPixel; 261 274 var maxValue,invMaxValue,r,g,b: integer; 262 275 begin … … 280 293 end; 281 294 282 if maxValue <= 65535 then 283 begin 284 if AColor.r <= 0 then result.red := 0 else 285 result.red := AColor.r shr 8 - (AColor.r shr 15); 286 287 if AColor.g <= 0 then result.green := 0 else 288 result.green := AColor.g shr 8 - (AColor.g shr 15); 289 290 if AColor.b <= 0 then result.blue := 0 else 291 result.blue := AColor.b shr 8 - (AColor.b shr 15); 292 exit; 293 end; 294 295 invMaxValue := (1073741824+maxValue-1) div maxValue; 296 maxValue := (maxValue-65535) shr 9; 297 if AColor.r < 0 then r := 0 else 298 r := AColor.r*invMaxValue shr 22 + maxValue; 299 if AColor.g < 0 then g := 0 else 300 g := AColor.g*invMaxValue shr 22 + maxValue; 301 if AColor.b < 0 then b := 0 else 302 b := AColor.b*invMaxValue shr 22 + maxValue; 303 304 if r >= 255 then result.red := 255 else 305 result.red := r; 306 if g >= 255 then result.green := 255 else 307 result.green := g; 308 if b >= 255 then result.blue := 255 else 309 result.blue := b; 295 if AGammaCompression then 296 begin 297 if maxValue <= 65535 then 298 begin 299 if AColor.r <= 0 then result.red := 0 else 300 result.red := GammaCompressionTab[AColor.r - (AColor.r shr 15)]; 301 302 if AColor.g <= 0 then result.green := 0 else 303 result.green :=GammaCompressionTab[AColor.g - (AColor.g shr 15)]; 304 305 if AColor.b <= 0 then result.blue := 0 else 306 result.blue := GammaCompressionTab[AColor.b - (AColor.b shr 15)]; 307 exit; 308 end; 309 310 invMaxValue := (1073741824+maxValue-1) div maxValue; 311 312 maxValue := (maxValue-65535) shr 1; 313 if AColor.r < 0 then r := maxValue else 314 r := AColor.r*invMaxValue shr 14 + maxValue; 315 if AColor.g < 0 then g := maxValue else 316 g := AColor.g*invMaxValue shr 14 + maxValue; 317 if AColor.b < 0 then b := maxValue else 318 b := AColor.b*invMaxValue shr 14 + maxValue; 319 320 if r >= 65535 then result.red := 255 else 321 result.red := GammaCompressionTab[r]; 322 if g >= 65535 then result.green := 255 else 323 result.green := GammaCompressionTab[g]; 324 if b >= 65535 then result.blue := 255 else 325 result.blue := GammaCompressionTab[b]; 326 end else 327 begin 328 if maxValue <= 65535 then 329 begin 330 if AColor.r <= 0 then result.red := 0 else 331 result.red := AColor.r shr 8 - (AColor.r shr 15); 332 333 if AColor.g <= 0 then result.green := 0 else 334 result.green := AColor.g shr 8 - (AColor.g shr 15); 335 336 if AColor.b <= 0 then result.blue := 0 else 337 result.blue := AColor.b shr 8 - (AColor.b shr 15); 338 exit; 339 end; 340 341 invMaxValue := (1073741824+maxValue-1) div maxValue; 342 343 maxValue := (maxValue-65535) shr 9; 344 if AColor.r < 0 then r := maxValue else 345 r := AColor.r*invMaxValue shr 22 + maxValue; 346 if AColor.g < 0 then g := maxValue else 347 g := AColor.g*invMaxValue shr 22 + maxValue; 348 if AColor.b < 0 then b := maxValue else 349 b := AColor.b*invMaxValue shr 22 + maxValue; 350 351 if r >= 255 then result.red := 255 else 352 result.red := r; 353 if g >= 255 then result.green := 255 else 354 result.green := g; 355 if b >= 255 then result.blue := 255 else 356 result.blue := b; 357 end; 310 358 end; 311 359
Note:
See TracChangeset
for help on using the changeset viewer.