mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-12-24 21:16:50 +03:00
Reverting r12367, cannot get incremental image loading to work correctly.
svn path=/trunk/netsurf/; revision=12432
This commit is contained in:
parent
830da3a915
commit
658959bc88
@ -44,12 +44,10 @@ static bool apple_image_redraw(struct content *c, int x, int y,
|
||||
static nserror apple_image_clone(const struct content *old,
|
||||
struct content **newc);
|
||||
static content_type apple_image_content_type(lwc_string *mime_type);
|
||||
static bool apple_image_process_data(struct content *c, const char *data, unsigned int size);
|
||||
|
||||
static const content_handler apple_image_content_handler = {
|
||||
.create = apple_image_create,
|
||||
.data_complete = apple_image_convert,
|
||||
.process_data = apple_image_process_data,
|
||||
.destroy = apple_image_destroy,
|
||||
.redraw = apple_image_redraw,
|
||||
.clone = apple_image_clone,
|
||||
@ -57,9 +55,6 @@ static const content_handler apple_image_content_handler = {
|
||||
.no_share = false
|
||||
};
|
||||
|
||||
static NSBitmapImageRep *ImageRepForContent( struct content *c );
|
||||
static NSData *DataForContent( struct content * c);
|
||||
|
||||
static nserror register_for_type( NSString *mime )
|
||||
{
|
||||
const char *type = [mime UTF8String];
|
||||
@ -137,21 +132,22 @@ nserror apple_image_create(const content_handler *handler,
|
||||
|
||||
bool apple_image_convert(struct content *c)
|
||||
{
|
||||
NSBitmapImageRep *image = ImageRepForContent( c );
|
||||
if (image == nil) return false;
|
||||
|
||||
NSData *data = DataForContent( c );
|
||||
|
||||
NSInteger rc = [image incrementalLoadFromData: data complete: YES];
|
||||
if (rc != NSImageRepLoadStatusCompleted) {
|
||||
unsigned long size;
|
||||
const char *bytes = content__get_source_data(c, &size);
|
||||
|
||||
NSData *data = [NSData dataWithBytesNoCopy: (char *)bytes length: size freeWhenDone: NO];
|
||||
NSBitmapImageRep *image = [[NSBitmapImageRep imageRepWithData: data] retain];
|
||||
|
||||
if (image == nil) {
|
||||
union content_msg_data msg_data;
|
||||
msg_data.error = "invalid image data";
|
||||
msg_data.error = "cannot decode image";
|
||||
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
|
||||
return false;
|
||||
}
|
||||
|
||||
c->width = [image pixelsWide];
|
||||
c->height = [image pixelsHigh];
|
||||
c->bitmap = (void *)image;
|
||||
|
||||
NSString *url = [NSString stringWithUTF8String: llcache_handle_get_url( content_get_llcache_handle( c ) )];
|
||||
NSString *title = [NSString stringWithFormat: @"%@ (%dx%d)", [url lastPathComponent], c->width, c->height];
|
||||
@ -225,45 +221,4 @@ bool apple_image_redraw(struct content *c, int x, int y,
|
||||
flags);
|
||||
}
|
||||
|
||||
bool apple_image_process_data(struct content *c, const char *newData, unsigned int newSize)
|
||||
{
|
||||
NSBitmapImageRep *image = ImageRepForContent( c );
|
||||
if (image == nil) return false;
|
||||
|
||||
NSData *data = DataForContent( c );
|
||||
|
||||
NSInteger rc = [image incrementalLoadFromData: data complete: NO];
|
||||
if (rc == NSImageRepLoadStatusInvalidData) {
|
||||
union content_msg_data msg_data;
|
||||
msg_data.error = "invalid data";
|
||||
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
NSData *DataForContent( struct content * c)
|
||||
{
|
||||
unsigned long sz = 0;
|
||||
const char *bytes = content__get_source_data(c, &sz );
|
||||
return [NSData dataWithBytesNoCopy: (char *)bytes length: sz freeWhenDone: NO];
|
||||
}
|
||||
|
||||
NSBitmapImageRep *ImageRepForContent( struct content *c )
|
||||
{
|
||||
NSBitmapImageRep *image = (NSBitmapImageRep *)c->bitmap;
|
||||
if (image == nil) {
|
||||
image = [[NSBitmapImageRep alloc] initForIncrementalLoad];
|
||||
if (image == nil) {
|
||||
union content_msg_data msg_data;
|
||||
msg_data.error = "not enough memory for image";
|
||||
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
|
||||
}
|
||||
c->bitmap = (void *)image;
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
|
||||
#endif /* WITH_APPLE_IMAGE */
|
||||
|
Loading…
Reference in New Issue
Block a user