static bool read_tile(openslide_t *osr, cairo_t *cr, struct _openslide_level *level, int64_t tile_col, int64_t tile_row, void *arg, GError **err) { struct level *l = (struct level *) level; struct _openslide_tiff_level *tiffl = &l->tiffl; TIFF *tiff = arg; // tile size int64_t tw = tiffl->tile_w; int64_t th = tiffl->tile_h; // cache struct _openslide_cache_entry *cache_entry; uint32_t *tiledata = _openslide_cache_get(osr->cache, level, tile_col, tile_row, &cache_entry); if (!tiledata) { tiledata = g_slice_alloc(tw * th * 4); if (!decode_tile(l, tiff, tiledata, tile_col, tile_row, err)) { g_slice_free1(tw * th * 4, tiledata); return false; } // clip, if necessary if (!_openslide_tiff_clip_tile(tiffl, tiledata, tile_col, tile_row, err)) { g_slice_free1(tw * th * 4, tiledata); return false; } // put it in the cache _openslide_cache_put(osr->cache, level, tile_col, tile_row, tiledata, tw * th * 4, &cache_entry); } // draw it cairo_surface_t *surface = cairo_image_surface_create_for_data((unsigned char *) tiledata, CAIRO_FORMAT_ARGB32, tw, th, tw * 4); cairo_set_source_surface(cr, surface, 0, 0); cairo_surface_destroy(surface); cairo_paint(cr); // done with the cache entry, release it _openslide_cache_entry_unref(cache_entry); return true; }
void CXCCTMPEditorView::OnDraw(CDC* pDC) { CXCCTMPEditorDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); pDC->GetClipBox(&m_clip_rect); TEXTMETRIC tm; pDC->GetTextMetrics(&tm); int x = 0; int y = 0; int y_inc = tm.tmHeight; t_rect global = pDoc->get_rect(view_true_height()); { int cx = global.r - global.x; int cy = global.b - global.y; byte* d = new byte[cx * cy]; pDoc->draw(d, m_selected, view_true_height()); load_color_table(pDoc->palet()); draw_image8(d, cx, cy, pDC, 0, y); y += cy + y_inc; delete[] d; } typedef CXCCTMPEditorDoc::t_map t_map; int cx = pDoc->header().cx; int cy = pDoc->header().cy; byte* d = new byte[cx * cy]; t_map map = pDoc->map(); int selection_color = 0xffffff; CBrush brush(selection_color); for (t_map::const_iterator i = map.begin(); i != map.end(); i++) { const t_tmp_image_header& header = i->second.header; if (i->second.extra_data.data()) { load_color_table(pDoc->palet()); draw_image8(i->second.extra_data.data(), header.cx_extra, header.cy_extra, pDC, 0, y); if (m_selected == i->first) pDC->FrameRect(CRect(CPoint(header.x_extra - global.x, header.y_extra - global.y - header.height * (cy / 2)), CSize(header.cx_extra, header.cy_extra)), &brush); // pDC->FrameRect(CRect(CPoint(header.x_extra - global.x, header.y_extra - global.y), CSize(header.cx_extra, header.cy_extra)), &brush); if (i->second.extra_z_data.data()) { load_grey_table(32); draw_image8(i->second.extra_z_data.data(), header.cx_extra, header.cy_extra, pDC, cx + y_inc, y); } y += header.cy_extra + y_inc; } decode_tile(i->second.data.data(), d, cx); load_color_table(pDoc->palet()); draw_image8(d, cx, cy, pDC, 0, y); if (m_selected == i->first) { // pDC->FrameRect(CRect(CPoint(header.x - global.x, header.y - global.y), CSize(cx, cy)), &brush); /* int half_cx = cx >> 1; int half_cy = cy >> 1; CPoint tl = CPoint(header.x - global.x, header.y - global.y); CPen pen(PS_SOLID, 1, selection_color); CPen* old_pen = pDC->SelectObject(&pen); pDC->MoveTo(tl + CPoint(half_cx, 0)); pDC->LineTo(tl + CPoint(cx, half_cy)); pDC->LineTo(tl + CPoint(half_cx, cy)); pDC->LineTo(tl + CPoint(0, half_cy)); pDC->LineTo(tl + CPoint(half_cx, 0)); pDC->SelectObject(old_pen); */ } if (i->second.z_data.data()) { decode_tile(i->second.z_data.data(), d, cx); load_grey_table(32); draw_image8(d, cx, cy, pDC, cx + y_inc, y); x = max(x, 2 * cx + y_inc); } y += cy + y_inc; } delete[] d; SetScrollSizes(MM_TEXT, CSize(x, y)); }
/** * @brief Main decoder function. It all starts here. * Input parameters: * 1) input JPEG 2000 image * * @return 0 on success */ int main(int argc, char **argv) { // println_start(INFO); type_image *img = (type_image *)malloc(sizeof(type_image)); memset(img, 0, sizeof(type_image)); if((parse_args(argc, argv, img) == ERROR) || (check_args_dec(img) == ERROR)) { fprintf(stderr, "Error occurred while parsing arguments.\n"); fprintf(stdout, "%s", help); return 1; } type_parameters *param = (type_parameters*)malloc(sizeof(type_parameters)); if((parse_config(img->conf_file, param) == ERROR) || (check_config(param) == ERROR)) { fprintf(stderr, "Error occurred while parsing configuration file.\n"); fprintf(stdout, "%s", help); return 1; } init_device(param); FILE *fsrc = fopen(img->in_file, "rb"); if (!fsrc) { fprintf(stderr, "Error, failed to open %s for reading\n", img->in_file); return 1; } type_tile *tile; int i; if(strstr(img->in_file, ".jp2") != NULL) { println(INFO, "It's a JP2 file"); //parse the JP2 boxes jp2_parse_boxes(fsrc, img); fclose(fsrc); // Do decoding for all tiles for(i = 0; i < img->num_tiles; i++) { tile = &(img->tile[i]); /* Decode data */ decode_tile(tile); /* Dequantize data */ dequantize_tile(tile); /* Do inverse wavelet transform */ iwt(tile); } if(img->use_mct == 1) { // lossless decoder if(img->wavelet_type == 0) { color_decoder_lossless(img); } else { //lossy decoder color_decoder_lossy(img); } } else if (img->use_part2_mct == 1) { decode_klt(img); } else { if(img->sign == UNSIGNED) { idc_level_shifting(img); } } } else {//It is not a JP2 file. type_buffer *src_buff = (type_buffer *) malloc(sizeof(type_buffer)); init_dec_buffer(fsrc, src_buff); fclose(fsrc); decode_codestream(src_buff, img); // get_next_box(fsrc); // Do decoding for all tiles for(i = 0; i < img->num_tiles; i++) { tile = &(img->tile[i]); /* Decode data */ decode_tile(tile); /* Dequantize data */ dequantize_tile(tile); /* Do inverse wavelet transform */ iwt(tile); } if(img->use_mct == 1) { // lossless decoder if(img->wavelet_type == 0) { color_decoder_lossless(img); } else { //lossy decoder color_decoder_lossy(img); } } else if (img->use_part2_mct == 1) { decode_klt(img); } else { if(img->sign == UNSIGNED) { idc_level_shifting(img); } } } save_image(img); }