380{
382 BOOL rescale;
383 size_t newSize;
384 uint8_t components;
386
388
389
390 if (_originalWidth == 0) _originalWidth = _width;
391 if (_originalHeight == 0) _originalHeight = _height;
392 if (_rowBytes == 0) _rowBytes = _width * components;
393
394 pixMap =
OOMakePixMap(_data, _width, _height, components, _rowBytes, 0);
395
396 if (_extractChannel)
397 {
399 {
401 components = 1;
402 }
403 else
404 {
405 OOLogWARN(
@"texture.load.extractChannel.invalid",
@"Cannot extract channel from texture \"%@\
"", [_path lastPathComponent]);
406 }
407 }
408
409 [self getDesiredWidth:&desiredWidth andHeight:&desiredHeight];
410
412 {
414 desiredHeight =
MIN(desiredWidth * 2, 512U);
416 desiredWidth = desiredHeight * 2;
417
420 pixMap = converted;
421 _isCubeMap = NO;
422
423#if DUMP_CONVERTED_CUBE_MAPS
424 OODumpPixMap(pixMap, [NSString stringWithFormat:
@"converted cube map %@", [[_path lastPathComponent] stringByDeletingPathExtension]]);
425#endif
426 }
427
428
429 rescale = (_width != desiredWidth || _height != desiredHeight);
430 if (rescale)
431 {
432 BOOL leaveSpaceForMipMaps = _generateMipMaps;
433#if OO_TEXTURE_CUBE_MAP
434 if (_isCubeMap) leaveSpaceForMipMaps = NO;
435#endif
436
437 OOLog(
@"texture.load.rescale",
@"Rescaling texture \"%@\
" from %u x %u to %u x %u.", [_path lastPathComponent], pixMap.
width, pixMap.
height, desiredWidth, desiredHeight);
438
439 pixMap =
OOScalePixMap(pixMap, desiredWidth, desiredHeight, leaveSpaceForMipMaps);
441
443 _width = pixMap.
width;
446 }
447
448#if OO_TEXTURE_CUBE_MAP
449 if (_isCubeMap)
450 {
451 if (_generateMipMaps)
452 {
453 [self generateMipMapsForCubeMap];
454 }
455 return;
456 }
457#endif
458
459
460 if (_generateMipMaps)
461 {
462
463 newSize = desiredWidth * components * desiredHeight;
464 newSize = (newSize * 4) / 3;
465
467
469 _width = pixMap.
width;
472 }
473 if (_generateMipMaps)
474 {
476 }
477
478
479}
OOPixMap OOConvertCubeMapToLatLong(OOPixMap sourcePixMap, OOPixMapDimension height, BOOL leaveSpaceForMipMaps)
#define OOLogWARN(class, format,...)
#define OOLog(class, format,...)
BOOL OOExtractPixMapChannel(OOPixMap *ioPixMap, uint8_t channelIndex, BOOL compactWhenDone)
BOOL OOPixMapToRGBA(OOPixMap *ioPixMap)
uint_fast32_t OOPixMapDimension
void OOFreePixMap(OOPixMap *ioPixMap)
void OODumpPixMap(OOPixMap pixMap, NSString *name)
OOPixMap OOMakePixMap(void *pixels, OOPixMapDimension width, OOPixMapDimension height, OOPixMapFormat format, size_t rowBytes, size_t bufferSize)
BOOL OOIsValidPixMap(OOPixMap pixMap)
BOOL OOExpandPixMap(OOPixMap *ioPixMap, size_t desiredSize)
static BOOL sReducedDetail
OOPixMap OOScalePixMap(OOPixMap srcPixMap, OOPixMapDimension dstWidth, OOPixMapDimension dstHeight, BOOL leaveSpaceForMipMaps)
BOOL OOGenerateMipMaps(void *textureBytes, OOPixMapDimension width, OOPixMapDimension height, OOPixMapFormat format)
BOOL OOCubeMapsAvailable(void)
uint8_t OOTextureComponentsForFormat(OOTextureDataFormat format)
@ kOOTextureDataGrayscale