/* Must remain idempotent. Also used to make sure that the ic->quantize has the same colorSpace info as the rest of ic. */ int il_init_quantize(il_container *ic) { size_t arraysize; int i, j; my_cquantize_ptr cquantize; if (ic->quantize) il_free_quantize(ic); ic->quantize = XP_NEW_ZAP(my_cquantize); if (!ic->quantize) { loser: ILTRACE(0,("il: MEM il_init_quantize")); return FALSE; } cquantize = (my_cquantize_ptr) ic->quantize; arraysize = (size_t) ((ic->image->header.width + 2) * SIZEOF(FSERROR)); for (i = 0; i < 3; i++) { cquantize->fserrors[i] = (FSERRPTR) XP_CALLOC(1, arraysize); if (!cquantize->fserrors[i]) { /* ran out of memory part way thru */ for (j = 0; j < i; j++) { if (cquantize->fserrors[j]) { XP_FREE(cquantize->fserrors[j]); cquantize->fserrors[j]=0; } } if (cquantize) { XP_FREE(cquantize); ic->quantize = 0; } goto loser; } } return TRUE; }
NET_StreamClass * IL_ViewStream(FO_Present_Types format_out, void *newshack, URL_Struct *urls, OPAQUE_CONTEXT *cx) { IL_Stream *stream = nil, *viewstream; il_container *ic = nil; char *org_content_type; char *image_url; /* multi-part reconnect hack */ ic = (il_container*)urls->fe_data; if(ic && ic->multi) { return IL_NewStream(format_out, IL_UNKNOWN, urls, cx); } /* Create stream object */ if (!(stream = XP_NEW_ZAP(NET_StreamClass))) { XP_TRACE(("il: IL_ViewStream memory lossage")); return 0; } stream->name = "image view"; stream->complete = il_view_complete; stream->abort = il_view_abort; stream->is_write_ready = il_view_write_ready; stream->data_object = NULL; stream->window_id = cx; stream->put_block = (MKStreamWriteFunc)il_view_write; ILTRACE(0,("il: new view stream, %s", urls->address)); XP_ASSERT(!unconnected_stream); unconnected_stream = stream; unconnected_urls = urls; if(!newshack) { char *buffer; org_content_type = urls->content_type; urls->content_type = 0; StrAllocCopy(urls->content_type, TEXT_HTML); urls->is_binary = 1; /* secret flag for mail-to save as */ /* Force layout to discard the old document and start a new one. We do this so that the pre-fetched image request won't be destroyed by a layout call to IL_DestroyImageGroup. */ viewstream = NET_StreamBuilder(format_out, urls, cx); if (!viewstream) { XP_FREE(stream); return NULL; } buffer = XP_STRDUP("<HTML>"); if (!buffer) { XP_FREE(stream); XP_FREE(viewstream); return NULL; } (*viewstream->put_block)(viewstream, buffer, XP_STRLEN(buffer)+1); XP_FREE(buffer); } /* !newshack */ /* Prefetch the image. We do this so that the image library can process image data even if the parser is blocked on the fake IMG tag that we send. Note that this image request will persist until the document is destroyed (when IL_DestroyImageGroup will be called.) */ image_url = (char*) XP_ALLOC(XP_STRLEN(urls->address) + 29); if (!image_url) { XP_FREE(stream); XP_FREE(viewstream); return NULL; } XP_SPRINTF(image_url, "internal-external-reconnect:%s", urls->address); if (!il_load_image(cx, image_url, urls->force_reload)) { XP_FREE(stream); XP_FREE(viewstream); return NULL; } XP_FREE(image_url); if (!newshack) { if (viewstream) { char *buffer = (char*) XP_ALLOC(XP_STRLEN(fakehtml) + XP_STRLEN(urls->address) + 1); if (buffer) { XP_SPRINTF(buffer, fakehtml, urls->address); (*viewstream->put_block)(viewstream, buffer, XP_STRLEN(buffer)); XP_FREE(buffer); } (*viewstream->complete)(viewstream); } /* this has to be set back for abort to work correctly */ XP_FREE(urls->content_type); urls->content_type = org_content_type; } /* !newshack */ return stream; }