12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628 |
- #define JPEG_INTERNALS
- #include "jinclude.h"
- #include "jpeglib.h"
- #include "transupp.h"
- #include "jpegcomp.h"
- #include <ctype.h> /* to declare isdigit() */
- #if JPEG_LIB_VERSION >= 70
- #define dstinfo_min_DCT_h_scaled_size dstinfo->min_DCT_h_scaled_size
- #define dstinfo_min_DCT_v_scaled_size dstinfo->min_DCT_v_scaled_size
- #else
- #define dstinfo_min_DCT_h_scaled_size DCTSIZE
- #define dstinfo_min_DCT_v_scaled_size DCTSIZE
- #endif
- #if TRANSFORMS_SUPPORTED
- LOCAL(void)
- do_crop(j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
- JDIMENSION x_crop_offset, JDIMENSION y_crop_offset,
- jvirt_barray_ptr *src_coef_arrays,
- jvirt_barray_ptr *dst_coef_arrays)
- {
- JDIMENSION dst_blk_y, x_crop_blocks, y_crop_blocks;
- int ci, offset_y;
- JBLOCKARRAY src_buffer, dst_buffer;
- jpeg_component_info *compptr;
-
- for (ci = 0; ci < dstinfo->num_components; ci++) {
- compptr = dstinfo->comp_info + ci;
- x_crop_blocks = x_crop_offset * compptr->h_samp_factor;
- y_crop_blocks = y_crop_offset * compptr->v_samp_factor;
- for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
- dst_blk_y += compptr->v_samp_factor) {
- dst_buffer = (*srcinfo->mem->access_virt_barray)
- ((j_common_ptr)srcinfo, dst_coef_arrays[ci], dst_blk_y,
- (JDIMENSION)compptr->v_samp_factor, TRUE);
- src_buffer = (*srcinfo->mem->access_virt_barray)
- ((j_common_ptr)srcinfo, src_coef_arrays[ci],
- dst_blk_y + y_crop_blocks,
- (JDIMENSION)compptr->v_samp_factor, FALSE);
- for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
- jcopy_block_row(src_buffer[offset_y] + x_crop_blocks,
- dst_buffer[offset_y],
- compptr->width_in_blocks);
- }
- }
- }
- }
- LOCAL(void)
- do_flip_h_no_crop(j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
- JDIMENSION x_crop_offset, jvirt_barray_ptr *src_coef_arrays)
- {
- JDIMENSION MCU_cols, comp_width, blk_x, blk_y, x_crop_blocks;
- int ci, k, offset_y;
- JBLOCKARRAY buffer;
- JCOEFPTR ptr1, ptr2;
- JCOEF temp1, temp2;
- jpeg_component_info *compptr;
-
- MCU_cols = srcinfo->output_width /
- (dstinfo->max_h_samp_factor * dstinfo_min_DCT_h_scaled_size);
- for (ci = 0; ci < dstinfo->num_components; ci++) {
- compptr = dstinfo->comp_info + ci;
- comp_width = MCU_cols * compptr->h_samp_factor;
- x_crop_blocks = x_crop_offset * compptr->h_samp_factor;
- for (blk_y = 0; blk_y < compptr->height_in_blocks;
- blk_y += compptr->v_samp_factor) {
- buffer = (*srcinfo->mem->access_virt_barray)
- ((j_common_ptr)srcinfo, src_coef_arrays[ci], blk_y,
- (JDIMENSION)compptr->v_samp_factor, TRUE);
- for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
-
- for (blk_x = 0; blk_x * 2 < comp_width; blk_x++) {
- ptr1 = buffer[offset_y][blk_x];
- ptr2 = buffer[offset_y][comp_width - blk_x - 1];
-
- for (k = 0; k < DCTSIZE2; k += 2) {
- temp1 = *ptr1;
- temp2 = *ptr2;
- *ptr1++ = temp2;
- *ptr2++ = temp1;
- temp1 = *ptr1;
- temp2 = *ptr2;
- *ptr1++ = -temp2;
- *ptr2++ = -temp1;
- }
- }
- if (x_crop_blocks > 0) {
-
- for (blk_x = 0; blk_x < compptr->width_in_blocks; blk_x++) {
- jcopy_block_row(buffer[offset_y] + blk_x + x_crop_blocks,
- buffer[offset_y] + blk_x, (JDIMENSION)1);
- }
- }
- }
- }
- }
- }
- LOCAL(void)
- do_flip_h(j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
- JDIMENSION x_crop_offset, JDIMENSION y_crop_offset,
- jvirt_barray_ptr *src_coef_arrays,
- jvirt_barray_ptr *dst_coef_arrays)
- {
- JDIMENSION MCU_cols, comp_width, dst_blk_x, dst_blk_y;
- JDIMENSION x_crop_blocks, y_crop_blocks;
- int ci, k, offset_y;
- JBLOCKARRAY src_buffer, dst_buffer;
- JBLOCKROW src_row_ptr, dst_row_ptr;
- JCOEFPTR src_ptr, dst_ptr;
- jpeg_component_info *compptr;
-
- MCU_cols = srcinfo->output_width /
- (dstinfo->max_h_samp_factor * dstinfo_min_DCT_h_scaled_size);
- for (ci = 0; ci < dstinfo->num_components; ci++) {
- compptr = dstinfo->comp_info + ci;
- comp_width = MCU_cols * compptr->h_samp_factor;
- x_crop_blocks = x_crop_offset * compptr->h_samp_factor;
- y_crop_blocks = y_crop_offset * compptr->v_samp_factor;
- for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
- dst_blk_y += compptr->v_samp_factor) {
- dst_buffer = (*srcinfo->mem->access_virt_barray)
- ((j_common_ptr)srcinfo, dst_coef_arrays[ci], dst_blk_y,
- (JDIMENSION)compptr->v_samp_factor, TRUE);
- src_buffer = (*srcinfo->mem->access_virt_barray)
- ((j_common_ptr)srcinfo, src_coef_arrays[ci],
- dst_blk_y + y_crop_blocks,
- (JDIMENSION)compptr->v_samp_factor, FALSE);
- for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
- dst_row_ptr = dst_buffer[offset_y];
- src_row_ptr = src_buffer[offset_y];
- for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
- dst_blk_x++) {
- if (x_crop_blocks + dst_blk_x < comp_width) {
-
- dst_ptr = dst_row_ptr[dst_blk_x];
- src_ptr = src_row_ptr[comp_width - x_crop_blocks - dst_blk_x - 1];
-
- for (k = 0; k < DCTSIZE2; k += 2) {
- *dst_ptr++ = *src_ptr++;
- *dst_ptr++ = - *src_ptr++;
- }
- } else {
-
- jcopy_block_row(src_row_ptr + dst_blk_x + x_crop_blocks,
- dst_row_ptr + dst_blk_x, (JDIMENSION)1);
- }
- }
- }
- }
- }
- }
- LOCAL(void)
- do_flip_v(j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
- JDIMENSION x_crop_offset, JDIMENSION y_crop_offset,
- jvirt_barray_ptr *src_coef_arrays,
- jvirt_barray_ptr *dst_coef_arrays)
- {
- JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y;
- JDIMENSION x_crop_blocks, y_crop_blocks;
- int ci, i, j, offset_y;
- JBLOCKARRAY src_buffer, dst_buffer;
- JBLOCKROW src_row_ptr, dst_row_ptr;
- JCOEFPTR src_ptr, dst_ptr;
- jpeg_component_info *compptr;
-
- MCU_rows = srcinfo->output_height /
- (dstinfo->max_v_samp_factor * dstinfo_min_DCT_v_scaled_size);
- for (ci = 0; ci < dstinfo->num_components; ci++) {
- compptr = dstinfo->comp_info + ci;
- comp_height = MCU_rows * compptr->v_samp_factor;
- x_crop_blocks = x_crop_offset * compptr->h_samp_factor;
- y_crop_blocks = y_crop_offset * compptr->v_samp_factor;
- for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
- dst_blk_y += compptr->v_samp_factor) {
- dst_buffer = (*srcinfo->mem->access_virt_barray)
- ((j_common_ptr)srcinfo, dst_coef_arrays[ci], dst_blk_y,
- (JDIMENSION)compptr->v_samp_factor, TRUE);
- if (y_crop_blocks + dst_blk_y < comp_height) {
-
- src_buffer = (*srcinfo->mem->access_virt_barray)
- ((j_common_ptr)srcinfo, src_coef_arrays[ci],
- comp_height - y_crop_blocks - dst_blk_y -
- (JDIMENSION)compptr->v_samp_factor,
- (JDIMENSION)compptr->v_samp_factor, FALSE);
- } else {
-
- src_buffer = (*srcinfo->mem->access_virt_barray)
- ((j_common_ptr)srcinfo, src_coef_arrays[ci],
- dst_blk_y + y_crop_blocks,
- (JDIMENSION)compptr->v_samp_factor, FALSE);
- }
- for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
- if (y_crop_blocks + dst_blk_y < comp_height) {
-
- dst_row_ptr = dst_buffer[offset_y];
- src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1];
- src_row_ptr += x_crop_blocks;
- for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
- dst_blk_x++) {
- dst_ptr = dst_row_ptr[dst_blk_x];
- src_ptr = src_row_ptr[dst_blk_x];
- for (i = 0; i < DCTSIZE; i += 2) {
-
- for (j = 0; j < DCTSIZE; j++)
- *dst_ptr++ = *src_ptr++;
-
- for (j = 0; j < DCTSIZE; j++)
- *dst_ptr++ = - *src_ptr++;
- }
- }
- } else {
-
- jcopy_block_row(src_buffer[offset_y] + x_crop_blocks,
- dst_buffer[offset_y],
- compptr->width_in_blocks);
- }
- }
- }
- }
- }
- LOCAL(void)
- do_transpose(j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
- JDIMENSION x_crop_offset, JDIMENSION y_crop_offset,
- jvirt_barray_ptr *src_coef_arrays,
- jvirt_barray_ptr *dst_coef_arrays)
- {
- JDIMENSION dst_blk_x, dst_blk_y, x_crop_blocks, y_crop_blocks;
- int ci, i, j, offset_x, offset_y;
- JBLOCKARRAY src_buffer, dst_buffer;
- JCOEFPTR src_ptr, dst_ptr;
- jpeg_component_info *compptr;
-
- for (ci = 0; ci < dstinfo->num_components; ci++) {
- compptr = dstinfo->comp_info + ci;
- x_crop_blocks = x_crop_offset * compptr->h_samp_factor;
- y_crop_blocks = y_crop_offset * compptr->v_samp_factor;
- for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
- dst_blk_y += compptr->v_samp_factor) {
- dst_buffer = (*srcinfo->mem->access_virt_barray)
- ((j_common_ptr)srcinfo, dst_coef_arrays[ci], dst_blk_y,
- (JDIMENSION)compptr->v_samp_factor, TRUE);
- for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
- for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
- dst_blk_x += compptr->h_samp_factor) {
- src_buffer = (*srcinfo->mem->access_virt_barray)
- ((j_common_ptr)srcinfo, src_coef_arrays[ci],
- dst_blk_x + x_crop_blocks,
- (JDIMENSION)compptr->h_samp_factor, FALSE);
- for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
- dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
- src_ptr =
- src_buffer[offset_x][dst_blk_y + offset_y + y_crop_blocks];
- for (i = 0; i < DCTSIZE; i++)
- for (j = 0; j < DCTSIZE; j++)
- dst_ptr[j * DCTSIZE + i] = src_ptr[i * DCTSIZE + j];
- }
- }
- }
- }
- }
- }
- LOCAL(void)
- do_rot_90(j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
- JDIMENSION x_crop_offset, JDIMENSION y_crop_offset,
- jvirt_barray_ptr *src_coef_arrays,
- jvirt_barray_ptr *dst_coef_arrays)
- {
- JDIMENSION MCU_cols, comp_width, dst_blk_x, dst_blk_y;
- JDIMENSION x_crop_blocks, y_crop_blocks;
- int ci, i, j, offset_x, offset_y;
- JBLOCKARRAY src_buffer, dst_buffer;
- JCOEFPTR src_ptr, dst_ptr;
- jpeg_component_info *compptr;
-
- MCU_cols = srcinfo->output_height /
- (dstinfo->max_h_samp_factor * dstinfo_min_DCT_h_scaled_size);
- for (ci = 0; ci < dstinfo->num_components; ci++) {
- compptr = dstinfo->comp_info + ci;
- comp_width = MCU_cols * compptr->h_samp_factor;
- x_crop_blocks = x_crop_offset * compptr->h_samp_factor;
- y_crop_blocks = y_crop_offset * compptr->v_samp_factor;
- for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
- dst_blk_y += compptr->v_samp_factor) {
- dst_buffer = (*srcinfo->mem->access_virt_barray)
- ((j_common_ptr)srcinfo, dst_coef_arrays[ci], dst_blk_y,
- (JDIMENSION)compptr->v_samp_factor, TRUE);
- for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
- for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
- dst_blk_x += compptr->h_samp_factor) {
- if (x_crop_blocks + dst_blk_x < comp_width) {
-
- src_buffer = (*srcinfo->mem->access_virt_barray)
- ((j_common_ptr)srcinfo, src_coef_arrays[ci],
- comp_width - x_crop_blocks - dst_blk_x -
- (JDIMENSION)compptr->h_samp_factor,
- (JDIMENSION)compptr->h_samp_factor, FALSE);
- } else {
-
- src_buffer = (*srcinfo->mem->access_virt_barray)
- ((j_common_ptr)srcinfo, src_coef_arrays[ci],
- dst_blk_x + x_crop_blocks,
- (JDIMENSION)compptr->h_samp_factor, FALSE);
- }
- for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
- dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
- if (x_crop_blocks + dst_blk_x < comp_width) {
-
- src_ptr = src_buffer[compptr->h_samp_factor - offset_x - 1]
- [dst_blk_y + offset_y + y_crop_blocks];
- for (i = 0; i < DCTSIZE; i++) {
- for (j = 0; j < DCTSIZE; j++)
- dst_ptr[j * DCTSIZE + i] = src_ptr[i * DCTSIZE + j];
- i++;
- for (j = 0; j < DCTSIZE; j++)
- dst_ptr[j * DCTSIZE + i] = -src_ptr[i * DCTSIZE + j];
- }
- } else {
-
- src_ptr = src_buffer[offset_x]
- [dst_blk_y + offset_y + y_crop_blocks];
- for (i = 0; i < DCTSIZE; i++)
- for (j = 0; j < DCTSIZE; j++)
- dst_ptr[j * DCTSIZE + i] = src_ptr[i * DCTSIZE + j];
- }
- }
- }
- }
- }
- }
- }
- LOCAL(void)
- do_rot_270(j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
- JDIMENSION x_crop_offset, JDIMENSION y_crop_offset,
- jvirt_barray_ptr *src_coef_arrays,
- jvirt_barray_ptr *dst_coef_arrays)
- {
- JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y;
- JDIMENSION x_crop_blocks, y_crop_blocks;
- int ci, i, j, offset_x, offset_y;
- JBLOCKARRAY src_buffer, dst_buffer;
- JCOEFPTR src_ptr, dst_ptr;
- jpeg_component_info *compptr;
-
- MCU_rows = srcinfo->output_width /
- (dstinfo->max_v_samp_factor * dstinfo_min_DCT_v_scaled_size);
- for (ci = 0; ci < dstinfo->num_components; ci++) {
- compptr = dstinfo->comp_info + ci;
- comp_height = MCU_rows * compptr->v_samp_factor;
- x_crop_blocks = x_crop_offset * compptr->h_samp_factor;
- y_crop_blocks = y_crop_offset * compptr->v_samp_factor;
- for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
- dst_blk_y += compptr->v_samp_factor) {
- dst_buffer = (*srcinfo->mem->access_virt_barray)
- ((j_common_ptr)srcinfo, dst_coef_arrays[ci], dst_blk_y,
- (JDIMENSION)compptr->v_samp_factor, TRUE);
- for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
- for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
- dst_blk_x += compptr->h_samp_factor) {
- src_buffer = (*srcinfo->mem->access_virt_barray)
- ((j_common_ptr)srcinfo, src_coef_arrays[ci],
- dst_blk_x + x_crop_blocks,
- (JDIMENSION)compptr->h_samp_factor, FALSE);
- for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
- dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
- if (y_crop_blocks + dst_blk_y < comp_height) {
-
- src_ptr = src_buffer[offset_x]
- [comp_height - y_crop_blocks - dst_blk_y - offset_y - 1];
- for (i = 0; i < DCTSIZE; i++) {
- for (j = 0; j < DCTSIZE; j++) {
- dst_ptr[j * DCTSIZE + i] = src_ptr[i * DCTSIZE + j];
- j++;
- dst_ptr[j * DCTSIZE + i] = -src_ptr[i * DCTSIZE + j];
- }
- }
- } else {
-
- src_ptr = src_buffer[offset_x]
- [dst_blk_y + offset_y + y_crop_blocks];
- for (i = 0; i < DCTSIZE; i++)
- for (j = 0; j < DCTSIZE; j++)
- dst_ptr[j * DCTSIZE + i] = src_ptr[i * DCTSIZE + j];
- }
- }
- }
- }
- }
- }
- }
- LOCAL(void)
- do_rot_180(j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
- JDIMENSION x_crop_offset, JDIMENSION y_crop_offset,
- jvirt_barray_ptr *src_coef_arrays,
- jvirt_barray_ptr *dst_coef_arrays)
- {
- JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y;
- JDIMENSION x_crop_blocks, y_crop_blocks;
- int ci, i, j, offset_y;
- JBLOCKARRAY src_buffer, dst_buffer;
- JBLOCKROW src_row_ptr, dst_row_ptr;
- JCOEFPTR src_ptr, dst_ptr;
- jpeg_component_info *compptr;
- MCU_cols = srcinfo->output_width /
- (dstinfo->max_h_samp_factor * dstinfo_min_DCT_h_scaled_size);
- MCU_rows = srcinfo->output_height /
- (dstinfo->max_v_samp_factor * dstinfo_min_DCT_v_scaled_size);
- for (ci = 0; ci < dstinfo->num_components; ci++) {
- compptr = dstinfo->comp_info + ci;
- comp_width = MCU_cols * compptr->h_samp_factor;
- comp_height = MCU_rows * compptr->v_samp_factor;
- x_crop_blocks = x_crop_offset * compptr->h_samp_factor;
- y_crop_blocks = y_crop_offset * compptr->v_samp_factor;
- for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
- dst_blk_y += compptr->v_samp_factor) {
- dst_buffer = (*srcinfo->mem->access_virt_barray)
- ((j_common_ptr)srcinfo, dst_coef_arrays[ci], dst_blk_y,
- (JDIMENSION)compptr->v_samp_factor, TRUE);
- if (y_crop_blocks + dst_blk_y < comp_height) {
-
- src_buffer = (*srcinfo->mem->access_virt_barray)
- ((j_common_ptr)srcinfo, src_coef_arrays[ci],
- comp_height - y_crop_blocks - dst_blk_y -
- (JDIMENSION)compptr->v_samp_factor,
- (JDIMENSION)compptr->v_samp_factor, FALSE);
- } else {
-
- src_buffer = (*srcinfo->mem->access_virt_barray)
- ((j_common_ptr)srcinfo, src_coef_arrays[ci],
- dst_blk_y + y_crop_blocks,
- (JDIMENSION)compptr->v_samp_factor, FALSE);
- }
- for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
- dst_row_ptr = dst_buffer[offset_y];
- if (y_crop_blocks + dst_blk_y < comp_height) {
-
- src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1];
- for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
- dst_blk_x++) {
- dst_ptr = dst_row_ptr[dst_blk_x];
- if (x_crop_blocks + dst_blk_x < comp_width) {
-
- src_ptr =
- src_row_ptr[comp_width - x_crop_blocks - dst_blk_x - 1];
- for (i = 0; i < DCTSIZE; i += 2) {
-
- for (j = 0; j < DCTSIZE; j += 2) {
- *dst_ptr++ = *src_ptr++;
- *dst_ptr++ = - *src_ptr++;
- }
-
- for (j = 0; j < DCTSIZE; j += 2) {
- *dst_ptr++ = - *src_ptr++;
- *dst_ptr++ = *src_ptr++;
- }
- }
- } else {
-
- src_ptr = src_row_ptr[x_crop_blocks + dst_blk_x];
- for (i = 0; i < DCTSIZE; i += 2) {
- for (j = 0; j < DCTSIZE; j++)
- *dst_ptr++ = *src_ptr++;
- for (j = 0; j < DCTSIZE; j++)
- *dst_ptr++ = - *src_ptr++;
- }
- }
- }
- } else {
-
- src_row_ptr = src_buffer[offset_y];
- for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
- dst_blk_x++) {
- if (x_crop_blocks + dst_blk_x < comp_width) {
-
- dst_ptr = dst_row_ptr[dst_blk_x];
- src_ptr =
- src_row_ptr[comp_width - x_crop_blocks - dst_blk_x - 1];
- for (i = 0; i < DCTSIZE2; i += 2) {
- *dst_ptr++ = *src_ptr++;
- *dst_ptr++ = - *src_ptr++;
- }
- } else {
-
- jcopy_block_row(src_row_ptr + dst_blk_x + x_crop_blocks,
- dst_row_ptr + dst_blk_x, (JDIMENSION)1);
- }
- }
- }
- }
- }
- }
- }
- LOCAL(void)
- do_transverse(j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
- JDIMENSION x_crop_offset, JDIMENSION y_crop_offset,
- jvirt_barray_ptr *src_coef_arrays,
- jvirt_barray_ptr *dst_coef_arrays)
- {
- JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y;
- JDIMENSION x_crop_blocks, y_crop_blocks;
- int ci, i, j, offset_x, offset_y;
- JBLOCKARRAY src_buffer, dst_buffer;
- JCOEFPTR src_ptr, dst_ptr;
- jpeg_component_info *compptr;
- MCU_cols = srcinfo->output_height /
- (dstinfo->max_h_samp_factor * dstinfo_min_DCT_h_scaled_size);
- MCU_rows = srcinfo->output_width /
- (dstinfo->max_v_samp_factor * dstinfo_min_DCT_v_scaled_size);
- for (ci = 0; ci < dstinfo->num_components; ci++) {
- compptr = dstinfo->comp_info + ci;
- comp_width = MCU_cols * compptr->h_samp_factor;
- comp_height = MCU_rows * compptr->v_samp_factor;
- x_crop_blocks = x_crop_offset * compptr->h_samp_factor;
- y_crop_blocks = y_crop_offset * compptr->v_samp_factor;
- for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
- dst_blk_y += compptr->v_samp_factor) {
- dst_buffer = (*srcinfo->mem->access_virt_barray)
- ((j_common_ptr)srcinfo, dst_coef_arrays[ci], dst_blk_y,
- (JDIMENSION)compptr->v_samp_factor, TRUE);
- for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
- for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
- dst_blk_x += compptr->h_samp_factor) {
- if (x_crop_blocks + dst_blk_x < comp_width) {
-
- src_buffer = (*srcinfo->mem->access_virt_barray)
- ((j_common_ptr)srcinfo, src_coef_arrays[ci],
- comp_width - x_crop_blocks - dst_blk_x -
- (JDIMENSION)compptr->h_samp_factor,
- (JDIMENSION)compptr->h_samp_factor, FALSE);
- } else {
- src_buffer = (*srcinfo->mem->access_virt_barray)
- ((j_common_ptr)srcinfo, src_coef_arrays[ci],
- dst_blk_x + x_crop_blocks,
- (JDIMENSION)compptr->h_samp_factor, FALSE);
- }
- for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
- dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
- if (y_crop_blocks + dst_blk_y < comp_height) {
- if (x_crop_blocks + dst_blk_x < comp_width) {
-
- src_ptr = src_buffer[compptr->h_samp_factor - offset_x - 1]
- [comp_height - y_crop_blocks - dst_blk_y - offset_y - 1];
- for (i = 0; i < DCTSIZE; i++) {
- for (j = 0; j < DCTSIZE; j++) {
- dst_ptr[j * DCTSIZE + i] = src_ptr[i * DCTSIZE + j];
- j++;
- dst_ptr[j * DCTSIZE + i] = -src_ptr[i * DCTSIZE + j];
- }
- i++;
- for (j = 0; j < DCTSIZE; j++) {
- dst_ptr[j * DCTSIZE + i] = -src_ptr[i * DCTSIZE + j];
- j++;
- dst_ptr[j * DCTSIZE + i] = src_ptr[i * DCTSIZE + j];
- }
- }
- } else {
-
- src_ptr = src_buffer[offset_x]
- [comp_height - y_crop_blocks - dst_blk_y - offset_y - 1];
- for (i = 0; i < DCTSIZE; i++) {
- for (j = 0; j < DCTSIZE; j++) {
- dst_ptr[j * DCTSIZE + i] = src_ptr[i * DCTSIZE + j];
- j++;
- dst_ptr[j * DCTSIZE + i] = -src_ptr[i * DCTSIZE + j];
- }
- }
- }
- } else {
- if (x_crop_blocks + dst_blk_x < comp_width) {
-
- src_ptr = src_buffer[compptr->h_samp_factor - offset_x - 1]
- [dst_blk_y + offset_y + y_crop_blocks];
- for (i = 0; i < DCTSIZE; i++) {
- for (j = 0; j < DCTSIZE; j++)
- dst_ptr[j * DCTSIZE + i] = src_ptr[i * DCTSIZE + j];
- i++;
- for (j = 0; j < DCTSIZE; j++)
- dst_ptr[j * DCTSIZE + i] = -src_ptr[i * DCTSIZE + j];
- }
- } else {
-
- src_ptr = src_buffer[offset_x]
- [dst_blk_y + offset_y + y_crop_blocks];
- for (i = 0; i < DCTSIZE; i++)
- for (j = 0; j < DCTSIZE; j++)
- dst_ptr[j * DCTSIZE + i] = src_ptr[i * DCTSIZE + j];
- }
- }
- }
- }
- }
- }
- }
- }
- LOCAL(boolean)
- jt_read_integer(const char **strptr, JDIMENSION *result)
- {
- const char *ptr = *strptr;
- JDIMENSION val = 0;
- for (; isdigit(*ptr); ptr++) {
- val = val * 10 + (JDIMENSION)(*ptr - '0');
- }
- *result = val;
- if (ptr == *strptr)
- return FALSE;
- *strptr = ptr;
- return TRUE;
- }
- GLOBAL(boolean)
- jtransform_parse_crop_spec(jpeg_transform_info *info, const char *spec)
- {
- info->crop = FALSE;
- info->crop_width_set = JCROP_UNSET;
- info->crop_height_set = JCROP_UNSET;
- info->crop_xoffset_set = JCROP_UNSET;
- info->crop_yoffset_set = JCROP_UNSET;
- if (isdigit(*spec)) {
-
- if (!jt_read_integer(&spec, &info->crop_width))
- return FALSE;
- if (*spec == 'f' || *spec == 'F') {
- spec++;
- info->crop_width_set = JCROP_FORCE;
- } else
- info->crop_width_set = JCROP_POS;
- }
- if (*spec == 'x' || *spec == 'X') {
-
- spec++;
- if (!jt_read_integer(&spec, &info->crop_height))
- return FALSE;
- if (*spec == 'f' || *spec == 'F') {
- spec++;
- info->crop_height_set = JCROP_FORCE;
- } else
- info->crop_height_set = JCROP_POS;
- }
- if (*spec == '+' || *spec == '-') {
-
- info->crop_xoffset_set = (*spec == '-') ? JCROP_NEG : JCROP_POS;
- spec++;
- if (!jt_read_integer(&spec, &info->crop_xoffset))
- return FALSE;
- }
- if (*spec == '+' || *spec == '-') {
-
- info->crop_yoffset_set = (*spec == '-') ? JCROP_NEG : JCROP_POS;
- spec++;
- if (!jt_read_integer(&spec, &info->crop_yoffset))
- return FALSE;
- }
-
- if (*spec != '\0')
- return FALSE;
- info->crop = TRUE;
- return TRUE;
- }
- LOCAL(void)
- trim_right_edge(jpeg_transform_info *info, JDIMENSION full_width)
- {
- JDIMENSION MCU_cols;
- MCU_cols = info->output_width / info->iMCU_sample_width;
- if (MCU_cols > 0 && info->x_crop_offset + MCU_cols ==
- full_width / info->iMCU_sample_width)
- info->output_width = MCU_cols * info->iMCU_sample_width;
- }
- LOCAL(void)
- trim_bottom_edge(jpeg_transform_info *info, JDIMENSION full_height)
- {
- JDIMENSION MCU_rows;
- MCU_rows = info->output_height / info->iMCU_sample_height;
- if (MCU_rows > 0 && info->y_crop_offset + MCU_rows ==
- full_height / info->iMCU_sample_height)
- info->output_height = MCU_rows * info->iMCU_sample_height;
- }
- GLOBAL(boolean)
- jtransform_request_workspace(j_decompress_ptr srcinfo,
- jpeg_transform_info *info)
- {
- jvirt_barray_ptr *coef_arrays;
- boolean need_workspace, transpose_it;
- jpeg_component_info *compptr;
- JDIMENSION xoffset, yoffset;
- JDIMENSION width_in_iMCUs, height_in_iMCUs;
- JDIMENSION width_in_blocks, height_in_blocks;
- int ci, h_samp_factor, v_samp_factor;
-
- if (info->force_grayscale &&
- srcinfo->jpeg_color_space == JCS_YCbCr &&
- srcinfo->num_components == 3)
-
- info->num_components = 1;
- else
-
- info->num_components = srcinfo->num_components;
-
- #if JPEG_LIB_VERSION >= 80
- jpeg_core_output_dimensions(srcinfo);
- #else
- srcinfo->output_width = srcinfo->image_width;
- srcinfo->output_height = srcinfo->image_height;
- #endif
-
- if (info->perfect) {
- if (info->num_components == 1) {
- if (!jtransform_perfect_transform(srcinfo->output_width,
- srcinfo->output_height,
- srcinfo->_min_DCT_h_scaled_size,
- srcinfo->_min_DCT_v_scaled_size,
- info->transform))
- return FALSE;
- } else {
- if (!jtransform_perfect_transform(srcinfo->output_width,
- srcinfo->output_height,
- srcinfo->max_h_samp_factor * srcinfo->_min_DCT_h_scaled_size,
- srcinfo->max_v_samp_factor * srcinfo->_min_DCT_v_scaled_size,
- info->transform))
- return FALSE;
- }
- }
-
- switch (info->transform) {
- case JXFORM_TRANSPOSE:
- case JXFORM_TRANSVERSE:
- case JXFORM_ROT_90:
- case JXFORM_ROT_270:
- info->output_width = srcinfo->output_height;
- info->output_height = srcinfo->output_width;
- if (info->num_components == 1) {
- info->iMCU_sample_width = srcinfo->_min_DCT_v_scaled_size;
- info->iMCU_sample_height = srcinfo->_min_DCT_h_scaled_size;
- } else {
- info->iMCU_sample_width =
- srcinfo->max_v_samp_factor * srcinfo->_min_DCT_v_scaled_size;
- info->iMCU_sample_height =
- srcinfo->max_h_samp_factor * srcinfo->_min_DCT_h_scaled_size;
- }
- break;
- default:
- info->output_width = srcinfo->output_width;
- info->output_height = srcinfo->output_height;
- if (info->num_components == 1) {
- info->iMCU_sample_width = srcinfo->_min_DCT_h_scaled_size;
- info->iMCU_sample_height = srcinfo->_min_DCT_v_scaled_size;
- } else {
- info->iMCU_sample_width =
- srcinfo->max_h_samp_factor * srcinfo->_min_DCT_h_scaled_size;
- info->iMCU_sample_height =
- srcinfo->max_v_samp_factor * srcinfo->_min_DCT_v_scaled_size;
- }
- break;
- }
-
- if (info->crop) {
-
- if (info->crop_xoffset_set == JCROP_UNSET)
- info->crop_xoffset = 0;
- if (info->crop_yoffset_set == JCROP_UNSET)
- info->crop_yoffset = 0;
- if (info->crop_xoffset >= info->output_width ||
- info->crop_yoffset >= info->output_height)
- ERREXIT(srcinfo, JERR_BAD_CROP_SPEC);
- if (info->crop_width_set == JCROP_UNSET)
- info->crop_width = info->output_width - info->crop_xoffset;
- if (info->crop_height_set == JCROP_UNSET)
- info->crop_height = info->output_height - info->crop_yoffset;
-
- if (info->crop_width <= 0 || info->crop_width > info->output_width ||
- info->crop_height <= 0 || info->crop_height > info->output_height ||
- info->crop_xoffset > info->output_width - info->crop_width ||
- info->crop_yoffset > info->output_height - info->crop_height)
- ERREXIT(srcinfo, JERR_BAD_CROP_SPEC);
-
- if (info->crop_xoffset_set == JCROP_NEG)
- xoffset = info->output_width - info->crop_width - info->crop_xoffset;
- else
- xoffset = info->crop_xoffset;
- if (info->crop_yoffset_set == JCROP_NEG)
- yoffset = info->output_height - info->crop_height - info->crop_yoffset;
- else
- yoffset = info->crop_yoffset;
-
- if (info->crop_width_set == JCROP_FORCE)
- info->output_width = info->crop_width;
- else
- info->output_width =
- info->crop_width + (xoffset % info->iMCU_sample_width);
- if (info->crop_height_set == JCROP_FORCE)
- info->output_height = info->crop_height;
- else
- info->output_height =
- info->crop_height + (yoffset % info->iMCU_sample_height);
-
- info->x_crop_offset = xoffset / info->iMCU_sample_width;
- info->y_crop_offset = yoffset / info->iMCU_sample_height;
- } else {
- info->x_crop_offset = 0;
- info->y_crop_offset = 0;
- }
-
- need_workspace = FALSE;
- transpose_it = FALSE;
- switch (info->transform) {
- case JXFORM_NONE:
- if (info->x_crop_offset != 0 || info->y_crop_offset != 0)
- need_workspace = TRUE;
-
- break;
- case JXFORM_FLIP_H:
- if (info->trim)
- trim_right_edge(info, srcinfo->output_width);
- if (info->y_crop_offset != 0 || info->slow_hflip)
- need_workspace = TRUE;
-
- break;
- case JXFORM_FLIP_V:
- if (info->trim)
- trim_bottom_edge(info, srcinfo->output_height);
-
- need_workspace = TRUE;
- break;
- case JXFORM_TRANSPOSE:
-
-
- need_workspace = TRUE;
- transpose_it = TRUE;
- break;
- case JXFORM_TRANSVERSE:
- if (info->trim) {
- trim_right_edge(info, srcinfo->output_height);
- trim_bottom_edge(info, srcinfo->output_width);
- }
-
- need_workspace = TRUE;
- transpose_it = TRUE;
- break;
- case JXFORM_ROT_90:
- if (info->trim)
- trim_right_edge(info, srcinfo->output_height);
-
- need_workspace = TRUE;
- transpose_it = TRUE;
- break;
- case JXFORM_ROT_180:
- if (info->trim) {
- trim_right_edge(info, srcinfo->output_width);
- trim_bottom_edge(info, srcinfo->output_height);
- }
-
- need_workspace = TRUE;
- break;
- case JXFORM_ROT_270:
- if (info->trim)
- trim_bottom_edge(info, srcinfo->output_width);
-
- need_workspace = TRUE;
- transpose_it = TRUE;
- break;
- }
-
- if (need_workspace) {
- coef_arrays = (jvirt_barray_ptr *)
- (*srcinfo->mem->alloc_small) ((j_common_ptr)srcinfo, JPOOL_IMAGE,
- sizeof(jvirt_barray_ptr) * info->num_components);
- width_in_iMCUs = (JDIMENSION)
- jdiv_round_up((long)info->output_width, (long)info->iMCU_sample_width);
- height_in_iMCUs = (JDIMENSION)
- jdiv_round_up((long)info->output_height, (long)info->iMCU_sample_height);
- for (ci = 0; ci < info->num_components; ci++) {
- compptr = srcinfo->comp_info + ci;
- if (info->num_components == 1) {
-
- h_samp_factor = v_samp_factor = 1;
- } else if (transpose_it) {
- h_samp_factor = compptr->v_samp_factor;
- v_samp_factor = compptr->h_samp_factor;
- } else {
- h_samp_factor = compptr->h_samp_factor;
- v_samp_factor = compptr->v_samp_factor;
- }
- width_in_blocks = width_in_iMCUs * h_samp_factor;
- height_in_blocks = height_in_iMCUs * v_samp_factor;
- coef_arrays[ci] = (*srcinfo->mem->request_virt_barray)
- ((j_common_ptr)srcinfo, JPOOL_IMAGE, FALSE,
- width_in_blocks, height_in_blocks, (JDIMENSION)v_samp_factor);
- }
- info->workspace_coef_arrays = coef_arrays;
- } else
- info->workspace_coef_arrays = NULL;
- return TRUE;
- }
- LOCAL(void)
- transpose_critical_parameters(j_compress_ptr dstinfo)
- {
- int tblno, i, j, ci, itemp;
- jpeg_component_info *compptr;
- JQUANT_TBL *qtblptr;
- JDIMENSION jtemp;
- UINT16 qtemp;
-
- jtemp = dstinfo->image_width;
- dstinfo->image_width = dstinfo->image_height;
- dstinfo->image_height = jtemp;
- #if JPEG_LIB_VERSION >= 70
- itemp = dstinfo->min_DCT_h_scaled_size;
- dstinfo->min_DCT_h_scaled_size = dstinfo->min_DCT_v_scaled_size;
- dstinfo->min_DCT_v_scaled_size = itemp;
- #endif
-
- for (ci = 0; ci < dstinfo->num_components; ci++) {
- compptr = dstinfo->comp_info + ci;
- itemp = compptr->h_samp_factor;
- compptr->h_samp_factor = compptr->v_samp_factor;
- compptr->v_samp_factor = itemp;
- }
-
- for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
- qtblptr = dstinfo->quant_tbl_ptrs[tblno];
- if (qtblptr != NULL) {
- for (i = 0; i < DCTSIZE; i++) {
- for (j = 0; j < i; j++) {
- qtemp = qtblptr->quantval[i * DCTSIZE + j];
- qtblptr->quantval[i * DCTSIZE + j] =
- qtblptr->quantval[j * DCTSIZE + i];
- qtblptr->quantval[j * DCTSIZE + i] = qtemp;
- }
- }
- }
- }
- }
- LOCAL(void)
- adjust_exif_parameters(JOCTET *data, unsigned int length, JDIMENSION new_width,
- JDIMENSION new_height)
- {
- boolean is_motorola;
- unsigned int number_of_tags, tagnum;
- unsigned int firstoffset, offset;
- JDIMENSION new_value;
- if (length < 12) return;
-
- if (GETJOCTET(data[0]) == 0x49 && GETJOCTET(data[1]) == 0x49)
- is_motorola = FALSE;
- else if (GETJOCTET(data[0]) == 0x4D && GETJOCTET(data[1]) == 0x4D)
- is_motorola = TRUE;
- else
- return;
-
- if (is_motorola) {
- if (GETJOCTET(data[2]) != 0) return;
- if (GETJOCTET(data[3]) != 0x2A) return;
- } else {
- if (GETJOCTET(data[3]) != 0) return;
- if (GETJOCTET(data[2]) != 0x2A) return;
- }
-
- if (is_motorola) {
- if (GETJOCTET(data[4]) != 0) return;
- if (GETJOCTET(data[5]) != 0) return;
- firstoffset = GETJOCTET(data[6]);
- firstoffset <<= 8;
- firstoffset += GETJOCTET(data[7]);
- } else {
- if (GETJOCTET(data[7]) != 0) return;
- if (GETJOCTET(data[6]) != 0) return;
- firstoffset = GETJOCTET(data[5]);
- firstoffset <<= 8;
- firstoffset += GETJOCTET(data[4]);
- }
- if (firstoffset > length - 2) return;
-
- if (is_motorola) {
- number_of_tags = GETJOCTET(data[firstoffset]);
- number_of_tags <<= 8;
- number_of_tags += GETJOCTET(data[firstoffset + 1]);
- } else {
- number_of_tags = GETJOCTET(data[firstoffset + 1]);
- number_of_tags <<= 8;
- number_of_tags += GETJOCTET(data[firstoffset]);
- }
- if (number_of_tags == 0) return;
- firstoffset += 2;
-
- for (;;) {
- if (firstoffset > length - 12) return;
-
- if (is_motorola) {
- tagnum = GETJOCTET(data[firstoffset]);
- tagnum <<= 8;
- tagnum += GETJOCTET(data[firstoffset + 1]);
- } else {
- tagnum = GETJOCTET(data[firstoffset + 1]);
- tagnum <<= 8;
- tagnum += GETJOCTET(data[firstoffset]);
- }
- if (tagnum == 0x8769) break;
- if (--number_of_tags == 0) return;
- firstoffset += 12;
- }
-
- if (is_motorola) {
- if (GETJOCTET(data[firstoffset + 8]) != 0) return;
- if (GETJOCTET(data[firstoffset + 9]) != 0) return;
- offset = GETJOCTET(data[firstoffset + 10]);
- offset <<= 8;
- offset += GETJOCTET(data[firstoffset + 11]);
- } else {
- if (GETJOCTET(data[firstoffset + 11]) != 0) return;
- if (GETJOCTET(data[firstoffset + 10]) != 0) return;
- offset = GETJOCTET(data[firstoffset + 9]);
- offset <<= 8;
- offset += GETJOCTET(data[firstoffset + 8]);
- }
- if (offset > length - 2) return;
-
- if (is_motorola) {
- number_of_tags = GETJOCTET(data[offset]);
- number_of_tags <<= 8;
- number_of_tags += GETJOCTET(data[offset + 1]);
- } else {
- number_of_tags = GETJOCTET(data[offset + 1]);
- number_of_tags <<= 8;
- number_of_tags += GETJOCTET(data[offset]);
- }
- if (number_of_tags < 2) return;
- offset += 2;
-
- do {
- if (offset > length - 12) return;
-
- if (is_motorola) {
- tagnum = GETJOCTET(data[offset]);
- tagnum <<= 8;
- tagnum += GETJOCTET(data[offset + 1]);
- } else {
- tagnum = GETJOCTET(data[offset + 1]);
- tagnum <<= 8;
- tagnum += GETJOCTET(data[offset]);
- }
- if (tagnum == 0xA002 || tagnum == 0xA003) {
- if (tagnum == 0xA002)
- new_value = new_width;
- else
- new_value = new_height;
- if (is_motorola) {
- data[offset + 2] = 0;
- data[offset + 3] = 4;
- data[offset + 4] = 0;
- data[offset + 5] = 0;
- data[offset + 6] = 0;
- data[offset + 7] = 1;
- data[offset + 8] = 0;
- data[offset + 9] = 0;
- data[offset + 10] = (JOCTET)((new_value >> 8) & 0xFF);
- data[offset + 11] = (JOCTET)(new_value & 0xFF);
- } else {
- data[offset + 2] = 4;
- data[offset + 3] = 0;
- data[offset + 4] = 1;
- data[offset + 5] = 0;
- data[offset + 6] = 0;
- data[offset + 7] = 0;
- data[offset + 8] = (JOCTET)(new_value & 0xFF);
- data[offset + 9] = (JOCTET)((new_value >> 8) & 0xFF);
- data[offset + 10] = 0;
- data[offset + 11] = 0;
- }
- }
- offset += 12;
- } while (--number_of_tags);
- }
- GLOBAL(jvirt_barray_ptr *)
- jtransform_adjust_parameters(j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
- jvirt_barray_ptr *src_coef_arrays,
- jpeg_transform_info *info)
- {
-
- if (info->force_grayscale) {
-
- if (((dstinfo->jpeg_color_space == JCS_YCbCr &&
- dstinfo->num_components == 3) ||
- (dstinfo->jpeg_color_space == JCS_GRAYSCALE &&
- dstinfo->num_components == 1)) &&
- srcinfo->comp_info[0].h_samp_factor == srcinfo->max_h_samp_factor &&
- srcinfo->comp_info[0].v_samp_factor == srcinfo->max_v_samp_factor) {
-
- int sv_quant_tbl_no = dstinfo->comp_info[0].quant_tbl_no;
- jpeg_set_colorspace(dstinfo, JCS_GRAYSCALE);
- dstinfo->comp_info[0].quant_tbl_no = sv_quant_tbl_no;
- } else {
-
- ERREXIT(dstinfo, JERR_CONVERSION_NOTIMPL);
- }
- } else if (info->num_components == 1) {
-
- dstinfo->comp_info[0].h_samp_factor = 1;
- dstinfo->comp_info[0].v_samp_factor = 1;
- }
-
- #if JPEG_LIB_VERSION >= 80
- dstinfo->jpeg_width = info->output_width;
- dstinfo->jpeg_height = info->output_height;
- #endif
-
- switch (info->transform) {
- case JXFORM_TRANSPOSE:
- case JXFORM_TRANSVERSE:
- case JXFORM_ROT_90:
- case JXFORM_ROT_270:
- #if JPEG_LIB_VERSION < 80
- dstinfo->image_width = info->output_height;
- dstinfo->image_height = info->output_width;
- #endif
- transpose_critical_parameters(dstinfo);
- break;
- default:
- #if JPEG_LIB_VERSION < 80
- dstinfo->image_width = info->output_width;
- dstinfo->image_height = info->output_height;
- #endif
- break;
- }
-
- if (srcinfo->marker_list != NULL &&
- srcinfo->marker_list->marker == JPEG_APP0 + 1 &&
- srcinfo->marker_list->data_length >= 6 &&
- GETJOCTET(srcinfo->marker_list->data[0]) == 0x45 &&
- GETJOCTET(srcinfo->marker_list->data[1]) == 0x78 &&
- GETJOCTET(srcinfo->marker_list->data[2]) == 0x69 &&
- GETJOCTET(srcinfo->marker_list->data[3]) == 0x66 &&
- GETJOCTET(srcinfo->marker_list->data[4]) == 0 &&
- GETJOCTET(srcinfo->marker_list->data[5]) == 0) {
-
- dstinfo->write_JFIF_header = FALSE;
-
- #if JPEG_LIB_VERSION >= 80
- if (dstinfo->jpeg_width != srcinfo->image_width ||
- dstinfo->jpeg_height != srcinfo->image_height)
-
- adjust_exif_parameters(srcinfo->marker_list->data + 6,
- srcinfo->marker_list->data_length - 6,
- dstinfo->jpeg_width, dstinfo->jpeg_height);
- #else
- if (dstinfo->image_width != srcinfo->image_width ||
- dstinfo->image_height != srcinfo->image_height)
-
- adjust_exif_parameters(srcinfo->marker_list->data + 6,
- srcinfo->marker_list->data_length - 6,
- dstinfo->image_width, dstinfo->image_height);
- #endif
- }
-
- if (info->workspace_coef_arrays != NULL)
- return info->workspace_coef_arrays;
- return src_coef_arrays;
- }
- GLOBAL(void)
- jtransform_execute_transform(j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
- jvirt_barray_ptr *src_coef_arrays,
- jpeg_transform_info *info)
- {
- jvirt_barray_ptr *dst_coef_arrays = info->workspace_coef_arrays;
-
- switch (info->transform) {
- case JXFORM_NONE:
- if (info->x_crop_offset != 0 || info->y_crop_offset != 0)
- do_crop(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset,
- src_coef_arrays, dst_coef_arrays);
- break;
- case JXFORM_FLIP_H:
- if (info->y_crop_offset != 0 || info->slow_hflip)
- do_flip_h(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset,
- src_coef_arrays, dst_coef_arrays);
- else
- do_flip_h_no_crop(srcinfo, dstinfo, info->x_crop_offset,
- src_coef_arrays);
- break;
- case JXFORM_FLIP_V:
- do_flip_v(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset,
- src_coef_arrays, dst_coef_arrays);
- break;
- case JXFORM_TRANSPOSE:
- do_transpose(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset,
- src_coef_arrays, dst_coef_arrays);
- break;
- case JXFORM_TRANSVERSE:
- do_transverse(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset,
- src_coef_arrays, dst_coef_arrays);
- break;
- case JXFORM_ROT_90:
- do_rot_90(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset,
- src_coef_arrays, dst_coef_arrays);
- break;
- case JXFORM_ROT_180:
- do_rot_180(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset,
- src_coef_arrays, dst_coef_arrays);
- break;
- case JXFORM_ROT_270:
- do_rot_270(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset,
- src_coef_arrays, dst_coef_arrays);
- break;
- }
- }
- GLOBAL(boolean)
- jtransform_perfect_transform(JDIMENSION image_width, JDIMENSION image_height,
- int MCU_width, int MCU_height,
- JXFORM_CODE transform)
- {
- boolean result = TRUE;
- switch (transform) {
- case JXFORM_FLIP_H:
- case JXFORM_ROT_270:
- if (image_width % (JDIMENSION)MCU_width)
- result = FALSE;
- break;
- case JXFORM_FLIP_V:
- case JXFORM_ROT_90:
- if (image_height % (JDIMENSION)MCU_height)
- result = FALSE;
- break;
- case JXFORM_TRANSVERSE:
- case JXFORM_ROT_180:
- if (image_width % (JDIMENSION)MCU_width)
- result = FALSE;
- if (image_height % (JDIMENSION)MCU_height)
- result = FALSE;
- break;
- default:
- break;
- }
- return result;
- }
- #endif
- GLOBAL(void)
- jcopy_markers_setup(j_decompress_ptr srcinfo, JCOPY_OPTION option)
- {
- #ifdef SAVE_MARKERS_SUPPORTED
- int m;
-
- if (option != JCOPYOPT_NONE) {
- jpeg_save_markers(srcinfo, JPEG_COM, 0xFFFF);
- }
-
- if (option == JCOPYOPT_ALL || option == JCOPYOPT_ALL_EXCEPT_ICC) {
- for (m = 0; m < 16; m++) {
- if (option == JCOPYOPT_ALL_EXCEPT_ICC && m == 2)
- continue;
- jpeg_save_markers(srcinfo, JPEG_APP0 + m, 0xFFFF);
- }
- }
- #endif
- }
- GLOBAL(void)
- jcopy_markers_execute(j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
- JCOPY_OPTION option)
- {
- jpeg_saved_marker_ptr marker;
-
- for (marker = srcinfo->marker_list; marker != NULL; marker = marker->next) {
- if (dstinfo->write_JFIF_header &&
- marker->marker == JPEG_APP0 &&
- marker->data_length >= 5 &&
- GETJOCTET(marker->data[0]) == 0x4A &&
- GETJOCTET(marker->data[1]) == 0x46 &&
- GETJOCTET(marker->data[2]) == 0x49 &&
- GETJOCTET(marker->data[3]) == 0x46 &&
- GETJOCTET(marker->data[4]) == 0)
- continue;
- if (dstinfo->write_Adobe_marker &&
- marker->marker == JPEG_APP0 + 14 &&
- marker->data_length >= 5 &&
- GETJOCTET(marker->data[0]) == 0x41 &&
- GETJOCTET(marker->data[1]) == 0x64 &&
- GETJOCTET(marker->data[2]) == 0x6F &&
- GETJOCTET(marker->data[3]) == 0x62 &&
- GETJOCTET(marker->data[4]) == 0x65)
- continue;
- jpeg_write_marker(dstinfo, marker->marker,
- marker->data, marker->data_length);
- }
- }
|