/* -*- mode: C++; tab-width: 4; c-basic-offset: 4; -*- */ /* AbiSource * * Copyright (C) 2009 Marc 'Foddex' Oude Kotte * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. */ #include "abiword-garble.h" extern "C" { #include } //----------------------------------------------------------------------------- typedef struct { struct jpeg_destination_mgr pub; JOCTET *buf; size_t bufsize; size_t jpegsize; } mem_destination_mgr, *mem_dest_ptr; //----------------------------------------------------------------------------- static void _jpeg_init_destination( j_compress_ptr cinfo ) { mem_dest_ptr dest = (mem_dest_ptr) cinfo->dest; dest->pub.next_output_byte = dest->buf; dest->pub.free_in_buffer = dest->bufsize; dest->jpegsize = 0; } //----------------------------------------------------------------------------- static boolean _jpeg_empty_output_buffer( j_compress_ptr cinfo ) { mem_dest_ptr dest = (mem_dest_ptr) cinfo->dest; dest->pub.next_output_byte = dest->buf; dest->pub.free_in_buffer = dest->bufsize; return FALSE; } //----------------------------------------------------------------------------- static void _jpeg_term_destination( j_compress_ptr cinfo ) { mem_dest_ptr dest = (mem_dest_ptr) cinfo->dest; dest->jpegsize = dest->bufsize - dest->pub.free_in_buffer; } //----------------------------------------------------------------------------- bool abiword_document::garble_jpeg( void*& data, size_t& length ) { // get dimensions UT_ByteBuf bb; bb.append( static_cast( data), length ); UT_sint32 w, h; UT_JPEG_getDimensions( &bb, w, h ); // create garbled image with given dimensions size_t rowbytes = w * 3; char** dib = (char**) malloc( sizeof(char*) * h ); for (int i=0; ialloc_small)((j_common_ptr)&cinfo, JPOOL_PERMANENT, sizeof(mem_destination_mgr)); dest = (mem_dest_ptr) cinfo.dest; dest->pub.init_destination = _jpeg_init_destination; dest->pub.empty_output_buffer = _jpeg_empty_output_buffer; dest->pub.term_destination = _jpeg_term_destination; dest->buf = (JOCTET*)data; dest->bufsize = length; dest->jpegsize = 0; jpeg_start_compress (&cinfo, TRUE); // write data for (int i=0; ijpegsize; jpeg_destroy_compress(&cinfo); // cleanup for (int i=0; i