bmpacc.cxx (9f62ea84) bmpacc.cxx (f8c0d554)
1/**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance

--- 310 unchanged lines hidden (view full) ---

319
320// ------------------------------------------------------------------
321
322sal_uInt16 BitmapReadAccess::GetBestPaletteIndex( const BitmapColor& rBitmapColor ) const
323{
324 return( HasPalette() ? mpBuffer->maPalette.GetBestIndex( rBitmapColor ) : 0 );
325}
326
1/**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance

--- 310 unchanged lines hidden (view full) ---

319
320// ------------------------------------------------------------------
321
322sal_uInt16 BitmapReadAccess::GetBestPaletteIndex( const BitmapColor& rBitmapColor ) const
323{
324 return( HasPalette() ? mpBuffer->maPalette.GetBestIndex( rBitmapColor ) : 0 );
325}
326
327BitmapColor BitmapReadAccess::GetInterpolatedColorWithFallback( double fY, double fX, const BitmapColor& rFallback ) const
328{
329 // ask directly doubles >= 0.0 here to avoid rounded values of 0 at small negative
330 // double values, e.g. static_cast< sal_Int32 >(-0.25) is 0, not -1, but *has* to be outside (!)
331 if(mpBuffer && fX >= 0.0 && fY >= 0.0)
332 {
333 const sal_Int32 nX(static_cast< sal_Int32 >(fX));
334 const sal_Int32 nY(static_cast< sal_Int32 >(fY));
335
336 if(nX < mpBuffer->mnWidth && nY < mpBuffer->mnHeight)
337 {
338 // get base-return value from inside pixel
339 BitmapColor aRetval(GetColor(nY, nX));
340
341 // calculate deltas and indices for neighbour accesses
342 sal_Int16 nDeltaX((fX - (nX + 0.5)) * 255.0); // [-255 .. 255]
343 sal_Int16 nDeltaY((fY - (nY + 0.5)) * 255.0); // [-255 .. 255]
344 sal_Int16 nIndX(0);
345 sal_Int16 nIndY(0);
346
347 if(nDeltaX > 0)
348 {
349 nIndX = nX + 1;
350 }
351 else
352 {
353 nIndX = nX - 1;
354 nDeltaX = -nDeltaX;
355 }
356
357 if(nDeltaY > 0)
358 {
359 nIndY = nY + 1;
360 }
361 else
362 {
363 nIndY = nY - 1;
364 nDeltaY = -nDeltaY;
365 }
366
367 // get right/left neighbour
368 BitmapColor aXCol(rFallback);
369
370 if(nDeltaX && nIndX >= 0 && nIndX < mpBuffer->mnWidth)
371 {
372 aXCol = GetColor(nY, nIndX);
373 }
374
375 // get top/bottom neighbour
376 BitmapColor aYCol(rFallback);
377
378 if(nDeltaY && nIndY >= 0 && nIndY < mpBuffer->mnHeight)
379 {
380 aYCol = GetColor(nIndY, nX);
381 }
382
383 // get one of four edge neighbours
384 BitmapColor aXYCol(rFallback);
385
386 if(nDeltaX && nDeltaY && nIndX >=0 && nIndY >= 0 && nIndX < mpBuffer->mnWidth && nIndY < mpBuffer->mnHeight)
387 {
388 aXYCol = GetColor(nIndY, nIndX);
389 }
390
391 // merge return value with right/left neighbour
392 if(aXCol != aRetval)
393 {
394 aRetval.Merge(aXCol, 255 - nDeltaX);
395 }
396
397 // merge top/bottom neighbour with edge
398 if(aYCol != aXYCol)
399 {
400 aYCol.Merge(aXYCol, 255 - nDeltaX);
401 }
402
403 // merge return value with already merged top/bottom neighbour
404 if(aRetval != aYCol)
405 {
406 aRetval.Merge(aYCol, 255 - nDeltaY);
407 }
408
409 return aRetval;
410 }
411 }
412
413 return rFallback;
414}
415
416BitmapColor BitmapReadAccess::GetColorWithFallback( double fY, double fX, const BitmapColor& rFallback ) const
417{
418 // ask directly doubles >= 0.0 here to avoid rounded values of 0 at small negative
419 // double values, e.g. static_cast< sal_Int32 >(-0.25) is 0, not -1, but *has* to be outside (!)
420 if(mpBuffer && fX >= 0.0 && fY >= 0.0)
421 {
422 const sal_Int32 nX(static_cast< sal_Int32 >(fX));
423 const sal_Int32 nY(static_cast< sal_Int32 >(fY));
424
425 if(nX < mpBuffer->mnWidth && nY < mpBuffer->mnHeight)
426 {
427 return GetColor(nY, nX);
428 }
429 }
430
431 return rFallback;
432}
433
434BitmapColor BitmapReadAccess::GetColorWithFallback( long nY, long nX, const BitmapColor& rFallback ) const
435{
436 if(mpBuffer)
437 {
438 if(nX >= 0 && nY >= 0 && nX < mpBuffer->mnWidth && nY < mpBuffer->mnHeight)
439 {
440 return GetColor(nY, nX);
441 }
442 }
443
444 return rFallback;
445}
446
327// ---------------------
328// - BitmapWriteAccess -
329// ---------------------
330
331BitmapWriteAccess::BitmapWriteAccess( Bitmap& rBitmap ) :
332 BitmapReadAccess( rBitmap, sal_True ),
333 mpLineColor ( NULL ),
334 mpFillColor ( NULL )

--- 112 unchanged lines hidden ---
447// ---------------------
448// - BitmapWriteAccess -
449// ---------------------
450
451BitmapWriteAccess::BitmapWriteAccess( Bitmap& rBitmap ) :
452 BitmapReadAccess( rBitmap, sal_True ),
453 mpLineColor ( NULL ),
454 mpFillColor ( NULL )

--- 112 unchanged lines hidden ---