348{
350 BOOL rescale;
351 size_t newSize;
352 uint8_t components;
354
356
357
358 if (_originalWidth == 0)
359 _originalWidth = _width;
360 if (_originalHeight == 0)
361 _originalHeight = _height;
362 if (_rowBytes == 0)
363 _rowBytes = _width * components;
364
365 pixMap =
OOMakePixMap(_data, _width, _height, components, _rowBytes, 0);
366
367 if (_extractChannel) {
370 components = 1;
371 } else {
372 OOLogWARN(
@"texture.load.extractChannel.invalid",
@"Cannot extract channel from texture \"%@\
"", [_path lastPathComponent]);
373 }
374 }
375
376 [self getDesiredWidth:&desiredWidth andHeight:&desiredHeight];
377
380 desiredHeight =
MIN(desiredWidth * 2, 512U);
382 desiredHeight /= 2;
383 desiredWidth = desiredHeight * 2;
384
387 pixMap = converted;
388 _isCubeMap = NO;
389
390#if DUMP_CONVERTED_CUBE_MAPS
391 OODumpPixMap(pixMap, [NSString stringWithFormat:
@"converted cube map %@", [[_path lastPathComponent] stringByDeletingPathExtension]]);
392#endif
393 }
394
395
396 rescale = (_width != desiredWidth || _height != desiredHeight);
397 if (rescale) {
398 BOOL leaveSpaceForMipMaps = _generateMipMaps;
399#if OO_TEXTURE_CUBE_MAP
400 if (_isCubeMap)
401 leaveSpaceForMipMaps = NO;
402#endif
403
404 OOLog(
@"texture.load.rescale",
@"Rescaling texture \"%@\
" from %u x %u to %u x %u.", [_path lastPathComponent], pixMap.
width, pixMap.
height, desiredWidth, desiredHeight);
405
406 pixMap =
OOScalePixMap(pixMap, desiredWidth, desiredHeight, leaveSpaceForMipMaps);
408 return;
409
411 _width = pixMap.
width;
414 }
415
416#if OO_TEXTURE_CUBE_MAP
417 if (_isCubeMap) {
418 if (_generateMipMaps) {
419 [self generateMipMapsForCubeMap];
420 }
421 return;
422 }
423#endif
424
425
426 if (_generateMipMaps) {
427
428 newSize = desiredWidth * components * desiredHeight;
429 newSize = (newSize * 4) / 3;
430
432
434 _width = pixMap.
width;
437 }
438 if (_generateMipMaps) {
440 }
441
442
443}
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)
void OOFreePixMap(OOPixMap *ioPixMap)
uint32_t OOPixMapDimension
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